comparison src/LazyTensors/lazy_array.jl @ 1015:4dd3c2312d9e refactor/lazy_tensors

Fix some @boundscheck @inboudns combos
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 21 Mar 2022 13:11:37 +0100
parents 7fd37aab84fe
children 6104db60b7a3
comparison
equal deleted inserted replaced
1013:56fe037641ef 1015:4dd3c2312d9e
34 34
35 Base.size(lfa::LazyFunctionArray) = lfa.size 35 Base.size(lfa::LazyFunctionArray) = lfa.size
36 36
37 function Base.getindex(lfa::LazyFunctionArray{F,T,D}, I::Vararg{Int,D}) where {F,T,D} 37 function Base.getindex(lfa::LazyFunctionArray{F,T,D}, I::Vararg{Int,D}) where {F,T,D}
38 @boundscheck checkbounds(lfa, I...) 38 @boundscheck checkbounds(lfa, I...)
39 return lfa.f(I...) 39 return @inbounds lfa.f(I...)
40 end 40 end
41 41
42 42
43 """ 43 """
44 LazyElementwiseOperation{T,D,Op} <: LazyArray{T,D} 44 LazyElementwiseOperation{T,D,Op} <: LazyArray{T,D}
62 LazyElementwiseOperation{T,D,Op}(a::AbstractArray{T,D},b::T) where {T,D,Op} = LazyElementwiseOperation{T,D,Op}(a, LazyConstantArray(b, size(a))) 62 LazyElementwiseOperation{T,D,Op}(a::AbstractArray{T,D},b::T) where {T,D,Op} = LazyElementwiseOperation{T,D,Op}(a, LazyConstantArray(b, size(a)))
63 LazyElementwiseOperation{T,D,Op}(a::T,b::AbstractArray{T,D}) where {T,D,Op} = LazyElementwiseOperation{T,D,Op}(LazyConstantArray(a, size(b)), b) 63 LazyElementwiseOperation{T,D,Op}(a::T,b::AbstractArray{T,D}) where {T,D,Op} = LazyElementwiseOperation{T,D,Op}(LazyConstantArray(a, size(b)), b)
64 64
65 Base.size(v::LazyElementwiseOperation) = size(v.a) 65 Base.size(v::LazyElementwiseOperation) = size(v.a)
66 66
67 evaluate(leo::LazyElementwiseOperation{T,D,:+}, I::Vararg{Int,D}) where {T,D} = @inbounds leo.a[I...] + leo.b[I...] 67 Base.@propagate_inbounds evaluate(leo::LazyElementwiseOperation{T,D,:+}, I::Vararg{Int,D}) where {T,D} = leo.a[I...] + leo.b[I...]
68 evaluate(leo::LazyElementwiseOperation{T,D,:-}, I::Vararg{Int,D}) where {T,D} = @inbounds leo.a[I...] - leo.b[I...] 68 Base.@propagate_inbounds evaluate(leo::LazyElementwiseOperation{T,D,:-}, I::Vararg{Int,D}) where {T,D} = leo.a[I...] - leo.b[I...]
69 evaluate(leo::LazyElementwiseOperation{T,D,:*}, I::Vararg{Int,D}) where {T,D} = @inbounds leo.a[I...] * leo.b[I...] 69 Base.@propagate_inbounds evaluate(leo::LazyElementwiseOperation{T,D,:*}, I::Vararg{Int,D}) where {T,D} = leo.a[I...] * leo.b[I...]
70 evaluate(leo::LazyElementwiseOperation{T,D,:/}, I::Vararg{Int,D}) where {T,D} = @inbounds leo.a[I...] / leo.b[I...] 70 Base.@propagate_inbounds evaluate(leo::LazyElementwiseOperation{T,D,:/}, I::Vararg{Int,D}) where {T,D} = leo.a[I...] / leo.b[I...]
71 71
72 function Base.getindex(leo::LazyElementwiseOperation{T,D}, I::Vararg{Int,D}) where {T,D} 72 function Base.getindex(leo::LazyElementwiseOperation{T,D}, I::Vararg{Int,D}) where {T,D}
73 @boundscheck checkbounds(leo.a, I...) 73 @boundscheck checkbounds(leo.a, I...)
74 return evaluate(leo, I...) 74 return @inbounds evaluate(leo, I...)
75 end 75 end
76 76
77 # Define lazy operations for AbstractArrays. Operations constructs a LazyElementwiseOperation which 77 # Define lazy operations for AbstractArrays. Operations constructs a LazyElementwiseOperation which
78 # can later be indexed into. Lazy operations are denoted by the usual operator followed by a tilde 78 # can later be indexed into. Lazy operations are denoted by the usual operator followed by a tilde
79 Base.@propagate_inbounds +̃(a::AbstractArray{T,D}, b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:+}(a,b) 79 Base.@propagate_inbounds +̃(a::AbstractArray{T,D}, b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:+}(a,b)