// Copyright (C) 2012-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup spop_strans //! @{ template arma_hot inline void spop_strans::apply_spmat(SpMat& out, const SpMat& X) { arma_extra_debug_sigprint(); typedef typename umat::elem_type ueT; const uword N = X.n_nonzero; if(N == uword(0)) { out.zeros(X.n_cols, X.n_rows); return; } umat locs(2, N); typename SpMat::const_iterator it = X.begin(); for(uword count = 0; count < N; ++count) { ueT* locs_ptr = locs.colptr(count); locs_ptr[0] = it.col(); locs_ptr[1] = it.row(); ++it; } const Col vals(const_cast(X.values), N, false); SpMat tmp(locs, vals, X.n_cols, X.n_rows); out.steal_mem(tmp); } template arma_hot inline void spop_strans::apply_proxy(SpMat& out, const T1& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename umat::elem_type ueT; const SpProxy p(X); const uword N = p.get_n_nonzero(); if(N == uword(0)) { out.zeros(p.get_n_cols(), p.get_n_rows()); return; } umat locs(2, N); Col vals(N); eT* vals_ptr = vals.memptr(); typename SpProxy::const_iterator_type it = p.begin(); for(uword count = 0; count < N; ++count) { ueT* locs_ptr = locs.colptr(count); locs_ptr[0] = it.col(); locs_ptr[1] = it.row(); vals_ptr[count] = (*it); ++it; } SpMat tmp(locs, vals, p.get_n_cols(), p.get_n_rows()); out.steal_mem(tmp); } template arma_hot inline void spop_strans::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); if(is_SpMat::value) { const unwrap_spmat tmp(in.m); spop_strans::apply_spmat(out, tmp.M); } else { spop_strans::apply_proxy(out, in.m); } } //! for transpose of non-complex matrices, redirected from spop_htrans::apply() template arma_hot inline void spop_strans::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); if(is_SpMat::value) { const unwrap_spmat tmp(in.m); spop_strans::apply_spmat(out, tmp.M); } else { spop_strans::apply_proxy(out, in.m); } } //! @}