Mercurial > repos > public > sbplib_julia
comparison src/LazyTensors/lazy_array.jl @ 1854:654a2b7e6824 tooling/benchmarks
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sat, 11 Jan 2025 10:19:47 +0100 |
parents | dfb43fdac9fc |
children |
comparison
equal
deleted
inserted
replaced
1378:2b5480e2d4bf | 1854:654a2b7e6824 |
---|---|
1 """ | 1 """ |
2 LazyArray{T,D} <: AbstractArray{T,D} | 2 LazyArray{T,D} <: AbstractArray{T,D} |
3 | 3 |
4 Array which is calcualted lazily when indexing. | 4 Array which is calculated lazily when indexing. |
5 | 5 |
6 A subtype of `LazyArray` will use lazy version of `+`, `-`, `*`, `/`. | 6 A subtype of `LazyArray` will use lazy version of `+`, `-`, `*`, `/`. |
7 """ | 7 """ |
8 abstract type LazyArray{T,D} <: AbstractArray{T,D} end | 8 abstract type LazyArray{T,D} <: AbstractArray{T,D} end |
9 export LazyArray | |
10 | 9 |
11 struct LazyConstantArray{T,D} <: LazyArray{T,D} | 10 struct LazyConstantArray{T,D} <: LazyArray{T,D} |
12 val::T | 11 val::T |
13 size::NTuple{D,Int} | 12 size::NTuple{D,Int} |
14 end | 13 end |
23 """ | 22 """ |
24 struct LazyFunctionArray{F<:Function,T, D} <: LazyArray{T,D} | 23 struct LazyFunctionArray{F<:Function,T, D} <: LazyArray{T,D} |
25 f::F | 24 f::F |
26 size::NTuple{D,Int} | 25 size::NTuple{D,Int} |
27 end | 26 end |
28 export LazyFunctionArray | |
29 | 27 |
30 function LazyFunctionArray(f::F, size::NTuple{D,Int}) where {F<:Function,D} | 28 function LazyFunctionArray(f::F, size::NTuple{D,Int}) where {F<:Function,D} |
31 T = typeof(f(ones(Int, D)...)) | 29 T = typeof(f(ones(Int, D)...)) |
32 return LazyFunctionArray{F,T,D}(f,size) | 30 return LazyFunctionArray{F,T,D}(f,size) |
33 end | 31 end |
40 end | 38 end |
41 | 39 |
42 | 40 |
43 """ | 41 """ |
44 LazyElementwiseOperation{T,D,Op} <: LazyArray{T,D} | 42 LazyElementwiseOperation{T,D,Op} <: LazyArray{T,D} |
45 Struct allowing for lazy evaluation of elementwise operations on `AbstractArray`s. | 43 Struct allowing for lazy evaluation of element-wise operations on `AbstractArray`s. |
46 | 44 |
47 A `LazyElementwiseOperation` contains two arrays together with an operation. | 45 A `LazyElementwiseOperation` contains two arrays together with an operation. |
48 The operations are carried out when the `LazyElementwiseOperation` is indexed. | 46 The operations are carried out when the `LazyElementwiseOperation` is indexed. |
49 """ | 47 """ |
50 struct LazyElementwiseOperation{T,D,Op,T1<:AbstractArray{T,D},T2<:AbstractArray{T,D}} <: LazyArray{T,D} | 48 struct LazyElementwiseOperation{T,D,Op,T1<:AbstractArray{T,D},T2<:AbstractArray{T,D}} <: LazyArray{T,D} |
108 Base.@propagate_inbounds Base.:+(a::LazyArray{T,D}, b::T) where {T,D} = a +̃ b | 106 Base.@propagate_inbounds Base.:+(a::LazyArray{T,D}, b::T) where {T,D} = a +̃ b |
109 Base.@propagate_inbounds Base.:-(a::LazyArray{T,D}, b::T) where {T,D} = a -̃ b | 107 Base.@propagate_inbounds Base.:-(a::LazyArray{T,D}, b::T) where {T,D} = a -̃ b |
110 | 108 |
111 Base.@propagate_inbounds Base.:+(a::T, b::LazyArray{T,D}) where {T,D} = a +̃ b | 109 Base.@propagate_inbounds Base.:+(a::T, b::LazyArray{T,D}) where {T,D} = a +̃ b |
112 Base.@propagate_inbounds Base.:-(a::T, b::LazyArray{T,D}) where {T,D} = a -̃ b | 110 Base.@propagate_inbounds Base.:-(a::T, b::LazyArray{T,D}) where {T,D} = a -̃ b |
113 | |
114 export +̃, -̃, *̃, /̃ |