-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathTrivialTensorFun.jl
More file actions
43 lines (35 loc) · 1.13 KB
/
TrivialTensorFun.jl
File metadata and controls
43 lines (35 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
struct TrivialTensorFun{d, SS<:TensorSpaceND{d}, T<:Number} <: MultivariateFun{T, d}
space::SS
coefficients::AbstractVector{T}
iterator::TrivialTensorizer{d}
orders::Block{1, Int}
end
function TrivialTensorFun(iter::TrivialTensorizer{d},
cfs::AbstractVector{T}, blk::Block, sp::TensorSpaceND{d}) where {T<:Number,d}
TrivialTensorFun(sp, cfs, iter, blk)
end
(f::TrivialTensorFun)(x...) = evaluate(f, x...)
# TensorSpace evaluation
function evaluate(f::TrivialTensorFun{d, SS, T},x...) where {d, SS, T}
highest_order = f.orders.n[1]-1
n = length(f.coefficients)
# this could be lazy evaluated for the sparse case
A = T[Fun(f.space.spaces[i], [zeros(T, k);1])(x[i]) for k=0:highest_order, i=1:d]
result::T = 0
coef_counter::Int = 1
for i in f.iterator
tmp = f.coefficients[coef_counter]
if tmp != 0
tmp_res = 1
for k=1:d
tmp_res *= A[i[k], k]
end
result += tmp * tmp_res
end
coef_counter += 1
if coef_counter > n
break
end
end
return result
end