-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New library features for strings and ranges #610
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
Conversation
With this commit, now you can do this: s = "swap me" indx = [4,3,6] s[indx]
This commit adds a deep-copy operation for range objects. If this is not desired, feel free to ignore.
I believe ranges are intended to be immutable. |
I wondered about that. Presumably, the second patch isn't useful then. However, the first seems to be. Do I need to do something to extract the 5fefef8 patch, or can you cherry pick? |
Cherry picked 327c39c. |
It seems that the following works if you include my range patch, and doesn't if you don't: Is there a better way to do this? Statements like [100:300,70:400] expand into one long list. I guess the alternative is |
Ah, it's the old shallow-vs-deep copying problem. Range is actually a kind of AbstractArray, since you often want it to work like a vector. Therefore without your patch, the following unintentionally happens:
I'll take a look, and it might be better to just make array copying shallow by default. We could also add
to fix this. |
On a related note, I'll ask whether there's any chance that range expansion, as in [3:5], could be viewed as a convenience-motivated potential "wart" on the language. Let's suppose we want to create a function with this syntax: Let's consider how to initialize a: Let's try {}: julia> typeof(a) So {} is not very useful (?) unless convert(Array{Range1{Int},1},a) works. How about ()? julia> typeof(a) I don't think this is directly useful? (I'd love to be wrong.) julia> [a...] julia> convert(Array{Range1{Int32},1},a) julia> function tuple2array(a) julia> tuple2array(a) julia> map(x->x,a) The following works, but it's uncomfortably long: julia> a1 = myrange(3,5) julia> a2 = myrange(6,8) julia> a3 = myrange(15,20) julia> aall = [a1,a2,a3] julia> b = map(x->x.min:x.max,aall) How about a vector of pairs? Since this gets converted to a matrix, I'm not sure how to use this via map (one wants a "map over columns"). This works: julia> for i = 1:length(a) julia> av In my view, using convert on {} is the best of these; currently it doesn't work, but could be made to do so. But my concern is that [3:5] -> [3,4,5] is the real root of the problem. I recognize that there are surely many more people who want a convenient syntax for range expansion than people who are interested in arrays of range objects, but the fact that their natural syntaxes collide seems like an issue worth raising. Would it be worth forcing people to use an "expand" function explicitly? |
The thing is that Short answer is that The Somebody did write "map over columns", I believe it's called |
Very informative! Thanks! |
Stdlib: SparseArrays URL: https://github.com/JuliaSparse/SparseArrays.jl.git Stdlib branch: main Julia branch: master Old commit: f3610c0 New commit: 6d072a8 Julia version: 1.13.0-DEV SparseArrays version: 1.12.0(Does not match) Bump invoked by: @IanButterworth Powered by: [BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl) Diff: JuliaSparse/SparseArrays.jl@f3610c0...6d072a8 ``` $ git log --oneline f3610c0..6d072a8 6d072a8 Lazily init cholmod (#626) 8ff11da fix libsuitesparseconfig bug (#625) fac1548 lazily init cholmod 75eaa18 fix libsuitesparseconfig bug 7b6e810 Use `libsuitesparseconfig` from JLL (#620) b225a85 Clarify pros, cons and limitations of Cholesky and LDLt (#621) 3d42644 Update index.md (#623) 16bbcbc 5-term mul! with Diagonal (#603) d050b1b Relax `eltype` in `Diagonal` `ldiv!`/`rdiv!` (#616) 4968cff `ldiv!` for `Diagonal` and a sparse vector (#613) 5062034 Fix `issymmetric` for matrices with empty columns (#606) 9a46561 Replace `v == zero(v)` with `_iszero` (#610) ``` Co-authored-by: IanButterworth <[email protected]>
…to cdbad55 (#58724) Stdlib: SparseArrays URL: https://github.com/JuliaSparse/SparseArrays.jl.git Stdlib branch: release-1.12 Julia branch: backports-release-1.12 Old commit: 72c7cac New commit: cdbad55 Julia version: 1.12.0-beta4 SparseArrays version: 1.12.0 Bump invoked by: @fredrikekre Powered by: [BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl) Diff: JuliaSparse/SparseArrays.jl@72c7cac...cdbad55 ``` $ git log --oneline 72c7cac..cdbad55 cdbad55 Delete lock interface implementation from UmfpackLU (#617) 415bc9e [release-1.12] Run CI with Julia 1.12 (#635) d921308 fix libsuitesparseconfig bug f51dace Fix compat for SuiteSparse_jll fa9736c [release-1.12] Run CI with Julia 1.12 d1b0cd0 Backports for v1.12 (#624) e1817e8 Clarify pros, cons and limitations of Cholesky and LDLt (#621) b38f273 Use `libsuitesparseconfig` from JLL (#620) 66d65cc Relax `eltype` in `Diagonal` `ldiv!`/`rdiv!` (#616) 2ae8768 `ldiv!` for `Diagonal` and a sparse vector (#613) 08a15ca Replace `v == zero(v)` with `_iszero` (#610) 7ec2889 Fix `issymmetric` for matrices with empty columns (#606) f3610c0 SuiteSparse 7.10.1 wrappers and simpliefied wrapper generator process (#608) 9548149 Use `axes` instead of `1:size` (#602) ae727fe Explicitly import `Matrix` and `Vector` in CHOLMOD (#601) ce852af cleanup support for Float32 and ComplexF32 (#597) ``` Co-authored-by: fredrikekre <[email protected]>
These commits support more generic indexing on ASCIIStrings and deep-copy on range types. I'm not certain the last one is really desired, but I'm sure you'll decide.