simplifications

This commit is contained in:
conrad
2023-01-14 02:35:34 +10:00
parent 0d2c385715
commit 73e22653ca
3 changed files with 37 additions and 69 deletions
+24 -6
View File
@@ -48,12 +48,12 @@ shift
template<typename T1>
arma_warn_unused
arma_inline
inline
typename
enable_if2
<
is_arma_type<T1>::value && resolves_to_vector<T1>::no,
const Op<T1, op_shift>
Mat<typename T1::elem_type>
>::result
shift
(
@@ -63,22 +63,30 @@ shift
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const uword len = (N < 0) ? uword(-N) : uword(N);
const uword neg = (N < 0) ? uword( 1) : uword(0);
return Op<T1, op_shift>(X, len, neg, uword(0), 'j');
quasi_unwrap<T1> U(X);
Mat<eT> out;
op_shift::apply_noalias(out, U.M, len, neg, 0);
return out;
}
template<typename T1>
arma_warn_unused
arma_inline
inline
typename
enable_if2
<
(is_arma_type<T1>::value),
const Op<T1, op_shift>
Mat<typename T1::elem_type>
>::result
shift
(
@@ -89,10 +97,20 @@ shift
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
arma_debug_check( (dim > 1), "vectorise(): parameter 'dim' must be 0 or 1" );
const uword len = (N < 0) ? uword(-N) : uword(N);
const uword neg = (N < 0) ? uword( 1) : uword(0);
return Op<T1, op_shift>(X, len, neg, dim, 'j');
quasi_unwrap<T1> U(X);
Mat<eT> out;
op_shift::apply_noalias(out, U.M, len, neg, dim);
return out;
}
@@ -37,13 +37,7 @@ class op_shift
{
public:
template<typename T1> inline static void apply(Mat<typename T1::elem_type>& out, const Op<T1,op_shift>& in);
template<typename eT> inline static void apply_direct(Mat<eT>& out, const Mat<eT>& X, const uword len, const uword neg, const uword dim);
template<typename eT> inline static void apply_noalias(Mat<eT>& out, const Mat<eT>& X, const uword len, const uword neg, const uword dim);
template<typename eT> inline static void apply_alias(Mat<eT>& out, const uword len, const uword neg, const uword dim);
};
+13 -57
View File
@@ -29,55 +29,26 @@ op_shift_vec::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_shift_vec>&
{
arma_extra_debug_sigprint();
const unwrap<T1> U(in.m);
typedef typename T1::elem_type eT;
const quasi_unwrap<T1> U(in.m);
const uword len = in.aux_uword_a;
const uword neg = in.aux_uword_b;
const uword dim = (T1::is_xvec) ? uword(U.M.is_rowvec() ? 1 : 0) : uword((T1::is_row) ? 1 : 0);
op_shift::apply_direct(out, U.M, len, neg, dim);
}
template<typename T1>
inline
void
op_shift::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_shift>& in)
{
arma_extra_debug_sigprint();
const unwrap<T1> U(in.m);
const uword len = in.aux_uword_a;
const uword neg = in.aux_uword_b;
const uword dim = in.aux_uword_c;
arma_debug_check( (dim > 1), "shift(): parameter 'dim' must be 0 or 1" );
op_shift::apply_direct(out, U.M, len, neg, dim);
}
template<typename eT>
inline
void
op_shift::apply_direct(Mat<eT>& out, const Mat<eT>& X, const uword len, const uword neg, const uword dim)
{
arma_extra_debug_sigprint();
arma_debug_check_bounds( ((dim == 0) && (len >= X.n_rows)), "shift(): shift amount out of bounds" );
arma_debug_check_bounds( ((dim == 1) && (len >= X.n_cols)), "shift(): shift amount out of bounds" );
if(&out == &X)
if(U.is_alias(out))
{
op_shift::apply_alias(out, len, neg, dim);
Mat<eT> tmp;
op_shift::apply_noalias(tmp, U.M, len, neg, dim);
out.steal_mem(tmp);
}
else
{
op_shift::apply_noalias(out, X, len, neg, dim);
op_shift::apply_noalias(out, U.M, len, neg, dim);
}
}
@@ -90,6 +61,9 @@ op_shift::apply_noalias(Mat<eT>& out, const Mat<eT>& X, const uword len, const u
{
arma_extra_debug_sigprint();
arma_debug_check_bounds( ((dim == 0) && (len >= X.n_rows)), "shift(): shift amount out of bounds" );
arma_debug_check_bounds( ((dim == 1) && (len >= X.n_cols)), "shift(): shift amount out of bounds" );
out.copy_size(X);
const uword X_n_rows = X.n_rows;
@@ -204,22 +178,4 @@ op_shift::apply_noalias(Mat<eT>& out, const Mat<eT>& X, const uword len, const u
template<typename eT>
inline
void
op_shift::apply_alias(Mat<eT>& X, const uword len, const uword neg, const uword dim)
{
arma_extra_debug_sigprint();
// TODO: replace with better implementation
Mat<eT> tmp;
op_shift::apply_noalias(tmp, X, len, neg, dim);
X.steal_mem(tmp);
}
//! @}