JuliaLang/julia — pull request #7568 by timholy (2014-07-11 20:35:33+00:00)
Title: WIP: implementation of fixed-size arrays

This implements fixed-size arrays (whose size is part of the type parameters). Compared to the proof-of-concept in #5857, it solves the constructor problems. There was some debate in #5857 (and echoed [on julia-dev](https://groups.google.com/d/msg/julia-dev/vFRa0B2IiAk/RAwmBU7MiccJ)) about whether mutable or immutable would be more desirable, so for fun this implements both.

Ultimately, the multiplication routine will be a nice application of staged functions. As it is, this defines 128 new methods for `*`.

This has uncovered some type-inference problems, to be filed in other issues. Given that I'd expect such problems to destroy performance, it's shockingly good. (Of the fixed-size tests, only the last line below does not suffer from type-stability problems. Hence, it is more illustrative of what one might ultimately hope for.)

Timing info:
```julia
f(n::Integer, A, B) = (C = A*B; for i = 1:n; C = A*B; end)
g(n::Integer, A, B) = (C = A*B; for i = 1:n; A_mul_B!(C,A,B); end)
A = rand(2,2)
B = rand(2,3)
AfI = FixedArrayI(A)
BfI = FixedArrayI(B)
AfM = FixedArrayM(A)
BfM = FixedArrayM(B)
# hide warmup
julia> @time f(10^6, A, B)
elapsed time: 0.505924798 seconds (128000224 bytes allocated, 18.89% gc time)

julia> @time f(10^6, AfI, BfI)
elapsed time: 1.244501688 seconds (504000600 bytes allocated, 28.19% gc time)

julia> @time f(10^6, AfM, BfM)
elapsed time: 0.632096601 seconds (144000240 bytes allocated, 14.57% gc time)

julia> @time g(10^6, A, B)
elapsed time: 0.349824437 seconds (224 bytes allocated)

julia> @time g(10^6, AfM, BfM)
elapsed time: 0.056289786 seconds (240 bytes allocated)
```