inline void op_nonzeros::apply_noalias(Mat<typename T1::elem_type>& out, const SpBase<typename T1::elem_type,T1>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy<T1> P(X.get_ref()); const uword N = P.get_n_nonzero(); out.set_size(N,1); if(N > 0) { if(is_SpMat<typename SpProxy<T1>::stored_type>::value) { const unwrap_spmat<typename SpProxy<T1>::stored_type> U(P.Q); arrayops::copy(out.memptr(), U.M.values, N); } else { eT* out_mem = out.memptr(); typename SpProxy<T1>::const_iterator_type it = P.begin(); for(uword i=0; i<N; ++i) { out_mem[i] = (*it); ++it; } } } }
inline void op_stddev::apply(Mat<typename T1::pod_type>& out, const mtOp<typename T1::pod_type, T1, op_stddev>& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type in_eT; typedef typename T1::pod_type out_eT; const unwrap_check_mixed<T1> tmp(in.m, out); const Mat<in_eT>& X = tmp.M; const uword norm_type = in.aux_uword_a; const uword dim = in.aux_uword_b; arma_debug_check( (norm_type > 1), "stddev(): incorrect usage. norm_type must be 0 or 1"); arma_debug_check( (dim > 1), "stddev(): incorrect usage. dim must be 0 or 1" ); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) { arma_extra_debug_print("op_stddev::apply(), dim = 0"); arma_debug_check( (X_n_rows == 0), "stddev(): given object has zero rows" ); out.set_size(1, X_n_cols); out_eT* out_mem = out.memptr(); for(uword col=0; col<X_n_cols; ++col) { out_mem[col] = std::sqrt( op_var::direct_var( X.colptr(col), X_n_rows, norm_type ) ); } } else if(dim == 1) { arma_extra_debug_print("op_stddev::apply(), dim = 1"); arma_debug_check( (X_n_cols == 0), "stddev(): given object has zero columns" ); out.set_size(X_n_rows, 1); podarray<in_eT> dat(X_n_cols); in_eT* dat_mem = dat.memptr(); out_eT* out_mem = out.memptr(); for(uword row=0; row<X_n_rows; ++row) { dat.copy_row(X, row); out_mem[row] = std::sqrt( op_var::direct_var( dat_mem, X_n_cols, norm_type) ); } } }
inline void op_vectorise_cube_col::apply_proxy(Mat<typename T1::elem_type>& out, const ProxyCube<T1>& P) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword N = P.get_n_elem(); out.set_size(N, 1); if(is_Cube<typename ProxyCube<T1>::stored_type>::value == true) { const unwrap_cube<typename ProxyCube<T1>::stored_type> tmp(P.Q); arrayops::copy(out.memptr(), tmp.M.memptr(), N); } else { eT* outmem = out.memptr(); if(ProxyCube<T1>::use_at == false) { typename ProxyCube<T1>::ea_type A = P.get_ea(); uword i,j; for(i=0, j=1; j < N; i+=2, j+=2) { const eT tmp_i = A[i]; const eT tmp_j = A[j]; outmem[i] = tmp_i; outmem[j] = tmp_j; } if(i < N) { outmem[i] = A[i]; } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const uword n_slices = P.get_n_slices(); for(uword slice=0; slice < n_slices; ++slice) for(uword col=0; col < n_cols; ++col ) for(uword row=0; row < n_rows; ++row ) { *outmem = P.at(row,col,slice); outmem++; } } } }
inline void interp1_helper_nearest(const Mat<eT>& XG, const Mat<eT>& YG, const Mat<eT>& XI, Mat<eT>& YI, const eT extrap_val) { arma_extra_debug_sigprint(); const eT XG_min = XG.min(); const eT XG_max = XG.max(); YI.copy_size(XI); const eT* XG_mem = XG.memptr(); const eT* YG_mem = YG.memptr(); const eT* XI_mem = XI.memptr(); eT* YI_mem = YI.memptr(); const uword NG = XG.n_elem; const uword NI = XI.n_elem; uword best_j = 0; for(uword i=0; i<NI; ++i) { eT best_err = Datum<eT>::inf; const eT XI_val = XI_mem[i]; if((XI_val < XG_min) || (XI_val > XG_max)) { YI_mem[i] = extrap_val; } else { // XG and XI are guaranteed to be sorted in ascending manner, // so start searching XG from last known optimum position for(uword j=best_j; j<NG; ++j) { const eT tmp = XG_mem[j] - XI_val; const eT err = (tmp >= eT(0)) ? tmp : -tmp; if(err >= best_err) { // error is going up, so we have found the optimum position break; } else { best_err = err; best_j = j; // remember the optimum position } } YI_mem[i] = YG_mem[best_j]; } } }
inline void op_fliplr::apply_direct(Mat<eT>& out, const Mat<eT>& X) { arma_extra_debug_sigprint(); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; const uword X_n_cols_m1 = X_n_cols - 1; if(&out != &X) { out.set_size(X_n_rows, X_n_cols); if(X_n_rows == 1) { const eT* X_mem = X.memptr(); eT* out_mem = out.memptr(); for(uword col=0; col < X_n_cols; ++col) { out_mem[X_n_cols_m1 - col] = X_mem[col]; } } else { for(uword col=0; col < X_n_cols; ++col) { out.col(X_n_cols_m1 - col) = X.col(col); } } } else // in-place operation { const uword N = X_n_cols / 2; if(X_n_rows == 1) { eT* out_mem = out.memptr(); for(uword col=0; col < N; ++col) { std::swap(out_mem[X_n_cols_m1 - col], out_mem[col]); } } else { for(uword col=0; col < N; ++col) { out.swap_cols(X_n_cols_m1 - col, col); } } } }
arma_hot inline void op_sum::apply_noalias_proxy(Mat<typename T1::elem_type>& out, const Proxy<T1>& P, const uword dim) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword P_n_rows = P.get_n_rows(); const uword P_n_cols = P.get_n_cols(); if(dim == 0) { out.set_size(1, P_n_cols); eT* out_mem = out.memptr(); for(uword col=0; col < P_n_cols; ++col) { eT val1 = eT(0); eT val2 = eT(0); uword i,j; for(i=0, j=1; j < P_n_rows; i+=2, j+=2) { val1 += P.at(i,col); val2 += P.at(j,col); } if(i < P_n_rows) { val1 += P.at(i,col); } out_mem[col] = (val1 + val2); } } else { out.zeros(P_n_rows, 1); eT* out_mem = out.memptr(); for(uword col=0; col < P_n_cols; ++col) for(uword row=0; row < P_n_rows; ++row) { out_mem[row] += P.at(row,col); } } }
inline void op_min::apply_noalias(Mat<eT>& out, const Mat<eT>& X, const uword dim, const typename arma_not_cx<eT>::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) { arma_extra_debug_print("op_min::apply(): dim = 0"); out.set_size((X_n_rows > 0) ? 1 : 0, X_n_cols); if(X_n_rows == 0) { return; } eT* out_mem = out.memptr(); for(uword col=0; col<X_n_cols; ++col) { out_mem[col] = op_min::direct_min( X.colptr(col), X_n_rows ); } } else if(dim == 1) { arma_extra_debug_print("op_min::apply(): dim = 1"); out.set_size(X_n_rows, (X_n_cols > 0) ? 1 : 0); if(X_n_cols == 0) { return; } eT* out_mem = out.memptr(); arrayops::copy(out_mem, X.colptr(0), X_n_rows); for(uword col=1; col<X_n_cols; ++col) { const eT* col_mem = X.colptr(col); for(uword row=0; row<X_n_rows; ++row) { const eT col_val = col_mem[row]; if(col_val < out_mem[row]) { out_mem[row] = col_val; } } } } }
inline void glue_cov::direct_cov(Mat< std::complex<T> >& out, const Mat< std::complex<T> >& A, const Mat< std::complex<T> >& B, const u32 norm_type) { arma_extra_debug_sigprint(); typedef typename std::complex<T> eT; if(A.is_vec() && B.is_vec()) { arma_debug_check( (A.n_elem != B.n_elem), "cov(): the number of elements in A and B must match" ); const eT* A_ptr = A.memptr(); const eT* B_ptr = B.memptr(); eT A_acc = eT(0); eT B_acc = eT(0); eT out_acc = eT(0); const u32 N = A.n_elem; for(u32 i=0; i<N; ++i) { const eT A_tmp = A_ptr[i]; const eT B_tmp = B_ptr[i]; A_acc += A_tmp; B_acc += B_tmp; out_acc += std::conj(A_tmp) * B_tmp; } out_acc -= (std::conj(A_acc) * B_acc)/eT(N); const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N); out.set_size(1,1); out[0] = out_acc/norm_val; } else { arma_debug_assert_same_size(A, B, "cov()"); const u32 N = A.n_rows; const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N); out = trans(A) * B; // out = strans(conj(A)) * B; out -= (trans(sum(A)) * sum(B))/eT(N); // out -= (strans(conj(sum(A))) * sum(B))/eT(N); out /= norm_val; } }
inline void op_max::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_max>& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check<T1> tmp(in.m, out); const Mat<eT>& X = tmp.M; const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "max(): incorrect usage. dim must be 0 or 1"); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) { arma_extra_debug_print("op_max::apply(), dim = 0"); arma_debug_check( (X_n_rows == 0), "max(): given object has zero rows" ); out.set_size(1, X_n_cols); eT* out_mem = out.memptr(); for(uword col=0; col<X_n_cols; ++col) { out_mem[col] = op_max::direct_max( X.colptr(col), X_n_rows ); } } else if(dim == 1) { arma_extra_debug_print("op_max::apply(), dim = 1"); arma_debug_check( (X_n_cols == 0), "max(): given object has zero columns" ); out.set_size(X_n_rows, 1); eT* out_mem = out.memptr(); for(uword row=0; row<X_n_rows; ++row) { out_mem[row] = op_max::direct_max( X, row ); } } }
inline void internal_regspace_default_delta ( Mat<eT>& x, const typename Mat<eT>::pod_type start, const typename Mat<eT>::pod_type end ) { arma_extra_debug_sigprint(); typedef typename Mat<eT>::pod_type T; const bool ascend = (start <= end); const uword N = uword(1) + uword((ascend) ? (end-start) : (start-end)); x.set_size(N); eT* x_mem = x.memptr(); if(ascend) { for(uword i=0; i < N; ++i) { x_mem[i] = eT(start + T(i)); } } else { for(uword i=0; i < N; ++i) { x_mem[i] = eT(start - T(i)); } } }
inline void glue_cross::apply(Mat<typename T1::elem_type>& out, const Glue<T1, T2, glue_cross>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename Proxy<T1>::ea_type ea_type1; typedef typename Proxy<T2>::ea_type ea_type2; const Proxy<T1> A(X.A); const Proxy<T2> B(X.B); arma_debug_check( ((A.get_n_elem() != 3) || (B.get_n_elem() != 3)), "cross(): input vectors must have 3 elements" ); out.set_size(A.get_n_rows(), A.get_n_cols()); eT* out_mem = out.memptr(); ea_type1 PA = A.get_ea(); ea_type2 PB = B.get_ea(); const eT ax = PA[0]; const eT ay = PA[1]; const eT az = PA[2]; const eT bx = PB[0]; const eT by = PB[1]; const eT bz = PB[2]; out_mem[0] = ay*bz - az*by; out_mem[1] = az*bx - ax*bz; out_mem[2] = ax*by - ay*bx; }
inline void op_cx_scalar_minus_pre::apply ( Mat< typename std::complex<typename T1::pod_type> >& out, const mtOp<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_minus_pre>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex<typename T1::pod_type> eT; typedef typename T1::pod_type T; const Proxy<T1> A(X.m); out.set_size(A.n_rows, A.n_cols); const u32 n_elem = A.n_elem; const eT k = X.aux_out_eT; eT* out_mem = out.memptr(); for(u32 i=0; i<n_elem; ++i) { out_mem[i] = k - A[i]; } }
inline void glue_rel_lteq::apply ( Mat <u32>& out, const mtGlue<u32, T1, T2, glue_rel_lteq>& X ) { arma_extra_debug_sigprint(); const Proxy<T1> A(X.A); const Proxy<T2> B(X.B); arma_debug_assert_same_size(A, B, "operator<="); out.set_size(A.n_rows, A.n_cols); const u32 n_elem = A.n_elem; u32* out_mem = out.memptr(); for(u32 i=0; i<n_elem; ++i) { out_mem[i] = (A[i] <= B[i]) ? u32(1) : u32(0); } }
inline void op_cumsum_vec::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_cumsum_vec>& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap<T1> tmp(in.m); const Mat<eT>& X = tmp.M; const uword n_elem = X.n_elem; out.copy_size(X); eT* out_mem = out.memptr(); const eT* X_mem = X.memptr(); eT acc = eT(0); for(uword i=0; i<n_elem; ++i) { acc += X_mem[i]; out_mem[i] = acc; } }
arma_hot inline void eop_core<eop_type>::apply(Mat<typename T1::elem_type>& out, const eOp<T1, eop_type>& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing; // size setting and alias checking is done by either the Mat contructor or operator=() const eT k = x.aux; eT* out_mem = out.memptr(); if(Proxy<T1>::prefer_at_accessor == false) { const uword n_elem = (Proxy<T1>::is_fixed) ? x.get_n_elem() : out.n_elem; //if(memory::is_aligned(out_mem)) if( memory::is_aligned(out_mem) && ((Proxy<T1>::is_fixed) ? (x.get_n_elem() >= 32) : true) ) { memory::mark_as_aligned(out_mem); if(x.P.is_aligned()) { typename Proxy<T1>::aligned_ea_type P = x.P.get_aligned_ea(); arma_applier_1a(=); } else {
inline void diagview<eT>::div_inplace(Mat<eT>& out, const diagview<eT>& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols, "element-wise division"); const Mat<eT>& in_m = in.m; const uword in_n_elem = in.n_elem; const uword in_row_offset = in.row_offset; const uword in_col_offset = in.col_offset; eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j < in_n_elem; i+=2, j+=2) { const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset ); const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset ); out_mem[i] /= tmp_i; out_mem[j] /= tmp_j; } if(i < in_n_elem) { out_mem[i] /= in_m.at( i + in_row_offset, i + in_col_offset ); } }
inline void diagview<eT>::extract(Mat<eT>& out, const diagview<eT>& in) { arma_extra_debug_sigprint(); // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing; // size setting and alias checking is done by either the Mat contructor or operator=() const Mat<eT>& in_m = in.m; const uword in_n_elem = in.n_elem; const uword in_row_offset = in.row_offset; const uword in_col_offset = in.col_offset; eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j < in_n_elem; i+=2, j+=2) { const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset ); const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset ); out_mem[i] = tmp_i; out_mem[j] = tmp_j; } if(i < in_n_elem) { out_mem[i] = in_m.at( i + in_row_offset, i + in_col_offset ); } }
inline u32 op_find::helper ( Mat<u32>& indices, const Base<typename T1::elem_type, T1>& X ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy<T1> P(X.get_ref()); const u32 n_elem = P.get_n_elem(); indices.set_size(n_elem, 1); u32* indices_mem = indices.memptr(); u32 n_nz = 0; for(u32 i=0; i<n_elem; ++i) { if(P[i] != eT(0)) { indices_mem[n_nz] = i; ++n_nz; } } return n_nz; }
arma_hot inline void eop_core<eop_type>::apply(Mat<typename T1::elem_type>& out, const eOp<T1, eop_type>& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing; // size setting and alias checking is done by either the Mat contructor or operator=() const eT k = x.aux; eT* out_mem = out.memptr(); if(Proxy<T1>::prefer_at_accessor == false) { // for fixed-sized vectors with n_elem >= 6, using x.get_n_elem() directly can cause a mis-optimisation (slowdown) of the loop under GCC 4.4 const uword n_elem = (Proxy<T1>::is_fixed) ? ( (x.get_n_elem() <= 4) ? x.get_n_elem() : out.n_elem ) : out.n_elem; typename Proxy<T1>::ea_type P = x.P.get_ea(); arma_applier_1(=); } else {
arma_hot inline void eop_core<eop_type>::apply(Mat<typename T1::elem_type>& out, const eOp<T1, eop_type>& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing; // size setting and alias checking is done by either the Mat contructor or operator=() const eT k = x.aux; eT* out_mem = out.memptr(); if(Proxy<T1>::prefer_at_accessor == false) { const uword n_elem = out.n_elem; typename Proxy<T1>::ea_type P = x.P.get_ea(); arma_applier_1(=); } else {
inline void glue_mixed_plus::apply(Mat<typename eT_promoter<T1,T2>::eT>& out, const mtGlue<typename eT_promoter<T1,T2>::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<eT1,eT2>::result out_eT; promote_type<eT1,eT2>::check(); const Proxy<T1> A(X.A); const Proxy<T2> B(X.B); arma_debug_assert_same_size(A, B, "matrix addition"); out.set_size(A.n_rows, A.n_cols); out_eT* out_mem = out.memptr(); const u32 n_elem = out.n_elem; for(u32 i=0; i<n_elem; ++i) { out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) + upgrade_val<eT1,eT2>::apply(B[i]); } }
inline void op_vectorise_col::apply_subview(Mat<eT>& out, const subview<eT>& sv) { arma_extra_debug_sigprint(); const bool is_alias = (&out == &(sv.m)); if(is_alias == false) { const uword sv_n_rows = sv.n_rows; const uword sv_n_cols = sv.n_cols; out.set_size(sv.n_elem, 1); eT* out_mem = out.memptr(); for(uword col=0; col < sv_n_cols; ++col) { arrayops::copy(out_mem, sv.colptr(col), sv_n_rows); out_mem += sv_n_rows; } } else { Mat<eT> tmp; op_vectorise_col::apply_subview(tmp, sv); out.steal_mem(tmp); } }
arma_hot inline eT op_norm::vec_norm_1_direct_std(const Mat<eT>& X) { arma_extra_debug_sigprint(); const uword N = X.n_elem; const eT* A = X.memptr(); if(N < uword(32)) { return op_norm::vec_norm_1_direct_mem(N,A); } else { #if defined(ARMA_USE_ATLAS) { return atlas::cblas_asum(N,A); } #elif defined(ARMA_USE_BLAS) { return blas::asum(N,A); } #else { return op_norm::vec_norm_1_direct_mem(N,A); } #endif } }
inline void op_sum::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_sum>& in) { arma_extra_debug_sigprint(); const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "sum(): incorrect usage. dim must be 0 or 1"); typedef typename T1::elem_type eT; const unwrap_check<T1> tmp(in.m, out); const Mat<eT>& X = tmp.M; const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) // traverse across rows (i.e. find the sum in each column) { out.set_size(1, X_n_cols); eT* out_mem = out.memptr(); for(uword col=0; col<X_n_cols; ++col) { out_mem[col] = arrayops::accumulate(X.colptr(col), X_n_rows); } } else // traverse across columns (i.e. find the sum in each row) { out.set_size(X_n_rows, 1); eT* out_mem = out.memptr(); for(uword row=0; row<X_n_rows; ++row) { eT val = eT(0); for(uword col=0; col<X_n_cols; ++col) { val += X.at(row,col); } out_mem[row] = val; } } }
inline void op_sort::apply_noalias(Mat<eT>& out, const Mat<eT>& X, const uword sort_type, const uword dim) { arma_extra_debug_sigprint(); if( (X.n_rows * X.n_cols) <= 1 ) { out = X; return; } if(dim == 0) // sort the contents of each column { arma_extra_debug_print("op_sort::apply(), dim = 0"); out = X; const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; for(uword col=0; col < n_cols; ++col) { op_sort::direct_sort( out.colptr(col), n_rows, sort_type ); } } else if(dim == 1) // sort the contents of each row { if(X.n_rows == 1) // a row vector { arma_extra_debug_print("op_sort::apply(), dim = 1, vector specific"); out = X; op_sort::direct_sort(out.memptr(), out.n_elem, sort_type); } else // not a row vector { arma_extra_debug_print("op_sort::apply(), dim = 1, generic"); out.copy_size(X); const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; podarray<eT> tmp_array(n_cols); for(uword row=0; row < n_rows; ++row) { op_sort::copy_row(tmp_array.memptr(), X, row); op_sort::direct_sort( tmp_array.memptr(), n_cols, sort_type ); op_sort::copy_row(out, tmp_array.memptr(), row); } } } }
inline void op_clamp::apply_noalias(Mat<typename T1::elem_type>& out, const Proxy<T1>& P, const typename T1::elem_type min_val, const typename T1::elem_type max_val) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); out.set_size(n_rows, n_cols); eT* out_mem = out.memptr(); if(Proxy<T1>::use_at == false) { const uword N = P.get_n_elem(); typename Proxy<T1>::ea_type A = P.get_ea(); uword j; for(j=1; j<N; j+=2) { eT val_i = A[j-1]; eT val_j = A[j ]; val_i = (val_i < min_val) ? min_val : ((val_i > max_val) ? max_val : val_i); val_j = (val_j < min_val) ? min_val : ((val_j > max_val) ? max_val : val_j); (*out_mem) = val_i; out_mem++; (*out_mem) = val_j; out_mem++; } const uword i = j-1; if(i < N) { eT val_i = A[i]; val_i = (val_i < min_val) ? min_val : ((val_i > max_val) ? max_val : val_i); (*out_mem) = val_i; } } else { for(uword col=0; col<n_cols; ++col) for(uword row=0; row<n_rows; ++row) { eT val = P.at(row,col); val = (val < min_val) ? min_val : ((val > max_val) ? max_val : val); (*out_mem) = val; out_mem++; } } }
// Return double complex valued matrix to Matlab/Octave inline void armaSetPi(mxArray *matlabMatrix, const Mat<double>& armaMatrix) { double *dst_pointer = mxGetPi(matlabMatrix); const double *src_pointer = armaMatrix.memptr(); std::memcpy(dst_pointer, src_pointer, sizeof(double)*armaMatrix.n_elem); }
inline void armaSetImagData(mxArray *matlabMatrix, const Mat<Type>& armaMatrix) { Type *dst_pointer = (Type*)mxGetImagData(matlabMatrix); const Type *src_pointer = (Type*)armaMatrix.memptr(); std::memcpy(dst_pointer, src_pointer, sizeof(Type)*armaMatrix.n_elem); }
inline uword op_find::helper ( Mat<uword>& indices, const mtGlue<uword, T1, T2, glue_type>& X, const typename arma_glue_rel_only<glue_type>::result junk1, const typename arma_not_cx<typename T1::elem_type>::result junk2, const typename arma_not_cx<typename T2::elem_type>::result junk3 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); arma_ignore(junk3); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename Proxy<T1>::ea_type ea_type1; typedef typename Proxy<T2>::ea_type ea_type2; const Proxy<T1> A(X.A); const Proxy<T2> B(X.B); arma_debug_assert_same_size(A, B, "relational operator"); ea_type1 PA = A.get_ea(); ea_type2 PB = B.get_ea(); const uword n_elem = B.get_n_elem(); indices.set_size(n_elem, 1); uword* indices_mem = indices.memptr(); uword n_nz = 0; for(uword i=0; i<n_elem; ++i) { const eT1 tmp1 = PA[i]; const eT2 tmp2 = PB[i]; bool not_zero; if(is_same_type<glue_type, glue_rel_lt >::value == true) { not_zero = (tmp1 < tmp2); } else if(is_same_type<glue_type, glue_rel_gt >::value == true) { not_zero = (tmp1 > tmp2); } else if(is_same_type<glue_type, glue_rel_lteq >::value == true) { not_zero = (tmp1 <= tmp2); } else if(is_same_type<glue_type, glue_rel_gteq >::value == true) { not_zero = (tmp1 >= tmp2); } else if(is_same_type<glue_type, glue_rel_eq >::value == true) { not_zero = (tmp1 == tmp2); } else if(is_same_type<glue_type, glue_rel_noteq >::value == true) { not_zero = (tmp1 != tmp2); } else not_zero = false; if(not_zero == true) { indices_mem[n_nz] = i; ++n_nz; } } return n_nz; }
inline void arma_ostream::print(std::ostream& o, const Mat<eT>& m, const bool modify) { arma_extra_debug_sigprint(); const arma_ostream_state stream_state(o); const std::streamsize cell_width = modify ? arma_ostream::modify_stream(o, m.memptr(), m.n_elem) : o.width(); const uword m_n_rows = m.n_rows; const uword m_n_cols = m.n_cols; if(m.is_empty() == false) { if(m_n_cols > 0) { if(cell_width > 0) { for(uword row=0; row < m_n_rows; ++row) { for(uword col=0; col < m_n_cols; ++col) { // the cell width appears to be reset after each element is printed, // hence we need to restore it o.width(cell_width); arma_ostream::print_elem(o, m.at(row,col), modify); } o << '\n'; } } else { for(uword row=0; row < m_n_rows; ++row) { for(uword col=0; col < m_n_cols-1; ++col) { arma_ostream::print_elem(o, m.at(row,col), modify); o << ' '; } arma_ostream::print_elem(o, m.at(row, m_n_cols-1), modify); o << '\n'; } } } } else { o << "[matrix size: " << m_n_rows << 'x' << m_n_cols << "]\n"; } o.flush(); stream_state.restore(o); }