-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
AbstractImmutableArray or ImmutableArray Trait #21869
Comments
Why not use a Trait? |
A trait would be fine. It would need to be some kind of Base trait added to the array interface, since the current options don't work very well. Note that a simple trait on |
Wouldn't something like struct MutableArray end
struct ImmutableArray end
MutableStyle(::AbstractArray) = MutableArray()
MutableStyle(::StaticArray) = ImmutableArray() in StaticArrays be enough? |
No, it can't. The the generated function will either lie to you or generate garbage. It operates in the same computational domain as regular functions, so there's nothing it can do that regular functions can't also do. |
Yes @KristofferC, that would be exactly enough if |
I just want to make sure I understand where this fits at a higher API level. As I see it, given array
Time to start allowing |
I proposed |
i strongly support having some more traits for arrays - specifically for mutability and another to replace I agree working out a higher level API here would be wonderful, but it seems significantly harder... |
Yeah, that's what I was discussing with @mbauman in a Gitter chat. I would like a high level API here as well, but I don't know if it could hit every point. If there's at least the traits available, I can special case as I see fit, which would be special casing in areas Base has not made this easy. The goal of a high level API would be to make this not necessary, but I am not sure you can cover every single aspect. |
Using different types of immutable indexable types can be useful, but this is very difficult (if not impossible?) to handle with generic code right now. For example, an
SArray
from StaticVectors.jl is<:AbstractArray
. Many times you may want to have separate code paths for abstract arrays, like:However, there is currently no way to distinguish between immutable and mutable collections. Note that this exact case would actually be solved by
#19992
but that is just a bandaid for a single case. Another case for example would be choosing between
fill!
ing a vector or creating a new one matching the immutable array type withzeros
. I'm not sure Julia can always automate this choice in every case, and so the ability to distinguish between these classes of types is crucial. Without a Base abstract type, this requires a dependency for each array type you want to support like this. A simpleAbstractImmtableArray{T,N} <: AbstractArray{T,N}
could handle this.The text was updated successfully, but these errors were encountered: