formsumf(x :: Array{T,2}, A::Array{NTuple{3,T}} ) where T<: Number = sum(x*mapreduce(Base.splat(Base.vect),hcat, A))
julia> A=[(1,2,4),(3,5,4),(3,2,1),(9,2,6),(1,1,2)]
5-element Vector{Tuple{Int64, Int64, Int64}}:
(1, 2, 4)
(3, 5, 4)
(3, 2, 1)
(9, 2, 6)
(1, 1, 2)
julia> x=[3 3 3]
1×3 Matrix{Int64}:
3 3 3
julia> formsum(A,x)
1-element Vector{Int64}:
138
julia> x=[3 3 3 ; 2 2 2]
2×3 Matrix{Int64}:
3 3 3
2 2 2
julia> formsum(A,x)
2-element Vector{Int64}:
138
92
julia> x=[3 3 3 4; 2 2 2 4]
2×4 Matrix{Int64}:
3 3 3 4
2 2 2 4
julia> formsum(x,A)
ERROR: DimensionMismatch("matrix A has dimensions (2,4), vector B has length 3")
I’m trying to practice using types in function definitions.
Is there a way to force x to be an Nx3 matrix?
or the only way, if you want to introduce a control, is to do it in the body of the function with the if then else?