-
-
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
Interfaces for immutable arrays #11610
Comments
What exactly is the well-defined case? I think the term "type stable" is getting a bit out of hand. Consider
Is the |
Also #8450 |
Haha, yeah... Sorry, for contributing to further dilute this term. import Base: sum
abstract FixedArray{T, NDim} <: AbstractArray{T, NDim}
sum{T <: FixedArray}(x::T) = ...
I'm not even sure if these warnings are even justified. |
The benchmark results are a little weird though. I think the |
You need Is your concern about Unfortunately, I fear those ambiguity warnings are justified (at least, in their current form). |
Good to know!
Makes sense now. If you have Yes, immutable arrays with immutable elements are the issue (like 90% of the types in FixedSizeArrays) |
There are currently some performance issues with indexing into SubArrays, but it'd be very interesting to see what would happen if you simply defined: getindex(FA::FixedArray, I::Integer...) = … # scalar lookup
getindex(FA::FixedArray, I...) = sub(FA, I...) # nonscalar indexing returns a SubArray It's definitely worth considering how we can improve the interfaces for arrays with immutable elements. Actually, would you mind changing the issue title? "Interfaces for arrays with immutable elements" seems like a good description here. I was a little confused what this was about at first. |
Anything here not included in something like #11902? |
This can be closed, now that almost everything is a broadcast ;) |
I hope this is not too redundant. I have the feeling that this was discussed before, but I couldn't find the issues.
Now that #10525 is coming around, I was digging around in
array.jl
to get an idea of how far we're away of having all array functions ofFixedSizeArrays
defined by simply inheriting from AbstractArray.(SimonDanisch/FixedSizeArrays.jl#6)
The
similar
function seems to be the biggest problem, as this pattern is more or less impossible for immutable types. I think the newgetindex
operations in #10525 also relies on similar :(I created quite a few mapping operations in order to avoid
similar
, which helped to reduce most of the indexing and other operations to a call to map.So this :
Would need to change.
We could just use
map($(generatefunctor(f)), A, B)
in this place and we would be all set, I think.If we do this elegantly, we could just use map and map! to also generate in-place versions without much effort.
Are there reasons to not have it this way?
The only explanation I came up with is, that the current map implementation seems to guard against functions which are not type stable, which is not necessary in this well-defined case.
I think all this is another call for having return types and purity encoded into the function type.
With that, we could even default to a parallel map implementations for pure functions.
Or define an OpenCL kernel for map, which seems to generate superior assembly for mapping operations. (and all functions like
+
,.*
etc would immediately be made faster)Even GPU arrays could just inherit from abstract array and would have all base functions defined for it (Especially if we enable SPIR as an LLVM target. But even now this would be possible with a well-defined set of functors, for which we create a lookup table with OpenCL kernel source).
To sum this up, I just want to ask if we can use map here and if not, discuss what other options we have.
Here are some benchmark from
Commit 2fda426 (1 day old master)
(windows):Best,
Simon
The text was updated successfully, but these errors were encountered: