Mercurial > repos > public > sbplib_julia
annotate LazyTensors/src/lazy_operations.jl @ 199:a22b419bbdf0 boundary_conditions
Attempt fix for assertion inside constructor of LazyElementWiseOperation
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Sat, 22 Jun 2019 20:56:17 +0200 |
parents | b5c9be7f391c |
children | 9e737d19fcfe |
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 |
199
a22b419bbdf0
Attempt fix for assertion inside constructor of LazyElementWiseOperation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
198
diff
changeset
|
56 @inline function LazyElementwiseOperation{T,D,Op}(a::T1,b::T2) where {T,D,Op, T1<:AbstractArray{T,D}, T2<:AbstractArray{T,D}} |
a22b419bbdf0
Attempt fix for assertion inside constructor of LazyElementWiseOperation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
198
diff
changeset
|
57 # TODO: Remove boundscheck once assert can be turned off by |
a22b419bbdf0
Attempt fix for assertion inside constructor of LazyElementWiseOperation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
198
diff
changeset
|
58 # optimization flags. Ugly fix. |
a22b419bbdf0
Attempt fix for assertion inside constructor of LazyElementWiseOperation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
198
diff
changeset
|
59 # NOTE: Seems like adding the boundscheck introduces allocations. Can this |
a22b419bbdf0
Attempt fix for assertion inside constructor of LazyElementWiseOperation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
198
diff
changeset
|
60 # be fixed? Since boundscheck is removed when inlined into inbounds this |
a22b419bbdf0
Attempt fix for assertion inside constructor of LazyElementWiseOperation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
198
diff
changeset
|
61 # should not in practise effect performance. |
a22b419bbdf0
Attempt fix for assertion inside constructor of LazyElementWiseOperation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
198
diff
changeset
|
62 @boundscheck @assert size(a)==size(b) |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
63 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
|
64 end |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
65 end |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
66 |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
67 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
|
68 |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
69 # 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
|
70 # 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
|
71 # 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
|
72 # 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
|
73 # boundschecking differently. |
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 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
|
93 @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
|
94 throw(BoundsError([leo],[I...])) |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
95 end |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
96 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
|
97 end |
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 # 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
|
100 # can later be indexed into. Lazy operations are denoted by the usual operator followed by a tilde |
199
a22b419bbdf0
Attempt fix for assertion inside constructor of LazyElementWiseOperation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
198
diff
changeset
|
101 Base.@propagate_inbounds +̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:+}(a,b) |
a22b419bbdf0
Attempt fix for assertion inside constructor of LazyElementWiseOperation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
198
diff
changeset
|
102 Base.@propagate_inbounds -̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:-}(a,b) |
a22b419bbdf0
Attempt fix for assertion inside constructor of LazyElementWiseOperation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
198
diff
changeset
|
103 Base.@propagate_inbounds *̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:*}(a,b) |
a22b419bbdf0
Attempt fix for assertion inside constructor of LazyElementWiseOperation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
198
diff
changeset
|
104 Base.@propagate_inbounds /̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:/}(a,b) |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
105 |
199
a22b419bbdf0
Attempt fix for assertion inside constructor of LazyElementWiseOperation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
198
diff
changeset
|
106 Base.@propagate_inbounds Base.:+(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a +̃ b |
a22b419bbdf0
Attempt fix for assertion inside constructor of LazyElementWiseOperation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
198
diff
changeset
|
107 Base.@propagate_inbounds Base.:+(a::AbstractArray{T,D}, b::LazyArray{T,D}) where {T,D} = b + a |
a22b419bbdf0
Attempt fix for assertion inside constructor of LazyElementWiseOperation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
198
diff
changeset
|
108 Base.@propagate_inbounds Base.:-(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a -̃ b |
a22b419bbdf0
Attempt fix for assertion inside constructor of LazyElementWiseOperation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
198
diff
changeset
|
109 Base.@propagate_inbounds Base.:-(a::AbstractArray{T,D}, b::LazyArray{T,D}) where {T,D} = a -̃ b |
a22b419bbdf0
Attempt fix for assertion inside constructor of LazyElementWiseOperation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
198
diff
changeset
|
110 Base.@propagate_inbounds Base.:*(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a *̃ b |
a22b419bbdf0
Attempt fix for assertion inside constructor of LazyElementWiseOperation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
198
diff
changeset
|
111 Base.@propagate_inbounds Base.:*(a::AbstractArray{T,D},b::LazyArray{T,D}) where {T,D} = b * a |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
112 # TODO: / seems to be ambiguous |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
113 # 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
|
114 # 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
|
115 |
195
5413067d2c4a
Remove semicolon and some unneeded exports
Jonatan Werpers <jonatan@werpers.com>
parents:
194
diff
changeset
|
116 export +̃, -̃, *̃, /̃ |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
117 |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
118 |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
119 |
197
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
120 """ |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
121 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
|
122 |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
123 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
|
124 |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
125 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
|
126 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
|
127 the appropriate methods of `m`. |
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 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
|
130 tm::TensorMapping{T,R,D} |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
131 end |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
132 export LazyTensorMappingTranspose |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
133 |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
134 # # 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
|
135 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
|
136 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
|
137 |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
138 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
|
139 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
|
140 |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
141 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
|
142 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
|
143 |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
144 |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
145 |
190
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
146 # TODO: Write tests and documentation for LazyTensorMappingComposition |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
147 # 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
|
148 # t1::TensorMapping{T,R,K} |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
149 # t2::TensorMapping{T,K,D} |
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 # 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
|
153 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
154 # 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
|
155 # 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
|
156 # end |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
157 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
158 # 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
|
159 # 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
|
160 # end |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
161 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
162 # 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
|
163 # apply(c.t1, LazyTensorMappingApplication(c.t2,v), I...) |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
164 # end |
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 # 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
|
167 # apply_transpose(c.t2, LazyTensorMappingApplication(c.t1',v), I...) |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
168 # end |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
169 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
170 # # 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
|
171 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
172 # export → |