Skip to content

Commit

Permalink
Do not allow using adjoint for Vec (#197)
Browse files Browse the repository at this point in the history
* Do not allow using adjoint for Vec

* Bump version
  • Loading branch information
KeitaNakamura authored Dec 8, 2023
1 parent 79c41bd commit 104e5c0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Tensorial"
uuid = "98f94333-fa9f-48a9-ad80-1c66397b2b38"
authors = ["Keita Nakamura <[email protected]>"]
version = "0.13.1"
version = "0.13.2"

[deps]
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Expand Down
4 changes: 0 additions & 4 deletions src/AbstractTensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const AbstractMat{m, n, T} = AbstractTensor{Tuple{m, n}, T, 2}
const AbstractMatLike{T} = Union{
AbstractMat{<: Any, <: Any, T},
AbstractSymmetricSecondOrderTensor{<: Any, T},
Transpose{T, <: AbstractVec{<: Any, T}},
}
const AbstractVecOrMatLike{T} = Union{AbstractVec{<: Any, T}, AbstractMatLike{T}}

Expand Down Expand Up @@ -78,6 +77,3 @@ end
@inbounds SArray{Tuple{$(size(x)...)}}($(exps...))
end
end
function StaticArrays.SArray(x::Transpose{<: T, <: AbstractVec{dim, T}}) where {dim, T}
SMatrix{1, dim}(Tuple(parent(x)))
end
1 change: 1 addition & 0 deletions src/ops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ end
@inline transpose(x::AbstractTensor{Tuple{@Symmetry({dim, dim})}}) where {dim} = x
@inline transpose(x::AbstractTensor{Tuple{m, n}}) where {m, n} = Tensor{Tuple{n, m}}((i,j) -> @inbounds x[j,i])
@inline adjoint(x::AbstractTensor) = transpose(x)
@inline adjoint(::AbstractVec) = throw(ArgumentError("adjoint for `AbstractVec` is not allowed"))

# det
@generated function extract_vecs(x::AbstractSquareTensor{dim}) where {dim}
Expand Down
12 changes: 4 additions & 8 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,15 @@
end
@testset "vcat/hcat" begin
@test @inferred(vcat(Vec(1,2,3))) === Vec(1,2,3)
@test @inferred(vcat(Vec(1,2,3)')) === Vec(1,2,3)'
@test @inferred(vcat(Mat{1,3}(1,2,3))) === Mat{1,3}(1,2,3)
@test @inferred(hcat(Vec(1,2,3))) === Mat{3,1}(1,2,3)
@test @inferred(hcat(Vec(1,2,3)')) === Vec(1,2,3)'
@test @inferred(hcat(Mat{3,1}(1,2,3))) === Mat{3,1}(1,2,3)

@test @inferred(vcat(Vec(1,2,3), Vec(4,5,6))) === Vec(1,2,3,4,5,6)
@test @inferred(vcat(Vec(1,2,3), Mat{3,1}(4,5,6))) === Mat{6,1}(1,2,3,4,5,6)
@test @inferred(vcat(Mat{1,3}(1,2,3), Mat{1,3}(4,5,6))) === @Mat [1 2 3; 4 5 6]
@test @inferred(vcat(Mat{1,3}(1,2,3), Vec(4,5,6)')) === @Mat [1 2 3; 4 5 6]
@test @inferred(vcat(symmetric(Mat{2,2}(1,2,2,3), :U), Vec(4,5)')) === @Mat [1 2; 2 3; 4 5]
@test @inferred(vcat(symmetric(Mat{2,2}(1,2,2,3), :U), Mat{1,2}(4,5))) === @Mat [1 2; 2 3; 4 5]
@test @inferred(hcat(Vec(1,2,3), Vec(4,5,6))) === Mat{3,2}(1,2,3,4,5,6)
@test @inferred(hcat(Vec(1,2,3)', Vec(4,5,6)')) === Mat{1,6}(1,2,3,4,5,6)
@test @inferred(hcat(Vec(1,2,3), Mat{3,2}(4,5,6,7,8,9))) === Mat{3,3}(1,2,3,4,5,6,7,8,9)
@test @inferred(hcat(Mat{3,1}(1,2,3), Mat{3,2}(4,5,6,7,8,9))) === Mat{3,3}(1,2,3,4,5,6,7,8,9)
@test @inferred(hcat(symmetric(Mat{2,2}(1,2,2,3), :U), Vec(4,5))) === @Mat [1 2 4; 2 3 5]
Expand Down Expand Up @@ -89,7 +85,7 @@
for T in (Float32, Float64)
x11 = rand(Mat{2,2,T})
x12 = rand(Vec{2,T})
x21 = rand(Vec{2,T})'
x21 = rand(Mat{1,2,T})
x22 = rand(T)
@test (@inferred f_2_2(x11, x12, x21, x22))::Mat{3,3,T} == f_2_2(Array.((x11, x12, x21))..., x22)
x11 = rand(SymmetricSecondOrderTensor{3,T})
Expand All @@ -99,11 +95,11 @@
x23 = rand(Mat{2,3,T})
@test (@inferred f_2_3(x11, x12, x21, x22, x23))::Mat{5,6,T} == f_2_3(Array.((x11, x12, x21, x22, x23))...)
x11 = rand(T)
x12 = rand(Vec{3,T})'
x12 = rand(Mat{1,3,T})
x21 = rand(Vec{3,T})
x22_11 = rand(SymmetricSecondOrderTensor{2,T})
x22_12 = rand(Vec{2,T})
x22_21 = rand(Vec{2,T})'
x22_21 = rand(Mat{1,2,T})
x22_22 = rand(T)
@test (@inferred f_2_2_recurse(x11,x12,x21,x22,x22_11,x22_12,x22_21,x22_22))::Mat{4,4,T} == f_2_2_recurse(x11,Array.((x12,x21,x22,x22_11,x22_12,x22_21))...,x22_22)
end
Expand Down

2 comments on commit 104e5c0

@KeitaNakamura
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/96725

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.13.2 -m "<description of version>" 104e5c00a3c34b082e4afbf1c6e27a796b2e13c6
git push origin v0.13.2

Please sign in to comment.