Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Mar 18, 2017
1 parent 48b5acf commit ad54bed
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
end
end

@generated function (::Type{Tensor{order, dim}}){order, dim}(data::AbstractArray)
N = n_components(Tensor{order,dim})
exp = Expr(:tuple, [:(data[$i]) for i in 1:N]...)
return quote
if length(data) != $N
throw(ArgumentError("wrong number of elements, expected $($N), got $(length(data))"))
end
Tensor{order, dim}($exp)
# Applies the function f to all indices f(1), f(2), ... f(n_independent_components)
@generated function apply_all{order, dim}(S::Union{Type{Tensor{order, dim}}, Type{SymmetricTensor{order, dim}}}, f::Function)
TensorType = get_base(get_type(S))
exp = tensor_create_linear(TensorType, (i) -> :(f($i)))
quote
$(Expr(:meta, :inline))
@inbounds return $TensorType($exp)
end
end

Expand All @@ -39,7 +38,6 @@ function (T::Type{Tensor{order, dim}}){order, dim}(data::AbstractArray)
end



# SymmetricTensor from AbstractArray
@generated function (::Type{SymmetricTensor{order, dim}}){order, dim}(data::AbstractArray)
N = n_components(Tensor{order,dim})
Expand Down

0 comments on commit ad54bed

Please sign in to comment.