JuliaArrays / ReadOnlyArrays.jl

A wrapper type around AbstractArray that is read-only
Other
27 stars 5 forks source link

Slicing a read-only matrix does not provide a read-only vector #2

Closed orenbenkiki closed 2 years ago

orenbenkiki commented 2 years ago

As shown by:

m = ReadOnlyArray([1 2; 3 4])
typeof(m[1,:])

I'd have expected a slize of a read-only array to also be a read-only array.

bkamins commented 2 years ago

As you can see the package is not actively maintained as people did not really decide to start using it. Still - feel free to make a PR and I can make a release. Thank you!

orenbenkiki commented 2 years ago

Hmmm... I was planning to use it, or at least support its usage in my package (which allows people to store all kind of arrays in a container). Should I worry about the package being incomplete in general?

I suppose that since Julia doesn't really believe in immutability, I shouldn't fight on being uniodiomatic and settle for "strongly urging" people to avoid modifying things they shouldn't?

If so, a pity - immutability is important for thread-safety, and I was planning on using this package to (mostly) ensure it in the relevant cases for people using the "normal operations". I realize people can always access .parent if they want to forcibly get mutable access but anyone doing that should "really know what he's doing".

Thanks :-(

bkamins commented 2 years ago

I guess what you write is indeed the core of the problem. The immutability is easily broken so people did not start to rely on this package as it does not give much benefit. Maybe use https://github.com/JuliaArrays/StaticArrays.jl as they can guarantee immutability (assuming your arrays are not super large).

orenbenkiki commented 2 years ago

Oh, my arrays are definitely super-large... up to several GBs in size.

I can enforce some immutability in the special case where I memory-map the arrays from disk files - mmap mercifully does work on files opened for read-only. But my APIs are uniform for in-memory and memory-mapped arrays and I was hoping to be able to provide immutability in both cases.

I can't help but think that if Julia is successful (which I definitely wish it to be), it will discover that ignoring immutability will be an issue, since multi-threaded code is becoming more and more prevailent. And immutability is useful in general - even Python with its GIL (so effectively no multi-threading) supports a writeable flag in Numpy arrays...

Oh well. Thanks for the quick response!

bkamins commented 2 years ago

maybe open an issue for this in Julia Base repo and CC me there as I agree :).

orenbenkiki commented 2 years ago

I submitted JuliaLang/julia#42157 FWIW.