@@ -39,14 +39,41 @@ function getindex(B::HeavisideSpline{T}, x::Number, k::Int) where T
39
39
x ∈ axes (B,1 ) && 1 ≤ k ≤ size (B,2 )|| throw (BoundsError ())
40
40
41
41
p = B. points
42
- n = length (p)
43
-
44
42
p[k] < x < p[k+ 1 ] && return one (T)
45
43
p[k] == x && return one (T)/ 2
46
44
p[k+ 1 ] == x && return one (T)/ 2
47
45
return zero (T)
48
46
end
49
47
48
+ function getindex (B:: Spline{-1,T} , x:: Number , k:: Int ) where T
49
+ x ∈ axes (B,1 ) && 1 ≤ k ≤ size (B,2 )|| throw (BoundsError ())
50
+
51
+ p = B. points
52
+ p[k+ 1 ] == x && return convert (T,Inf )
53
+ zero (T)
54
+ end
55
+
56
+
57
+
58
+ grid (L:: HeavisideSpline , n... ) = L. points[1 : end - 1 ] .+ diff (L. points)/ 2
59
+ plotgrid (L:: HeavisideSpline , n... ) = [L. points' ; L. points' ][2 : end - 1 ]
60
+ function plotgridvalues (f:: ApplyQuasiVector{<:Any,typeof(*),<:Tuple{HeavisideSpline,Any}} )
61
+ g = plotgrid (basis (f))
62
+ c = coefficients (f)
63
+ g,vec ([c' ; c' ])
64
+ end
65
+
66
+ function plotgrid (L:: Spline{-1} , n... )
67
+ p = L. points[2 : end - 1 ]
68
+ vec ([p' ; p' ; p' ])
69
+ end
70
+ function plotgridvalues (f:: ApplyQuasiVector{<:Any,typeof(*),<:Tuple{Spline{-1},Any}} )
71
+ g = plotgrid (basis (f))
72
+ c = coefficients (f)
73
+ g,vec ([zeros (1 ,length (c)); c' ; fill (NaN ,1 ,length (c))])
74
+ end
75
+
76
+
50
77
# Splines sample same number of points regardless of length.
51
78
grid (L:: HeavisideSpline , :: Integer ) = L. points[1 : end - 1 ] .+ diff (L. points)/ 2
52
79
grid (L:: LinearSpline , :: Integer ) = L. points
@@ -88,6 +115,17 @@ function diff(L::LinearSpline{T}; dims::Integer=1) where T
88
115
ApplyQuasiMatrix (* , HeavisideSpline {T} (x), D)
89
116
end
90
117
118
+ function diff (L:: HeavisideSpline{T} ; dims:: Integer = 1 ) where T
119
+ dims == 1 || error (" not implemented" )
120
+ n = size (L,2 )
121
+ x = L. points
122
+ D = BandedMatrix {T} (undef, (n- 1 ,n), (0 ,1 ))
123
+ d = diff (x)
124
+ D[band (0 )] .= - one (T)
125
+ D[band (1 )] .= one (T)
126
+ ApplyQuasiMatrix (* , Spline {-1,T} (x), D)
127
+ end
128
+
91
129
92
130
# #
93
131
# sum
@@ -99,6 +137,7 @@ function _sum(A::HeavisideSpline, dims)
99
137
end
100
138
101
139
function _sum (P:: LinearSpline , dims)
140
+ dims == 1 || error (" not implemented" )
102
141
d = diff (P. points)
103
142
ret = Array {float(eltype(d))} (undef, length (d)+ 1 )
104
143
ret[1 ] = d[1 ]/ 2
@@ -109,4 +148,10 @@ function _sum(P::LinearSpline, dims)
109
148
permutedims (ret)
110
149
end
111
150
112
- _cumsum (H:: HeavisideSpline{T} , dims) where T = LinearSpline (H. points) * tril (Ones {T} (length (H. points),length (H. points)- 1 ) .* diff (H. points)' ,- 1 )
151
+ function _sum (P:: Spline{-1,T} , dims) where T
152
+ dims == 1 || error (" not implemented" )
153
+ Ones {T} (1 , size (P,2 ))
154
+ end
155
+
156
+ _cumsum (H:: HeavisideSpline{T} , dims) where T = LinearSpline (H. points) * tril (Ones {T} (length (H. points),length (H. points)- 1 ) .* diff (H. points)' ,- 1 )
157
+ _cumsum (S:: Spline{-1,T} , dims) where T = HeavisideSpline (S. points) * tril (ones (T,length (S. points)- 1 ,length (S. points)- 2 ),- 1 )
0 commit comments