-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: NamedIndex and NamedVector types #1190
Conversation
initial commit, including simple test suite: ```julia load("named.jl") load("test.jl") tests("test/test_named.jl") ```
Love it. |
I'm completely down to merge this, but I'm holding off because of the RFC subject line. Whenever you're good to go, Harlan, this is in. I've always wanted this kind of thing. Very handy. |
Where does the mapping from name to index come from? Insertion order? |
@toivoh , yes, mostly. Typical use cases are setting all the names at once, replacing a name, or appending a new index. For the applications we've used this for (DataFrame and a project I'm doing for work), inserting in the middle hasn't come up. |
Looks nice. I presume the main extra functionality this adds over Very minor suggestion: you can avoid two
|
@timholy Yes, that's right. It has fast access by name (via a Dict) and even faster access by index. It just passes integers (and Ranges, and Boolean vectors...) through to the usual array referencing code. Thanks for the reminder on ht_keyindex()! I'll take a look and see where that can be used. |
…tor by symbol `nv[:cat] == nv["cat"]` Note that there's no `assign(NamedIndex)`, as it wouldn't make sense, but `nv[:cat] = 7` works.
all tests pass replace_named!(ni, 1, "one") now works
Jeff/Tom, I pushed some changes here that pull the implementation of groups out into a separate Dict, as suggested. Seems to work fine. I want to do one more thing on this before it could be merged in, which is make groups work for NamedVectors. |
values() gives the underlying array values find() gives the position of the value in the array, or 0
This is why we definitely need multiple inheritance. Huge language change though. |
I don't think something can be both a Vector and Associative, the way we've defined them so far. A vector implicitly has consecutive integers as keys, and an Associative has arbitrary keys. Iterating an Associative yields (key,value) tuples, and a vector just gives values. |
Yes, that's right. My intention for this data type (or, really, Tom's I've been slammed and haven't been able to work on this stuff recently. On Wed, Sep 12, 2012 at 3:13 PM, Jeff Bezanson [email protected]:
|
It can still inherit from an AbstractVector and have iteration defined like an Associative type. I'm not sure whether Vector or Associative iteration is best in this case. The main reason for inheriting from an AbstractVector is so that One option to make these two types of iterations more compatible is to switch the (k,v) order around to (v,k) on Associative iteration. Then, if you leave off the key, you still get the value, and it would be like vector indexing. |
so "sum(x::NamedVector)" now works. all tests pass. needed to add a promote_rule(ByteString,ASCIIString) -- should that go elsewhere? added similar(NamedVector), which is weird, but seems to work. some duplicated code to deal with warnings -- is there a better way? repl_show() just calls show().
OK, could use some more feedback. See the comments on the most recent commit. Added groups for NamedVector, changed NamedVector to inherit from AbstractVector, and added more tests. |
Will make this a package instead. Closing pull request. |
) Stdlib: LinearAlgebra URL: https://github.com/JuliaLang/LinearAlgebra.jl.git Stdlib branch: master Julia branch: master Old commit: e7da19f New commit: f781708 Julia version: 1.13.0-DEV LinearAlgebra version: 1.12.0(Does not match) Bump invoked by: @KristofferC Powered by: [BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl) Diff: JuliaLang/LinearAlgebra.jl@e7da19f...f781708 ``` $ git log --oneline e7da19f..f781708 f781708 use the custom sysimage when running documentation (and doctests) as well (#1226) 8fdbfd5 Add `getindex` for `SymTridiagonal` using a `BandIndex` (#1223) 91b8845 Use `BandIndex` directly in `diagzero` call in `getindex` (#1222) ef7ef3a Restrict triangular type aliases to `AbstractMatrix`es (#1220) af7a9ac Use `BandIndex` directly in `diagzero` call in `getindex` for banded matrices 579b5f7 Specialize Diagonal * Adjoint (#1207) 5cf41c4 Indirection in matrix multiplication to avoid ambiguities (#1210) 0a9c164 Remove specialized `issymmetric`/`ishermitian` for `Diagonal{<:Number}` (#1213) ff5648a Make unitary matrices in `svd`/`eigen` of `Diagonal` be unitless (#1155) e096a03 Don't mutate arrays in symmetric trig functions (#1206) c234bed Loop over `diagind` in `diag` for banded matrices (#1211) 57785c7 More resizing for truncating return values from LAPACK (#1190) b464203 Materialize adjoint in mul with `HermOrSym` (#1191) 16d9d61 Restrict Diagonal sqrt branch to positive diag (#1203) baa48b7 Verbose `showerror` for `SingularException` (#1204) e0b59a7 Remove `LinearAlgebra` qualifications in `cholesky.jl` (#1209) 95d009b Remove `LinearAlgebra` qualifications in `cholesky.jl` c550974 change to pivot ed35a37 Add fast path in generic matmul (#1202) 8c7fe68 Detailed `showerror` for `SingularException` 2a1696a Explicitly declare type constructor imports (#1196) 101f766 Added note to BLAS.[g|s]et_num_threads about Apple Accelerate not supporting it (#1195) 5aca26f Simplify `getproperty` for `Cholesky*` (#1197) 924dda4 remove copy-allocation on accessing `cholesky` factors (`.L`, `.U`) (#1186) 6f02532 Use `BLAS.trsm!` instead of `LAPACK.trtrs!` in left-triangular solves (#1194) ``` Co-authored-by: KristofferC <[email protected]>
These are relatively simple data types that are useful for data structures that are worked with in the REPL. NamedIndex is a mapping from either names (strings) or integer indexes to integer indexes. NamedVector wraps that in a type that also includes an arbitrary vector. These structures also include grouped names, which refer to groups of other names, and can be used transparently. The majority of this code is by Tom Short @tshort. NamedIndex is used by JuliaData.
NamedVector is missing most functionality but the basics, but thought I'd get comments before writing that code.
Simple example of NamedVector (see also the test suite):