Mercurial > repos > public > sbplib_julia
comparison src/LazyTensors/lazy_array.jl @ 1003:7ef605b8f132 refactor/lazy_tensors
Remove a bunch of todos
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sun, 20 Mar 2022 21:19:00 +0100 |
parents | 76e5682d0e52 |
children | 7fd37aab84fe |
comparison
equal
deleted
inserted
replaced
1002:271aa6ae1055 | 1003:7ef605b8f132 |
---|---|
59 end | 59 end |
60 | 60 |
61 end | 61 end |
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 # TODO: Move Op to be the first parameter? Compare to Binary operations | |
65 | 64 |
66 Base.size(v::LazyElementwiseOperation) = size(v.a) | 65 Base.size(v::LazyElementwiseOperation) = size(v.a) |
67 | 66 |
68 evaluate(leo::LazyElementwiseOperation{T,D,:+}, I::Vararg{Int,D}) where {T,D} = leo.a[I...] + leo.b[I...] | 67 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} = leo.a[I...] - leo.b[I...] | 68 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} = leo.a[I...] * leo.b[I...] | 69 evaluate(leo::LazyElementwiseOperation{T,D,:*}, I::Vararg{Int,D}) where {T,D} = leo.a[I...] * leo.b[I...] |
71 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} = leo.a[I...] / leo.b[I...] |
72 | 71 |
73 # TODO: Make sure boundschecking is done properly and that the lenght of the vectors are equal | |
74 # NOTE: Boundschecking in getindex functions now assumes that the size of the | |
75 # vectors in the LazyElementwiseOperation are the same size. If we remove the | |
76 # size assertion in the constructor we might have to handle | |
77 # boundschecking differently. | |
78 Base.@propagate_inbounds @inline function Base.getindex(leo::LazyElementwiseOperation{T,D}, I::Vararg{Int,D}) where {T,D} | 72 Base.@propagate_inbounds @inline function Base.getindex(leo::LazyElementwiseOperation{T,D}, I::Vararg{Int,D}) where {T,D} |
79 @boundscheck if !checkbounds(Bool, leo.a, I...) | 73 @boundscheck if !checkbounds(Bool, leo.a, I...) |
80 throw(BoundsError([leo], I...)) | 74 throw(BoundsError([leo], I...)) |
81 end | 75 end |
82 return evaluate(leo, I...) | 76 return evaluate(leo, I...) |