comparison src/LazyTensors/lazy_tensor_operations.jl @ 942:7829c09f8137 feature/tensormapping_application_promotion

Add promotion calculation of element type for LazyTensorMappingApplication
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 10 Mar 2022 11:13:34 +0100
parents 76e5682d0e52
children fb060e98ac0a
comparison
equal deleted inserted replaced
921:de1625deb27e 942:7829c09f8137
5 5
6 Allows the result of a `TensorMapping` applied to a vector to be treated as an `AbstractArray`. 6 Allows the result of a `TensorMapping` applied to a vector to be treated as an `AbstractArray`.
7 With a mapping `m` and a vector `v` the LazyTensorMappingApplication object can be created by `m*v`. 7 With a mapping `m` and a vector `v` the LazyTensorMappingApplication object can be created by `m*v`.
8 The actual result will be calcualted when indexing into `m*v`. 8 The actual result will be calcualted when indexing into `m*v`.
9 """ 9 """
10 struct LazyTensorMappingApplication{T,R,D, TM<:TensorMapping{T,R,D}, AA<:AbstractArray{T,D}} <: LazyArray{T,R} 10 struct LazyTensorMappingApplication{T,R,D, TM<:TensorMapping{<:Any,R,D}, AA<:AbstractArray{<:Any,D}} <: LazyArray{T,R}
11 t::TM 11 t::TM
12 o::AA 12 o::AA
13
14 function LazyTensorMappingApplication(t::TensorMapping{<:Any,R,D}, o::AbstractArray{<:Any,D}) where {R,D}
15 T = promote_type(eltype(t), eltype(o))
16 return new{T,R,D,typeof(t), typeof(o)}(t,o)
17 end
13 end 18 end
14 # TODO: Do boundschecking on creation! 19 # TODO: Do boundschecking on creation!
15 export LazyTensorMappingApplication 20 export LazyTensorMappingApplication
16 21
17 Base.getindex(ta::LazyTensorMappingApplication{T,R}, I::Vararg{Any,R}) where {T,R} = apply(ta.t, ta.o, I...) 22 Base.getindex(ta::LazyTensorMappingApplication{T,R}, I::Vararg{Any,R}) where {T,R} = apply(ta.t, ta.o, I...)