Mercurial > repos > public > sbplib_julia
comparison src/LazyTensors/lazy_tensor_operations.jl @ 1836:368999a2e243 refactor/lazy_tensors/elementwise_ops
Add TensorNegation
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 09 Jan 2025 15:32:47 +0100 |
parents | 48eaa973159a |
children | 200971c71657 |
comparison
equal
deleted
inserted
replaced
1835:a6f28a8b8f3f | 1836:368999a2e243 |
---|---|
48 apply(tmt::TensorTranspose{T,R,D}, v::AbstractArray{<:Any,R}, I::Vararg{Any,D}) where {T,R,D} = apply_transpose(tmt.tm, v, I...) | 48 apply(tmt::TensorTranspose{T,R,D}, v::AbstractArray{<:Any,R}, I::Vararg{Any,D}) where {T,R,D} = apply_transpose(tmt.tm, v, I...) |
49 apply_transpose(tmt::TensorTranspose{T,R,D}, v::AbstractArray{<:Any,D}, I::Vararg{Any,R}) where {T,R,D} = apply(tmt.tm, v, I...) | 49 apply_transpose(tmt::TensorTranspose{T,R,D}, v::AbstractArray{<:Any,D}, I::Vararg{Any,R}) where {T,R,D} = apply(tmt.tm, v, I...) |
50 | 50 |
51 range_size(tmt::TensorTranspose) = domain_size(tmt.tm) | 51 range_size(tmt::TensorTranspose) = domain_size(tmt.tm) |
52 domain_size(tmt::TensorTranspose) = range_size(tmt.tm) | 52 domain_size(tmt::TensorTranspose) = range_size(tmt.tm) |
53 | |
54 struct TensorNegation{T,R,D, TM<:LazyTensor{T,R,D}} <: LazyTensor{T,R,D} | |
55 tm::TM | |
56 end | |
57 | |
58 apply(tm::TensorNegation, v, I...) = -apply(tm.tm, v, I...) | |
59 apply_transpose(tm::TensorNegation, v, I...) = -apply_transpose(tm.tm, v, I...) | |
60 | |
61 range_size(tm::TensorNegation) = range_size(tm.tm) | |
62 domain_size(tm::TensorNegation) = domain_size(tm.tm) | |
53 | 63 |
54 | 64 |
55 struct ElementwiseTensorOperation{Op,T,R,D,TT<:NTuple{N, LazyTensor{T,R,D}} where N} <: LazyTensor{T,R,D} | 65 struct ElementwiseTensorOperation{Op,T,R,D,TT<:NTuple{N, LazyTensor{T,R,D}} where N} <: LazyTensor{T,R,D} |
56 tms::TT | 66 tms::TT |
57 | 67 |
155 return tmi | 165 return tmi |
156 end | 166 end |
157 | 167 |
158 Base.:*(a::T, tm::LazyTensor{T}) where T = TensorComposition(ScalingTensor{T,range_dim(tm)}(a,range_size(tm)), tm) | 168 Base.:*(a::T, tm::LazyTensor{T}) where T = TensorComposition(ScalingTensor{T,range_dim(tm)}(a,range_size(tm)), tm) |
159 Base.:*(tm::LazyTensor{T}, a::T) where T = a*tm | 169 Base.:*(tm::LazyTensor{T}, a::T) where T = a*tm |
160 Base.:-(tm::LazyTensor) = (-one(eltype(tm)))*tm | |
161 | 170 |
162 """ | 171 """ |
163 InflatedTensor{T,R,D} <: LazyTensor{T,R,D} | 172 InflatedTensor{T,R,D} <: LazyTensor{T,R,D} |
164 | 173 |
165 An inflated `LazyTensor` with dimensions added before and after its actual dimensions. | 174 An inflated `LazyTensor` with dimensions added before and after its actual dimensions. |