From eda5bc26f44ee9a6f83dcf8c91f17296d7fc509d Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 12 Feb 2024 14:52:43 +0100 Subject: Move into version control --- .../include/armadillo_bits/glue_trapz_meat.hpp | 168 +++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 src/armadillo/include/armadillo_bits/glue_trapz_meat.hpp (limited to 'src/armadillo/include/armadillo_bits/glue_trapz_meat.hpp') diff --git a/src/armadillo/include/armadillo_bits/glue_trapz_meat.hpp b/src/armadillo/include/armadillo_bits/glue_trapz_meat.hpp new file mode 100644 index 0000000..ed7b577 --- /dev/null +++ b/src/armadillo/include/armadillo_bits/glue_trapz_meat.hpp @@ -0,0 +1,168 @@ +// SPDX-License-Identifier: Apache-2.0 +// +// Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au) +// Copyright 2008-2016 National ICT Australia (NICTA) +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + + +//! \addtogroup glue_trapz +//! @{ + + + +template +inline +void +glue_trapz::apply(Mat& out, const Glue& in) + { + arma_extra_debug_sigprint(); + + typedef typename T1::elem_type eT; + + const uword dim = in.aux_uword; + + const quasi_unwrap UX(in.A); + const quasi_unwrap UY(in.B); + + if( UX.is_alias(out) || UY.is_alias(out) ) + { + Mat tmp; + + glue_trapz::apply_noalias(tmp, UX.M, UY.M, dim); + + out.steal_mem(tmp); + } + else + { + glue_trapz::apply_noalias(out, UX.M, UY.M, dim); + } + } + + + +template +inline +void +glue_trapz::apply_noalias(Mat& out, const Mat& X, const Mat& Y, const uword dim) + { + arma_extra_debug_sigprint(); + + arma_debug_check( (dim > 1), "trapz(): argument 'dim' must be 0 or 1" ); + + arma_debug_check( ((X.is_vec() == false) && (X.is_empty() == false)), "trapz(): argument 'X' must be a vector" ); + + const uword N = X.n_elem; + + if(dim == 0) + { + arma_debug_check( (N != Y.n_rows), "trapz(): length of X must equal the number of rows in Y when dim=0" ); + } + else + if(dim == 1) + { + arma_debug_check( (N != Y.n_cols), "trapz(): length of X must equal the number of columns in Y when dim=1" ); + } + + if(N <= 1) + { + if(dim == 0) { out.zeros(1, Y.n_cols); } + else if(dim == 1) { out.zeros(Y.n_rows, 1); } + + return; + } + + const Col vec_X( const_cast(X.memptr()), X.n_elem, false, true ); + + const Col diff_X = diff(vec_X); + + if(dim == 0) + { + const Row diff_X_t( const_cast(diff_X.memptr()), diff_X.n_elem, false, true ); + + out = diff_X_t * (0.5 * (Y.rows(0, N-2) + Y.rows(1, N-1))); + } + else + if(dim == 1) + { + out = (0.5 * (Y.cols(0, N-2) + Y.cols(1, N-1))) * diff_X; + } + } + + + +template +inline +void +op_trapz::apply(Mat& out, const Op& in) + { + arma_extra_debug_sigprint(); + + typedef typename T1::elem_type eT; + + const uword dim = in.aux_uword_a; + + const quasi_unwrap UY(in.m); + + if(UY.is_alias(out)) + { + Mat tmp; + + op_trapz::apply_noalias(tmp, UY.M, dim); + + out.steal_mem(tmp); + } + else + { + op_trapz::apply_noalias(out, UY.M, dim); + } + } + + + +template +inline +void +op_trapz::apply_noalias(Mat& out, const Mat& Y, const uword dim) + { + arma_extra_debug_sigprint(); + + arma_debug_check( (dim > 1), "trapz(): argument 'dim' must be 0 or 1" ); + + uword N = 0; + + if(dim == 0) { N = Y.n_rows; } + else if(dim == 1) { N = Y.n_cols; } + + if(N <= 1) + { + if(dim == 0) { out.zeros(1, Y.n_cols); } + else if(dim == 1) { out.zeros(Y.n_rows, 1); } + + return; + } + + if(dim == 0) + { + out = sum( (0.5 * (Y.rows(0, N-2) + Y.rows(1, N-1))), 0 ); + } + else + if(dim == 1) + { + out = sum( (0.5 * (Y.cols(0, N-2) + Y.cols(1, N-1))), 1 ); + } + } + + + +//! @} -- cgit v1.2.1