Interface AbstractHermiteSpline
The AbstractHermiteSpline
defines an interface to cubic Hermite splines with various possible implementations.
HermiteSpline.AbstractHermiteSpline
— TypeDefines interface for cubic Hermite Splines.
Base.append!
— Methodappend!(r::H, s::H) # H<:AbstractHermiteSpline
Concatenate Hermite splines r
and s
by appending all knots
, values
and derivative
of s
to r
.
The knot sequences of s
and t
must be compatible (ismonotone
). If knots last
(s)
and first
(r)
are identical and their values and derivatives coincide, the first knot of s
is ignored and will not be append.
See also vcat
Base.copy!
— Methodcopy(hdst::H, h::H) # where {H<:AbstractHermiteSpline}
Deep copy of h
into hdst
Base.copy
— Methodhc = copy(h::AbstractHermiteSpline)
Get (deep) copy of h
.
Base.eachindex
— Methodfor i in eachindex(h::AbstractHermiteSpline)
Iterate over knots
and control points.
Base.eltype
— Methodeltype(h::AbstractHermiteSpline)
Get type Tuple
type of knot
, value
, derivative
. This is the type of h[idx]
.
Base.first
— MethodBase.getindex
— Methodh::AbstractHermiteSpline
t, x, dx = h[i]
Get knotr value, value and derivative vector at knot index i
.
See also knot
, value
, derivative
Base.isempty
— Methodisempty(h::AbstractHermiteSpline)
knot
vector is empty or contains only one single knot.
See also length
Base.last
— MethodBase.length
— Methodn = length(h::AbstractHermiteSpline)
Get number of knots
Base.push!
— Methodpush!(h::AbstractHermiteSpline, t, x, dx)
Add knot
t
with value
x
and derivative
dx
.
Requires (and checks) ismonotone(h, t)
.
See also ismonotone
.
Base.reverse!
— Methodreverse!(h::AbstractHermiteSpline)
Reverse knot vector and coefficient vector(s).
Base.reverse
— Methodhr = reverse!(h::AbstractHermiteSpline)
Copy h
with reversed knot vector and coefficient vector(s).
Base.similar
— Methodsimilar(h::AbstractHermiteSpline)
Get empty spline of tyepof(h)
.
Base.values
— Methodt = values(h::AbstractHermiteSpline)
Get (possibly a generator of) values per knot. (Use collect
to create an Array
.)
See also value
, knots
, derivatives
Base.vcat
— Methodvcat(s::H, r::H, ...) # H<:AbstractHermiteSpline
Construct a new Hermite spline by concatenating r, s, ...
.
Same requirements as for append!
!
See also append!
HermiteSpline.boundedindex
— Methodi = boundedindex(h::AbstractHermiteSpline, t, [lo = 1])
Find index of knot
interval for parameter t
. Returns the index of the first or last knot
interval if t < first(h)
or t > last(h)
, respectvely, for extrapolation.
The result is undefined if isempty
See also index
HermiteSpline.derivative
— MethodHermiteSpline.derivatives
— Methodt = derivatives(h::AbstractHermiteSpline)
Get (possibly a generator of) derivative vectors per knot. (Use collect
to create an Array
.)
See also derivative
, knots
, valuess
HermiteSpline.hermitespline
— FunctionEmpty spline
s = hermitespline(n, type[, impl = :t_xdx])
s = hermitespline(Val(n), type, Val(impl))
s = hermitespline(SVector{n, type}[, impl = :t_xdx])
Construct empty Hermite spline with scalar knot type
and n
-vectors (SVector{n, type}
) for values
and derivatives
. To "fill" data use, e.g., push!
or append!
The implementation defines the storage layout. Possible values are :t_x_dx
, :t_xdx
and :txdx
, where speration by "_"
indicates use of a Vector
(e.g., for :t_x_dx
one for knots
, values
and derivatives
).
For n==1
, i.e., scalar values and derivatives, values and derivatives are stored as scalars of type
(not SVector{1, type}
).
Spline from data:
s = hermitespline(t, x, dx[, impl = :t_x_dx])
s = hermitespline(t, xdx[, impl = :t_xdx])
s = hermitespline(txdx[, impl = :txdx])
Construct Hermite spline from knots t
, values x
and derivatives dx
or vectors of tuples.
- The passed vectors must have equal length.
- The passed vectors are for exclusive use by
hermitespline
, the constructor doesn't copy!
See also AbstractHermiteSpline
HermiteSpline.index
— Methodi = index(h::AbstractHermiteSpline, t[, lo=1])
Find index of knot
interval for parameter t
.
The optional argument lo
defines the initial lower (left) bound for the binary serach, which must be a valid index!
The method returns an invalid index (0
or length(h)
) if t ∉ span(h)
. This method is intended for internal use.
See also piece
, boundedindex
HermiteSpline.isascending
— Methodisascending(h::AbstractHermiteSpline)
Does h
have knots
in ascending order? This is determined by testing the first two knots.
Requires not isempty
.
See also ismonotone
HermiteSpline.isindex
— MethodHermiteSpline.isindex
— Methodisindex(h::AbstractHermiteSpline, i, t)
Is i
a valid index for h
such that t
is within the i
-th knot
interval?
Returns false
if t < first(s)
or last(s) < t
(extrapolation).
See also index
HermiteSpline.ismonotone
— Functionismonotone(h::AbstractHermiteSpline)
Test if knot
sequence is strictly monotone. This method iterates over all knots
and is intended for (internal) checks.
Returns true
if isempty
ismonotone(h::AbstractHermiteSpline, t)
Test if t
could be added to the knot sequence such that the sequence is still (strictly) monotone. This method is is called by push!
Returns true
if isempty
, returns false
if t == last(h)
(zero length knot interval).
See also push!
HermiteSpline.knot
— MethodHermiteSpline.knots
— Methodt = knots(h::AbstractHermiteSpline)
Get (possibly a generator of) knot sequence. (Use collect
to create an Array
.)
See also knot
, values
, derivatives
HermiteSpline.knottype
— MethodHermiteSpline.piece
— Functionp = piece(h::AbstractHermiteSpline, i::Int)
p = piece(h::AbstractHermiteSpline, t[, i::Int])
Get HermitePiece
for evaluation from index i
or parameter t
. No search if t
is within i
-th interval.
- Requires not
isempty(h)
. - For indices, requires
1 <= i < length(h)
. - For parameters, computes
index
but returns the first or last piece ift ∉ span(h)
.
HermiteSpline.somepiece
— Methodp = somepiece(h::AbstractHermiteSpline)
Get some arbitrary, possibly invalid HermitePiece
for h
. The intended use is initialization of an undefine piece.
HermiteSpline.span
— Methodt0, t1 = span(h::AbstractHermiteSpline)
Get first
and last
knot
. They determine the parameter interval of h
.
The spline can certainly extrapolated beyond t0
or t1
. Note, however, that extrapolaiton is numerically unstable if the parameter is too far w.r.t. the length of the knot interval (evaluation of monomials away from $[0, 1]$).
HermiteSpline.value
— MethodHermiteSpline.valuetype
— MethodHermiteSpline.AbstractHermiteSpline
— MethodEvaluate AbstractHermiteSpline
h(t)
, delegates arguments to ev
.
See ev
HermiteSpline.ev
— Function(x, dx), idx = ev(h, t, ValueDerivative, idx) # value and derivative
x, dx = ev(h, t, ValueDerivative)
x_dx = collect(ev(h, range(t0, t1, length=n))) # from generator
x_dx = ev(h, ts::Vector, ValueDerivative[; issorted=false])
x, idx = ev(h, t, Value, idx) # value only
x = ev(h, t, Value)
x = collect(ev(h, range(t0, t1, length=n))) # from generator
x = ev(h, ts::Vector, Value[; issorted=false])
Evaluate AbstractHermiteSpline
h(t)
, provide (possibly reused) knot interval index idx
from previous evaluation. Compute value and derivative (x, dx)
or only value x
.
The evaluation at parameters ts
in a Vector
is more efficient if ts
is sorted (w.r.t isascending
) due to use of caches and because the current index
is stored for lookup. However, sorting ts
exclusively for a single pass of evaluation may be more expensive than point-location tests for an unsorted ts
.
- If
sorted = false
is passed, theev
sorts enforces sortingts
before evaluation (ifts
are not already sorted). The returned values apprear in the order ofts
as for input (i.e., in addition tosort!
there is an extra overhead for usingsortperm!
and applying the permutation). - If
sorted = true
is passed,ev
evaluates at parametersts
without assumptions on order.
Passing sorted = true
is not an assertion that parameters ts
are sorted but rather a hint that ev
shall not perform any sorting.
Alternative syntax
AbstractHermiteSpline
h
is a callable object, which delegates arguments to ev(h, t, ...)
.
output = h(t, ...) # output: see above
x = h(t) # default: value only