annotate LazyTensors/src/lazy_operations.jl @ 197:a340fa91b1fc boundary_conditions

Move transpose def to the bottom of the file
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 20 Jun 2019 23:26:43 +0200
parents b3c252280a19
children b5c9be7f391c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
190
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
1 """
196
b3c252280a19 Move LazyArray and make LazyTensorMappingApplication and LazyElementwiseOperation subtypes of it
Jonatan Werpers <jonatan@werpers.com>
parents: 195
diff changeset
2 LazyArray{T,D} <: AbstractArray{T,D}
b3c252280a19 Move LazyArray and make LazyTensorMappingApplication and LazyElementwiseOperation subtypes of it
Jonatan Werpers <jonatan@werpers.com>
parents: 195
diff changeset
3
b3c252280a19 Move LazyArray and make LazyTensorMappingApplication and LazyElementwiseOperation subtypes of it
Jonatan Werpers <jonatan@werpers.com>
parents: 195
diff changeset
4 Array which is calcualted lazily when indexing.
b3c252280a19 Move LazyArray and make LazyTensorMappingApplication and LazyElementwiseOperation subtypes of it
Jonatan Werpers <jonatan@werpers.com>
parents: 195
diff changeset
5
b3c252280a19 Move LazyArray and make LazyTensorMappingApplication and LazyElementwiseOperation subtypes of it
Jonatan Werpers <jonatan@werpers.com>
parents: 195
diff changeset
6 A subtype of `LazyArray` will use lazy version of `+`, `-`, `*`, `/`.
b3c252280a19 Move LazyArray and make LazyTensorMappingApplication and LazyElementwiseOperation subtypes of it
Jonatan Werpers <jonatan@werpers.com>
parents: 195
diff changeset
7 """
b3c252280a19 Move LazyArray and make LazyTensorMappingApplication and LazyElementwiseOperation subtypes of it
Jonatan Werpers <jonatan@werpers.com>
parents: 195
diff changeset
8 abstract type LazyArray{T,D} <: AbstractArray{T,D} end
b3c252280a19 Move LazyArray and make LazyTensorMappingApplication and LazyElementwiseOperation subtypes of it
Jonatan Werpers <jonatan@werpers.com>
parents: 195
diff changeset
9 export LazyArray
b3c252280a19 Move LazyArray and make LazyTensorMappingApplication and LazyElementwiseOperation subtypes of it
Jonatan Werpers <jonatan@werpers.com>
parents: 195
diff changeset
10
b3c252280a19 Move LazyArray and make LazyTensorMappingApplication and LazyElementwiseOperation subtypes of it
Jonatan Werpers <jonatan@werpers.com>
parents: 195
diff changeset
11 """
b3c252280a19 Move LazyArray and make LazyTensorMappingApplication and LazyElementwiseOperation subtypes of it
Jonatan Werpers <jonatan@werpers.com>
parents: 195
diff changeset
12 LazyTensorMappingApplication{T,R,D} <: LazyArray{T,R}
190
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
13
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
14 Struct for lazy application of a TensorMapping. Created using `*`.
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
15
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
16 Allows the result of a `TensorMapping` applied to a vector to be treated as an `AbstractArray`.
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
17 With a mapping `m` and a vector `v` the LazyTensorMappingApplication object can be created by `m*v`.
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
18 The actual result will be calcualted when indexing into `m*v`.
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
19 """
196
b3c252280a19 Move LazyArray and make LazyTensorMappingApplication and LazyElementwiseOperation subtypes of it
Jonatan Werpers <jonatan@werpers.com>
parents: 195
diff changeset
20 struct LazyTensorMappingApplication{T,R,D} <: LazyArray{T,R}
190
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
21 t::TensorMapping{T,R,D}
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
22 o::AbstractArray{T,D}
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
23 end
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
24 export LazyTensorMappingApplication
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
25
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
26 Base.:*(tm::TensorMapping{T,R,D}, o::AbstractArray{T,D}) where {T,R,D} = LazyTensorMappingApplication(tm,o)
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
27
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
28 Base.getindex(ta::LazyTensorMappingApplication{T,R,D}, I::Vararg) where {T,R,D} = apply(ta.t, ta.o, I...)
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
29 Base.size(ta::LazyTensorMappingApplication{T,R,D}) where {T,R,D} = range_size(ta.t,size(ta.o))
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
30 # TODO: What else is needed to implement the AbstractArray interface?
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
31
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
32
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
33 # # We need the associativity to be a→b→c = a→(b→c), which is the case for '→'
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
34 Base.:*(args::Union{TensorMapping{T}, AbstractArray{T}}...) where T = foldr(*,args)
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
35 # # Should we overload some other infix binary operator?
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
36 # →(tm::TensorMapping{T,R,D}, o::AbstractArray{T,D}) where {T,R,D} = LazyTensorMappingApplication(tm,o)
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
37 # TODO: We need to be really careful about good error messages.
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
38 # For example what happens if you try to multiply LazyTensorMappingApplication with a TensorMapping(wrong order)?
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
39
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
40
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
41
194
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
42 """
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
43 LazyElementwiseOperation{T,D,Op, T1<:AbstractArray{T,D}, T2 <: AbstractArray{T,D}} <: AbstractArray{T,D}
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
44
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
45 Struct allowing for lazy evaluation of elementwise operations on AbstractArrays.
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
46
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
47 A LazyElementwiseOperation contains two AbstractArrays of equal size,
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
48 together with an operation. The operations are carried out when the
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
49 LazyElementwiseOperation is indexed.
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
50 """
196
b3c252280a19 Move LazyArray and make LazyTensorMappingApplication and LazyElementwiseOperation subtypes of it
Jonatan Werpers <jonatan@werpers.com>
parents: 195
diff changeset
51 struct LazyElementwiseOperation{T,D,Op, T1<:AbstractArray{T,D}, T2 <: AbstractArray{T,D}} <: LazyArray{T,D}
194
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
52 a::T1
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
53 b::T2
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
54
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
55 function LazyElementwiseOperation{T,D,Op}(a::T1,b::T2) where {T,D,Op, T1<:AbstractArray{T,D}, T2<:AbstractArray{T,D}}
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
56 return new{T,D,Op,T1,T2}(a,b)
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
57 end
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
58 end
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
59
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
60 Base.size(v::LazyElementwiseOperation) = size(v.a)
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
61
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
62 # TODO: Make sure boundschecking is done properly and that the lenght of the vectors are equal
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
63 # NOTE: Boundschecking in getindex functions now assumes that the size of the
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
64 # vectors in the LazyElementwiseOperation are the same size. If we remove the
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
65 # size assertion in the constructor we might have to handle
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
66 # boundschecking differently.
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
67 Base.@propagate_inbounds @inline function Base.getindex(leo::LazyElementwiseOperation{T,D,:+}, I...) where {T,D}
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
68 @boundscheck if !checkbounds(Bool,leo.a,I...)
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
69 throw(BoundsError([leo],[I...]))
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
70 end
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
71 return leo.a[I...] + leo.b[I...]
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
72 end
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
73 Base.@propagate_inbounds @inline function Base.getindex(leo::LazyElementwiseOperation{T,D,:-}, I...) where {T,D}
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
74 @boundscheck if !checkbounds(Bool,leo.a,I...)
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
75 throw(BoundsError([leo],[I...]))
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
76 end
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
77 return leo.a[I...] - leo.b[I...]
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
78 end
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
79 Base.@propagate_inbounds @inline function Base.getindex(leo::LazyElementwiseOperation{T,D,:*}, I...) where {T,D}
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
80 @boundscheck if !checkbounds(Bool,leo.a,I...)
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
81 throw(BoundsError([leo],[I...]))
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
82 end
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
83 return leo.a[I...] * leo.b[I...]
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
84 end
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
85 Base.@propagate_inbounds @inline function Base.getindex(leo::LazyElementwiseOperation{T,D,:/}, I...) where {T,D}
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
86 @boundscheck if !checkbounds(Bool,leo.a,I...)
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
87 throw(BoundsError([leo],[I...]))
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
88 end
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
89 return leo.a[I...] / leo.b[I...]
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
90 end
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
91
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
92 # Define lazy operations for AbstractArrays. Operations constructs a LazyElementwiseOperation which
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
93 # can later be indexed into. Lazy operations are denoted by the usual operator followed by a tilde
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
94 @inline +̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:+}(a,b)
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
95 @inline -̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:-}(a,b)
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
96 @inline *̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:*}(a,b)
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
97 @inline /̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:/}(a,b)
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
98
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
99
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
100 Base.:+(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a +̃ b
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
101 Base.:+(a::AbstractArray{T,D}, b::LazyArray{T,D}) where {T,D} = b + a
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
102 Base.:-(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a -̃ b
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
103 Base.:-(a::AbstractArray{T,D}, b::LazyArray{T,D}) where {T,D} = a -̃ b
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
104 Base.:*(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a *̃ b
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
105 Base.:*(a::AbstractArray{T,D},b::LazyArray{T,D}) where {T,D} = b * a
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
106 # TODO: / seems to be ambiguous
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
107 # Base.:/(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a /̃ b
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
108 # Base.:/(a::AbstractArray{T,D},b::LazyArray{T,D}) where {T,D} = a /̃ b
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
109
195
5413067d2c4a Remove semicolon and some unneeded exports
Jonatan Werpers <jonatan@werpers.com>
parents: 194
diff changeset
110 export +̃, -̃, *̃, /̃
194
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
111
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
112
d30d42a11566 Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents: 190
diff changeset
113
197
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
114 """
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
115 LazyTensorMappingTranspose{T,R,D} <: TensorMapping{T,D,R}
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
116
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
117 Struct for lazy transpose of a TensorMapping.
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
118
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
119 If a mapping implements the the `apply_transpose` method this allows working with
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
120 the transpose of mapping `m` by using `m'`. `m'` will work as a regular TensorMapping lazily calling
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
121 the appropriate methods of `m`.
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
122 """
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
123 struct LazyTensorMappingTranspose{T,R,D} <: TensorMapping{T,D,R}
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
124 tm::TensorMapping{T,R,D}
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
125 end
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
126 export LazyTensorMappingTranspose
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
127
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
128 # # TBD: Should this be implemented on a type by type basis or through a trait to provide earlier errors?
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
129 Base.adjoint(t::TensorMapping) = LazyTensorMappingTranspose(t)
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
130 Base.adjoint(t::LazyTensorMappingTranspose) = t.tm
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
131
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
132 apply(tm::LazyTensorMappingTranspose{T,R,D}, v::AbstractArray{T,R}, I::Vararg) where {T,R,D} = apply_transpose(tm.tm, v, I...)
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
133 apply_transpose(tm::LazyTensorMappingTranspose{T,R,D}, v::AbstractArray{T,D}, I::Vararg) where {T,R,D} = apply(tm.tm, v, I...)
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
134
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
135 range_size(tmt::LazyTensorMappingTranspose{T,R,D}, d_size::NTuple{R,Integer}) where {T,R,D} = domain_size(tmt.tm, domain_size)
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
136 domain_size(tmt::LazyTensorMappingTranspose{T,R,D}, r_size::NTuple{D,Integer}) where {T,R,D} = range_size(tmt.tm, range_size)
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
137
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
138
a340fa91b1fc Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents: 196
diff changeset
139
190
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
140 # TODO: Write tests and documentation for LazyTensorMappingComposition
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
141 # struct LazyTensorMappingComposition{T,R,K,D} <: TensorMapping{T,R,D}
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
142 # t1::TensorMapping{T,R,K}
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
143 # t2::TensorMapping{T,K,D}
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
144 # end
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
145
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
146 # Base.:∘(s::TensorMapping{T,R,K}, t::TensorMapping{T,K,D}) where {T,R,K,D} = LazyTensorMappingComposition(s,t)
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
147
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
148 # function range_size(tm::LazyTensorMappingComposition{T,R,K,D}, domain_size::NTuple{D,Integer}) where {T,R,K,D}
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
149 # range_size(tm.t1, domain_size(tm.t2, domain_size))
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
150 # end
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
151
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
152 # function domain_size(tm::LazyTensorMappingComposition{T,R,K,D}, range_size::NTuple{R,Integer}) where {T,R,K,D}
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
153 # domain_size(tm.t1, domain_size(tm.t2, range_size))
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
154 # end
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
155
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
156 # function apply(c::LazyTensorMappingComposition{T,R,K,D}, v::AbstractArray{T,D}, I::Vararg) where {T,R,K,D}
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
157 # apply(c.t1, LazyTensorMappingApplication(c.t2,v), I...)
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
158 # end
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
159
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
160 # function apply_transpose(c::LazyTensorMappingComposition{T,R,K,D}, v::AbstractArray{T,D}, I::Vararg) where {T,R,K,D}
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
161 # apply_transpose(c.t2, LazyTensorMappingApplication(c.t1',v), I...)
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
162 # end
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
163
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
164 # # Have i gone too crazy with the type parameters? Maybe they aren't all needed?
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
165
8964b3165097 Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
166 # export →