comparison src/LazyTensors/lazy_tensor_operations.jl @ 393:b14eacf823b6 feature/lazy_linear_map

Test applying LazyLinearMap to random vectors and matrices. Fix indentation
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Fri, 02 Oct 2020 14:56:03 +0200
parents 418cfd945715
children 7ad644d112de
comparison
equal deleted inserted replaced
392:418cfd945715 393:b14eacf823b6
99 99
100 # # Have i gone too crazy with the type parameters? Maybe they aren't all needed? 100 # # Have i gone too crazy with the type parameters? Maybe they aren't all needed?
101 101
102 # export → 102 # export →
103 """ 103 """
104 LazyLinearMap{T,R,D,...}(A, range_indicies, ) 104 LazyLinearMap{T,R,D,...}(A, range_indicies, domain_indicies)
105 105
106 TensorMapping defined by the AbstractArray A. `range_indicies` and `domain_indicies` define which indicies of A should 106 TensorMapping defined by the AbstractArray A. `range_indicies` and `domain_indicies` define which indicies of A should
107 be considerd the range and domain of the TensorMapping. 107 be considerd the range and domain of the TensorMapping.
108 """ 108 """
109 struct LazyLinearMap{T,R,D, RD, AA<:AbstractArray{T,RD}} <: TensorMapping{T,R,D} 109 struct LazyLinearMap{T,R,D, RD, AA<:AbstractArray{T,RD}} <: TensorMapping{T,R,D}
119 function apply(llm::LazyLinearMap{T,R,D}, v::AbstractArray{T,D}, I::Vararg{Index,R}) where {T,R,D} 119 function apply(llm::LazyLinearMap{T,R,D}, v::AbstractArray{T,D}, I::Vararg{Index,R}) where {T,R,D}
120 view_index = ntuple(i->:,ndims(llm.A)) 120 view_index = ntuple(i->:,ndims(llm.A))
121 for i ∈ 1:R 121 for i ∈ 1:R
122 view_index = Base.setindex(view_index, Int(I[i]), llm.range_indicies[i]) 122 view_index = Base.setindex(view_index, Int(I[i]), llm.range_indicies[i])
123 end 123 end
124
125 A_view = @view llm.A[view_index...] 124 A_view = @view llm.A[view_index...]
126
127 return sum(A_view.*v) 125 return sum(A_view.*v)
128 end 126 end