Skip to content

Commit

Permalink
Merge pull request #18 from SimonDanisch/sd/fsa
Browse files Browse the repository at this point in the history
integrated fsa macro fixing #16
  • Loading branch information
SimonDanisch committed Aug 28, 2015
2 parents 4a81479 + 97f432a commit e02becf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/FixedSizeArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export MutableFixedArray
export MutableFixedVector
export MutableFixedMatrix
export Mat, Vec, Point
export @fsa

export unit
export normalize
Expand Down
23 changes: 23 additions & 0 deletions src/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,26 @@ convert{T <: Tuple, FSA <: FixedArray}(::Type{T}, x::FSA) = map(eltype(T), x.(
convert{T <: FixedArray}(t::Type{T}, f::T) = f
convert{FSA1 <: FixedArray}(t::Type{FSA1}, f::FixedArray) =
map(ConversionIndexFunctor(f, eltype_or(FSA1, eltype(typeof(f)))), FSA1)



macro fsa(expr)
if expr.head == :vect
result = Expr(:call, :Vec, expr.args...)
elseif expr.head == :hcat
result = Expr(:call, :Mat, [Expr(:tuple, a) for a in expr.args]...)
elseif expr.head == :vcat
if isa(expr.args[1], Expr) && expr.args[1].head == :row
cols = [Any[] for _=1:length(expr.args[1].args)]
for row in expr.args
for (j, a) in enumerate(row.args)
push!(cols[j], a)
end
end
result = Expr(:call, :Mat, Expr(:tuple, [Expr(:tuple, col...) for col in cols]...))
else
result = Expr(:call, :Vec, expr.args...)
end
end
esc(result)
end
17 changes: 17 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ typealias Vec4d Vec{4, Float64}
typealias Vec3f Vec{3, Float32}
facts("FixedSizeArrays") do

context("fsa macro") do
a = 1
a1 = @fsa([a,2,3])
a2 = @fsa([a 2 3])
a3 = @fsa([a;2;3])
a4 = @fsa([a 2;3 4])
a5 = @fsa([a 2 3;4 5 6])
a6 = @fsa([a 2;3 4;5 6])

@fact a1 --> Vec(a,2,3)
@fact a2 --> Mat((a,),(2,),(3,))
@fact a3 --> Mat(((a,2,3),))
@fact a4 --> Mat(((a,3),(2,4)))
@fact a5 --> Mat(((a,4),(2,5),(3,6)))
@fact a6 --> Mat(((a,3,5),(2,4,6)))
end

context("Array of FixedArrays") do

N = 100
Expand Down

0 comments on commit e02becf

Please sign in to comment.