-
Notifications
You must be signed in to change notification settings - Fork 38
/
transpose.jl
50 lines (40 loc) · 1.28 KB
/
transpose.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# transpose, majortranspose, minortranspose
"""
transpose(::Vec)
transpose(::SecondOrderTensor)
transpose(::FourthOrderTensor)
Compute the transpose of a tensor.
For a fourth order tensor, the transpose is the minor transpose.
# Examples
```jldoctest
julia> A = rand(Tensor{2,2})
2×2 Tensor{2, 2, Float64, 4}:
0.590845 0.566237
0.766797 0.460085
julia> A'
2×2 Tensor{2, 2, Float64, 4}:
0.590845 0.766797
0.566237 0.460085
```
"""
@inline function Base.transpose(S::Tensor{2, dim}) where {dim}
Tensor{2, dim}(@inline function(i, j) @inbounds S[j,i]; end)
end
@inline Base.transpose(S::SymmetricTensor{2}) = S
"""
minortranspose(::FourthOrderTensor)
Compute the minor transpose of a fourth order tensor.
"""
@inline function minortranspose(S::Tensor{4, dim}) where {dim}
Tensor{4, dim}(@inline function(i, j, k, l) @inbounds S[j,i,l,k]; end)
end
@inline minortranspose(S::SymmetricTensor{4}) = S
@inline Base.transpose(S::FourthOrderTensor) = minortranspose(S)
"""
majortranspose(::FourthOrderTensor)
Compute the major transpose of a fourth order tensor.
"""
@inline function majortranspose(S::FourthOrderTensor{dim}) where {dim}
Tensor{4, dim}(@inline function(i, j, k, l) @inbounds S[k,l,i,j]; end)
end
@inline Base.adjoint(S::AllTensors) = transpose(S)