Mercurial > repos > public > sbplib_julia
comparison src/LazyTensors/lazy_tensor_operations.jl @ 1037:9e76bf19904c refactor/lazy_tensors
Drop more prefixes
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 22 Mar 2022 14:10:53 +0100 |
parents | 6abbb2c6c3e4 |
children | f857057e61e6 3bb94ce74697 2e606d4c0ab1 |
comparison
equal
deleted
inserted
replaced
1017:6abbb2c6c3e4 | 1037:9e76bf19904c |
---|---|
26 Base.@propagate_inbounds Base.getindex(ta::TensorApplication{T,1} where T, I::CartesianIndex{1}) = ta[Tuple(I)...] # Would otherwise be caught in the previous method. | 26 Base.@propagate_inbounds Base.getindex(ta::TensorApplication{T,1} where T, I::CartesianIndex{1}) = ta[Tuple(I)...] # Would otherwise be caught in the previous method. |
27 Base.size(ta::TensorApplication) = range_size(ta.t) | 27 Base.size(ta::TensorApplication) = range_size(ta.t) |
28 | 28 |
29 | 29 |
30 """ | 30 """ |
31 LazyTensorTranspose{T,R,D} <: LazyTensor{T,D,R} | 31 TensorTranspose{T,R,D} <: LazyTensor{T,D,R} |
32 | 32 |
33 Struct for lazy transpose of a LazyTensor. | 33 Struct for lazy transpose of a LazyTensor. |
34 | 34 |
35 If a mapping implements the the `apply_transpose` method this allows working with | 35 If a mapping implements the the `apply_transpose` method this allows working with |
36 the transpose of mapping `m` by using `m'`. `m'` will work as a regular LazyTensor lazily calling | 36 the transpose of mapping `m` by using `m'`. `m'` will work as a regular LazyTensor lazily calling |
37 the appropriate methods of `m`. | 37 the appropriate methods of `m`. |
38 """ | 38 """ |
39 struct LazyTensorTranspose{T,R,D, TM<:LazyTensor{T,R,D}} <: LazyTensor{T,D,R} | 39 struct TensorTranspose{T,R,D, TM<:LazyTensor{T,R,D}} <: LazyTensor{T,D,R} |
40 tm::TM | 40 tm::TM |
41 end | 41 end |
42 | 42 |
43 # # TBD: Should this be implemented on a type by type basis or through a trait to provide earlier errors? | 43 # # TBD: Should this be implemented on a type by type basis or through a trait to provide earlier errors? |
44 # Jonatan 2020-09-25: Is the problem that you can take the transpose of any LazyTensor even if it doesn't implement `apply_transpose`? | 44 # Jonatan 2020-09-25: Is the problem that you can take the transpose of any LazyTensor even if it doesn't implement `apply_transpose`? |
45 Base.adjoint(tm::LazyTensor) = LazyTensorTranspose(tm) | 45 Base.adjoint(tm::LazyTensor) = TensorTranspose(tm) |
46 Base.adjoint(tmt::LazyTensorTranspose) = tmt.tm | 46 Base.adjoint(tmt::TensorTranspose) = tmt.tm |
47 | 47 |
48 apply(tmt::LazyTensorTranspose{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::LazyTensorTranspose{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::LazyTensorTranspose) = domain_size(tmt.tm) | 51 range_size(tmt::TensorTranspose) = domain_size(tmt.tm) |
52 domain_size(tmt::LazyTensorTranspose) = range_size(tmt.tm) | 52 domain_size(tmt::TensorTranspose) = range_size(tmt.tm) |
53 | 53 |
54 | 54 |
55 struct LazyTensorBinaryOperation{Op,T,R,D,T1<:LazyTensor{T,R,D},T2<:LazyTensor{T,R,D}} <: LazyTensor{T,D,R} | 55 struct ElementwiseTensorOperation{Op,T,R,D,T1<:LazyTensor{T,R,D},T2<:LazyTensor{T,R,D}} <: LazyTensor{T,D,R} |
56 tm1::T1 | 56 tm1::T1 |
57 tm2::T2 | 57 tm2::T2 |
58 | 58 |
59 function LazyTensorBinaryOperation{Op,T,R,D}(tm1::T1,tm2::T2) where {Op,T,R,D, T1<:LazyTensor{T,R,D},T2<:LazyTensor{T,R,D}} | 59 function ElementwiseTensorOperation{Op,T,R,D}(tm1::T1,tm2::T2) where {Op,T,R,D, T1<:LazyTensor{T,R,D},T2<:LazyTensor{T,R,D}} |
60 @boundscheck check_domain_size(tm2, domain_size(tm1)) | 60 @boundscheck check_domain_size(tm2, domain_size(tm1)) |
61 @boundscheck check_range_size(tm2, range_size(tm1)) | 61 @boundscheck check_range_size(tm2, range_size(tm1)) |
62 return new{Op,T,R,D,T1,T2}(tm1,tm2) | 62 return new{Op,T,R,D,T1,T2}(tm1,tm2) |
63 end | 63 end |
64 end | 64 end |
65 | 65 |
66 LazyTensorBinaryOperation{Op}(s,t) where Op = LazyTensorBinaryOperation{Op,eltype(s), range_dim(s), domain_dim(s)}(s,t) | 66 ElementwiseTensorOperation{Op}(s,t) where Op = ElementwiseTensorOperation{Op,eltype(s), range_dim(s), domain_dim(s)}(s,t) |
67 | 67 |
68 apply(tmBinOp::LazyTensorBinaryOperation{:+,T,R,D}, v::AbstractArray{<:Any,D}, I::Vararg{Any,R}) where {T,R,D} = apply(tmBinOp.tm1, v, I...) + apply(tmBinOp.tm2, v, I...) | 68 apply(tmBinOp::ElementwiseTensorOperation{:+,T,R,D}, v::AbstractArray{<:Any,D}, I::Vararg{Any,R}) where {T,R,D} = apply(tmBinOp.tm1, v, I...) + apply(tmBinOp.tm2, v, I...) |
69 apply(tmBinOp::LazyTensorBinaryOperation{:-,T,R,D}, v::AbstractArray{<:Any,D}, I::Vararg{Any,R}) where {T,R,D} = apply(tmBinOp.tm1, v, I...) - apply(tmBinOp.tm2, v, I...) | 69 apply(tmBinOp::ElementwiseTensorOperation{:-,T,R,D}, v::AbstractArray{<:Any,D}, I::Vararg{Any,R}) where {T,R,D} = apply(tmBinOp.tm1, v, I...) - apply(tmBinOp.tm2, v, I...) |
70 | 70 |
71 range_size(tmBinOp::LazyTensorBinaryOperation) = range_size(tmBinOp.tm1) | 71 range_size(tmBinOp::ElementwiseTensorOperation) = range_size(tmBinOp.tm1) |
72 domain_size(tmBinOp::LazyTensorBinaryOperation) = domain_size(tmBinOp.tm1) | 72 domain_size(tmBinOp::ElementwiseTensorOperation) = domain_size(tmBinOp.tm1) |
73 | 73 |
74 | 74 |
75 """ | 75 """ |
76 TensorComposition{T,R,K,D} | 76 TensorComposition{T,R,K,D} |
77 | 77 |