-
Notifications
You must be signed in to change notification settings - Fork 152
Closed
Labels
designspeculative design related issuespeculative design related issue
Description
As mentioned in #31, nobody wants to write two versions of code, one for mutable arrays, vs one for immutable arrays like StaticArray
. I'd like a central place where we identify the main issues, and discuss minimal changes to the AbstractArray
interface or julia compiler which would allow packages like StaticArrays
to exist without rewriting a lot of algorithms from Base. Here's a very incomplete list, I hope people will jump in with more detail:
API
similar()
assumes a mutable container can be created efficiently filled in an iterative way. Julep: setfield! for mutable references to immutables JuliaLang/julia#17115 goes some way to solving this, though we'd be working with a statically sized buffer, something likeRef{T<:StaticArray}
and would need to unwrap this to return the value.- The
hvcat()
API doesn't reflect the structure of the input expression AST in a way which can give a type inferred output. (Potentially solvable with constant prop, without API changes?)
Optimization
similar()
with a size argument is not type inferrable forStaticArray
. Constant prop in inference could potentially fix this in many cases, Ref. Do some constant propagation before type inference runs JuliaLang/julia#5560.getindex()
with fancy indexing is not type inferrable forStaticArray
. Constant prop in inference could fix a bunch of important instances of this, eg literal rangesv[3:5]
could be known to be aSVector{3}
. But what about non-inferrable cases, even after constant prop? We'd like to return anArray
in those cases, can we achieve this in principle?- Loop unrolling - small static arrays can benefit a lot from this, but in
StaticArrays
we're forced to do it at the AST level via@generated
functions which no doubt pushes the compiler pretty hard and generates a heap of garbage. More interesting would be an@unroll
meta to instruct codegen to unroll a given loop if the range is statically known.
Obviously one thing we can't fix is differences in the most appropriate algorithm for small vs large objects. For example, eigen decomposition of 2x2 matrices should probably just be done using a specialized analytical expression for that size.
Metadata
Metadata
Assignees
Labels
designspeculative design related issuespeculative design related issue