@@ -64,24 +64,31 @@ function one!(t::AbstractTensorMap)
64
64
return t
65
65
end
66
66
67
- """
67
+ @doc """
68
68
id([T::Type=Float64,] V::TensorSpace) -> TensorMap
69
+ id!(t::AbstractTensorMap) -> AbstractTensorMap
69
70
70
71
Construct the identity endomorphism on space `V`, i.e. return a `t::TensorMap` with
71
72
`domain(t) == codomain(t) == V`, where either `scalartype(t) = T` if `T` is a `Number` type
72
73
or `storagetype(t) = T` if `T` is a `DenseVector` type.
73
- """
74
+
75
+ See also [`one!`](@ref).
76
+ """ id, id!
77
+
74
78
id (V:: TensorSpace ) = id (Float64, V)
75
79
function id (A:: Type , V:: TensorSpace{S} ) where {S}
76
80
W = V ← V
77
81
N = length (codomain (W))
78
- return one! (tensormaptype (S, N, N, A)(undef, W))
82
+ dst = tensormaptype (S, N, N, A)(undef, W)
83
+ return id! (dst)
79
84
end
85
+ const id! = one!
80
86
81
- """
87
+ @doc """
82
88
isomorphism([T::Type=Float64,] codomain::TensorSpace, domain::TensorSpace) -> TensorMap
83
89
isomorphism([T::Type=Float64,] codomain ← domain) -> TensorMap
84
90
isomorphism([T::Type=Float64,] domain → codomain) -> TensorMap
91
+ isomorphism!(t::AbstractTensorMap) -> AbstractTensorMap
85
92
86
93
Construct a specific isomorphism between the codomain and the domain, i.e. return a
87
94
`t::TensorMap` where either `scalartype(t) = T` if `T` is a `Number` type or
@@ -93,21 +100,22 @@ error will be thrown.
93
100
that `isomorphism(cod, dom) == inv(isomorphism(dom, cod))`.
94
101
95
102
See also [`unitary`](@ref) when `InnerProductStyle(cod) === EuclideanInnerProduct()`.
96
- """
97
- function isomorphism (A :: Type , V :: TensorMapSpace{S,N₁,N₂} ) where {S,N₁,N₂}
98
- codomain (V) ≅ domain (V) ||
99
- throw ( SpaceMismatch ( " codomain and domain are not isomorphic: $V " ))
100
- t = tensormaptype (S, N₁, N₂, A)(undef, V )
103
+ """ isomorphism, isomorphism!
104
+
105
+ function isomorphism! (t :: AbstractTensorMap )
106
+ domain (t) ≅ codomain (t) ||
107
+ throw ( SpaceMismatch ( lazy " domain and codomain are not isomorphic: $(space(t)) " ) )
101
108
for (_, b) in blocks (t)
102
109
MatrixAlgebra. one! (b)
103
110
end
104
111
return t
105
112
end
106
113
107
- """
114
+ @doc """
108
115
unitary([T::Type=Float64,] codomain::TensorSpace, domain::TensorSpace) -> TensorMap
109
116
unitary([T::Type=Float64,] codomain ← domain) -> TensorMap
110
117
unitary([T::Type=Float64,] domain → codomain) -> TensorMap
118
+ unitary!(t::AbstractTensorMap) -> AbstractTensorMap
111
119
112
120
Construct a specific unitary morphism between the codomain and the domain, i.e. return a
113
121
`t::TensorMap` where either `scalartype(t) = T` if `T` is a `Number` type or
@@ -119,16 +127,18 @@ the spacetype does not have a Euclidean inner product, an error will be thrown.
119
127
`unitary(cod, dom) == inv(unitary(dom, cod)) = adjoint(unitary(dom, cod))`.
120
128
121
129
See also [`isomorphism`](@ref) and [`isometry`](@ref).
122
- """
123
- function unitary (A:: Type , V:: TensorMapSpace{S,N₁,N₂} ) where {S,N₁,N₂}
124
- InnerProductStyle (S) === EuclideanInnerProduct () || throw_invalid_innerproduct (:unitary )
125
- return isomorphism (A, V)
130
+ """ unitary, unitary!
131
+
132
+ function unitary! (t:: AbstractTensorMap )
133
+ InnerProductStyle (t) === EuclideanInnerProduct () || throw_invalid_innerproduct (:unitary )
134
+ return isomorphism! (t)
126
135
end
127
136
128
- """
137
+ @doc """
129
138
isometry([T::Type=Float64,] codomain::TensorSpace, domain::TensorSpace) -> TensorMap
130
139
isometry([T::Type=Float64,] codomain ← domain) -> TensorMap
131
140
isometry([T::Type=Float64,] domain → codomain) -> TensorMap
141
+ isometry!(t::AbstractTensorMap) -> AbstractTensorMap
132
142
133
143
Construct a specific isometry between the codomain and the domain, i.e. return a
134
144
`t::TensorMap` where either `scalartype(t) = T` if `T` is a `Number` type or
@@ -137,13 +147,13 @@ Construct a specific isometry between the codomain and the domain, i.e. return a
137
147
isometric inclusion, an error will be thrown.
138
148
139
149
See also [`isomorphism`](@ref) and [`unitary`](@ref).
140
- """
141
- function isometry (A:: Type , V:: TensorMapSpace{S,N₁,N₂} ) where {S,N₁,N₂}
142
- InnerProductStyle (S) === EuclideanInnerProduct () ||
150
+ """ isometry, isometry!
151
+
152
+ function isometry! (t:: AbstractTensorMap )
153
+ InnerProductStyle (t) === EuclideanInnerProduct () ||
143
154
throw_invalid_innerproduct (:isometry )
144
- domain (V) ≾ codomain (V) ||
145
- throw (SpaceMismatch (" $V does not allow for an isometric inclusion" ))
146
- t = tensormaptype (S, N₁, N₂, A)(undef, V)
155
+ domain (t) ≾ codomain (t) ||
156
+ throw (SpaceMismatch (lazy " domain and codomain are not isometrically embeddable: $(space(t))" ))
147
157
for (_, b) in blocks (t)
148
158
MatrixAlgebra. one! (b)
149
159
end
@@ -152,13 +162,18 @@ end
152
162
153
163
# expand methods with default arguments
154
164
for morphism in (:isomorphism , :unitary , :isometry )
165
+ morphism! = Symbol (morphism, :! )
155
166
@eval begin
156
167
$ morphism (V:: TensorMapSpace ) = $ morphism (Float64, V)
157
168
$ morphism (codomain:: TensorSpace , domain:: TensorSpace ) = $ morphism (codomain ← domain)
158
169
function $morphism (A:: Type , codomain:: TensorSpace , domain:: TensorSpace )
159
170
return $ morphism (A, codomain ← domain)
160
171
end
161
- $ morphism (t:: AbstractTensorMap ) = $ morphism (storagetype (t), space (t))
172
+ function $morphism (A:: Type , V:: TensorMapSpace{S,N₁,N₂} ) where {S,N₁,N₂}
173
+ t = tensormaptype (S, N₁, N₂, A)(undef, V)
174
+ return $ morphism! (t)
175
+ end
176
+ $ morphism (t:: AbstractTensorMap ) = $ morphism! (similar (t))
162
177
end
163
178
end
164
179
0 commit comments