annotate armadillo-2.4.4/include/armadillo_bits/op_resize_meat.hpp @ 18:8d046a9d36aa slimline

Back out rev 13:ac07c60aa798. Like an idiot, I committed a whole pile of unrelated changes in the guise of a single typo fix. Will re-commit in stages
author Chris Cannam
date Thu, 10 May 2012 10:45:44 +0100
parents 8b6102e2a9b0
children
rev   line source
max@0 1 // Copyright (C) 2011 NICTA (www.nicta.com.au)
max@0 2 // Copyright (C) 2011 Conrad Sanderson
max@0 3 //
max@0 4 // This file is part of the Armadillo C++ library.
max@0 5 // It is provided without any warranty of fitness
max@0 6 // for any purpose. You can redistribute this file
max@0 7 // and/or modify it under the terms of the GNU
max@0 8 // Lesser General Public License (LGPL) as published
max@0 9 // by the Free Software Foundation, either version 3
max@0 10 // of the License or (at your option) any later version.
max@0 11 // (see http://www.opensource.org/licenses for more info)
max@0 12
max@0 13
max@0 14
max@0 15 //! \addtogroup op_resize
max@0 16 //! @{
max@0 17
max@0 18
max@0 19
max@0 20 template<typename T1>
max@0 21 inline
max@0 22 void
max@0 23 op_resize::apply(Mat<typename T1::elem_type>& actual_out, const Op<T1,op_resize>& in)
max@0 24 {
max@0 25 arma_extra_debug_sigprint();
max@0 26
max@0 27 typedef typename T1::elem_type eT;
max@0 28
max@0 29 const uword out_n_rows = in.aux_uword_a;
max@0 30 const uword out_n_cols = in.aux_uword_b;
max@0 31
max@0 32 const unwrap<T1> tmp(in.m);
max@0 33 const Mat<eT>& A = tmp.M;
max@0 34
max@0 35 const uword A_n_rows = A.n_rows;
max@0 36 const uword A_n_cols = A.n_cols;
max@0 37
max@0 38 Mat<eT> B;
max@0 39
max@0 40 const bool alias = (&actual_out == &A);
max@0 41
max@0 42 Mat<eT>& out = alias ? B : actual_out;
max@0 43
max@0 44 out.set_size(out_n_rows, out_n_cols);
max@0 45
max@0 46 if( (out_n_rows > A_n_rows) || (out_n_cols > A_n_cols) )
max@0 47 {
max@0 48 out.zeros();
max@0 49 }
max@0 50
max@0 51 if( (out.n_elem > 0) && (A.n_elem > 0) )
max@0 52 {
max@0 53 const uword end_row = (std::min)(out_n_rows, A_n_rows) - 1;
max@0 54 const uword end_col = (std::min)(out_n_cols, A_n_cols) - 1;
max@0 55
max@0 56 out.submat(0, 0, end_row, end_col) = A.submat(0, 0, end_row, end_col);
max@0 57 }
max@0 58
max@0 59 if(alias)
max@0 60 {
max@0 61 actual_out.steal_mem(B);
max@0 62 }
max@0 63
max@0 64 }
max@0 65
max@0 66
max@0 67
max@0 68 template<typename T1>
max@0 69 inline
max@0 70 void
max@0 71 op_resize::apply(Cube<typename T1::elem_type>& actual_out, const OpCube<T1,op_resize>& in)
max@0 72 {
max@0 73 arma_extra_debug_sigprint();
max@0 74
max@0 75 typedef typename T1::elem_type eT;
max@0 76
max@0 77 const uword out_n_rows = in.aux_uword_a;
max@0 78 const uword out_n_cols = in.aux_uword_b;
max@0 79 const uword out_n_slices = in.aux_uword_c;
max@0 80
max@0 81 const unwrap_cube<T1> tmp(in.m);
max@0 82 const Cube<eT>& A = tmp.M;
max@0 83
max@0 84 const uword A_n_rows = A.n_rows;
max@0 85 const uword A_n_cols = A.n_cols;
max@0 86 const uword A_n_slices = A.n_slices;
max@0 87
max@0 88 Cube<eT> B;
max@0 89
max@0 90 const bool alias = (&actual_out == &A);
max@0 91
max@0 92 Cube<eT>& out = alias ? B : actual_out;
max@0 93
max@0 94 out.set_size(out_n_rows, out_n_cols, out_n_slices);
max@0 95
max@0 96 if( (out_n_rows > A_n_rows) || (out_n_cols > A_n_cols) || (out_n_slices > A_n_slices) )
max@0 97 {
max@0 98 out.zeros();
max@0 99 }
max@0 100
max@0 101 if( (out.n_elem > 0) && (A.n_elem > 0) )
max@0 102 {
max@0 103 const uword end_row = (std::min)(out_n_rows, A_n_rows) - 1;
max@0 104 const uword end_col = (std::min)(out_n_cols, A_n_cols) - 1;
max@0 105 const uword end_slice = (std::min)(out_n_slices, A_n_slices) - 1;
max@0 106
max@0 107 out.subcube(0, 0, 0, end_row, end_col, end_slice) = A.subcube(0, 0, 0, end_row, end_col, end_slice);
max@0 108 }
max@0 109
max@0 110 if(alias)
max@0 111 {
max@0 112 actual_out.steal_mem(B);
max@0 113 }
max@0 114
max@0 115 }
max@0 116
max@0 117
max@0 118
max@0 119 //! @}