Skip to content
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

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

Closed
orenbenkiki opened this issue Sep 8, 2021 · 6 comments
Closed

Comments

@orenbenkiki
Copy link

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
Copy link
Collaborator

bkamins commented Sep 8, 2021

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
Copy link
Author

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
Copy link
Collaborator

bkamins commented Sep 8, 2021

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
Copy link
Author

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
Copy link
Collaborator

bkamins commented Sep 8, 2021

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

@orenbenkiki
Copy link
Author

I submitted JuliaLang/julia#42157 FWIW.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants