comparison src/LazyTensors/lazy_array.jl @ 374:99296cbb7bcd

Merge feature/lazy_function
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 30 Sep 2020 21:08:03 +0200
parents 33c360c3c6bc
children f65809a26a17
comparison
equal deleted inserted replaced
370:8e55dee6a1a1 374:99296cbb7bcd
13 size::NTuple{D,Int} 13 size::NTuple{D,Int}
14 end 14 end
15 15
16 Base.size(lca::LazyConstantArray) = lca.size 16 Base.size(lca::LazyConstantArray) = lca.size
17 Base.getindex(lca::LazyConstantArray{T,D}, I::Vararg{Int,D}) where {T,D} = lca.val 17 Base.getindex(lca::LazyConstantArray{T,D}, I::Vararg{Int,D}) where {T,D} = lca.val
18
19 """
20 LazyFunctionArray{F<:Function,T, D} <: LazyArray{T,D}
21
22 A lazy array where each element is defined by a function f(i,j,...)
23 """
24 struct LazyFunctionArray{F<:Function,T, D} <: LazyArray{T,D}
25 f::F
26 size::NTuple{D,Int}
27 end
28 export LazyFunctionArray
29
30 function LazyFunctionArray(f::F, size::NTuple{D,Int}) where {F<:Function,D}
31 T = typeof(f(ones(D)...))
32 return LazyFunctionArray{F,T,D}(f,size)
33 end
34
35 Base.size(lfa::LazyFunctionArray) = lfa.size
36
37 function Base.getindex(lfa::LazyFunctionArray{F,T,D}, I::Vararg{Int,D}) where {F,T,D}
38 @boundscheck checkbounds(lfa, I...)
39 return lfa.f(I...)
40 end
41
18 42
19 """ 43 """
20 LazyElementwiseOperation{T,D,Op} <: LazyArray{T,D} 44 LazyElementwiseOperation{T,D,Op} <: LazyArray{T,D}
21 Struct allowing for lazy evaluation of elementwise operations on AbstractArrays. 45 Struct allowing for lazy evaluation of elementwise operations on AbstractArrays.
22 46