FixedSizeArrays

Julia's generic FixedSizeArray implementation. Can be used for all kinds of Vector constructs


License
Other

Documentation

FixedSizeArrays

Join the chat at https://gitter.im/SimonDanisch/FixedSizeArrays.jl

Build Status Coverage Status codecov.io Build status

This package doesn't support 0.3

Packages that use FixedSizeArrays:

GeometryTypes.jl

Usage and advantages:

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
    function RGB(a::NTuple{3, T}) #needs to be like this to keep constructor code sane
        new{T}(a[1], a[2], a[3])
    end
end
immutable Vec{N, T} <: FixedVector{N, T} # defined in FixedSizeArrays already
    _::NTuple{N, T}
end
Vec{3, Float32}(77) # constructor with 1 argument already defined
rand(Vec{3, Float64})+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)

Note that all of the above types are stack allocated and the speed of operations should be fairly fast! If you find operations to be slow, please file a bug report!

FixedSizeArrays can be used in a lot of different ways. 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.

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.

Roadmap

TODO's

  • 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 slices e.g. Matrix{RGBA} -> Matrix{Red} (sort of)
  • 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)

Acknowledgements

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 !