From 70d5dc9c430d092a449841453516fa2c53ed5e8d Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Tue, 23 Oct 2018 08:05:00 +0200 Subject: [PATCH] Make transpose/adjoint of Vec an error. (#103) --- src/tensor_ops_errors.jl | 6 ++++++ src/transpose.jl | 2 -- test/test_misc.jl | 6 ++++++ test/test_ops.jl | 1 - 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/tensor_ops_errors.jl b/src/tensor_ops_errors.jl index 3e0e1fbd..fb091c1f 100644 --- a/src/tensor_ops_errors.jl +++ b/src/tensor_ops_errors.jl @@ -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 diff --git a/src/transpose.jl b/src/transpose.jl index 4951f3bf..2075ee6c 100644 --- a/src/transpose.jl +++ b/src/transpose.jl @@ -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 diff --git a/test/test_misc.jl b/test/test_misc.jl index e0f78e0f..848044d1 100644 --- a/test/test_misc.jl +++ b/test/test_misc.jl @@ -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 diff --git a/test/test_ops.jl b/test/test_ops.jl index 5f8db095..b2ace8fe 100644 --- a/test/test_ops.jl +++ b/test/test_ops.jl @@ -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)'