Skip to content

Commit

Permalink
Make transpose/adjoint of Vec an error. (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre authored Oct 23, 2018
1 parent f82210d commit 70d5dc9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/tensor_ops_errors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
function Base.:*(S1::AbstractTensor, S2::AbstractTensor)
error("use `⋅` (`\\cdot`) for single contraction and `⊡` (`\\boxdot`) for double contraction instead of `*`")
end

for f in (:transpose, :adjoint)
@eval function LinearAlgebra.$f(::Vec)
throw(ArgumentError("the (no-op) $($f) is discontinued for `Tensors.Vec`"))
end
end
2 changes: 0 additions & 2 deletions src/transpose.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ julia> A'
0.566237 0.460085
```
"""
@inline Base.transpose(S::Vec) = S

@inline function Base.transpose(S::Tensor{2, dim}) where {dim}
Tensor{2, dim}(@inline function(i, j) @inbounds S[j,i]; end)
end
Expand Down
6 changes: 6 additions & 0 deletions test/test_misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -494,4 +494,10 @@ end
A2 = rand(Tensor{2, 2})
@test_throws DimensionMismatch A + A2
@test_throws DimensionMismatch AA - A

# transpose/adjoint of Vec
x = rand(Vec{3})
@test_throws ArgumentError x'
@test_throws ArgumentError transpose(x)
@test_throws ArgumentError adjoint(x)
end # of testset
1 change: 0 additions & 1 deletion test/test_ops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ end # of testsection
end # of testsection

@testsection "transpose" begin
@test (@inferred transpose(a))::Vec{dim, T} a' a
@test (@inferred transpose(A))::Tensor{2, dim, T} Array(A)'
@test transpose(transpose(A)) A
@test (@inferred transpose(A_sym))::SymmetricTensor{2, dim, T} A_sym Array(A_sym)'
Expand Down

0 comments on commit 70d5dc9

Please sign in to comment.