Mercurial > repos > public > sbplib_julia
annotate LazyTensors/src/lazy_operations.jl @ 265:4308b500d6e7 boundary_conditions
Add ideas to TODO.txt
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Thu, 05 Dec 2019 09:25:31 +0100 |
parents | 8ffd9c2e2119 |
children |
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 |
237
1c6afdcfd657
Regretsies on the CartesianIndex stuff. Use Vararg instead
Jonatan Werpers <jonatan@werpers.com>
parents:
236
diff
changeset
|
30 Base.getindex(ta::LazyTensorMappingApplication{T,R,D}, I::Vararg{Int,R}) where {T,R,D} = apply(ta.t, ta.o, I) |
190
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 '→' |
257
d4cd4882ee9f
Improve error messages when multiblying with TensorMappings and add some tests for TensorOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
237
diff
changeset
|
35 Base.:*(a::TensorMapping{T,R,D}, b::TensorMapping{T,D,K}, args::Union{TensorMapping{T}, AbstractArray{T}}...) where {T,R,D,K} = foldr(*,(a,b,args...)) |
190
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 |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
41 """ |
263
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
42 LazyElementwiseOperation{T,D,Op,T1,T2} <: LazyArray{T,D} |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
43 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
|
44 |
264
8ffd9c2e2119
Update documentation and formating
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
263
diff
changeset
|
45 A LazyElementwiseOperation contains two datatypes T1, and T2, together with an operation, |
8ffd9c2e2119
Update documentation and formating
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
263
diff
changeset
|
46 where at least one of T1 and T2 is an AbstractArray, and one may be a Real. |
8ffd9c2e2119
Update documentation and formating
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
263
diff
changeset
|
47 The operations are carried out when the LazyElementwiseOperation is indexed. |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
48 """ |
264
8ffd9c2e2119
Update documentation and formating
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
263
diff
changeset
|
49 struct LazyElementwiseOperation{T,D,Op,T1,T2} <: LazyArray{T,D} |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
50 a::T1 |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
51 b::T2 |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
52 |
264
8ffd9c2e2119
Update documentation and formating
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
263
diff
changeset
|
53 @inline function LazyElementwiseOperation{T,D,Op}(a::T1,b::T2) where {T,D,Op,T1<:AbstractArray{T,D},T2<:AbstractArray{T,D}} |
207
f85a0b38f3ff
Change error type when doing element wise operations on lazy arrays of missmatching dimension
Jonatan Werpers <jonatan@werpers.com>
parents:
206
diff
changeset
|
54 @boundscheck if size(a) != size(b) |
f85a0b38f3ff
Change error type when doing element wise operations on lazy arrays of missmatching dimension
Jonatan Werpers <jonatan@werpers.com>
parents:
206
diff
changeset
|
55 throw(DimensionMismatch("dimensions must match")) |
f85a0b38f3ff
Change error type when doing element wise operations on lazy arrays of missmatching dimension
Jonatan Werpers <jonatan@werpers.com>
parents:
206
diff
changeset
|
56 end |
194
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 |
263
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
59 |
264
8ffd9c2e2119
Update documentation and formating
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
263
diff
changeset
|
60 @inline function LazyElementwiseOperation{T,D,Op}(a::T1,b::T2) where {T,D,Op,T1<:AbstractArray{T,D},T2<:Real} |
263
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
61 return new{T,D,Op,T1,T2}(a,b) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
62 end |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
63 |
264
8ffd9c2e2119
Update documentation and formating
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
263
diff
changeset
|
64 @inline function LazyElementwiseOperation{T,D,Op}(a::T1,b::T2) where {T,D,Op,T1<:Real,T2<:AbstractArray{T,D}} |
263
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
65 return new{T,D,Op,T1,T2}(a,b) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
66 end |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
67 end |
210
2aa33d0eef90
Add ability to add and subtract TensorMappings
Jonatan Werpers <jonatan@werpers.com>
parents:
209
diff
changeset
|
68 # TODO: Move Op to be the first parameter? Compare to Binary operations |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
69 |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
70 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
|
71 |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
72 # 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
|
73 # 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
|
74 # 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
|
75 # 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
|
76 # boundschecking differently. |
263
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
77 Base.@propagate_inbounds @inline function Base.getindex(leo::LazyElementwiseOperation{T,D,:+,T1,T2}, I::Vararg{Int,D}) where {T,D,T1<:AbstractArray{T,D},T2<:AbstractArray{T,D}} |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
78 @boundscheck if !checkbounds(Bool,leo.a,I...) |
237
1c6afdcfd657
Regretsies on the CartesianIndex stuff. Use Vararg instead
Jonatan Werpers <jonatan@werpers.com>
parents:
236
diff
changeset
|
79 throw(BoundsError([leo],I...)) |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
80 end |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
81 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
|
82 end |
263
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
83 |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
84 Base.@propagate_inbounds @inline function Base.getindex(leo::LazyElementwiseOperation{T,D,:-,T1,T2}, I::Vararg{Int,D}) where {T,D,T1<:AbstractArray{T,D},T2<:AbstractArray{T,D}} |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
85 @boundscheck if !checkbounds(Bool,leo.a,I...) |
237
1c6afdcfd657
Regretsies on the CartesianIndex stuff. Use Vararg instead
Jonatan Werpers <jonatan@werpers.com>
parents:
236
diff
changeset
|
86 throw(BoundsError([leo],I...)) |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
87 end |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
88 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
|
89 end |
263
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
90 |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
91 Base.@propagate_inbounds @inline function Base.getindex(leo::LazyElementwiseOperation{T,D,:*,T1,T2}, I::Vararg{Int,D}) where {T,D,T1<:AbstractArray{T,D},T2<:AbstractArray{T,D}} |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
92 @boundscheck if !checkbounds(Bool,leo.a,I...) |
237
1c6afdcfd657
Regretsies on the CartesianIndex stuff. Use Vararg instead
Jonatan Werpers <jonatan@werpers.com>
parents:
236
diff
changeset
|
93 throw(BoundsError([leo],I...)) |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
94 end |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
95 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
|
96 end |
263
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
97 |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
98 Base.@propagate_inbounds @inline function Base.getindex(leo::LazyElementwiseOperation{T,D,:/,T1,T2}, I::Vararg{Int,D}) where {T,D,T1<:AbstractArray{T,D},T2<:AbstractArray{T,D}} |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
99 @boundscheck if !checkbounds(Bool,leo.a,I...) |
237
1c6afdcfd657
Regretsies on the CartesianIndex stuff. Use Vararg instead
Jonatan Werpers <jonatan@werpers.com>
parents:
236
diff
changeset
|
100 throw(BoundsError([leo],I...)) |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
101 end |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
102 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
|
103 end |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
104 |
263
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
105 Base.@propagate_inbounds @inline function Base.getindex(leo::LazyElementwiseOperation{T,D,:+,T1,T2}, I::Vararg{Int,D}) where {T,D,T1<:AbstractArray{T,D},T2<:Real} |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
106 @boundscheck if !checkbounds(Bool,leo.a,I...) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
107 throw(BoundsError([leo],I...)) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
108 end |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
109 return leo.a[I...] + leo.b |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
110 end |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
111 |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
112 Base.@propagate_inbounds @inline function Base.getindex(leo::LazyElementwiseOperation{T,D,:-,T1,T2}, I::Vararg{Int,D}) where {T,D,T1<:AbstractArray{T,D},T2<:Real} |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
113 @boundscheck if !checkbounds(Bool,leo.a,I...) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
114 throw(BoundsError([leo],I...)) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
115 end |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
116 return leo.a[I...] - leo.b |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
117 end |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
118 |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
119 Base.@propagate_inbounds @inline function Base.getindex(leo::LazyElementwiseOperation{T,D,:*,T1,T2}, I::Vararg{Int,D}) where {T,D,T1<:AbstractArray{T,D},T2<:Real} |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
120 @boundscheck if !checkbounds(Bool,leo.a,I...) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
121 throw(BoundsError([leo],I...)) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
122 end |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
123 return leo.a[I...] * leo.b |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
124 end |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
125 |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
126 Base.@propagate_inbounds @inline function Base.getindex(leo::LazyElementwiseOperation{T,D,:/,T1,T2}, I::Vararg{Int,D}) where {T,D,T1<:AbstractArray{T,D},T2<:Real} |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
127 @boundscheck if !checkbounds(Bool,leo.a,I...) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
128 throw(BoundsError([leo],I...)) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
129 end |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
130 return leo.a[I...] / leo.b |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
131 end |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
132 |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
133 Base.@propagate_inbounds @inline function Base.getindex(leo::LazyElementwiseOperation{T,D,:+,T1,T2}, I::Vararg{Int,D}) where {T,D,T1<:Real,T2<:AbstractArray{T,D}} |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
134 @boundscheck if !checkbounds(Bool,leo.b,I...) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
135 throw(BoundsError([leo],I...)) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
136 end |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
137 return leo.a + leo.b[I...] |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
138 end |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
139 |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
140 Base.@propagate_inbounds @inline function Base.getindex(leo::LazyElementwiseOperation{T,D,:-,T1,T2}, I::Vararg{Int,D}) where {T,D,T1<:Real,T2<:AbstractArray{T,D}} |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
141 @boundscheck if !checkbounds(Bool,leo.b,I...) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
142 throw(BoundsError([leo],I...)) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
143 end |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
144 return leo.a - leo.b[I...] |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
145 end |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
146 |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
147 Base.@propagate_inbounds @inline function Base.getindex(leo::LazyElementwiseOperation{T,D,:*,T1,T2}, I::Vararg{Int,D}) where {T,D,T1<:Real,T2<:AbstractArray{T,D}} |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
148 @boundscheck if !checkbounds(Bool,leo.b,I...) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
149 throw(BoundsError([leo],I...)) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
150 end |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
151 return leo.a * leo.b[I...] |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
152 end |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
153 |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
154 Base.@propagate_inbounds @inline function Base.getindex(leo::LazyElementwiseOperation{T,D,:/,T1,T2}, I::Vararg{Int,D}) where {T,D,T1<:Real,T2<:AbstractArray{T,D}} |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
155 @boundscheck if !checkbounds(Bool,leo.b,I...) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
156 throw(BoundsError([leo],I...)) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
157 end |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
158 return leo.a / leo.b[I...] |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
159 end |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
160 |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
161 # 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
|
162 # can later be indexed into. Lazy operations are denoted by the usual operator followed by a tilde |
202
9e737d19fcfe
Fix formatting
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
199
diff
changeset
|
163 Base.@propagate_inbounds +̃(a::AbstractArray{T,D}, b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:+}(a,b) |
9e737d19fcfe
Fix formatting
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
199
diff
changeset
|
164 Base.@propagate_inbounds -̃(a::AbstractArray{T,D}, b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:-}(a,b) |
9e737d19fcfe
Fix formatting
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
199
diff
changeset
|
165 Base.@propagate_inbounds *̃(a::AbstractArray{T,D}, b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:*}(a,b) |
9e737d19fcfe
Fix formatting
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
199
diff
changeset
|
166 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
|
167 |
263
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
168 Base.@propagate_inbounds +̃(a::AbstractArray{T,D}, b::Real) where {T,D} = LazyElementwiseOperation{T,D,:+}(a,b) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
169 Base.@propagate_inbounds -̃(a::AbstractArray{T,D}, b::Real) where {T,D} = LazyElementwiseOperation{T,D,:-}(a,b) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
170 Base.@propagate_inbounds *̃(a::AbstractArray{T,D}, b::Real) where {T,D} = LazyElementwiseOperation{T,D,:*}(a,b) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
171 Base.@propagate_inbounds /̃(a::AbstractArray{T,D}, b::Real) where {T,D} = LazyElementwiseOperation{T,D,:/}(a,b) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
172 |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
173 Base.@propagate_inbounds +̃(a::Real, b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:+}(a,b) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
174 Base.@propagate_inbounds -̃(a::Real, b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:-}(a,b) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
175 Base.@propagate_inbounds *̃(a::Real, b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:*}(a,b) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
176 Base.@propagate_inbounds /̃(a::Real, b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:/}(a,b) |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
177 |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
178 |
b577b5f64530
Add lazy elementwise operations for array with scalar
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
257
diff
changeset
|
179 |
204
9d9f7b0e514b
Modify the implementation of elementwise operations to be more direct and add a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
198
diff
changeset
|
180 # NOTE: Är det knas att vi har till exempel * istället för .* ?? |
9d9f7b0e514b
Modify the implementation of elementwise operations to be more direct and add a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
198
diff
changeset
|
181 # Oklart om det ens går att lösa.. |
205
70e1f3401d82
Merge. Throw away tests written by Jonatan
Jonatan Werpers <jonatan@werpers.com>
diff
changeset
|
182 Base.@propagate_inbounds Base.:+(a::LazyArray{T,D}, b::LazyArray{T,D}) where {T,D} = a +̃ b |
202
9e737d19fcfe
Fix formatting
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
199
diff
changeset
|
183 Base.@propagate_inbounds Base.:+(a::LazyArray{T,D}, b::AbstractArray{T,D}) where {T,D} = a +̃ b |
205
70e1f3401d82
Merge. Throw away tests written by Jonatan
Jonatan Werpers <jonatan@werpers.com>
diff
changeset
|
184 Base.@propagate_inbounds Base.:+(a::AbstractArray{T,D}, b::LazyArray{T,D}) where {T,D} = a +̃ b |
204
9d9f7b0e514b
Modify the implementation of elementwise operations to be more direct and add a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
198
diff
changeset
|
185 |
205
70e1f3401d82
Merge. Throw away tests written by Jonatan
Jonatan Werpers <jonatan@werpers.com>
diff
changeset
|
186 Base.@propagate_inbounds Base.:-(a::LazyArray{T,D}, b::LazyArray{T,D}) where {T,D} = a -̃ b |
202
9e737d19fcfe
Fix formatting
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
199
diff
changeset
|
187 Base.@propagate_inbounds Base.:-(a::LazyArray{T,D}, b::AbstractArray{T,D}) where {T,D} = a -̃ b |
199
a22b419bbdf0
Attempt fix for assertion inside constructor of LazyElementWiseOperation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
198
diff
changeset
|
188 Base.@propagate_inbounds Base.:-(a::AbstractArray{T,D}, b::LazyArray{T,D}) where {T,D} = a -̃ b |
204
9d9f7b0e514b
Modify the implementation of elementwise operations to be more direct and add a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
198
diff
changeset
|
189 |
206
7b0650021b36
Remove implementations of elementwise operation for * and /
Jonatan Werpers <jonatan@werpers.com>
parents:
205
diff
changeset
|
190 # Element wise operation for `*` and `\` are not overloaded due to conflicts with the behavior |
7b0650021b36
Remove implementations of elementwise operation for * and /
Jonatan Werpers <jonatan@werpers.com>
parents:
205
diff
changeset
|
191 # of regular `*` and `/` for AbstractArrays. Use tilde versions instead. |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
192 |
195
5413067d2c4a
Remove semicolon and some unneeded exports
Jonatan Werpers <jonatan@werpers.com>
parents:
194
diff
changeset
|
193 export +̃, -̃, *̃, /̃ |
194
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
194 |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
195 |
d30d42a11566
Move all Lazy operation into the same module
Jonatan Werpers <jonatan@werpers.com>
parents:
190
diff
changeset
|
196 |
197
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
197 """ |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
198 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
|
199 |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
200 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
|
201 |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
202 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
|
203 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
|
204 the appropriate methods of `m`. |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
205 """ |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
206 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
|
207 tm::TensorMapping{T,R,D} |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
208 end |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
209 export LazyTensorMappingTranspose |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
210 |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
211 # # 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
|
212 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
|
213 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
|
214 |
237
1c6afdcfd657
Regretsies on the CartesianIndex stuff. Use Vararg instead
Jonatan Werpers <jonatan@werpers.com>
parents:
236
diff
changeset
|
215 apply(tm::LazyTensorMappingTranspose{T,R,D}, v::AbstractArray{T,R}, I::NTuple{D,Int}) where {T,R,D} = apply_transpose(tm.tm, v, I) |
1c6afdcfd657
Regretsies on the CartesianIndex stuff. Use Vararg instead
Jonatan Werpers <jonatan@werpers.com>
parents:
236
diff
changeset
|
216 apply_transpose(tm::LazyTensorMappingTranspose{T,R,D}, v::AbstractArray{T,D}, I::NTuple{R,Int}) where {T,R,D} = apply(tm.tm, v, I) |
197
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
217 |
232
a20bb4fac23d
Improve tests for LazyTensors
Jonatan Werpers <jonatan@werpers.com>
parents:
210
diff
changeset
|
218 range_size(tmt::LazyTensorMappingTranspose{T,R,D}, d_size::NTuple{R,Integer}) where {T,R,D} = domain_size(tmt.tm, d_size) |
a20bb4fac23d
Improve tests for LazyTensors
Jonatan Werpers <jonatan@werpers.com>
parents:
210
diff
changeset
|
219 domain_size(tmt::LazyTensorMappingTranspose{T,R,D}, r_size::NTuple{D,Integer}) where {T,R,D} = range_size(tmt.tm, r_size) |
197
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
220 |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
221 |
a340fa91b1fc
Move transpose def to the bottom of the file
Jonatan Werpers <jonatan@werpers.com>
parents:
196
diff
changeset
|
222 |
210
2aa33d0eef90
Add ability to add and subtract TensorMappings
Jonatan Werpers <jonatan@werpers.com>
parents:
209
diff
changeset
|
223 |
2aa33d0eef90
Add ability to add and subtract TensorMappings
Jonatan Werpers <jonatan@werpers.com>
parents:
209
diff
changeset
|
224 struct LazyTensorMappingBinaryOperation{Op,T,R,D,T1<:TensorMapping{T,R,D},T2<:TensorMapping{T,R,D}} <: TensorMapping{T,D,R} |
2aa33d0eef90
Add ability to add and subtract TensorMappings
Jonatan Werpers <jonatan@werpers.com>
parents:
209
diff
changeset
|
225 A::T1 |
2aa33d0eef90
Add ability to add and subtract TensorMappings
Jonatan Werpers <jonatan@werpers.com>
parents:
209
diff
changeset
|
226 B::T2 |
2aa33d0eef90
Add ability to add and subtract TensorMappings
Jonatan Werpers <jonatan@werpers.com>
parents:
209
diff
changeset
|
227 |
2aa33d0eef90
Add ability to add and subtract TensorMappings
Jonatan Werpers <jonatan@werpers.com>
parents:
209
diff
changeset
|
228 @inline function LazyTensorMappingBinaryOperation{Op,T,R,D}(A::T1,B::T2) where {Op,T,R,D, T1<:TensorMapping{T,R,D},T2<:TensorMapping{T,R,D}} |
2aa33d0eef90
Add ability to add and subtract TensorMappings
Jonatan Werpers <jonatan@werpers.com>
parents:
209
diff
changeset
|
229 return new{Op,T,R,D,T1,T2}(A,B) |
2aa33d0eef90
Add ability to add and subtract TensorMappings
Jonatan Werpers <jonatan@werpers.com>
parents:
209
diff
changeset
|
230 end |
2aa33d0eef90
Add ability to add and subtract TensorMappings
Jonatan Werpers <jonatan@werpers.com>
parents:
209
diff
changeset
|
231 end |
2aa33d0eef90
Add ability to add and subtract TensorMappings
Jonatan Werpers <jonatan@werpers.com>
parents:
209
diff
changeset
|
232 |
237
1c6afdcfd657
Regretsies on the CartesianIndex stuff. Use Vararg instead
Jonatan Werpers <jonatan@werpers.com>
parents:
236
diff
changeset
|
233 apply(mb::LazyTensorMappingBinaryOperation{:+,T,R,D}, v::AbstractArray{T,D}, I::NTuple{R,Int}) where {T,R,D} = apply(mb.A, v, I...) + apply(mb.B,v,I...) |
1c6afdcfd657
Regretsies on the CartesianIndex stuff. Use Vararg instead
Jonatan Werpers <jonatan@werpers.com>
parents:
236
diff
changeset
|
234 apply(mb::LazyTensorMappingBinaryOperation{:-,T,R,D}, v::AbstractArray{T,D}, I::NTuple{R,Int}) where {T,R,D} = apply(mb.A, v, I...) - apply(mb.B,v,I...) |
210
2aa33d0eef90
Add ability to add and subtract TensorMappings
Jonatan Werpers <jonatan@werpers.com>
parents:
209
diff
changeset
|
235 |
2aa33d0eef90
Add ability to add and subtract TensorMappings
Jonatan Werpers <jonatan@werpers.com>
parents:
209
diff
changeset
|
236 range_size(mp::LazyTensorMappingBinaryOperation{Op,T,R,D}, domain_size::NTuple{D,Integer}) where {Op,T,R,D} = range_size(mp.A, domain_size) |
2aa33d0eef90
Add ability to add and subtract TensorMappings
Jonatan Werpers <jonatan@werpers.com>
parents:
209
diff
changeset
|
237 domain_size(mp::LazyTensorMappingBinaryOperation{Op,T,R,D}, range_size::NTuple{R,Integer}) where {Op,T,R,D} = domain_size(mp.A, range_size) |
2aa33d0eef90
Add ability to add and subtract TensorMappings
Jonatan Werpers <jonatan@werpers.com>
parents:
209
diff
changeset
|
238 |
2aa33d0eef90
Add ability to add and subtract TensorMappings
Jonatan Werpers <jonatan@werpers.com>
parents:
209
diff
changeset
|
239 Base.:+(A::TensorMapping{T,R,D}, B::TensorMapping{T,R,D}) where {T,R,D} = LazyTensorMappingBinaryOperation{:+,T,R,D}(A,B) |
2aa33d0eef90
Add ability to add and subtract TensorMappings
Jonatan Werpers <jonatan@werpers.com>
parents:
209
diff
changeset
|
240 Base.:-(A::TensorMapping{T,R,D}, B::TensorMapping{T,R,D}) where {T,R,D} = LazyTensorMappingBinaryOperation{:-,T,R,D}(A,B) |
2aa33d0eef90
Add ability to add and subtract TensorMappings
Jonatan Werpers <jonatan@werpers.com>
parents:
209
diff
changeset
|
241 |
2aa33d0eef90
Add ability to add and subtract TensorMappings
Jonatan Werpers <jonatan@werpers.com>
parents:
209
diff
changeset
|
242 |
190
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
243 # TODO: Write tests and documentation for LazyTensorMappingComposition |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
244 # 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
|
245 # t1::TensorMapping{T,R,K} |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
246 # t2::TensorMapping{T,K,D} |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
247 # end |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
248 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
249 # 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
|
250 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
251 # 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
|
252 # 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
|
253 # end |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
254 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
255 # 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
|
256 # 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
|
257 # end |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
258 |
237
1c6afdcfd657
Regretsies on the CartesianIndex stuff. Use Vararg instead
Jonatan Werpers <jonatan@werpers.com>
parents:
236
diff
changeset
|
259 # function apply(c::LazyTensorMappingComposition{T,R,K,D}, v::AbstractArray{T,D}, I::NTuple{R,Int}) where {T,R,K,D} |
190
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
260 # apply(c.t1, LazyTensorMappingApplication(c.t2,v), I...) |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
261 # end |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
262 |
237
1c6afdcfd657
Regretsies on the CartesianIndex stuff. Use Vararg instead
Jonatan Werpers <jonatan@werpers.com>
parents:
236
diff
changeset
|
263 # function apply_transpose(c::LazyTensorMappingComposition{T,R,K,D}, v::AbstractArray{T,D}, I::NTuple{D,Int}) where {T,R,K,D} |
190
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
264 # apply_transpose(c.t2, LazyTensorMappingApplication(c.t1',v), I...) |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
265 # end |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
266 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
267 # # 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
|
268 |
8964b3165097
Break LazyTensors.jl into several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
269 # export → |