These are chat archives for SimonDanisch/FixedSizeArrays.jl

28th
Aug 2015
Simon
@SimonDanisch
Aug 28 2015 00:35
Can you open an issue outlining what you really want/need?! That way I or some one else can implement it more easily and we can discuss the details
Cristóvão Duarte Sousa
@cdsousa
Aug 28 2015 11:29
Do you think range-indexing of Mats could return Mats or some kind of SubMat (as SubArrays)?
Cristóvão Duarte Sousa
@cdsousa
Aug 28 2015 11:53
I've just created #15, #16 and #17. Edit them at your will, @SimonDanisch .
Cristóvão Duarte Sousa
@cdsousa
Aug 28 2015 11:59
About slicing, I've just seen this Immutable Arrays issue: JuliaGeometry/ImmutableArrays.jl#22 . It seems that range-indexing the way I thought leads to type instability... (If I recall well, Eigen solves that by putting the slice ranges as template parameters)
Simon
@SimonDanisch
Aug 28 2015 12:31
yeaah!
I'm right now looking into it back again if something has changed
it's a pretty annoying issue
what is also a problem is that you can't easily remove the parameters from a type, which is a problem if you define these methods on an abstract type
getindex{FSA <: FixedArray}(::FSA) = FSA(...)
FSA will be something like Vec{3, Float32} at runtime
which then doesnt work with Vec{3, Float32}((1f0,2f0))
with mat we can actually achieve this, as I put mat into a special position as its integrated with FixedSizeArrays and the only mat type
but this means we would only specify the methods for Mat and to make them type stable we have to work with Val for indexes
and we can actually solve most of the problems with @generated.... but its a little troublesome it seems
Simon
@SimonDanisch
Aug 28 2015 12:40
```Julia
abstract FS{N, T}
immutable Vec{N, T} <: FS{N, T}
    _::NTuple{N, T}
end

Base.getindex{N,T}(v::Vec{N,T}, i) = Vec(v._[i])
immutable IndexFunc{T <: Tuple} <: Base.Func{1}
    x::T
end
Base.call(x::IndexFunc, i::Int) = x.x[i]
@generated function Base.getindex{R}(v::Vec, i::Type{Val{R}})
    :(Vec(tuple($([:(v._[$i]) for i in R]...))))
end

a = Vec((1,2,3))
@code_llvm a[Val{1:2}]
@show a[Val{1:2}]
this seems to generate relatively fast code
uhm the indexfunc is not necessary
Simon
@SimonDanisch
Aug 28 2015 12:45
with the indexfunc we can live without @generated which comes at the cost of an extra allocation of the indexfunctor
test1{R}(v::Vec, i::Type{Val{R}}) = map(IndexFunc(v._), R)
we could also look into creating some macros
which would do everything that a staged function could do, at the cost of looking slightly more verbose, but at least jeff won't be angry at us :D
Cristóvão Duarte Sousa
@cdsousa
Aug 28 2015 12:56
:smile: I see
Simon
@SimonDanisch
Aug 28 2015 12:57
Julia's core answer will be Ref{NTuple} by the way
which would allow for setindex and such
Cristóvão Duarte Sousa
@cdsousa
Aug 28 2015 13:08
I didn't check that feature yet. I'll take a look.
Simon
@SimonDanisch
Aug 28 2015 13:08
this is not a feature yet