Mercurial > repos > public > sbplib_julia
comparison src/LazyTensors/lazy_array.jl @ 1835:a6f28a8b8f3f refactor/lazy_tensors/elementwise_ops
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 09 Jan 2025 12:40:49 +0100 |
parents | dfb43fdac9fc |
children |
comparison
equal
deleted
inserted
replaced
1789:48eaa973159a | 1835:a6f28a8b8f3f |
---|---|
4 Array which is calculated 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 |
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 +̃, -̃, *̃, /̃ |