FixedSizeArrays is giving any composite type array like behavior by inheriting from FixedSizeArrays. So you can do something like this:
immutable RGB{T} <: FixedVectorNoTuple{3, T}
r::T
g::T
b::T
end
immutable Vec{N, T} <: FixedVector{N, T} # defined in FixedSizeArrays already
_::NTuple{N, T}
end
Vec{3, Float32}(0) # constructor with 1 argument already defined
rand(Vec{3, Int})+sin(Vec(0,2,2)) # a lot of array functions are already defined
#There is also a matrix type
eye(Mat{3,3,Float32}) * rand(Vec{3, Float32}) # will also "just work"
a = Vec(1,2,3)[1:2] # returns (1,2)
This is expendable to a lot of other areas. You can define color types the same way, and arbitrary other point types like normals, vertices etc. As they all inherit from FixedSizeArray, it's very easy to handle them in the same way. I'm using this for my GPU array types, which can take any fixedsizearray, if its a color, a point or what not, because I can be sure that all the important functions are defined and the GPU can handle them. If we are able to to compile Julia directly to OpenCL, FixedSizeArrays will hopefully directly map to native OpenCL types.
For some more advantages, you can take a look at MeshIO.
Because it's so easy to define different types like Point3, RGB, HSV or Normal3, one can create customized code for these types via multiple dispatch. This is great for visualizing data, as you can offer default visualizations based on the type. Without FixedSizeArrays, this would end up in a lot of types which would all need to define the same functions over and over again.
- improve coverage
- incorperate https://github.com/StephenVavasis/Modifyfield.jl
- improve API and consistency
- Core Array
- basic array interface
- Inherit from DenseArray (a lot of warnings is caused by this)
- use tuples as a basis
- Indexing:
- multidimensional access
- colon access for matrices
- multidimensional colon access
- setindex!
- setindex!/getindex for arrays of FSA (e.g. easy acces to single fields)
- access via dimension type (Red -> redchannel)
- Constructor
- generic constructor for arbitrary Nvectors
- fast constructor for arbitrary types
- parsing constructor e.g Vec{3, Float32}(["23.", "23.", "0.23"])
- different constructors for ease of use (zero, eye, from other FSAs, etc...) (could be more)
- clean up constructor code (very messy since its hard to write constructors for abstract types)
- Functions
- all kinds of unary/binary operators
- matrix multiplication
- matrix functions (inv, transpose, etc...) (could be more)
ImmutableArrays by twadleigh was the package that got me going and gave the initial inspirations. There has been quite a few discussions on JuliaLang/julia#7568 shaping the implementation. Also, aaalexandrov supplied some code and inspirations. Big thanks to all the other contributors !