Mercurial > repos > public > sbplib_julia
comparison src/LazyTensors/lazy_tensor_operations.jl @ 2061:e70417f95713 feature/lazy_tensors/zero_tensor
Add ZeroTensor
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Mon, 16 Feb 2026 21:46:35 +0100 |
| parents | ed50eec18365 |
| children |
comparison
equal
deleted
inserted
replaced
| 2059:377df47849cb | 2061:e70417f95713 |
|---|---|
| 111 end | 111 end |
| 112 | 112 |
| 113 range_size(tmBinOp::TensorSum) = range_size(tmBinOp.tms[1]) | 113 range_size(tmBinOp::TensorSum) = range_size(tmBinOp.tms[1]) |
| 114 domain_size(tmBinOp::TensorSum) = domain_size(tmBinOp.tms[1]) | 114 domain_size(tmBinOp::TensorSum) = domain_size(tmBinOp.tms[1]) |
| 115 | 115 |
| 116 TensorSum(a::ZeroTensor{T,R,D}, b::ZeroTensor{T,R,D}) where {T,R,D} = ZeroTensor{T,R,D}() | |
| 117 TensorSum(::ZeroTensor, t::LazyTensor) = t | |
| 118 TensorSum(t::LazyTensor, ::ZeroTensor) = t | |
| 116 | 119 |
| 117 """ | 120 """ |
| 118 TensorComposition{T,R,K,D} | 121 TensorComposition{T,R,K,D} |
| 119 | 122 |
| 120 Lazily compose two `LazyTensor`s, so that they can be handled as a single `LazyTensor`. | 123 Lazily compose two `LazyTensor`s, so that they can be handled as a single `LazyTensor`. |
| 158 # Specialization for the case where tm is an IdentityTensor. Required to resolve ambiguity. | 161 # Specialization for the case where tm is an IdentityTensor. Required to resolve ambiguity. |
| 159 function TensorComposition(tm::IdentityTensor{T,D}, tmi::IdentityTensor{T,D}) where {T,D} | 162 function TensorComposition(tm::IdentityTensor{T,D}, tmi::IdentityTensor{T,D}) where {T,D} |
| 160 @boundscheck check_domain_size(tm, range_size(tmi)) | 163 @boundscheck check_domain_size(tm, range_size(tmi)) |
| 161 return tmi | 164 return tmi |
| 162 end | 165 end |
| 166 | |
| 167 | |
| 168 function TensorComposition(a::ZeroTensor{T,R,D}, b::ZeroTensor{T,D,K}) where {T,R,D,K} | |
| 169 return ZeroTensor{T,R,K}() | |
| 170 end | |
| 171 | |
| 172 function TensorComposition(a::ZeroTensor{T,R,D}, b::LazyTensor{T,D,K}) where {T,R,D,K} | |
| 173 return ZeroTensor{T,R,K}() | |
| 174 end | |
| 175 | |
| 176 function TensorComposition(a::LazyTensor{T,R,D}, b::ZeroTensor{T,D,K}) where {T,R,D,K} | |
| 177 return ZeroTensor{T,R,K}() | |
| 178 end | |
| 179 | |
| 163 | 180 |
| 164 Base.:*(a::T, tm::LazyTensor{T}) where T = TensorComposition(ScalingTensor{T,range_dim(tm)}(a,range_size(tm)), tm) | 181 Base.:*(a::T, tm::LazyTensor{T}) where T = TensorComposition(ScalingTensor{T,range_dim(tm)}(a,range_size(tm)), tm) |
| 165 Base.:*(tm::LazyTensor{T}, a::T) where T = a*tm | 182 Base.:*(tm::LazyTensor{T}, a::T) where T = a*tm |
| 166 | 183 |
| 167 """ | 184 """ |
