ElasticArrays.jl icon indicating copy to clipboard operation
ElasticArrays.jl copied to clipboard

add deleteat! method

Open vlepori opened this issue 3 years ago • 19 comments

As discussed in #55. I kept the deleteat!(A,(),i) API.

The following are supported

a = ElasticArray(rand(7, 7, 7))
deleteat!(a, (), (), ())
deleteat!(a, (), (), 6)
deleteat!(a, (), (), [1, 5])
deleteat!(a, (), (), 3:4)

And this errors

deleteat!(a, 1:2, (), 1:2)
# ERROR: ArgumentError: Can only delete elements in the last dimension of A

vlepori avatar Apr 04 '23 09:04 vlepori

@vlepori looking at this again, maybe the primary way to do it should be deleteat!(A, ((), i)), but we should support deleteat!(A, (), i) as well. It matches how handle resize! in https://github.com/JuliaArrays/ElasticArrays.jl/blob/7e0b6f8b4134d0b203fc45f6f80296524fa419eb/src/elasticarray.jl#L108 .

Could you change idxs::Vararg{...} to idxs::NTuple{...} in the primary method and then add a convenience method with idxs::Vararg{...} like in https://github.com/JuliaArrays/ElasticArrays.jl/blob/7e0b6f8b4134d0b203fc45f6f80296524fa419eb/src/elasticarray.jl#L106

?

oschulz avatar Apr 04 '23 13:04 oschulz

Oh, and could you add a test or two?

oschulz avatar Apr 04 '23 13:04 oschulz

Good point, both APIs are supported now. I also added a couple of tests.

vlepori avatar Apr 06 '23 08:04 vlepori

Ok, let's run Ci on it then. :-)

oschulz avatar Apr 07 '23 16:04 oschulz

Codecov Report

Merging #56 (34d0809) into main (03bfd5d) will decrease coverage by 0.25%. The diff coverage is 80.00%.

@@            Coverage Diff             @@
##             main      #56      +/-   ##
==========================================
- Coverage   84.74%   84.49%   -0.25%     
==========================================
  Files           2        3       +1     
  Lines         118      129      +11     
==========================================
+ Hits          100      109       +9     
- Misses         18       20       +2     
Impacted Files Coverage Δ
src/elasticarray.jl 84.00% <80.00%> (-0.35%) :arrow_down:

... and 1 file with indirect coverage changes

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

codecov[bot] avatar Apr 07 '23 16:04 codecov[bot]

Hm, looks like there trouble on v1.0 .

oschulz avatar Apr 07 '23 18:04 oschulz

At least one problem here is that the method first(v,i) was introduced only in Julia 1.6. But since idxs is a Tuple I think we can safely change first(idxs, length(idxs) - 1) to idxs[1:end-1] and not worry about non-standard indexing? I can update the PR later today.

vlepori avatar Apr 19 '23 08:04 vlepori

But since idxs is a Tuple I think we can safely change first(idxs, length(idxs) - 1) to idxs[1:end-1] and not worry about non-standard indexing?

Yes, I think that should be Ok.

oschulz avatar Apr 19 '23 13:04 oschulz

Hey @vlepori I'm so sorry this got stalled, I completely forgot to click "run CI" ...

oschulz avatar May 13 '23 08:05 oschulz

@vlepori could you take a look at the failing tests?

oschulz avatar May 25 '23 12:05 oschulz

@oschulz yes sorry, I'll try to get a working installation of Julia 1.0 and look into this soon !

vlepori avatar Jun 21 '23 14:06 vlepori

Thanks @vlepori , no worries!

oschulz avatar Jun 21 '23 15:06 oschulz

Would love to see this added, could be great to use it to implement pop!

jeremiahpslewis avatar Mar 22 '24 14:03 jeremiahpslewis

@vlepori want to get back on this?

oschulz avatar Mar 22 '24 15:03 oschulz

Sure! Got sidetracked and forgot about this but if there is interest I will try to get it done!

vlepori avatar Mar 22 '24 16:03 vlepori

So I went down the rabbit hole behind this failing test on julia 1.0 https://github.com/JuliaArrays/ElasticArrays.jl/blob/34d0809ed801caa5700a05977eacc071e9f9cb26/test/elasticarray.jl#L310

It seems to have nothing to do with ElasticArrays but seems related to a weird side effect of the @test macro in older versions of Julia. I can reproduce it in Julia 1.0.3 like so

using Test

function fun()
    d = 2
    @test true # works as aspected when commenting out this line
    ntuple(i -> i == d ? true : false, 2)
end
fun() # should return (false,true) but gives (true,true)

I don't quite understand further (?) but the bug has been fixed in more recent versions, so maybe just skip the test ?

vlepori avatar Jul 27 '24 16:07 vlepori

Hm, now that v1.10 is set to become the new LTS, maybe it's time to drop v1.0 support?

oschulz avatar Jul 28 '24 09:07 oschulz

Not sure if it's necessary for just this one test, but I'd be surprised if many people still use 1.0. For comparison DifferentialEquations stopped supporting it 4 years ago and now requires julia 1.9

vlepori avatar Jul 29 '24 16:07 vlepori

Looks like among the package that depend on ElasticArrays, the packages EfficientGlobalOptimization, StanSample and SphericalHarmonics still (claim to ) support Julia v1.0.

So I suggest we do indeed skip the test, but keep v1.0 compatibility for now.

oschulz avatar Jul 29 '24 17:07 oschulz