BSplinebasis
Loading...
Searching...
No Matches
Derivative.h
1/*
2 * ########################################################################
3 * The contents of this file is free and unencumbered software released into the
4 * public domain. For more information, please refer to <http://unlicense.org/>
5 * ########################################################################
6 */
7
8#ifndef BSPLINE_OPERATORS_DERIVATIVE_H
9#define BSPLINE_OPERATORS_DERIVATIVE_H
10
11#include <bspline/internal/misc.h>
12#include <bspline/operators/GenericOperators.h>
13
17namespace bspline::operators {
18namespace internal = bspline::internal;
19
27template <size_t n>
28class Derivative final : public Operator {
29 public:
36 static constexpr size_t outputOrder(size_t inputOrder) {
37 return std::max(n, inputOrder) - n;
38 }
39
55 template <typename T, size_t size>
56 std::array<T, outputOrder(size - 1) + 1> transform(
57 const std::array<T, size> &input,
59 [[maybe_unused]] size_t intervalIndex) const {
60 static_assert(size >= 1, "Arrays of size zero not supported.");
61 // The order of the input spline.
62 constexpr size_t SPLINE_ORDER = size - 1;
63 // The size of the output array.
64 constexpr size_t OUTPUT_SIZE = outputOrder(SPLINE_ORDER) + 1;
65
66 if constexpr (n > SPLINE_ORDER) {
67 return {static_cast<T>(0)};
68 } else {
69 std::array<T, OUTPUT_SIZE> retVal;
70 for (size_t i = 0; i < OUTPUT_SIZE; i++) {
71 retVal[i] = internal::facultyRatio<T>(i + n, i) * input[i + n];
72 }
73 return retVal;
74 }
75 }
76};
77
85template <size_t n>
87
88} // namespace bspline::operators
89#endif // BSPLINE_OPERATORS_DERIVATIVE_H
Derivative operator.
Definition Derivative.h:28
static constexpr size_t outputOrder(size_t inputOrder)
Returns the order of the output spline for a given input order.
Definition Derivative.h:36
std::array< T, outputOrder(size - 1)+1 > transform(const std::array< T, size > &input, const support::Grid< T > &grid, size_t intervalIndex) const
Applies operator to one interval.
Definition Derivative.h:56
Marker interface for operators.
Definition GenericOperators.h:23
Represents a global Grid.
Definition Grid.h:27
Operator definitions.
Definition CompoundOperators.h:13