diff --git a/src/Types.jl b/src/Types.jl index f487f44..0ea9327 100644 --- a/src/Types.jl +++ b/src/Types.jl @@ -38,6 +38,10 @@ function (::Type{MultiValue{S,T}})(x::Vararg) where {S<:Tuple,T} MultiValue{S,T}(x) end +function MultiValue(a::StaticArray{S,T}) where {S,T} + MultiValue{S,T}(a.data) +end + # Constructors (TensorValue) function (::Type{TensorValue{D}})(x::Tuple) where D @@ -69,6 +73,10 @@ function TensorValue(args::Vararg) TensorValue(args) end +function TensorValue(a::StaticArray) + TensorValue(a.data) +end + # Constructors (VectorValue) function (::Type{VectorValue{D}})(x::Tuple) where D @@ -97,6 +105,10 @@ function VectorValue(args::Vararg) VectorValue(args) end +function VectorValue(a::StaticArray) + VectorValue(a.data) +end + # Initializers function zero(::Type{<:MultiValue{S,T,N,L}}) where {S,T,N,L} diff --git a/test/TypesTests.jl b/test/TypesTests.jl index 8204a25..bf0d7d1 100644 --- a/test/TypesTests.jl +++ b/test/TypesTests.jl @@ -6,6 +6,11 @@ using StaticArrays # Constructors (MultiValue) +a = MArray{Tuple{3,2}}((1,2,3,4,5,6)) +v = MultiValue(a) +@test isa(v,MultiValue{Tuple{3,2},Int}) +@test v.array.data === a.data + a = SArray{Tuple{3,2}}((1,2,3,4,5,6)) v = MultiValue(a) @@ -30,6 +35,16 @@ v = MultiValue{Tuple{3,2},Float64}(1,2,3,4,5,6) # Constructors (TensorValue) +a = SMatrix{2,2}(1,2,3,4) +t = TensorValue(a) +@test isa(t,TensorValue{2,Int}) +@test t.array == [1 3;2 4] + +a = MMatrix{2,2}(1,2,3,4) +t = TensorValue(a) +@test isa(t,TensorValue{2,Int}) +@test t.array == [1 3;2 4] + t = TensorValue{2}((1,2,3,4)) @test isa(t,TensorValue{2,Int}) @test t.array == [1 3;2 4] @@ -56,6 +71,16 @@ t = TensorValue((1,2,3,4)) # Constructors (VectorValue) +a = SVector(1,2,3,4) +g = VectorValue(a) +@test isa(g,VectorValue{4,Int}) +@test g.array == [1,2,3,4] + +a = MVector(1,2,3,4) +g = VectorValue(a) +@test isa(g,VectorValue{4,Int}) +@test g.array == [1,2,3,4] + g = VectorValue{4}((1,2,3,4)) @test isa(g,VectorValue{4,Int}) @test g.array == [1,2,3,4]