20 #ifndef ACCESSORY_IMPL_H 21 #define ACCESSORY_IMPL_H 29 template <
typename T> T
conv_fft(
const T &A,
const T &B, std::string type);
30 template <
typename T> T
rotate(
const T &X, arma::uword shift_by,
bool slide_back =
true);
31 template <
typename T> T
diff(
const T &X, arma::uword deriv_order = 1);
51 for (arma::uword i = 0; i < deriv_order; ++i){
52 T offset(difference.n_rows, difference.n_cols);
54 offset.rows(1, offset.n_rows - 1) = difference.rows(0, difference.n_rows - 2);
55 difference = difference - offset;
56 difference.shed_row(0);
70 if (shift_by >= X.n_rows){
71 shift_by = shift_by - X.n_rows;
77 else if (shift_by == 1){
79 start = X.rows(1, X.n_rows - 1);
83 start = X.row(X.n_rows - 1);
84 end = X.rows(0, X.n_rows - 2);
89 start = X.rows(shift_by, X.n_rows - 1);
90 end = X.rows(0, shift_by - 1);
93 start = X.rows(X.n_rows - shift_by, X.n_rows - 1);
94 end = X.rows(0, X.n_rows - shift_by - 1);
98 return join_vert(start, end);
105 if (A.n_rows < B.n_rows){
106 throw std::invalid_argument(
"B must have the same number of rows or fewer rows than A");
109 if (type ==
"filter"){
110 arma::uword next_p2 = std::ceil(std::log(A.n_elem) / std::log(2));
111 arma::uword n = std::pow(2, next_p2);
112 arma::cx_mat A_hat = fft(A, n);
113 arma::cx_mat B_hat = fft(B, n);
114 arma::cx_mat
w = ifft(A_hat % B_hat, n);
115 w = w.rows(0, A.n_rows - 1);
116 return arma::real(w);
118 else if (type ==
"circular"){
120 T A_padded = join_vert(A, arma::zeros(B.n_rows- 1));
121 T B_padded = join_vert(B, arma::zeros(A.n_rows - 1));
123 arma::uword next_p2 = std::ceil(std::log(A.n_elem) / std::log(2));
124 arma::uword n = std::pow(2, next_p2);
126 arma::cx_mat A_hat = fft(A_padded, n);
127 arma::cx_mat B_hat = fft(B_padded, n);
128 arma::cx_mat
w = ifft(A_hat % B_hat, n);
129 return arma::real(w);
132 throw(std::invalid_argument(
"argument 'type' invalid"));
136 #endif // ACCESSORY_IMPL_H
T diff(const T &X, arma::uword deriv_order=1)
Vespucci::Math::diff.
T conv_fft(const T &A, const T &B, std::string type)
T rotate(const T &X, arma::uword shift_by, bool slide_back=true)
cmplx FADDEEVA() w(cmplx z, double relerr)
A namespace for "global" functions, including math functions.