BSplinebasis
Loading...
Searching...
No Matches
ScalarOperators.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_SCALAROPERATORS_H
9#define BSPLINE_OPERATORS_SCALAROPERATORS_H
10
11#include <bspline/Spline.h>
12#include <bspline/operators/CompoundOperators.h>
13
17namespace bspline::operators {
18
28template <typename T, typename O>
29inline constexpr bool are_scalar_multiplication_types_v =
31
40template <typename S, typename O,
41 std::enable_if_t<are_scalar_multiplication_types_v<S, O>, bool> =
42 true>
44 private:
46 S _s;
48 O _o;
49
50 public:
60 ScalarMultiplication(S s, O o) : _s(std::move(s)), _o(std::move(o)){};
61
69 ScalarMultiplication(S s) : _s(s), _o(O{}){};
70
77 static constexpr size_t outputOrder(size_t inputOrder) {
78 return O::outputOrder(inputOrder);
79 }
80
96 template <typename T, size_t size>
97 auto transform(const std::array<T, size> &input, const support::Grid<T> &grid,
98 size_t intervalIndex) const {
99 auto a = _o.transform(input, grid, intervalIndex);
100
101 // Multiply a.
102 for (T &el : a) {
103 el *= static_cast<T>(_s);
104 }
105 return a;
106 }
107};
108
116template <typename S>
118
130template <
131 typename S, typename O,
132 std::enable_if_t<are_scalar_multiplication_types_v<S, O>, bool> = true>
134 return ScalarMultiplication(s, std::forward<O>(o));
135}
136
146template <
147 typename S, typename O,
148 std::enable_if_t<are_scalar_multiplication_types_v<S, O>, bool> = true>
150 return ScalarMultiplication(s, std::forward<O>(o));
151}
152
162template <
163 typename S, typename O,
164 std::enable_if_t<are_scalar_multiplication_types_v<S, O>, bool> = true>
166 return ScalarMultiplication(static_cast<S>(1) / s, std::forward<O>(o));
167}
168
178template <
179 typename S, typename O,
180 std::enable_if_t<are_scalar_multiplication_types_v<S, O>, bool> = true>
181auto operator+(O &&o, const S &s) {
182 return std::forward<O>(o) + ScalarMultiplication{s};
183}
184
194template <
195 typename S, typename O,
196 std::enable_if_t<are_scalar_multiplication_types_v<S, O>, bool> = true>
197auto operator+(const S &s, O &&o) {
198 return ScalarMultiplication{s} + std::forward<O>(o);
199}
200
210template <
211 typename S, typename O,
212 std::enable_if_t<are_scalar_multiplication_types_v<S, O>, bool> = true>
213auto operator-(O &&o, const S &s) {
214 return std::forward<O>(o) - ScalarMultiplication{s};
215}
216
226template <
227 typename S, typename O,
228 std::enable_if_t<are_scalar_multiplication_types_v<S, O>, bool> = true>
229auto operator-(const S &s, O &&o) {
230 return ScalarMultiplication{s} - std::forward<O>(o);
231}
232
243template <typename O, std::enable_if_t<is_operator_v<O>, bool> = true>
245 return ScalarMultiplication<int, O>(-1, std::forward<O>(o));
246}
247} // namespace bspline::operators
248#endif // BSPLINE_OPERATORS_SCALAROPERATORS_H
Marker interface for operators.
Definition GenericOperators.h:23
Multiplication operator for Operator and scalar.
Definition ScalarOperators.h:43
ScalarMultiplication(S s, O o)
Multiplication of scalar and Operator.
Definition ScalarOperators.h:60
ScalarMultiplication(S s)
Multiplication of scalar and a default constructed Operator.
Definition ScalarOperators.h:69
static constexpr size_t outputOrder(size_t inputOrder)
Returns the order of the output spline for a given input order.
Definition ScalarOperators.h:77
auto transform(const std::array< T, size > &input, const support::Grid< T > &grid, size_t intervalIndex) const
Applies operator to one interval.
Definition ScalarOperators.h:97
Represents a global Grid.
Definition Grid.h:27
Operator definitions.
Definition CompoundOperators.h:13
auto operator-(O1 &&o1, O2 &&o2)
Operator difference.
Definition CompoundOperators.h:244
auto operator+(O1 &&o1, O2 &&o2)
Operator sum.
Definition CompoundOperators.h:226
OperatorProduct< O1, O2 > operator*(O1 &&o1, O2 &&o2)
Operator multiplication operator.
Definition CompoundOperators.h:84
constexpr bool are_scalar_multiplication_types_v
Validates ScalarOperator template parameters.
Definition ScalarOperators.h:29
ScalarMultiplication< S, O > operator/(O &&o, const S &s)
The scalar division operator for an operator.
Definition ScalarOperators.h:165