diff src/LazyTensors/lazy_tensor_operations.jl @ 1005:becd95ba0fce refactor/lazy_tensors

Add bounds checking for lazy tensor application and clea up tests a bit
author Jonatan Werpers <jonatan@werpers.com>
date Sun, 20 Mar 2022 22:15:29 +0100
parents 271aa6ae1055
children d9476fede83d
line wrap: on
line diff
--- a/src/LazyTensors/lazy_tensor_operations.jl	Sun Mar 20 21:35:20 2022 +0100
+++ b/src/LazyTensors/lazy_tensor_operations.jl	Sun Mar 20 22:15:29 2022 +0100
@@ -1,7 +1,5 @@
-# TODO: We need to be really careful about good error messages.
 # TODO: Go over type parameters
 
-
 """
     LazyTensorApplication{T,R,D} <: LazyArray{T,R}
 
@@ -16,17 +14,19 @@
     o::AA
 
     function LazyTensorApplication(t::LazyTensor{<:Any,R,D}, o::AbstractArray{<:Any,D}) where {R,D}
+        @boundscheck check_domain_size(t, size(o))
         I = ntuple(i->1, range_dim(t))
         T = typeof(apply(t,o,I...))
         return new{T,R,D,typeof(t), typeof(o)}(t,o)
     end
 end
-# TODO: Do boundschecking on creation!
 
-Base.getindex(ta::LazyTensorApplication{T,R}, I::Vararg{Any,R}) where {T,R} = apply(ta.t, ta.o, I...)
-Base.getindex(ta::LazyTensorApplication{T,1}, I::CartesianIndex{1}) where {T} = apply(ta.t, ta.o, I.I...) # Would otherwise be caught in the previous method.
+function Base.getindex(ta::LazyTensorApplication{T,R}, I::Vararg{Any,R}) where {T,R}
+    @boundscheck checkbounds(ta, Int.(I)...)
+    return apply(ta.t, ta.o, I...)
+end
+Base.getindex(ta::LazyTensorApplication{T,1} where T, I::CartesianIndex{1}) = ta[Tuple(I)...] # Would otherwise be caught in the previous method.
 Base.size(ta::LazyTensorApplication) = range_size(ta.t)
-# TODO: What else is needed to implement the AbstractArray interface?
 
 
 """