Mercurial > repos > public > sbplib_julia
comparison src/LazyTensors/lazy_tensor_operations.jl @ 547:53828d3ed132 refactor/tensor_index_coupling
Remove unnecessary type parameters
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Sat, 28 Nov 2020 17:03:01 +0100 |
parents | 62d96e2cd165 |
children | 8f7919a9b398 |
comparison
equal
deleted
inserted
replaced
543:1a53eb83ed24 | 547:53828d3ed132 |
---|---|
12 o::AA | 12 o::AA |
13 end | 13 end |
14 # TODO: Do boundschecking on creation! | 14 # TODO: Do boundschecking on creation! |
15 export LazyTensorMappingApplication | 15 export LazyTensorMappingApplication |
16 | 16 |
17 # TODO: Go through and remove unneccerary type parameters on functions | 17 Base.getindex(ta::LazyTensorMappingApplication{T,R}, I::Vararg{Any,R}) where {T,R} = apply(ta.t, ta.o, I...) |
18 | |
19 Base.getindex(ta::LazyTensorMappingApplication{T,R,D}, I::Vararg{Any,R}) where {T,R,D} = apply(ta.t, ta.o, I...) | |
20 Base.size(ta::LazyTensorMappingApplication) = range_size(ta.t) | 18 Base.size(ta::LazyTensorMappingApplication) = range_size(ta.t) |
21 # TODO: What else is needed to implement the AbstractArray interface? | 19 # TODO: What else is needed to implement the AbstractArray interface? |
22 | 20 |
23 Base.:*(a::TensorMapping, v::AbstractArray) = LazyTensorMappingApplication(a,v) | 21 Base.:*(a::TensorMapping, v::AbstractArray) = LazyTensorMappingApplication(a,v) |
24 Base.:*(a::TensorMapping, b::TensorMapping) = throw(MethodError(Base.:*,(a,b))) | 22 Base.:*(a::TensorMapping, b::TensorMapping) = throw(MethodError(Base.:*,(a,b))) |
67 # TODO: Boundschecking in constructor. | 65 # TODO: Boundschecking in constructor. |
68 | 66 |
69 apply(tmBinOp::LazyTensorMappingBinaryOperation{:+,T,R,D}, v::AbstractArray{T,D}, I::Vararg{Any,R}) where {T,R,D} = apply(tmBinOp.tm1, v, I...) + apply(tmBinOp.tm2, v, I...) | 67 apply(tmBinOp::LazyTensorMappingBinaryOperation{:+,T,R,D}, v::AbstractArray{T,D}, I::Vararg{Any,R}) where {T,R,D} = apply(tmBinOp.tm1, v, I...) + apply(tmBinOp.tm2, v, I...) |
70 apply(tmBinOp::LazyTensorMappingBinaryOperation{:-,T,R,D}, v::AbstractArray{T,D}, I::Vararg{Any,R}) where {T,R,D} = apply(tmBinOp.tm1, v, I...) - apply(tmBinOp.tm2, v, I...) | 68 apply(tmBinOp::LazyTensorMappingBinaryOperation{:-,T,R,D}, v::AbstractArray{T,D}, I::Vararg{Any,R}) where {T,R,D} = apply(tmBinOp.tm1, v, I...) - apply(tmBinOp.tm2, v, I...) |
71 | 69 |
72 range_size(tmBinOp::LazyTensorMappingBinaryOperation{Op,T,R,D}) where {Op,T,R,D} = range_size(tmBinOp.tm1) | 70 range_size(tmBinOp::LazyTensorMappingBinaryOperation) = range_size(tmBinOp.tm1) |
73 domain_size(tmBinOp::LazyTensorMappingBinaryOperation{Op,T,R,D}) where {Op,T,R,D} = domain_size(tmBinOp.tm1) | 71 domain_size(tmBinOp::LazyTensorMappingBinaryOperation) = domain_size(tmBinOp.tm1) |
74 | 72 |
75 Base.:+(tm1::TensorMapping{T,R,D}, tm2::TensorMapping{T,R,D}) where {T,R,D} = LazyTensorMappingBinaryOperation{:+,T,R,D}(tm1,tm2) | 73 Base.:+(tm1::TensorMapping{T,R,D}, tm2::TensorMapping{T,R,D}) where {T,R,D} = LazyTensorMappingBinaryOperation{:+,T,R,D}(tm1,tm2) |
76 Base.:-(tm1::TensorMapping{T,R,D}, tm2::TensorMapping{T,R,D}) where {T,R,D} = LazyTensorMappingBinaryOperation{:-,T,R,D}(tm1,tm2) | 74 Base.:-(tm1::TensorMapping{T,R,D}, tm2::TensorMapping{T,R,D}) where {T,R,D} = LazyTensorMappingBinaryOperation{:-,T,R,D}(tm1,tm2) |
77 | 75 |
78 """ | 76 """ |
92 export TensorMappingComposition | 90 export TensorMappingComposition |
93 | 91 |
94 range_size(tm::TensorMappingComposition) = range_size(tm.t1) | 92 range_size(tm::TensorMappingComposition) = range_size(tm.t1) |
95 domain_size(tm::TensorMappingComposition) = domain_size(tm.t2) | 93 domain_size(tm::TensorMappingComposition) = domain_size(tm.t2) |
96 | 94 |
97 function apply(c::TensorMappingComposition{T,R,K,D}, v::AbstractArray{T,D}, I::Vararg{S,R} where S) where {T,R,K,D} | 95 function apply(c::TensorMappingComposition{T,R,K,D}, v::AbstractArray{T,D}, I::Vararg{Any,R}) where {T,R,K,D} |
98 apply(c.t1, c.t2*v, I...) | 96 apply(c.t1, c.t2*v, I...) |
99 end | 97 end |
100 | 98 |
101 function apply_transpose(c::TensorMappingComposition{T,R,K,D}, v::AbstractArray{T,R}, I::Vararg{S,D} where S) where {T,R,K,D} | 99 function apply_transpose(c::TensorMappingComposition{T,R,K,D}, v::AbstractArray{T,R}, I::Vararg{Any,D}) where {T,R,K,D} |
102 apply_transpose(c.t2, c.t1'*v, I...) | 100 apply_transpose(c.t2, c.t1'*v, I...) |
103 end | 101 end |
104 | 102 |
105 Base.@propagate_inbounds Base.:∘(s::TensorMapping, t::TensorMapping) = TensorMappingComposition(s,t) | 103 Base.@propagate_inbounds Base.:∘(s::TensorMapping, t::TensorMapping) = TensorMappingComposition(s,t) |
106 | 104 |