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_mixed_meat.hpp | 560 +++++++++++++++++++++ 1 file changed, 560 insertions(+) create mode 100644 src/armadillo/include/armadillo_bits/glue_mixed_meat.hpp (limited to 'src/armadillo/include/armadillo_bits/glue_mixed_meat.hpp') diff --git a/src/armadillo/include/armadillo_bits/glue_mixed_meat.hpp b/src/armadillo/include/armadillo_bits/glue_mixed_meat.hpp new file mode 100644 index 0000000..21b6dc4 --- /dev/null +++ b/src/armadillo/include/armadillo_bits/glue_mixed_meat.hpp @@ -0,0 +1,560 @@ +// 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_mixed +//! @{ + + + +//! matrix multiplication with different element types +template +inline +void +glue_mixed_times::apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_times>& X) + { + arma_extra_debug_sigprint(); + + typedef typename T1::elem_type in_eT1; + typedef typename T2::elem_type in_eT2; + + typedef typename eT_promoter::eT out_eT; + + const partial_unwrap tmp1(X.A); + const partial_unwrap tmp2(X.B); + + const typename partial_unwrap::stored_type& A = tmp1.M; + const typename partial_unwrap::stored_type& B = tmp2.M; + + const bool use_alpha = partial_unwrap::do_times || partial_unwrap::do_times; + const out_eT alpha = use_alpha ? (upgrade_val::apply(tmp1.get_val()) * upgrade_val::apply(tmp2.get_val())) : out_eT(0); + + const bool do_trans_A = partial_unwrap::do_trans; + const bool do_trans_B = partial_unwrap::do_trans; + + arma_debug_assert_trans_mul_size(A.n_rows, A.n_cols, B.n_rows, B.n_cols, "matrix multiplication"); + + const uword out_n_rows = (do_trans_A == false) ? A.n_rows : A.n_cols; + const uword out_n_cols = (do_trans_B == false) ? B.n_cols : B.n_rows; + + const bool alias = tmp1.is_alias(out) || tmp2.is_alias(out); + + if(alias == false) + { + out.set_size(out_n_rows, out_n_cols); + + gemm_mixed::apply(out, A, B, alpha); + } + else + { + Mat tmp(out_n_rows, out_n_cols, arma_nozeros_indicator()); + + gemm_mixed::apply(tmp, A, B, alpha); + + out.steal_mem(tmp); + } + } + + + +//! matrix addition with different element types +template +inline +void +glue_mixed_plus::apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_plus>& X) + { + arma_extra_debug_sigprint(); + + typedef typename T1::elem_type eT1; + typedef typename T2::elem_type eT2; + + typedef typename promote_type::result out_eT; + + promote_type::check(); + + const Proxy A(X.A); + const Proxy B(X.B); + + arma_debug_assert_same_size(A, B, "addition"); + + const uword n_rows = A.get_n_rows(); + const uword n_cols = A.get_n_cols(); + + out.set_size(n_rows, n_cols); + + out_eT* out_mem = out.memptr(); + const uword n_elem = out.n_elem; + + const bool use_at = (Proxy::use_at || Proxy::use_at); + + if(use_at == false) + { + typename Proxy::ea_type AA = A.get_ea(); + typename Proxy::ea_type BB = B.get_ea(); + + if(memory::is_aligned(out_mem)) + { + memory::mark_as_aligned(out_mem); + + for(uword i=0; i::apply(AA[i]) + upgrade_val::apply(BB[i]); + } + } + else + { + for(uword i=0; i::apply(AA[i]) + upgrade_val::apply(BB[i]); + } + } + } + else + { + for(uword col=0; col < n_cols; ++col) + for(uword row=0; row < n_rows; ++row) + { + (*out_mem) = upgrade_val::apply(A.at(row,col)) + upgrade_val::apply(B.at(row,col)); + out_mem++; + } + } + } + + + +//! matrix subtraction with different element types +template +inline +void +glue_mixed_minus::apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_minus>& X) + { + arma_extra_debug_sigprint(); + + typedef typename T1::elem_type eT1; + typedef typename T2::elem_type eT2; + + typedef typename promote_type::result out_eT; + + promote_type::check(); + + const Proxy A(X.A); + const Proxy B(X.B); + + arma_debug_assert_same_size(A, B, "subtraction"); + + const uword n_rows = A.get_n_rows(); + const uword n_cols = A.get_n_cols(); + + out.set_size(n_rows, n_cols); + + out_eT* out_mem = out.memptr(); + const uword n_elem = out.n_elem; + + const bool use_at = (Proxy::use_at || Proxy::use_at); + + if(use_at == false) + { + typename Proxy::ea_type AA = A.get_ea(); + typename Proxy::ea_type BB = B.get_ea(); + + if(memory::is_aligned(out_mem)) + { + memory::mark_as_aligned(out_mem); + + for(uword i=0; i::apply(AA[i]) - upgrade_val::apply(BB[i]); + } + } + else + { + for(uword i=0; i::apply(AA[i]) - upgrade_val::apply(BB[i]); + } + } + } + else + { + for(uword col=0; col < n_cols; ++col) + for(uword row=0; row < n_rows; ++row) + { + (*out_mem) = upgrade_val::apply(A.at(row,col)) - upgrade_val::apply(B.at(row,col)); + out_mem++; + } + } + } + + + +//! element-wise matrix division with different element types +template +inline +void +glue_mixed_div::apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_div>& X) + { + arma_extra_debug_sigprint(); + + typedef typename T1::elem_type eT1; + typedef typename T2::elem_type eT2; + + typedef typename promote_type::result out_eT; + + promote_type::check(); + + const Proxy A(X.A); + const Proxy B(X.B); + + arma_debug_assert_same_size(A, B, "element-wise division"); + + const uword n_rows = A.get_n_rows(); + const uword n_cols = A.get_n_cols(); + + out.set_size(n_rows, n_cols); + + out_eT* out_mem = out.memptr(); + const uword n_elem = out.n_elem; + + const bool use_at = (Proxy::use_at || Proxy::use_at); + + if(use_at == false) + { + typename Proxy::ea_type AA = A.get_ea(); + typename Proxy::ea_type BB = B.get_ea(); + + if(memory::is_aligned(out_mem)) + { + memory::mark_as_aligned(out_mem); + + for(uword i=0; i::apply(AA[i]) / upgrade_val::apply(BB[i]); + } + } + else + { + for(uword i=0; i::apply(AA[i]) / upgrade_val::apply(BB[i]); + } + } + } + else + { + for(uword col=0; col < n_cols; ++col) + for(uword row=0; row < n_rows; ++row) + { + (*out_mem) = upgrade_val::apply(A.at(row,col)) / upgrade_val::apply(B.at(row,col)); + out_mem++; + } + } + } + + + +//! element-wise matrix multiplication with different element types +template +inline +void +glue_mixed_schur::apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_schur>& X) + { + arma_extra_debug_sigprint(); + + typedef typename T1::elem_type eT1; + typedef typename T2::elem_type eT2; + + typedef typename promote_type::result out_eT; + + promote_type::check(); + + const Proxy A(X.A); + const Proxy B(X.B); + + arma_debug_assert_same_size(A, B, "element-wise multiplication"); + + const uword n_rows = A.get_n_rows(); + const uword n_cols = A.get_n_cols(); + + out.set_size(n_rows, n_cols); + + out_eT* out_mem = out.memptr(); + const uword n_elem = out.n_elem; + + const bool use_at = (Proxy::use_at || Proxy::use_at); + + if(use_at == false) + { + typename Proxy::ea_type AA = A.get_ea(); + typename Proxy::ea_type BB = B.get_ea(); + + if(memory::is_aligned(out_mem)) + { + memory::mark_as_aligned(out_mem); + + for(uword i=0; i::apply(AA[i]) * upgrade_val::apply(BB[i]); + } + } + else + { + for(uword i=0; i::apply(AA[i]) * upgrade_val::apply(BB[i]); + } + } + } + else + { + for(uword col=0; col < n_cols; ++col) + for(uword row=0; row < n_rows; ++row) + { + (*out_mem) = upgrade_val::apply(A.at(row,col)) * upgrade_val::apply(B.at(row,col)); + out_mem++; + } + } + } + + + +// +// +// + + + +//! cube addition with different element types +template +inline +void +glue_mixed_plus::apply(Cube::eT>& out, const mtGlueCube::eT, T1, T2, glue_mixed_plus>& X) + { + arma_extra_debug_sigprint(); + + typedef typename T1::elem_type eT1; + typedef typename T2::elem_type eT2; + + typedef typename promote_type::result out_eT; + + promote_type::check(); + + const ProxyCube A(X.A); + const ProxyCube B(X.B); + + arma_debug_assert_same_size(A, B, "addition"); + + const uword n_rows = A.get_n_rows(); + const uword n_cols = A.get_n_cols(); + const uword n_slices = A.get_n_slices(); + + out.set_size(n_rows, n_cols, n_slices); + + out_eT* out_mem = out.memptr(); + const uword n_elem = out.n_elem; + + const bool use_at = (ProxyCube::use_at || ProxyCube::use_at); + + if(use_at == false) + { + typename ProxyCube::ea_type AA = A.get_ea(); + typename ProxyCube::ea_type BB = B.get_ea(); + + for(uword i=0; i::apply(AA[i]) + upgrade_val::apply(BB[i]); + } + } + else + { + for(uword slice = 0; slice < n_slices; ++slice) + for(uword col = 0; col < n_cols; ++col ) + for(uword row = 0; row < n_rows; ++row ) + { + (*out_mem) = upgrade_val::apply(A.at(row,col,slice)) + upgrade_val::apply(B.at(row,col,slice)); + out_mem++; + } + } + } + + + +//! cube subtraction with different element types +template +inline +void +glue_mixed_minus::apply(Cube::eT>& out, const mtGlueCube::eT, T1, T2, glue_mixed_minus>& X) + { + arma_extra_debug_sigprint(); + + typedef typename T1::elem_type eT1; + typedef typename T2::elem_type eT2; + + typedef typename promote_type::result out_eT; + + promote_type::check(); + + const ProxyCube A(X.A); + const ProxyCube B(X.B); + + arma_debug_assert_same_size(A, B, "subtraction"); + + const uword n_rows = A.get_n_rows(); + const uword n_cols = A.get_n_cols(); + const uword n_slices = A.get_n_slices(); + + out.set_size(n_rows, n_cols, n_slices); + + out_eT* out_mem = out.memptr(); + const uword n_elem = out.n_elem; + + const bool use_at = (ProxyCube::use_at || ProxyCube::use_at); + + if(use_at == false) + { + typename ProxyCube::ea_type AA = A.get_ea(); + typename ProxyCube::ea_type BB = B.get_ea(); + + for(uword i=0; i::apply(AA[i]) - upgrade_val::apply(BB[i]); + } + } + else + { + for(uword slice = 0; slice < n_slices; ++slice) + for(uword col = 0; col < n_cols; ++col ) + for(uword row = 0; row < n_rows; ++row ) + { + (*out_mem) = upgrade_val::apply(A.at(row,col,slice)) - upgrade_val::apply(B.at(row,col,slice)); + out_mem++; + } + } + } + + + +//! element-wise cube division with different element types +template +inline +void +glue_mixed_div::apply(Cube::eT>& out, const mtGlueCube::eT, T1, T2, glue_mixed_div>& X) + { + arma_extra_debug_sigprint(); + + typedef typename T1::elem_type eT1; + typedef typename T2::elem_type eT2; + + typedef typename promote_type::result out_eT; + + promote_type::check(); + + const ProxyCube A(X.A); + const ProxyCube B(X.B); + + arma_debug_assert_same_size(A, B, "element-wise division"); + + const uword n_rows = A.get_n_rows(); + const uword n_cols = A.get_n_cols(); + const uword n_slices = A.get_n_slices(); + + out.set_size(n_rows, n_cols, n_slices); + + out_eT* out_mem = out.memptr(); + const uword n_elem = out.n_elem; + + const bool use_at = (ProxyCube::use_at || ProxyCube::use_at); + + if(use_at == false) + { + typename ProxyCube::ea_type AA = A.get_ea(); + typename ProxyCube::ea_type BB = B.get_ea(); + + for(uword i=0; i::apply(AA[i]) / upgrade_val::apply(BB[i]); + } + } + else + { + for(uword slice = 0; slice < n_slices; ++slice) + for(uword col = 0; col < n_cols; ++col ) + for(uword row = 0; row < n_rows; ++row ) + { + (*out_mem) = upgrade_val::apply(A.at(row,col,slice)) / upgrade_val::apply(B.at(row,col,slice)); + out_mem++; + } + } + } + + + +//! element-wise cube multiplication with different element types +template +inline +void +glue_mixed_schur::apply(Cube::eT>& out, const mtGlueCube::eT, T1, T2, glue_mixed_schur>& X) + { + arma_extra_debug_sigprint(); + + typedef typename T1::elem_type eT1; + typedef typename T2::elem_type eT2; + + typedef typename promote_type::result out_eT; + + promote_type::check(); + + const ProxyCube A(X.A); + const ProxyCube B(X.B); + + arma_debug_assert_same_size(A, B, "element-wise multiplication"); + + const uword n_rows = A.get_n_rows(); + const uword n_cols = A.get_n_cols(); + const uword n_slices = A.get_n_slices(); + + out.set_size(n_rows, n_cols, n_slices); + + out_eT* out_mem = out.memptr(); + const uword n_elem = out.n_elem; + + const bool use_at = (ProxyCube::use_at || ProxyCube::use_at); + + if(use_at == false) + { + typename ProxyCube::ea_type AA = A.get_ea(); + typename ProxyCube::ea_type BB = B.get_ea(); + + for(uword i=0; i::apply(AA[i]) * upgrade_val::apply(BB[i]); + } + } + else + { + for(uword slice = 0; slice < n_slices; ++slice) + for(uword col = 0; col < n_cols; ++col ) + for(uword row = 0; row < n_rows; ++row ) + { + (*out_mem) = upgrade_val::apply(A.at(row,col,slice)) * upgrade_val::apply(B.at(row,col,slice)); + out_mem++; + } + } + } + + + +//! @} -- cgit v1.2.1