Mercurial > repos > public > sbplib_julia
annotate LazyTensors/src/lazy_operations.jl @ 198:b5c9be7f391c boundary_conditions
Fix up some formatting
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 20 Jun 2019 23:28:02 +0200 |
parents | a340fa91b1fc |
children | a22b419bbdf0 9d9f7b0e514b |
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 |
198
b5c9be7f391c
Fix up some formatting
Jonatan Werpers <jonatan@werpers.com>
parents:
197
diff
changeset
|
11 |
b5c9be7f391c
Fix up some formatting
Jonatan Werpers <jonatan@werpers.com>
parents:
197
diff
changeset
|
12 |
196
b3c252280a19
Move LazyArray and make LazyTensorMappingApplication and LazyElementwiseOperation subtypes of it
Jonatan Werpers <jonatan@werpers.com>
parents:
195
diff
changeset
|
13 """ |
b3c252280a19
Move LazyArray and make LazyTensorMappingApplication and LazyElementwiseOperation subtypes of it
Jonatan Werpers <jonatan@werpers.com>
parents:
195
diff
changeset
|
14 LazyTensorMappingApplication{T,R,D} <: LazyArray{T,R} |
190
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 Struct for lazy application of a TensorMapping. Created using `*`. |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
17 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
18 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
|
19 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
|
20 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
|
21 """ |
196
b3c252280a19
Move LazyArray and make LazyTensorMappingApplication and LazyElementwiseOperation subtypes of it
Jonatan Werpers <jonatan@werpers.com>
parents:
195
diff
changeset
|
22 struct LazyTensorMappingApplication{T,R,D} <: LazyArray{T,R} |
190
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
23 t::TensorMapping{T,R,D} |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
24 o::AbstractArray{T,D} |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
25 end |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
26 export LazyTensorMappingApplication |
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.:*(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
|
29 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
30 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
|
31 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
|
32 # 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
|
33 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
34 # # 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
|
35 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
|
36 # # Should we overload some other infix binary operator? |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
37 # →(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
|
38 # 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
|
39 # 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
|
40 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
41 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
42 |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
43 """ |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
44 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
|
45 |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
46 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
|
47 |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
48 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
|
49 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
|
50 LazyElementwiseOperation is indexed. |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
51 """ |
196
b3c252280a19
Move LazyArray and make LazyTensorMappingApplication and LazyElementwiseOperation subtypes of it
Jonatan Werpers <jonatan@werpers.com>
parents:
195
diff
changeset
|
52 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
|
53 a::T1 |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
54 b::T2 |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
55 |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
56 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
|
57 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
|
58 end |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
59 end |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
60 |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
61 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
|
62 |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
63 # 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
|
64 # 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
|
65 # 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
|
66 # 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
|
67 # boundschecking differently. |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
68 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
|
69 @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
|
70 throw(BoundsError([leo],[I...])) |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
71 end |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
72 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
|
73 end |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
74 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
|
75 @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
|
76 throw(BoundsError([leo],[I...])) |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
77 end |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
78 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
|
79 end |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
80 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
|
81 @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
|
82 throw(BoundsError([leo],[I...])) |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
83 end |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
84 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
|
85 end |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
86 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
|
87 @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
|
88 throw(BoundsError([leo],[I...])) |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
89 end |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
90 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
|
91 end |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
92 |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
93 # 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
|
94 # 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
|
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 @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
|
99 |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
100 |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 # TODO: / seems to be ambiguous |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
108 # 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
|
109 # 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
|
110 |
195
5413067d2c4a
Remove semicolon and some unneeded exports
Jonatan Werpers <jonatan@werpers.com>
parents:
194
diff
changeset
|
111 export +̃, -̃, *̃, /̃ |
194
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 |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
114 |
197
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
115 """ |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
116 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
|
117 |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
118 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
|
119 |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
120 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
|
121 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
|
122 the appropriate methods of `m`. |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
123 """ |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
124 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
|
125 tm::TensorMapping{T,R,D} |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
126 end |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
127 export LazyTensorMappingTranspose |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
128 |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
129 # # 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
|
130 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
|
131 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
|
132 |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
133 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
|
134 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
|
135 |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
136 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
|
137 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
|
138 |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
139 |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
140 |
190
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
141 # TODO: Write tests and documentation for LazyTensorMappingComposition |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
142 # 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
|
143 # t1::TensorMapping{T,R,K} |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
144 # t2::TensorMapping{T,K,D} |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
145 # end |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
146 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
147 # 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
|
148 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
149 # 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
|
150 # 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
|
151 # end |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
152 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
153 # 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
|
154 # 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
|
155 # end |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
156 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
157 # 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
|
158 # apply(c.t1, LazyTensorMappingApplication(c.t2,v), I...) |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
159 # end |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
160 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
161 # 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
|
162 # apply_transpose(c.t2, LazyTensorMappingApplication(c.t1',v), I...) |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
163 # end |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
164 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
165 # # 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
|
166 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
167 # export → |