Col_bones.hpp   Col_bones.hpp 
skipping to change at line 48 skipping to change at line 48
inline const Col& operator=(const std::string& text); inline const Col& operator=(const std::string& text);
inline Col(const std::vector<eT>& x); inline Col(const std::vector<eT>& x);
inline const Col& operator=(const std::vector<eT>& x); inline const Col& operator=(const std::vector<eT>& x);
#if defined(ARMA_USE_CXX11) #if defined(ARMA_USE_CXX11)
inline Col(const std::initializer_list<eT>& list); inline Col(const std::initializer_list<eT>& list);
inline const Col& operator=(const std::initializer_list<eT>& list); inline const Col& operator=(const std::initializer_list<eT>& list);
#endif #endif
inline explicit Col(const SpCol<eT>& X);
inline const Col& operator=(const eT val); inline const Col& operator=(const eT val);
template<typename T1> inline Col(const Base<eT,T1>& X); template<typename T1> inline Col(const Base<eT,T1>& X);
template<typename T1> inline const Col& operator=(const Base<eT,T1>& X); template<typename T1> inline const Col& operator=(const Base<eT,T1>& X);
inline Col( eT* aux_mem, const uword aux_length, const bool copy_aux _mem = true, const bool strict = true); inline Col( eT* aux_mem, const uword aux_length, const bool copy_aux _mem = true, const bool strict = true);
inline Col(const eT* aux_mem, const uword aux_length); inline Col(const eT* aux_mem, const uword aux_length);
template<typename T1, typename T2> template<typename T1, typename T2>
inline explicit Col(const Base<pod_type,T1>& A, const Base<pod_type,T2>& B); inline explicit Col(const Base<pod_type,T1>& A, const Base<pod_type,T2>& B);
 End of changes. 1 change blocks. 
0 lines changed or deleted 2 lines changed or added


 Col_meat.hpp   Col_meat.hpp 
skipping to change at line 195 skipping to change at line 195
access::rw(Mat<eT>::vec_state) = 1; access::rw(Mat<eT>::vec_state) = 1;
return *this; return *this;
} }
#endif #endif
template<typename eT> template<typename eT>
inline inline
Col<eT>::Col(const SpCol<eT>& X)
: Mat<eT>(arma_vec_indicator(), X.n_elem, 1, 1)
{
arma_extra_debug_sigprint_this(this);
arrayops::inplace_set(Mat<eT>::memptr(), eT(0), X.n_elem);
for(typename SpCol<eT>::const_iterator it = X.begin(); it != X.end(); ++i
t)
at(it.row()) = (*it);
}
template<typename eT>
inline
const Col<eT>& const Col<eT>&
Col<eT>::operator=(const eT val) Col<eT>::operator=(const eT val)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
Mat<eT>::operator=(val); Mat<eT>::operator=(val);
return *this; return *this;
} }
 End of changes. 1 change blocks. 
0 lines changed or deleted 14 lines changed or added


 Cube_meat.hpp   Cube_meat.hpp 
skipping to change at line 236 skipping to change at line 236
} }
} }
//! for constructing a complex cube out of two non-complex cubes //! for constructing a complex cube out of two non-complex cubes
template<typename eT> template<typename eT>
template<typename T1, typename T2> template<typename T1, typename T2>
inline inline
void void
Cube<eT>::init Cube<eT>::init
( (
const BaseCube<typename Cube<eT>::pod_type,T1>& A, const BaseCube<typename Cube<eT>::pod_type,T1>& X,
const BaseCube<typename Cube<eT>::pod_type,T2>& B const BaseCube<typename Cube<eT>::pod_type,T2>& Y
) )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type T; typedef typename T1::elem_type T;
typedef typename ProxyCube<T1>::ea_type ea_type1;
typedef typename ProxyCube<T2>::ea_type ea_type2;
arma_type_check(( is_complex<eT>::value == false )); //!< compile-time abort if eT isn't std::complex arma_type_check(( is_complex<eT>::value == false )); //!< compile-time abort if eT isn't std::complex
arma_type_check(( is_complex< T>::value == true )); //!< compile-time abort if T is std::complex arma_type_check(( is_complex< T>::value == true )); //!< compile-time abort if T is std::complex
arma_type_check(( is_same_type< std::complex<T>, eT >::value == false )); //!< compile-time abort if types are not compatible arma_type_check(( is_same_type< std::complex<T>, eT >::value == false )); //!< compile-time abort if types are not compatible
const ProxyCube<T1> X(A.get_ref()); const ProxyCube<T1> PX(X.get_ref());
const ProxyCube<T2> Y(B.get_ref()); const ProxyCube<T2> PY(Y.get_ref());
arma_assert_same_size(PX, PY, "Cube()");
arma_assert_same_size(X, Y, "Cube()"); const uword local_n_rows = PX.get_n_rows();
const uword local_n_cols = PX.get_n_cols();
const uword local_n_slices = PX.get_n_slices();
init_warm(X.get_n_rows(), X.get_n_cols(), X.get_n_slices()); init_warm(local_n_rows, local_n_cols, local_n_slices);
const uword N = n_elem; eT* out_mem = (*this).memptr();
eT* out_mem = memptr();
ea_type1 PX = X.get_ea();
ea_type2 PY = Y.get_ea();
// TODO: add handling for prefer_at_accessor = true const bool prefer_at_accessor = ( ProxyCube<T1>::prefer_at_accessor || Pr oxyCube<T2>::prefer_at_accessor );
for(uword i=0; i<N; ++i) if(prefer_at_accessor == false)
{ {
out_mem[i] = std::complex<T>(PX[i], PY[i]); typedef typename ProxyCube<T1>::ea_type ea_type1;
typedef typename ProxyCube<T2>::ea_type ea_type2;
const uword N = n_elem;
ea_type1 A = PX.get_ea();
ea_type2 B = PY.get_ea();
for(uword i=0; i<N; ++i)
{
out_mem[i] = std::complex<T>(A[i], B[i]);
}
}
else
{
for(uword uslice = 0; uslice < local_n_slices; ++uslice)
for(uword ucol = 0; ucol < local_n_cols; ++ucol )
for(uword urow = 0; urow < local_n_rows; ++urow )
{
*out_mem = std::complex<T>( PX.at(urow,ucol,uslice), PY.at(urow,ucol,
uslice) );
out_mem++;
}
} }
} }
//! try to steal the memory from a given cube; //! try to steal the memory from a given cube;
//! if memory can't be stolen, copy the given cube //! if memory can't be stolen, copy the given cube
template<typename eT> template<typename eT>
inline inline
void void
Cube<eT>::steal_mem(Cube<eT>& x) Cube<eT>::steal_mem(Cube<eT>& x)
{ {
skipping to change at line 2972 skipping to change at line 2992
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
template<typename T, typename T1> template<typename T, typename T1>
inline inline
void void
Cube_aux::set_real(Cube< std::complex<T> >& out, const BaseCube<T,T1>& X) Cube_aux::set_real(Cube< std::complex<T> >& out, const BaseCube<T,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename std::complex<T> eT; typedef typename std::complex<T> eT;
typedef typename ProxyCube<T1>::ea_type ea_type;
const ProxyCube<T1> A(X.get_ref()); const ProxyCube<T1> P(X.get_ref());
const uword local_n_rows = P.get_n_rows();
const uword local_n_cols = P.get_n_cols();
const uword local_n_slices = P.get_n_slices();
arma_debug_assert_same_size arma_debug_assert_same_size
( (
out.n_rows, out.n_cols, out.n_slices, out.n_rows, out.n_cols, out.n_slices,
A.get_n_rows(), A.get_n_cols(), A.get_n_slices(), local_n_rows, local_n_cols, local_n_slices,
"Cube::set_real()" "Cube::set_real()"
); );
const uword n_elem = out.n_elem; eT* out_mem = out.memptr();
eT* out_mem = out.memptr();
ea_type PA = A.get_ea(); if(ProxyCube<T1>::prefer_at_accessor == false)
{
typedef typename ProxyCube<T1>::ea_type ea_type;
ea_type A = P.get_ea();
// TODO: add handling for prefer_at_accessor = true const uword N = out.n_elem;
for(uword i=0; i<n_elem; ++i) for(uword i=0; i<N; ++i)
{
//out_mem[i].real() = PA[i];
out_mem[i] = std::complex<T>( A[i], out_mem[i].imag() );
}
}
else
{ {
//out_mem[i].real() = PA[i]; for(uword slice = 0; slice < local_n_slices; ++slice)
out_mem[i] = std::complex<T>( PA[i], out_mem[i].imag() ); for(uword col = 0; col < local_n_cols; ++col )
for(uword row = 0; row < local_n_rows; ++row )
{
(*out_mem) = std::complex<T>( P.at(row,col,slice), (*out_mem).imag()
);
out_mem++;
}
} }
} }
template<typename T, typename T1> template<typename T, typename T1>
inline inline
void void
Cube_aux::set_imag(Cube< std::complex<T> >& out, const BaseCube<T,T1>& X) Cube_aux::set_imag(Cube< std::complex<T> >& out, const BaseCube<T,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename std::complex<T> eT; typedef typename std::complex<T> eT;
typedef typename ProxyCube<T1>::ea_type ea_type;
const ProxyCube<T1> A(X.get_ref()); const ProxyCube<T1> P(X.get_ref());
const uword local_n_rows = P.get_n_rows();
const uword local_n_cols = P.get_n_cols();
const uword local_n_slices = P.get_n_slices();
arma_debug_assert_same_size arma_debug_assert_same_size
( (
out.n_rows, out.n_cols, out.n_slices, out.n_rows, out.n_cols, out.n_slices,
A.get_n_rows(), A.get_n_cols(), A.get_n_slices(), local_n_rows, local_n_cols, local_n_slices,
"Cube::set_imag()" "Cube::set_imag()"
); );
const uword n_elem = out.n_elem; eT* out_mem = out.memptr();
eT* out_mem = out.memptr();
ea_type PA = A.get_ea(); if(ProxyCube<T1>::prefer_at_accessor == false)
{
typedef typename ProxyCube<T1>::ea_type ea_type;
ea_type A = P.get_ea();
// TODO: add handling for prefer_at_accessor = true const uword N = out.n_elem;
for(uword i=0; i<n_elem; ++i) for(uword i=0; i<N; ++i)
{
//out_mem[i].imag() = PA[i];
out_mem[i] = std::complex<T>( out_mem[i].real(), A[i] );
}
}
else
{ {
//out_mem[i].imag() = PA[i]; for(uword slice = 0; slice < local_n_slices; ++slice)
out_mem[i] = std::complex<T>( out_mem[i].real(), PA[i] ); for(uword col = 0; col < local_n_cols; ++col )
for(uword row = 0; row < local_n_rows; ++row )
{
(*out_mem) = std::complex<T>( (*out_mem).real(), P.at(row,col,slice)
);
out_mem++;
}
} }
} }
#ifdef ARMA_EXTRA_CUBE_MEAT #ifdef ARMA_EXTRA_CUBE_MEAT
#include ARMA_INCFILE_WRAP(ARMA_EXTRA_CUBE_MEAT) #include ARMA_INCFILE_WRAP(ARMA_EXTRA_CUBE_MEAT)
#endif #endif
//! @} //! @}
 End of changes. 23 change blocks. 
39 lines changed or deleted 98 lines changed or added


 Mat_meat.hpp   Mat_meat.hpp 
skipping to change at line 653 skipping to change at line 653
ea_type1 A = PX.get_ea(); ea_type1 A = PX.get_ea();
ea_type2 B = PY.get_ea(); ea_type2 B = PY.get_ea();
for(uword ii=0; ii < N; ++ii) for(uword ii=0; ii < N; ++ii)
{ {
out_mem[ii] = std::complex<T>(A[ii], B[ii]); out_mem[ii] = std::complex<T>(A[ii], B[ii]);
} }
} }
else else
{ {
uword ii = 0;
for(uword ucol=0; ucol < local_n_cols; ++ucol) for(uword ucol=0; ucol < local_n_cols; ++ucol)
for(uword urow=0; urow < local_n_rows; ++urow, ++ii) for(uword urow=0; urow < local_n_rows; ++urow)
{ {
out_mem[ii] = std::complex<T>(PX.at(urow,ucol), PY.at(urow,ucol)); *out_mem = std::complex<T>(PX.at(urow,ucol), PY.at(urow,ucol));
out_mem++;
} }
} }
} }
//! try to steal the memory from a given matrix; //! try to steal the memory from a given matrix;
//! if memory can't be stolen, copy the given matrix //! if memory can't be stolen, copy the given matrix
template<typename eT> template<typename eT>
inline inline
void void
Mat<eT>::steal_mem(Mat<eT>& x) Mat<eT>::steal_mem(Mat<eT>& x)
skipping to change at line 5860 skipping to change at line 5859
const uword N = out.n_elem; const uword N = out.n_elem;
for(uword i=0; i<N; ++i) for(uword i=0; i<N; ++i)
{ {
out_mem[i] = std::complex<T>( A[i], out_mem[i].imag() ); out_mem[i] = std::complex<T>( A[i], out_mem[i].imag() );
} }
} }
else else
{ {
uword i = 0;
for(uword col=0; col < local_n_cols; ++col) for(uword col=0; col < local_n_cols; ++col)
for(uword row=0; row < local_n_rows; ++row, ++i) for(uword row=0; row < local_n_rows; ++row)
{ {
out_mem[i] = std::complex<T>( P.at(row,col), out_mem[i].imag()); (*out_mem) = std::complex<T>( P.at(row,col), (*out_mem).imag() );
out_mem++;
} }
} }
} }
template<typename T, typename T1> template<typename T, typename T1>
inline inline
void void
Mat_aux::set_imag(Mat< std::complex<T> >& out, const Base<T,T1>& X) Mat_aux::set_imag(Mat< std::complex<T> >& out, const Base<T,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
skipping to change at line 5903 skipping to change at line 5901
const uword N = out.n_elem; const uword N = out.n_elem;
for(uword i=0; i<N; ++i) for(uword i=0; i<N; ++i)
{ {
out_mem[i] = std::complex<T>( out_mem[i].real(), A[i] ); out_mem[i] = std::complex<T>( out_mem[i].real(), A[i] );
} }
} }
else else
{ {
uword i = 0;
for(uword col=0; col < local_n_cols; ++col) for(uword col=0; col < local_n_cols; ++col)
for(uword row=0; row < local_n_rows; ++row, ++i) for(uword row=0; row < local_n_rows; ++row)
{ {
out_mem[i] = std::complex<T>( out_mem[i].real(), P.at(row,col) ); (*out_mem) = std::complex<T>( (*out_mem).real(), P.at(row,col) );
out_mem++;
} }
} }
} }
#ifdef ARMA_EXTRA_MAT_MEAT #ifdef ARMA_EXTRA_MAT_MEAT
#include ARMA_INCFILE_WRAP(ARMA_EXTRA_MAT_MEAT) #include ARMA_INCFILE_WRAP(ARMA_EXTRA_MAT_MEAT)
#endif #endif
//! @} //! @}
 End of changes. 9 change blocks. 
12 lines changed or deleted 9 lines changed or added


 Row_bones.hpp   Row_bones.hpp 
skipping to change at line 48 skipping to change at line 48
inline const Row& operator=(const std::string& text); inline const Row& operator=(const std::string& text);
inline Row(const std::vector<eT>& x); inline Row(const std::vector<eT>& x);
inline const Row& operator=(const std::vector<eT>& x); inline const Row& operator=(const std::vector<eT>& x);
#if defined(ARMA_USE_CXX11) #if defined(ARMA_USE_CXX11)
inline Row(const std::initializer_list<eT>& list); inline Row(const std::initializer_list<eT>& list);
inline const Row& operator=(const std::initializer_list<eT>& list); inline const Row& operator=(const std::initializer_list<eT>& list);
#endif #endif
inline explicit Row(const SpRow<eT>& X);
inline const Row& operator=(const eT val); inline const Row& operator=(const eT val);
template<typename T1> inline Row(const Base<eT,T1>& X); template<typename T1> inline Row(const Base<eT,T1>& X);
template<typename T1> inline const Row& operator=(const Base<eT,T1>& X); template<typename T1> inline const Row& operator=(const Base<eT,T1>& X);
inline Row( eT* aux_mem, const uword aux_length, const bool copy_aux _mem = true, const bool strict = true); inline Row( eT* aux_mem, const uword aux_length, const bool copy_aux _mem = true, const bool strict = true);
inline Row(const eT* aux_mem, const uword aux_length); inline Row(const eT* aux_mem, const uword aux_length);
template<typename T1, typename T2> template<typename T1, typename T2>
inline explicit Row(const Base<pod_type,T1>& A, const Base<pod_type,T2>& B); inline explicit Row(const Base<pod_type,T1>& A, const Base<pod_type,T2>& B);
 End of changes. 1 change blocks. 
0 lines changed or deleted 2 lines changed or added


 Row_meat.hpp   Row_meat.hpp 
skipping to change at line 161 skipping to change at line 161
Mat<eT>::operator=(list); Mat<eT>::operator=(list);
return *this; return *this;
} }
#endif #endif
template<typename eT> template<typename eT>
inline inline
Row<eT>::Row(const SpRow<eT>& X)
: Mat<eT>(arma_vec_indicator(), 1, X.n_elem, 1)
{
arma_extra_debug_sigprint_this(this);
arrayops::inplace_set(Mat<eT>::memptr(), eT(0), X.n_elem);
for(typename SpRow<eT>::const_iterator it = X.begin(); it != X.end(); ++i
t)
at(it.col()) = (*it);
}
template<typename eT>
inline
const Row<eT>& const Row<eT>&
Row<eT>::operator=(const eT val) Row<eT>::operator=(const eT val)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
Mat<eT>::operator=(val); Mat<eT>::operator=(val);
return *this; return *this;
} }
 End of changes. 1 change blocks. 
0 lines changed or deleted 14 lines changed or added


 SpGlue_bones.hpp   SpGlue_bones.hpp 
skipping to change at line 23 skipping to change at line 23
//! @{ //! @{
template<typename T1, typename T2, typename spglue_type> template<typename T1, typename T2, typename spglue_type>
class SpGlue : public SpBase<typename T1::elem_type, SpGlue<T1, T2, spglue_ type> > class SpGlue : public SpBase<typename T1::elem_type, SpGlue<T1, T2, spglue_ type> >
{ {
public: public:
typedef typename T1::elem_type elem_type; typedef typename T1::elem_type elem_type;
typedef typename get_pod_type<elem_type>::result pod_type; typedef typename get_pod_type<elem_type>::result pod_type;
//static const bool is_row = (is_same_type<spglue_type, spglue_times>::va static const bool is_row = ( (T1::is_row || T2::is_row) && is_spglue_elem
lue) ? T1::is_row : false; <spglue_type>::value ) || ( (is_spglue_times<spglue_type>::value || is_spgl
//static const bool is_col = (is_same_type<spglue_type, spglue_times>::va ue_times2<spglue_type>::value) ? T1::is_row : false );
lue) ? T2::is_col : false; static const bool is_col = ( (T1::is_col || T2::is_col) && is_spglue_elem
<spglue_type>::value ) || ( (is_spglue_times<spglue_type>::value || is_spgl
static const bool is_row = false; ue_times2<spglue_type>::value) ? T2::is_col : false );
static const bool is_col = false;
arma_inline SpGlue(const T1& in_A, const T2& in_B); arma_inline SpGlue(const T1& in_A, const T2& in_B);
arma_inline SpGlue(const T1& in_A, const T2& in_B, const elem_type in_au x); arma_inline SpGlue(const T1& in_A, const T2& in_B, const elem_type in_au x);
arma_inline ~SpGlue(); arma_inline ~SpGlue();
const T1& A; //!< first operand const T1& A; //!< first operand
const T2& B; //!< second operand const T2& B; //!< second operand
elem_type aux; elem_type aux;
}; };
 End of changes. 1 change blocks. 
7 lines changed or deleted 6 lines changed or added


 SpMat_bones.hpp   SpMat_bones.hpp 
skipping to change at line 141 skipping to change at line 141
// delayed binary ops // delayed binary ops
template<typename T1, typename T2, typename spglue_type> inline SpMat(const SpGlue<T1, T2, spglue_type>& X); template<typename T1, typename T2, typename spglue_type> inline SpMat(const SpGlue<T1, T2, spglue_type>& X);
template<typename T1, typename T2, typename spglue_type> inline const SpM at& operator=(const SpGlue<T1, T2, spglue_type>& X); template<typename T1, typename T2, typename spglue_type> inline const SpM at& operator=(const SpGlue<T1, T2, spglue_type>& X);
template<typename T1, typename T2, typename spglue_type> inline const SpM at& operator+=(const SpGlue<T1, T2, spglue_type>& X); template<typename T1, typename T2, typename spglue_type> inline const SpM at& operator+=(const SpGlue<T1, T2, spglue_type>& X);
template<typename T1, typename T2, typename spglue_type> inline const SpM at& operator-=(const SpGlue<T1, T2, spglue_type>& X); template<typename T1, typename T2, typename spglue_type> inline const SpM at& operator-=(const SpGlue<T1, T2, spglue_type>& X);
template<typename T1, typename T2, typename spglue_type> inline const SpM at& operator*=(const SpGlue<T1, T2, spglue_type>& X); template<typename T1, typename T2, typename spglue_type> inline const SpM at& operator*=(const SpGlue<T1, T2, spglue_type>& X);
template<typename T1, typename T2, typename spglue_type> inline const SpM at& operator%=(const SpGlue<T1, T2, spglue_type>& X); template<typename T1, typename T2, typename spglue_type> inline const SpM at& operator%=(const SpGlue<T1, T2, spglue_type>& X);
template<typename T1, typename T2, typename spglue_type> inline const SpM at& operator/=(const SpGlue<T1, T2, spglue_type>& X); template<typename T1, typename T2, typename spglue_type> inline const SpM at& operator/=(const SpGlue<T1, T2, spglue_type>& X);
// delayed mixted-type unary ops
template<typename T1, typename spop_type> inline SpMat(
const mtSpOp<eT, T1, spop_type>& X);
template<typename T1, typename spop_type> inline const SpMat& operator=(
const mtSpOp<eT, T1, spop_type>& X);
template<typename T1, typename spop_type> inline const SpMat& operator+=(
const mtSpOp<eT, T1, spop_type>& X);
template<typename T1, typename spop_type> inline const SpMat& operator-=(
const mtSpOp<eT, T1, spop_type>& X);
template<typename T1, typename spop_type> inline const SpMat& operator*=(
const mtSpOp<eT, T1, spop_type>& X);
template<typename T1, typename spop_type> inline const SpMat& operator%=(
const mtSpOp<eT, T1, spop_type>& X);
template<typename T1, typename spop_type> inline const SpMat& operator/=(
const mtSpOp<eT, T1, spop_type>& X);
/** /**
* Submatrix methods. * Submatrix methods.
*/ */
arma_inline SpSubview<eT> row(const uword row_num); arma_inline SpSubview<eT> row(const uword row_num);
arma_inline const SpSubview<eT> row(const uword row_num) const; arma_inline const SpSubview<eT> row(const uword row_num) const;
inline SpSubview<eT> operator()(const uword row_num, const spa n& col_span); inline SpSubview<eT> operator()(const uword row_num, const spa n& col_span);
inline const SpSubview<eT> operator()(const uword row_num, const spa n& col_span) const; inline const SpSubview<eT> operator()(const uword row_num, const spa n& col_span) const;
arma_inline SpSubview<eT> col(const uword col_num); arma_inline SpSubview<eT> col(const uword col_num);
skipping to change at line 287 skipping to change at line 296
* Get the minimum or maximum of the matrix. * Get the minimum or maximum of the matrix.
*/ */
inline arma_warn_unused eT min() const; inline arma_warn_unused eT min() const;
inline eT min(uword& index_of_min_val) const; inline eT min(uword& index_of_min_val) const;
inline eT min(uword& row_of_min_val, uword& col_of_min_v al) const; inline eT min(uword& row_of_min_val, uword& col_of_min_v al) const;
inline arma_warn_unused eT max() const; inline arma_warn_unused eT max() const;
inline eT max(uword& index_of_max_val) const; inline eT max(uword& index_of_max_val) const;
inline eT max(uword& row_of_min_val, uword& col_of_min_v al) const; inline eT max(uword& row_of_min_val, uword& col_of_min_v al) const;
// saving and loading
inline bool save(const std::string name, const file_type type = arma_bi
nary, const bool print_status = true) const;
inline bool save( std::ostream& os, const file_type type = arma_bi
nary, const bool print_status = true) const;
inline bool load(const std::string name, const file_type type = arma_bi
nary, const bool print_status = true);
inline bool load( std::istream& is, const file_type type = arma_bi
nary, const bool print_status = true);
inline bool quiet_save(const std::string name, const file_type type = a
rma_binary) const;
inline bool quiet_save( std::ostream& os, const file_type type = a
rma_binary) const;
inline bool quiet_load(const std::string name, const file_type type = a
rma_binary);
inline bool quiet_load( std::istream& is, const file_type type = a
rma_binary);
// TODO: speed up loading of sparse matrices stored as text files (ie. ra
w_ascii and coord_ascii)
// TODO: implement auto_detect for sparse matrices
// TODO: modify docs to specify which formats are not applicable to spars
e matrices
// These forward declarations are necessary. // These forward declarations are necessary.
class iterator_base; class iterator_base;
class iterator; class iterator;
class const_iterator; class const_iterator;
class row_iterator; class row_iterator;
class const_row_iterator; class const_row_iterator;
// Iterator base provides comparison operators but not the actual logic o // Iterator base provides basic operators but not how to compare or how t
n how o
// to iterate. The validity of the position is not checked (that is left // iterate.
up
// to the user).
class iterator_base class iterator_base
{ {
public: public:
inline iterator_base(const SpMat& in_M); inline iterator_base(const SpMat& in_M);
inline iterator_base(const SpMat& in_M, const uword col, const uword po s); inline iterator_base(const SpMat& in_M, const uword col, const uword po s);
inline arma_hot eT operator*() const; inline arma_hot eT operator*() const;
inline arma_hot bool operator==(const iterator_base& rhs) const;
inline arma_hot bool operator!=(const iterator_base& rhs) const;
inline arma_hot bool operator==(const typename SpSubview<eT>::iterator_
base& rhs) const;
inline arma_hot bool operator!=(const typename SpSubview<eT>::iterator_
base& rhs) const;
// Don't hold location internally; call "dummy" methods to get that inf ormation. // Don't hold location internally; call "dummy" methods to get that inf ormation.
arma_inline uword row() const { return M.row_indices[internal_pos]; } arma_inline uword row() const { return M.row_indices[internal_pos]; }
arma_inline uword col() const { return internal_col; } arma_inline uword col() const { return internal_col; }
arma_inline uword pos() const { return internal_pos; } arma_inline uword pos() const { return internal_pos; }
arma_aligned const SpMat& M; arma_aligned const SpMat& M;
arma_aligned uword internal_col; arma_aligned uword internal_col;
arma_aligned uword internal_pos; arma_aligned uword internal_pos;
// So that we satisfy the STL iterator types.
typedef std::bidirectional_iterator_tag iterator_category;
typedef eT value_type;
typedef uword difference_type; // not certain
on this one
typedef const eT* pointer;
typedef const eT& reference;
}; };
class const_iterator : public iterator_base class const_iterator : public iterator_base
{ {
public: public:
inline const_iterator(const SpMat& in_M, uword initial_pos = 0); // Ass umes initial_pos is valid. inline const_iterator(const SpMat& in_M, uword initial_pos = 0); // Ass umes initial_pos is valid.
//! Once initialized, will be at the first nonzero value after the give n position (using forward columnwise traversal). //! Once initialized, will be at the first nonzero value after the give n position (using forward columnwise traversal).
inline const_iterator(const SpMat& in_M, uword in_row, uword in_col); inline const_iterator(const SpMat& in_M, uword in_row, uword in_col);
//! If you know the exact position of the iterator. in_row is a dummy argument. //! If you know the exact position of the iterator. in_row is a dummy argument.
inline const_iterator(const SpMat& in_M, uword in_row, uword in_col, uw ord in_pos); inline const_iterator(const SpMat& in_M, uword in_row, uword in_col, uw ord in_pos);
inline const_iterator(const const_iterator& other); inline const_iterator(const const_iterator& other);
inline arma_hot const_iterator& operator++(); inline arma_hot const_iterator& operator++();
inline arma_hot void operator++(int); inline arma_hot const_iterator operator++(int);
inline arma_hot const_iterator& operator--(); inline arma_hot const_iterator& operator--();
inline arma_hot void operator--(int); inline arma_hot const_iterator operator--(int);
inline arma_hot bool operator==(const const_iterator& rhs) const;
inline arma_hot bool operator!=(const const_iterator& rhs) const;
inline arma_hot bool operator==(const typename SpSubview<eT>::const_ite
rator& rhs) const;
inline arma_hot bool operator!=(const typename SpSubview<eT>::const_ite
rator& rhs) const;
inline arma_hot bool operator==(const const_row_iterator& rhs) const;
inline arma_hot bool operator!=(const const_row_iterator& rhs) const;
inline arma_hot bool operator==(const typename SpSubview<eT>::const_row
_iterator& rhs) const;
inline arma_hot bool operator!=(const typename SpSubview<eT>::const_row
_iterator& rhs) const;
}; };
/** /**
* So that we can iterate over nonzero values, we need an iterator * So that we can iterate over nonzero values, we need an iterator
* implementation. This can't be as simple as Mat's, which is just a poi nter * implementation. This can't be as simple as Mat's, which is just a poi nter
* to an eT. If a value is set to 0 using this iterator, the iterator is no * to an eT. If a value is set to 0 using this iterator, the iterator is no
* longer valid! * longer valid!
*/ */
class iterator : public const_iterator class iterator : public const_iterator
{ {
skipping to change at line 359 skipping to change at line 398
inline iterator(SpMat& in_M, uword initial_pos = 0) : const_iterator(in _M, initial_pos) { } inline iterator(SpMat& in_M, uword initial_pos = 0) : const_iterator(in _M, initial_pos) { }
inline iterator(SpMat& in_M, uword in_row, uword in_col) : const_iterat or(in_M, in_row, in_col) { } inline iterator(SpMat& in_M, uword in_row, uword in_col) : const_iterat or(in_M, in_row, in_col) { }
inline iterator(SpMat& in_M, uword in_row, uword in_col, uword in_pos) : const_iterator(in_M, in_row, in_col, in_pos) { } inline iterator(SpMat& in_M, uword in_row, uword in_col, uword in_pos) : const_iterator(in_M, in_row, in_col, in_pos) { }
inline iterator(const const_iterator& other) : const_iterator(other) { } inline iterator(const const_iterator& other) : const_iterator(other) { }
inline arma_hot SpValProxy<SpMat<eT> > operator*(); inline arma_hot SpValProxy<SpMat<eT> > operator*();
// overloads needed for return type correctness // overloads needed for return type correctness
inline arma_hot iterator& operator++(); inline arma_hot iterator& operator++();
inline arma_hot void operator++(int); inline arma_hot iterator operator++(int);
inline arma_hot iterator& operator--(); inline arma_hot iterator& operator--();
inline arma_hot void operator--(int); inline arma_hot iterator operator--(int);
// This has a different value_type than iterator_base.
typedef SpValProxy<SpMat<eT> > value_type;
typedef const SpValProxy<SpMat<eT> >* pointer;
typedef const SpValProxy<SpMat<eT> >& reference;
}; };
class const_row_iterator : public iterator_base class const_row_iterator : public iterator_base
{ {
public: public:
inline const_row_iterator(const SpMat& in_M, uword initial_pos = 0); inline const_row_iterator(const SpMat& in_M, uword initial_pos = 0);
//! Once initialized, will be at the first nonzero value after the give n position (using forward row-wise traversal). //! Once initialized, will be at the first nonzero value after the give n position (using forward row-wise traversal).
inline const_row_iterator(const SpMat& in_M, uword in_row, uword in_col ); inline const_row_iterator(const SpMat& in_M, uword in_row, uword in_col );
inline const_row_iterator(const const_row_iterator& other); inline const_row_iterator(const const_row_iterator& other);
inline arma_hot const_row_iterator& operator++(); inline arma_hot const_row_iterator& operator++();
inline arma_hot void operator++(int); inline arma_hot const_row_iterator operator++(int);
inline arma_hot const_row_iterator& operator--(); inline arma_hot const_row_iterator& operator--();
inline arma_hot void operator--(int); inline arma_hot const_row_iterator operator--(int);
uword internal_row; // Hold row internally because we use internal_pos differently. uword internal_row; // Hold row internally because we use internal_pos differently.
uword actual_pos; // Actual position in matrix. uword actual_pos; // Actual position in matrix.
arma_inline eT operator*() const { return iterator_base::M.values[actua l_pos]; } arma_inline eT operator*() const { return iterator_base::M.values[actua l_pos]; }
arma_inline uword row() const { return internal_row; } arma_inline uword row() const { return internal_row; }
inline arma_hot bool operator==(const const_iterator& rhs) const;
inline arma_hot bool operator!=(const const_iterator& rhs) const;
inline arma_hot bool operator==(const typename SpSubview<eT>::const_ite
rator& rhs) const;
inline arma_hot bool operator!=(const typename SpSubview<eT>::const_ite
rator& rhs) const;
inline arma_hot bool operator==(const const_row_iterator& rhs) const;
inline arma_hot bool operator!=(const const_row_iterator& rhs) const;
inline arma_hot bool operator==(const typename SpSubview<eT>::const_row
_iterator& rhs) const;
inline arma_hot bool operator!=(const typename SpSubview<eT>::const_row
_iterator& rhs) const;
}; };
class row_iterator : public const_row_iterator class row_iterator : public const_row_iterator
{ {
public: public:
inline row_iterator(SpMat& in_M, uword initial_pos = 0) : const_row_ite rator(in_M, initial_pos) { } inline row_iterator(SpMat& in_M, uword initial_pos = 0) : const_row_ite rator(in_M, initial_pos) { }
//! Once initialized, will be at the first nonzero value after the give n position (using forward row-wise traversal). //! Once initialized, will be at the first nonzero value after the give n position (using forward row-wise traversal).
inline row_iterator(SpMat& in_M, uword in_row, uword in_col) : const_ro w_iterator(in_M, in_row, in_col) { } inline row_iterator(SpMat& in_M, uword in_row, uword in_col) : const_ro w_iterator(in_M, in_row, in_col) { }
inline row_iterator(const row_iterator& other) : const_row_iterator(oth er) { } inline row_iterator(const row_iterator& other) : const_row_iterator(oth er) { }
inline arma_hot SpValProxy<SpMat<eT> > operator*(); inline arma_hot SpValProxy<SpMat<eT> > operator*();
// overloads required for return type correctness // overloads required for return type correctness
inline arma_hot row_iterator& operator++(); inline arma_hot row_iterator& operator++();
inline arma_hot void operator++(int); inline arma_hot row_iterator operator++(int);
inline arma_hot row_iterator& operator--(); inline arma_hot row_iterator& operator--();
inline arma_hot void operator--(int); inline arma_hot row_iterator operator--(int);
// This has a different value_type than iterator_base.
typedef SpValProxy<SpMat<eT> > value_type;
typedef const SpValProxy<SpMat<eT> >* pointer;
typedef const SpValProxy<SpMat<eT> >& reference;
}; };
inline iterator begin(); inline iterator begin();
inline const_iterator begin() const; inline const_iterator begin() const;
inline iterator end(); inline iterator end();
inline const_iterator end() const; inline const_iterator end() const;
inline iterator begin_col(const uword col_num); inline iterator begin_col(const uword col_num);
inline const_iterator begin_col(const uword col_num) const; inline const_iterator begin_col(const uword col_num) const;
skipping to change at line 440 skipping to change at line 501
inline uword size() const; inline uword size() const;
/** /**
* Resize memory. You are responsible for updating the column pointers a nd * Resize memory. You are responsible for updating the column pointers a nd
* filling the new memory (if the new size is larger). If the new size i s * filling the new memory (if the new size is larger). If the new size i s
* smaller, the first new_n_nonzero elements will be copied. n_nonzero i s * smaller, the first new_n_nonzero elements will be copied. n_nonzero i s
* updated. * updated.
*/ */
inline void mem_resize(const uword new_n_nonzero); inline void mem_resize(const uword new_n_nonzero);
inline void steal_mem(SpMat& X); //!< don't use this unless you're writin //! don't use this unless you're writing internal Armadillo code
g internal Armadillo code inline void steal_mem(SpMat& X);
//! don't use this unless you're writing internal Armadillo code
template< typename T1, typename Functor> arma_hot inline voi
d init_xform (const SpBase<eT, T1>& x, const Functor& func);
template<typename eT2, typename T1, typename Functor> arma_hot inline voi
d init_xform_mt(const SpBase<eT2,T1>& x, const Functor& func);
protected: protected:
/** /**
* Initialize the matrix to the specified size. Data is not preserved, s o the matrix is assumed to be entirely sparse (empty). * Initialize the matrix to the specified size. Data is not preserved, s o the matrix is assumed to be entirely sparse (empty).
*/ */
inline void init(uword in_rows, uword in_cols); inline void init(uword in_rows, uword in_cols);
/** /**
* Initialize the matrix from text. Data is (of course) not preserved, a nd * Initialize the matrix from text. Data is (of course) not preserved, a nd
 End of changes. 15 change blocks. 
23 lines changed or deleted 113 lines changed or added


 SpMat_iterators_meat.hpp   SpMat_iterators_meat.hpp 
skipping to change at line 50 skipping to change at line 50
template<typename eT> template<typename eT>
inline inline
arma_hot arma_hot
eT eT
SpMat<eT>::iterator_base::operator*() const SpMat<eT>::iterator_base::operator*() const
{ {
return M.values[internal_pos]; return M.values[internal_pos];
} }
template<typename eT>
inline
arma_hot
bool
SpMat<eT>::iterator_base::operator==(const iterator_base& rhs) const
{
return (rhs.row() == row()) && (rhs.col() == internal_col);
}
template<typename eT>
inline
arma_hot
bool
SpMat<eT>::iterator_base::operator!=(const iterator_base& rhs) const
{
return (rhs.row() != row()) || (rhs.col() != internal_col);
}
template<typename eT>
inline
arma_hot
bool
SpMat<eT>::iterator_base::operator==(const typename SpSubview<eT>::iterator
_base& rhs) const
{
return (rhs.row() == row()) && (rhs.col() == internal_col);
}
template<typename eT>
inline
arma_hot
bool
SpMat<eT>::iterator_base::operator!=(const typename SpSubview<eT>::iterator
_base& rhs) const
{
return (rhs.row() != row()) || (rhs.col() != internal_col);
}
/////////////////////////////////////////////////////////////////////////// //// /////////////////////////////////////////////////////////////////////////// ////
// SpMat::const_iterator implementation // // SpMat::const_iterator implementation //
/////////////////////////////////////////////////////////////////////////// //// /////////////////////////////////////////////////////////////////////////// ////
template<typename eT> template<typename eT>
inline inline
SpMat<eT>::const_iterator::const_iterator(const SpMat<eT>& in_M, uword init ial_pos) SpMat<eT>::const_iterator::const_iterator(const SpMat<eT>& in_M, uword init ial_pos)
: iterator_base(in_M, 0, initial_pos) : iterator_base(in_M, 0, initial_pos)
{ {
// Corner case for empty matrices. // Corner case for empty matrices.
skipping to change at line 172 skipping to change at line 136
{ {
++iterator_base::internal_col; ++iterator_base::internal_col;
} }
return *this; return *this;
} }
template<typename eT> template<typename eT>
inline inline
arma_hot arma_hot
void typename SpMat<eT>::const_iterator
SpMat<eT>::const_iterator::operator++(int) SpMat<eT>::const_iterator::operator++(int)
{ {
typename SpMat<eT>::const_iterator tmp(*this);
++(*this); ++(*this);
return tmp;
} }
template<typename eT> template<typename eT>
inline inline
arma_hot arma_hot
typename SpMat<eT>::const_iterator& typename SpMat<eT>::const_iterator&
SpMat<eT>::const_iterator::operator--() SpMat<eT>::const_iterator::operator--()
{ {
//iterator_base::M.print("M"); //iterator_base::M.print("M");
skipping to change at line 206 skipping to change at line 174
--iterator_base::internal_col; --iterator_base::internal_col;
} }
return *this; return *this;
} }
template<typename eT> template<typename eT>
inline inline
arma_hot arma_hot
void typename SpMat<eT>::const_iterator
SpMat<eT>::const_iterator::operator--(int) SpMat<eT>::const_iterator::operator--(int)
{ {
typename SpMat<eT>::const_iterator tmp(*this);
--(*this); --(*this);
return tmp;
}
template<typename eT>
inline
arma_hot
bool
SpMat<eT>::const_iterator::operator==(const const_iterator& rhs) const
{
return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::inter
nal_col);
}
template<typename eT>
inline
arma_hot
bool
SpMat<eT>::const_iterator::operator!=(const const_iterator& rhs) const
{
return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::inter
nal_col);
}
template<typename eT>
inline
arma_hot
bool
SpMat<eT>::const_iterator::operator==(const typename SpSubview<eT>::const_i
terator& rhs) const
{
return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::inter
nal_col);
}
template<typename eT>
inline
arma_hot
bool
SpMat<eT>::const_iterator::operator!=(const typename SpSubview<eT>::const_i
terator& rhs) const
{
return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::inter
nal_col);
}
template<typename eT>
inline
arma_hot
bool
SpMat<eT>::const_iterator::operator==(const const_row_iterator& rhs) const
{
return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::inter
nal_col);
}
template<typename eT>
inline
arma_hot
bool
SpMat<eT>::const_iterator::operator!=(const const_row_iterator& rhs) const
{
return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::inter
nal_col);
}
template<typename eT>
inline
arma_hot
bool
SpMat<eT>::const_iterator::operator==(const typename SpSubview<eT>::const_r
ow_iterator& rhs) const
{
return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::inter
nal_col);
}
template<typename eT>
inline
arma_hot
bool
SpMat<eT>::const_iterator::operator!=(const typename SpSubview<eT>::const_r
ow_iterator& rhs) const
{
return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::inter
nal_col);
} }
/////////////////////////////////////////////////////////////////////////// //// /////////////////////////////////////////////////////////////////////////// ////
// SpMat::iterator implementation // // SpMat::iterator implementation //
/////////////////////////////////////////////////////////////////////////// //// /////////////////////////////////////////////////////////////////////////// ////
template<typename eT> template<typename eT>
inline inline
arma_hot arma_hot
SpValProxy<SpMat<eT> > SpValProxy<SpMat<eT> >
skipping to change at line 242 skipping to change at line 286
typename SpMat<eT>::iterator& typename SpMat<eT>::iterator&
SpMat<eT>::iterator::operator++() SpMat<eT>::iterator::operator++()
{ {
const_iterator::operator++(); const_iterator::operator++();
return *this; return *this;
} }
template<typename eT> template<typename eT>
inline inline
arma_hot arma_hot
void typename SpMat<eT>::iterator
SpMat<eT>::iterator::operator++(int) SpMat<eT>::iterator::operator++(int)
{ {
typename SpMat<eT>::iterator tmp(*this);
const_iterator::operator++(); const_iterator::operator++();
return tmp;
} }
template<typename eT> template<typename eT>
inline inline
arma_hot arma_hot
typename SpMat<eT>::iterator& typename SpMat<eT>::iterator&
SpMat<eT>::iterator::operator--() SpMat<eT>::iterator::operator--()
{ {
const_iterator::operator--(); const_iterator::operator--();
return *this; return *this;
} }
template<typename eT> template<typename eT>
inline inline
arma_hot arma_hot
void typename SpMat<eT>::iterator
SpMat<eT>::iterator::operator--(int) SpMat<eT>::iterator::operator--(int)
{ {
typename SpMat<eT>::iterator tmp(*this);
const_iterator::operator--(); const_iterator::operator--();
return tmp;
} }
/////////////////////////////////////////////////////////////////////////// //// /////////////////////////////////////////////////////////////////////////// ////
// SpMat::const_row_iterator implementation // // SpMat::const_row_iterator implementation //
/////////////////////////////////////////////////////////////////////////// //// /////////////////////////////////////////////////////////////////////////// ////
/** /**
* Initialize the const_row_iterator. * Initialize the const_row_iterator.
*/ */
template<typename eT> template<typename eT>
inline inline
SpMat<eT>::const_row_iterator::const_row_iterator(const SpMat<eT>& in_M, uw ord initial_pos) SpMat<eT>::const_row_iterator::const_row_iterator(const SpMat<eT>& in_M, uw ord initial_pos)
: iterator_base(in_M, 0, initial_pos) : iterator_base(in_M, 0, initial_pos)
, internal_row(0) , internal_row(0)
, actual_pos(0) , actual_pos(0)
{ {
// Corner case for empty matrix. // Corner case for empty matrix.
if(in_M.n_nonzero == 0) if(in_M.n_nonzero == 0)
{ {
iterator_base::internal_col = in_M.n_cols; iterator_base::internal_col = 0;
internal_row = in_M.n_rows;
return; return;
} }
// We don't count zeroes in our position count, so we have to find the no nzero // We don't count zeroes in our position count, so we have to find the no nzero
// value corresponding to the given initial position. We assume initial_ pos // value corresponding to the given initial position. We assume initial_ pos
// is valid. // is valid.
// This is irritating because we don't know where the elements are in eac h // This is irritating because we don't know where the elements are in eac h
// row. What we will do is loop across all columns looking for elements in // row. What we will do is loop across all columns looking for elements in
// row 0 (and add to our sum), then in row 1, and so forth, until we get to // row 0 (and add to our sum), then in row 1, and so forth, until we get to
skipping to change at line 430 skipping to change at line 483
} }
} }
} }
/** /**
* Increment the row_iterator (but do not return anything. * Increment the row_iterator (but do not return anything.
*/ */
template<typename eT> template<typename eT>
inline inline
arma_hot arma_hot
void typename SpMat<eT>::const_row_iterator
SpMat<eT>::const_row_iterator::operator++(int) SpMat<eT>::const_row_iterator::operator++(int)
{ {
typename SpMat<eT>::const_row_iterator tmp(*this);
++(*this); ++(*this);
return tmp;
} }
/** /**
* Decrement the row_iterator. * Decrement the row_iterator.
*/ */
template<typename eT> template<typename eT>
inline inline
arma_hot arma_hot
typename SpMat<eT>::const_row_iterator& typename SpMat<eT>::const_row_iterator&
SpMat<eT>::const_row_iterator::operator--() SpMat<eT>::const_row_iterator::operator--()
skipping to change at line 482 skipping to change at line 539
} }
} }
} }
/** /**
* Decrement the row_iterator. * Decrement the row_iterator.
*/ */
template<typename eT> template<typename eT>
inline inline
arma_hot arma_hot
void typename SpMat<eT>::const_row_iterator
SpMat<eT>::const_row_iterator::operator--(int) SpMat<eT>::const_row_iterator::operator--(int)
{ {
typename SpMat<eT>::const_row_iterator tmp(*this);
--(*this); --(*this);
return tmp;
}
template<typename eT>
inline
arma_hot
bool
SpMat<eT>::const_row_iterator::operator==(const const_iterator& rhs) const
{
return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col)
;
}
template<typename eT>
inline
arma_hot
bool
SpMat<eT>::const_row_iterator::operator!=(const const_iterator& rhs) const
{
return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col)
;
}
template<typename eT>
inline
arma_hot
bool
SpMat<eT>::const_row_iterator::operator==(const typename SpSubview<eT>::con
st_iterator& rhs) const
{
return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col)
;
}
template<typename eT>
inline
arma_hot
bool
SpMat<eT>::const_row_iterator::operator!=(const typename SpSubview<eT>::con
st_iterator& rhs) const
{
return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col)
;
}
template<typename eT>
inline
arma_hot
bool
SpMat<eT>::const_row_iterator::operator==(const const_row_iterator& rhs) co
nst
{
return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col)
;
}
template<typename eT>
inline
arma_hot
bool
SpMat<eT>::const_row_iterator::operator!=(const const_row_iterator& rhs) co
nst
{
return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col)
;
}
template<typename eT>
inline
arma_hot
bool
SpMat<eT>::const_row_iterator::operator==(const typename SpSubview<eT>::con
st_row_iterator& rhs) const
{
return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col)
;
}
template<typename eT>
inline
arma_hot
bool
SpMat<eT>::const_row_iterator::operator!=(const typename SpSubview<eT>::con
st_row_iterator& rhs) const
{
return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col)
;
} }
/////////////////////////////////////////////////////////////////////////// //// /////////////////////////////////////////////////////////////////////////// ////
// SpMat::row_iterator implementation // // SpMat::row_iterator implementation //
/////////////////////////////////////////////////////////////////////////// //// /////////////////////////////////////////////////////////////////////////// ////
template<typename eT> template<typename eT>
inline inline
arma_hot arma_hot
SpValProxy<SpMat<eT> > SpValProxy<SpMat<eT> >
skipping to change at line 518 skipping to change at line 651
typename SpMat<eT>::row_iterator& typename SpMat<eT>::row_iterator&
SpMat<eT>::row_iterator::operator++() SpMat<eT>::row_iterator::operator++()
{ {
const_row_iterator::operator++(); const_row_iterator::operator++();
return *this; return *this;
} }
template<typename eT> template<typename eT>
inline inline
arma_hot arma_hot
void typename SpMat<eT>::row_iterator
SpMat<eT>::row_iterator::operator++(int) SpMat<eT>::row_iterator::operator++(int)
{ {
typename SpMat<eT>::row_iterator tmp(*this);
const_row_iterator::operator++(); const_row_iterator::operator++();
return tmp;
} }
template<typename eT> template<typename eT>
inline inline
arma_hot arma_hot
typename SpMat<eT>::row_iterator& typename SpMat<eT>::row_iterator&
SpMat<eT>::row_iterator::operator--() SpMat<eT>::row_iterator::operator--()
{ {
const_row_iterator::operator--(); const_row_iterator::operator--();
return *this; return *this;
} }
template<typename eT> template<typename eT>
inline inline
arma_hot arma_hot
void typename SpMat<eT>::row_iterator
SpMat<eT>::row_iterator::operator--(int) SpMat<eT>::row_iterator::operator--(int)
{ {
typename SpMat<eT>::row_iterator tmp(*this);
const_row_iterator::operator--(); const_row_iterator::operator--();
return tmp;
} }
//! @} //! @}
 End of changes. 26 change blocks. 
47 lines changed or deleted 212 lines changed or added


 SpMat_meat.hpp   SpMat_meat.hpp 
skipping to change at line 30 skipping to change at line 30
template<typename eT> template<typename eT>
inline inline
SpMat<eT>::SpMat() SpMat<eT>::SpMat()
: n_rows(0) : n_rows(0)
, n_cols(0) , n_cols(0)
, n_elem(0) , n_elem(0)
, n_nonzero(0) , n_nonzero(0)
, vec_state(0) , vec_state(0)
, values(memory::acquire_chunked<eT>(1)) , values(memory::acquire_chunked<eT>(1))
, row_indices(memory::acquire_chunked<uword>(1)) , row_indices(memory::acquire_chunked<uword>(1))
, col_ptrs(memory::acquire<uword>(1)) , col_ptrs(memory::acquire<uword>(2))
{ {
arma_extra_debug_sigprint_this(this); arma_extra_debug_sigprint_this(this);
access::rw(values[0]) = 0; access::rw(values[0]) = 0;
access::rw(row_indices[0]) = 0; access::rw(row_indices[0]) = 0;
access::rw(col_ptrs[0]) = 0; // No elements. access::rw(col_ptrs[0]) = 0; // No elements.
access::rw(col_ptrs[1]) = std::numeric_limits<uword>::max();
} }
/** /**
* Clean up the memory of a sparse matrix and destruct it. * Clean up the memory of a sparse matrix and destruct it.
*/ */
template<typename eT> template<typename eT>
inline inline
SpMat<eT>::~SpMat() SpMat<eT>::~SpMat()
{ {
arma_extra_debug_sigprint_this(this); arma_extra_debug_sigprint_this(this);
skipping to change at line 1224 skipping to change at line 1225
, col_ptrs(NULL) , col_ptrs(NULL)
{ {
arma_extra_debug_sigprint_this(this); arma_extra_debug_sigprint_this(this);
arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == fa lse )); arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == fa lse ));
spglue_type::apply(*this, X); spglue_type::apply(*this, X);
} }
template<typename eT> template<typename eT>
template<typename T1, typename spop_type>
inline
SpMat<eT>::SpMat(const mtSpOp<eT, T1, spop_type>& X)
: n_rows(0)
, n_cols(0)
, n_elem(0)
, n_nonzero(0)
, vec_state(0)
, values(NULL) // extra element set in application of sparse glue
, row_indices(NULL)
, col_ptrs(NULL)
{
arma_extra_debug_sigprint_this(this);
spop_type::apply(*this, X);
}
template<typename eT>
template<typename T1, typename spop_type>
inline
const SpMat<eT>&
SpMat<eT>::operator=(const mtSpOp<eT, T1, spop_type>& X)
{
arma_extra_debug_sigprint();
spop_type::apply(*this, X);
return *this;
}
template<typename eT>
template<typename T1, typename spop_type>
inline
const SpMat<eT>&
SpMat<eT>::operator+=(const mtSpOp<eT, T1, spop_type>& X)
{
arma_extra_debug_sigprint();
const SpMat<eT> m(X);
return (*this).operator+=(m);
}
template<typename eT>
template<typename T1, typename spop_type>
inline
const SpMat<eT>&
SpMat<eT>::operator-=(const mtSpOp<eT, T1, spop_type>& X)
{
arma_extra_debug_sigprint();
const SpMat<eT> m(X);
return (*this).operator-=(m);
}
template<typename eT>
template<typename T1, typename spop_type>
inline
const SpMat<eT>&
SpMat<eT>::operator*=(const mtSpOp<eT, T1, spop_type>& X)
{
arma_extra_debug_sigprint();
const SpMat<eT> m(X);
return (*this).operator*=(m);
}
template<typename eT>
template<typename T1, typename spop_type>
inline
const SpMat<eT>&
SpMat<eT>::operator%=(const mtSpOp<eT, T1, spop_type>& X)
{
arma_extra_debug_sigprint();
const SpMat<eT> m(X);
return (*this).operator%=(m);
}
template<typename eT>
template<typename T1, typename spop_type>
inline
const SpMat<eT>&
SpMat<eT>::operator/=(const mtSpOp<eT, T1, spop_type>& X)
{
arma_extra_debug_sigprint();
const SpMat<eT> m(X);
return (*this).operator/=(m);
}
template<typename eT>
template<typename T1, typename T2, typename spglue_type> template<typename T1, typename T2, typename spglue_type>
inline inline
const SpMat<eT>& const SpMat<eT>&
SpMat<eT>::operator=(const SpGlue<T1, T2, spglue_type>& X) SpMat<eT>::operator=(const SpGlue<T1, T2, spglue_type>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == fa lse )); arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == fa lse ));
spglue_type::apply(*this, X); spglue_type::apply(*this, X);
skipping to change at line 1750 skipping to change at line 1847
access::rw(values) = new_values; access::rw(values) = new_values;
access::rw(row_indices) = new_row_indices; access::rw(row_indices) = new_row_indices;
// Update counts and such. // Update counts and such.
access::rw(n_nonzero) -= diff; access::rw(n_nonzero) -= diff;
} }
// Update column pointers. // Update column pointers.
const uword new_n_cols = n_cols - ((in_col2 - in_col1) + 1); const uword new_n_cols = n_cols - ((in_col2 - in_col1) + 1);
uword* new_col_ptrs = memory::acquire<uword>(new_n_cols + 1); uword* new_col_ptrs = memory::acquire<uword>(new_n_cols + 2);
new_col_ptrs[new_n_cols + 1] = std::numeric_limits<uword>::max();
// Copy first set of columns (no manipulation required). // Copy first set of columns (no manipulation required).
if (in_col1 != 0) if (in_col1 != 0)
{ {
arrayops::copy(new_col_ptrs, col_ptrs, in_col1); arrayops::copy(new_col_ptrs, col_ptrs, in_col1);
} }
// Copy second set of columns (manipulation required). // Copy second set of columns (manipulation required).
uword cur_col = in_col1; uword cur_col = in_col1;
for (uword i = in_col2 + 1; i <= n_cols; ++i, ++cur_col) for (uword i = in_col2 + 1; i <= n_cols; ++i, ++cur_col)
skipping to change at line 1871 skipping to change at line 1969
return SpSubview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_c ols); return SpSubview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_c ols);
} }
template<typename eT> template<typename eT>
arma_inline arma_inline
const SpSubview<eT> const SpSubview<eT>
SpMat<eT>::submat(const uword in_row1, const uword in_col1, const uword in_ row2, const uword in_col2) const SpMat<eT>::submat(const uword in_row1, const uword in_col1, const uword in_ row2, const uword in_col2) const
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return submat(in_row1, in_col1, in_row2, in_col2); arma_debug_check
(
(in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (
in_col2 >= n_cols),
"SpMat::submat(): indices out of bounds or incorrectly used"
);
const uword subview_n_rows = in_row2 - in_row1 + 1;
const uword subview_n_cols = in_col2 - in_col1 + 1;
return SpSubview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_c
ols);
} }
template<typename eT> template<typename eT>
inline inline
SpSubview<eT> SpSubview<eT>
SpMat<eT>::submat (const span& row_span, const span& col_span) SpMat<eT>::submat (const span& row_span, const span& col_span)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const bool row_all = row_span.whole; const bool row_all = row_span.whole;
skipping to change at line 1914 skipping to change at line 2021
return SpSubview<eT>(*this, in_row1, in_col1, submat_n_rows, submat_n_col s); return SpSubview<eT>(*this, in_row1, in_col1, submat_n_rows, submat_n_col s);
} }
template<typename eT> template<typename eT>
inline inline
const SpSubview<eT> const SpSubview<eT>
SpMat<eT>::submat (const span& row_span, const span& col_span) const SpMat<eT>::submat (const span& row_span, const span& col_span) const
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
// Call the non-const version of this function, then cast back to const ( const bool row_all = row_span.whole;
avoids code duplication). const bool col_all = col_span.whole;
return const_cast<const SpSubview<eT> >(const_cast<SpMat<eT>* >(this)->su
bmat(row_span, col_span)); const uword local_n_rows = n_rows;
const uword local_n_cols = n_cols;
const uword in_row1 = row_all ? 0 : row_span.a;
const uword in_row2 = row_span.b;
const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 +
1;
const uword in_col1 = col_all ? 0 : col_span.a;
const uword in_col2 = col_span.b;
const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 +
1;
arma_debug_check
(
( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows))
)
||
( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols))
)
,
"SpMat::submat(): indices out of bounds or incorrectly used"
);
return SpSubview<eT>(*this, in_row1, in_col1, submat_n_rows, submat_n_col
s);
} }
template<typename eT> template<typename eT>
inline inline
SpSubview<eT> SpSubview<eT>
SpMat<eT>::operator()(const span& row_span, const span& col_span) SpMat<eT>::operator()(const span& row_span, const span& col_span)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return submat(row_span, col_span); return submat(row_span, col_span);
skipping to change at line 2448 skipping to change at line 2577
void void
SpMat<eT>::reshape(const uword in_rows, const uword in_cols, const uword di m) SpMat<eT>::reshape(const uword in_rows, const uword in_cols, const uword di m)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
if (dim == 0) if (dim == 0)
{ {
// We have to modify all of the relevant row indices and the relevant c olumn pointers. // We have to modify all of the relevant row indices and the relevant c olumn pointers.
// Iterate over all the points to do this. We won't be deleting any po ints, but we will be modifying // Iterate over all the points to do this. We won't be deleting any po ints, but we will be modifying
// columns and rows. We'll have to store a new set of column vectors. // columns and rows. We'll have to store a new set of column vectors.
uword* new_col_ptrs = memory::acquire<uword>(in_cols + 1); uword* new_col_ptrs = memory::acquire<uword>(in_cols + 2);
new_col_ptrs[in_cols + 1] = std::numeric_limits<uword>::max();
uword* new_row_indices = memory::acquire_chunked<uword>(n_nonzero + 1); uword* new_row_indices = memory::acquire_chunked<uword>(n_nonzero + 1);
access::rw(new_row_indices[n_nonzero]) = 0; access::rw(new_row_indices[n_nonzero]) = 0;
arrayops::inplace_set(new_col_ptrs, uword(0), in_cols + 1); arrayops::inplace_set(new_col_ptrs, uword(0), in_cols + 1);
for(const_iterator it = begin(); it != end(); it++) for(const_iterator it = begin(); it != end(); it++)
{ {
uword vector_position = (it.col() * n_rows) + it.row(); uword vector_position = (it.col() * n_rows) + it.row();
new_row_indices[it.pos()] = vector_position % in_rows; new_row_indices[it.pos()] = vector_position % in_rows;
skipping to change at line 2993 skipping to change at line 3123
{ {
get_position(location, row_of_max_val, col_of_max_val); get_position(location, row_of_max_val, col_of_max_val);
} }
} }
return val; return val;
} }
//! save the matrix to a file
template<typename eT>
inline
bool
SpMat<eT>::save(const std::string name, const file_type type, const bool pr
int_status) const
{
arma_extra_debug_sigprint();
bool save_okay;
switch(type)
{
// case raw_ascii:
// save_okay = diskio::save_raw_ascii(*this, name);
// break;
// case csv_ascii:
// save_okay = diskio::save_csv_ascii(*this, name);
// break;
case arma_binary:
save_okay = diskio::save_arma_binary(*this, name);
break;
case coord_ascii:
save_okay = diskio::save_coord_ascii(*this, name);
break;
default:
arma_warn(true, "SpMat::save(): unsupported file type");
save_okay = false;
}
arma_warn( (save_okay == false), "SpMat::save(): couldn't write to ", nam
e);
return save_okay;
}
//! save the matrix to a stream
template<typename eT>
inline
bool
SpMat<eT>::save(std::ostream& os, const file_type type, const bool print_st
atus) const
{
arma_extra_debug_sigprint();
bool save_okay;
switch(type)
{
// case raw_ascii:
// save_okay = diskio::save_raw_ascii(*this, os);
// break;
// case csv_ascii:
// save_okay = diskio::save_csv_ascii(*this, os);
// break;
case arma_binary:
save_okay = diskio::save_arma_binary(*this, os);
break;
case coord_ascii:
save_okay = diskio::save_coord_ascii(*this, os);
break;
default:
arma_warn(true, "SpMat::save(): unsupported file type");
save_okay = false;
}
arma_warn( (save_okay == false), "SpMat::save(): couldn't write to the gi
ven stream");
return save_okay;
}
//! load a matrix from a file
template<typename eT>
inline
bool
SpMat<eT>::load(const std::string name, const file_type type, const bool pr
int_status)
{
arma_extra_debug_sigprint();
bool load_okay;
std::string err_msg;
switch(type)
{
// case auto_detect:
// load_okay = diskio::load_auto_detect(*this, name, err_msg);
// break;
// case raw_ascii:
// load_okay = diskio::load_raw_ascii(*this, name, err_msg);
// break;
// case csv_ascii:
// load_okay = diskio::load_csv_ascii(*this, name, err_msg);
// break;
case arma_binary:
load_okay = diskio::load_arma_binary(*this, name, err_msg);
break;
case coord_ascii:
load_okay = diskio::load_coord_ascii(*this, name, err_msg);
break;
default:
arma_warn(true, "SpMat::load(): unsupported file type");
load_okay = false;
}
if(load_okay == false)
{
if(err_msg.length() > 0)
{
arma_warn(true, "SpMat::load(): ", err_msg, name);
}
else
{
arma_warn(true, "SpMat::load(): couldn't read ", name);
}
}
if(load_okay == false)
{
(*this).reset();
}
return load_okay;
}
//! load a matrix from a stream
template<typename eT>
inline
bool
SpMat<eT>::load(std::istream& is, const file_type type, const bool print_st
atus)
{
arma_extra_debug_sigprint();
bool load_okay;
std::string err_msg;
switch(type)
{
// case auto_detect:
// load_okay = diskio::load_auto_detect(*this, is, err_msg);
// break;
// case raw_ascii:
// load_okay = diskio::load_raw_ascii(*this, is, err_msg);
// break;
// case csv_ascii:
// load_okay = diskio::load_csv_ascii(*this, is, err_msg);
// break;
case arma_binary:
load_okay = diskio::load_arma_binary(*this, is, err_msg);
break;
case coord_ascii:
load_okay = diskio::load_coord_ascii(*this, is, err_msg);
break;
default:
arma_warn(true, "SpMat::load(): unsupported file type");
load_okay = false;
}
if(load_okay == false)
{
if(err_msg.length() > 0)
{
arma_warn(true, "SpMat::load(): ", err_msg, "the given stream");
}
else
{
arma_warn(true, "SpMat::load(): couldn't load from the given stream")
;
}
}
if(load_okay == false)
{
(*this).reset();
}
return load_okay;
}
//! save the matrix to a file, without printing any error messages
template<typename eT>
inline
bool
SpMat<eT>::quiet_save(const std::string name, const file_type type) const
{
arma_extra_debug_sigprint();
return (*this).save(name, type, false);
}
//! save the matrix to a stream, without printing any error messages
template<typename eT>
inline
bool
SpMat<eT>::quiet_save(std::ostream& os, const file_type type) const
{
arma_extra_debug_sigprint();
return (*this).save(os, type, false);
}
//! load a matrix from a file, without printing any error messages
template<typename eT>
inline
bool
SpMat<eT>::quiet_load(const std::string name, const file_type type)
{
arma_extra_debug_sigprint();
return (*this).load(name, type, false);
}
//! load a matrix from a stream, without printing any error messages
template<typename eT>
inline
bool
SpMat<eT>::quiet_load(std::istream& is, const file_type type)
{
arma_extra_debug_sigprint();
return (*this).load(is, type, false);
}
/** /**
* Initialize the matrix to the specified size. Data is not preserved, so the matrix is assumed to be entirely sparse (empty). * Initialize the matrix to the specified size. Data is not preserved, so the matrix is assumed to be entirely sparse (empty).
*/ */
template<typename eT> template<typename eT>
inline inline
void void
SpMat<eT>::init(uword in_rows, uword in_cols) SpMat<eT>::init(uword in_rows, uword in_cols)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
skipping to change at line 3046 skipping to change at line 3412
"SpMat::init(): requested size is too large" "SpMat::init(): requested size is too large"
); );
// Clean out the existing memory. // Clean out the existing memory.
if (values) if (values)
{ {
memory::release(values); memory::release(values);
memory::release(row_indices); memory::release(row_indices);
} }
access::rw(values) = memory::acquire_chunked<eT>(1); access::rw(values) = memory::acquire_chunked<eT> (1);
access::rw(row_indices) = memory::acquire_chunked<uword>(1); access::rw(row_indices) = memory::acquire_chunked<uword>(1);
access::rw(values[0]) = 0; access::rw(values[0]) = 0;
access::rw(row_indices[0]) = 0; access::rw(row_indices[0]) = 0;
memory::release(col_ptrs); memory::release(col_ptrs);
// Set the new size accordingly. // Set the new size accordingly.
access::rw(n_rows) = in_rows; access::rw(n_rows) = in_rows;
access::rw(n_cols) = in_cols; access::rw(n_cols) = in_cols;
access::rw(n_elem) = (in_rows * in_cols); access::rw(n_elem) = (in_rows * in_cols);
access::rw(n_nonzero) = 0; access::rw(n_nonzero) = 0;
// Try to allocate the column pointers, filling them with 0. // Try to allocate the column pointers, filling them with 0, except for t
access::rw(col_ptrs) = memory::acquire<uword>(in_cols + 1); he
// last element which contains the maximum possible element (so iterators
// terminate correctly).
access::rw(col_ptrs) = memory::acquire<uword>(in_cols + 2);
access::rw(col_ptrs[in_cols + 1]) = std::numeric_limits<uword>::max();
arrayops::inplace_set(access::rwp(col_ptrs), uword(0), in_cols + 1); arrayops::inplace_set(access::rwp(col_ptrs), uword(0), in_cols + 1);
} }
/** /**
* Initialize the matrix from a string. * Initialize the matrix from a string.
*/ */
template<typename eT> template<typename eT>
inline inline
void void
skipping to change at line 3228 skipping to change at line 3597
{ {
// Figure out the actual amount of memory currently allocated // Figure out the actual amount of memory currently allocated
// NOTE: this relies on memory::acquire_chunked() being used for the 'values' and 'row_indices' arrays // NOTE: this relies on memory::acquire_chunked() being used for the 'values' and 'row_indices' arrays
const uword n_alloc = memory::enlarge_to_mult_of_chunksize(n_nonzero) ; const uword n_alloc = memory::enlarge_to_mult_of_chunksize(n_nonzero) ;
if(n_alloc < new_n_nonzero) if(n_alloc < new_n_nonzero)
{ {
eT* new_values = memory::acquire_chunked<eT> (new_n_nonze ro + 1); eT* new_values = memory::acquire_chunked<eT> (new_n_nonze ro + 1);
uword* new_row_indices = memory::acquire_chunked<uword>(new_n_nonze ro + 1); uword* new_row_indices = memory::acquire_chunked<uword>(new_n_nonze ro + 1);
access::rw(new_values[new_n_nonzero]) = 0;
access::rw(new_row_indices[new_n_nonzero]) = 0;
if(n_nonzero > 0) if(n_nonzero > 0)
{ {
// Copy old elements. // Copy old elements.
uword copy_size = std::min(n_nonzero, new_n_nonzero); uword copy_size = std::min(n_nonzero, new_n_nonzero);
arrayops::copy(new_values, values, copy_size); arrayops::copy(new_values, values, copy_size);
arrayops::copy(new_row_indices, row_indices, copy_size); arrayops::copy(new_row_indices, row_indices, copy_size);
} }
memory::release(values); memory::release(values);
memory::release(row_indices); memory::release(row_indices);
access::rw(values) = new_values; access::rw(values) = new_values;
access::rw(row_indices) = new_row_indices; access::rw(row_indices) = new_row_indices;
} }
// Set the "fake end" of the matrix by setting the last value and row
// index to 0. This helps the iterators work correctly.
access::rw(values[new_n_nonzero]) = 0;
access::rw(row_indices[new_n_nonzero]) = 0;
} }
access::rw(n_nonzero) = new_n_nonzero; access::rw(n_nonzero) = new_n_nonzero;
} }
} }
// Steal memory from another matrix. // Steal memory from another matrix.
template<typename eT> template<typename eT>
inline inline
void void
skipping to change at line 3295 skipping to change at line 3666
access::rw(x.n_elem) = 0; access::rw(x.n_elem) = 0;
access::rw(x.n_nonzero) = 0; access::rw(x.n_nonzero) = 0;
access::rw(x.values) = NULL; access::rw(x.values) = NULL;
access::rw(x.row_indices) = NULL; access::rw(x.row_indices) = NULL;
access::rw(x.col_ptrs) = NULL; access::rw(x.col_ptrs) = NULL;
} }
} }
template<typename eT> template<typename eT>
template<typename T1, typename Functor>
arma_hot
inline
void
SpMat<eT>::init_xform(const SpBase<eT,T1>& A, const Functor& func)
{
arma_extra_debug_sigprint();
// if possible, avoid doing a copy and instead apply func to the generate
d elements
if(SpProxy<T1>::Q_created_by_proxy == true)
{
(*this) = A.get_ref();
const uword nnz = n_nonzero;
eT* t_values = access::rwp(values);
for(uword i=0; i < nnz; ++i)
{
t_values[i] = func(t_values[i]);
}
}
else
{
init_xform_mt(A.get_ref(), func);
}
}
template<typename eT>
template<typename eT2, typename T1, typename Functor>
arma_hot
inline
void
SpMat<eT>::init_xform_mt(const SpBase<eT2,T1>& A, const Functor& func)
{
arma_extra_debug_sigprint();
const SpProxy<T1> P(A.get_ref());
if( (P.is_alias(*this) == true) || (is_SpMat<typename SpProxy<T1>::stored
_type>::value == true) )
{
// NOTE: unwrap_spmat will convert a submatrix to a matrix, which in ef
fect takes care of aliasing with submatrices;
// NOTE: however, when more delayed ops are implemented, more elaborate
handling of aliasing will be necessary
const unwrap_spmat<typename SpProxy<T1>::stored_type> tmp(P.Q);
const SpMat<eT2>& x = tmp.M;
if(void_ptr(this) != void_ptr(&x))
{
init(x.n_rows, x.n_cols);
// values and row_indices may not be null.
if(values != NULL)
{
memory::release(values);
memory::release(row_indices);
}
access::rw(values) = memory::acquire_chunked<eT> (x.n_nonzero
+ 1);
access::rw(row_indices) = memory::acquire_chunked<uword>(x.n_nonzero
+ 1);
arrayops::copy(access::rwp(row_indices), x.row_indices, x.n_nonzero +
1);
arrayops::copy(access::rwp(col_ptrs), x.col_ptrs, x.n_cols +
1);
access::rw(n_nonzero) = x.n_nonzero;
}
// initialise the elements array with a transformed version of the elem
ents from x
const uword nnz = n_nonzero;
const eT2* x_values = x.values;
eT* t_values = access::rwp(values);
for(uword i=0; i < nnz; ++i)
{
t_values[i] = func(x_values[i]); // NOTE: func() must produce a val
ue of type eT (ie. act as a convertor between eT2 and eT)
}
}
else
{
init(P.get_n_rows(), P.get_n_cols());
mem_resize(P.get_n_nonzero());
typename SpProxy<T1>::const_iterator_type it = P.begin();
while(it != P.end())
{
access::rw(row_indices[it.pos()]) = it.row();
access::rw(values[it.pos()]) = func(*it); // NOTE: func() must prod
uce a value of type eT (ie. act as a convertor between eT2 and eT)
++access::rw(col_ptrs[it.col() + 1]);
++it;
}
// Now sum column pointers.
for(uword c = 1; c <= n_cols; ++c)
{
access::rw(col_ptrs[c]) += col_ptrs[c - 1];
}
}
}
template<typename eT>
inline inline
typename SpMat<eT>::iterator typename SpMat<eT>::iterator
SpMat<eT>::begin() SpMat<eT>::begin()
{ {
return iterator(*this); return iterator(*this);
} }
template<typename eT> template<typename eT>
inline inline
typename SpMat<eT>::const_iterator typename SpMat<eT>::const_iterator
skipping to change at line 3425 skipping to change at line 3900
access::rw(values) = memory::acquire_chunked<eT> (1); access::rw(values) = memory::acquire_chunked<eT> (1);
access::rw(row_indices) = memory::acquire_chunked<uword>(1); access::rw(row_indices) = memory::acquire_chunked<uword>(1);
access::rw(values[0]) = 0; access::rw(values[0]) = 0;
access::rw(row_indices[0]) = 0; access::rw(row_indices[0]) = 0;
} }
memory::release(col_ptrs); memory::release(col_ptrs);
access::rw(col_ptrs) = memory::acquire<uword>(n_cols + 1); access::rw(col_ptrs) = memory::acquire<uword>(n_cols + 2);
access::rw(col_ptrs[n_cols + 1]) = std::numeric_limits<uword>::max();
arrayops::inplace_set(col_ptrs, eT(0), n_cols + 1); arrayops::inplace_set(col_ptrs, eT(0), n_cols + 1);
access::rw(n_nonzero) = 0; access::rw(n_nonzero) = 0;
} }
template<typename eT> template<typename eT>
inline inline
bool bool
SpMat<eT>::empty() const SpMat<eT>::empty() const
 End of changes. 14 change blocks. 
15 lines changed or deleted 515 lines changed or added


 SpOp_bones.hpp   SpOp_bones.hpp 
skipping to change at line 23 skipping to change at line 23
//! @{ //! @{
template<typename T1, typename op_type> template<typename T1, typename op_type>
class SpOp : public SpBase<typename T1::elem_type, SpOp<T1, op_type> > class SpOp : public SpBase<typename T1::elem_type, SpOp<T1, op_type> >
{ {
public: public:
typedef typename T1::elem_type elem_type; typedef typename T1::elem_type elem_type;
typedef typename get_pod_type<elem_type>::result pod_type; typedef typename get_pod_type<elem_type>::result pod_type;
// static const bool is_row = ( T1::is_col && (is_same_type<op_type, op_s static const bool is_row = (T1::is_row && is_spop_elem<op_type>::value) |
trans>::value || is_same_type<op_type, op_htrans>::value) ); | ( T1::is_col && (is_same_type<op_type, spop_strans>::value || is_same_typ
// static const bool is_col = ( T1::is_row && (is_same_type<op_type, op_s e<op_type, spop_htrans>::value) );
trans>::value || is_same_type<op_type, op_htrans>::value) ); static const bool is_col = (T1::is_col && is_spop_elem<op_type>::value) |
| ( T1::is_row && (is_same_type<op_type, spop_strans>::value || is_same_typ
static const bool is_row = false; e<op_type, spop_htrans>::value) );
static const bool is_col = false;
inline explicit SpOp(const T1& in_m); inline explicit SpOp(const T1& in_m);
inline SpOp(const T1& in_m, const elem_type in_aux); inline SpOp(const T1& in_m, const elem_type in_aux);
inline SpOp(const T1& in_m, const uword in_aux_uword_a, cons t uword in_aux_uword_b); inline SpOp(const T1& in_m, const uword in_aux_uword_a, cons t uword in_aux_uword_b);
inline ~SpOp(); inline ~SpOp();
arma_aligned const T1& m; //!< storage of reference to t he operand (eg. a matrix) arma_aligned const T1& m; //!< storage of reference to t he operand (eg. a matrix)
arma_aligned elem_type aux; //!< storage of auxiliary data , user defined format arma_aligned elem_type aux; //!< storage of auxiliary data , user defined format
arma_aligned uword aux_uword_a; //!< storage of auxiliary data , uword format arma_aligned uword aux_uword_a; //!< storage of auxiliary data , uword format
arma_aligned uword aux_uword_b; //!< storage of auxiliary data , uword format arma_aligned uword aux_uword_b; //!< storage of auxiliary data , uword format
 End of changes. 1 change blocks. 
7 lines changed or deleted 6 lines changed or added


 SpProxy.hpp   SpProxy.hpp 
skipping to change at line 28 skipping to change at line 28
{ {
public: public:
typedef eT elem_type; typedef eT elem_type;
typedef typename get_pod_type<elem_type>::result pod_type; typedef typename get_pod_type<elem_type>::result pod_type;
typedef SpMat<eT> stored_type; typedef SpMat<eT> stored_type;
typedef typename SpMat<eT>::const_iterator const_iterator_type; typedef typename SpMat<eT>::const_iterator const_iterator_type;
typedef typename SpMat<eT>::const_row_iterator const_row_iterator_type; typedef typename SpMat<eT>::const_row_iterator const_row_iterator_type;
static const bool must_use_iterator = false; static const bool must_use_iterator = false;
static const bool Q_created_by_proxy = false;
static const bool is_row = false; static const bool is_row = false;
static const bool is_col = false; static const bool is_col = false;
arma_aligned const SpMat<eT>& Q; arma_aligned const SpMat<eT>& Q;
inline explicit SpProxy(const SpMat<eT>& A) inline explicit SpProxy(const SpMat<eT>& A)
: Q(A) : Q(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
skipping to change at line 53 skipping to change at line 54
arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline uword get_n_elem() const { return Q.n_elem; }
arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } arma_inline uword get_n_nonzero() const { return Q.n_nonzero; }
arma_inline elem_type operator[](const uword i) const { return Q[i]; } arma_inline elem_type operator[](const uword i) const { return Q[i]; }
arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
arma_inline const eT* get_values() const { return Q.values; } arma_inline const eT* get_values() const { return Q.values; }
arma_inline const uword* get_row_indices() const { return Q.row_indices; } arma_inline const uword* get_row_indices() const { return Q.row_indices; }
arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; } arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; }
arma_inline const_iterator_type begin() const arma_inline const_iterator_type begin() co
{ return Q.begin(); } nst { return Q.begin(); }
arma_inline const_iterator_type begin_col(const uword col_num) const arma_inline const_iterator_type begin_col(const uword col_num) co
{ return Q.begin_col(col_num); } nst { return Q.begin_col(col_num); }
arma_inline const_row_iterator_type begin_row() const arma_inline const_row_iterator_type begin_row(const uword row_num = 0) co
{ return Q.begin_row(); } nst { return Q.begin_row(row_num); }
arma_inline const_iterator_type end() const { return Q.end(); arma_inline const_iterator_type end() const {
} return Q.end(); }
arma_inline const_row_iterator_type end_row() const { return Q.end_row( arma_inline const_row_iterator_type end_row() const {
); } return Q.end_row(); }
arma_inline const_row_iterator_type end_row(const uword row_num) const {
return Q.end_row(row_num); }
template<typename eT2> template<typename eT2>
arma_inline bool is_alias(const SpMat<eT2>& X) const { return (void_ptr(& Q) == void_ptr(&X)); } arma_inline bool is_alias(const SpMat<eT2>& X) const { return (void_ptr(& Q) == void_ptr(&X)); }
}; };
template<typename eT> template<typename eT>
class SpProxy< SpCol<eT> > class SpProxy< SpCol<eT> >
{ {
public: public:
typedef eT elem_type; typedef eT elem_type;
typedef typename get_pod_type<elem_type>::result pod_type; typedef typename get_pod_type<elem_type>::result pod_type;
typedef SpCol<eT> stored_type; typedef SpCol<eT> stored_type;
typedef typename SpCol<eT>::const_iterator const_iterator_type; typedef typename SpCol<eT>::const_iterator const_iterator_type;
typedef typename SpCol<eT>::const_row_iterator const_row_iterator_type; typedef typename SpCol<eT>::const_row_iterator const_row_iterator_type;
static const bool must_use_iterator = false; static const bool must_use_iterator = false;
static const bool Q_created_by_proxy = false;
static const bool is_row = false; static const bool is_row = false;
static const bool is_col = true; static const bool is_col = true;
arma_aligned const SpCol<eT>& Q; arma_aligned const SpCol<eT>& Q;
inline explicit SpProxy(const SpCol<eT>& A) inline explicit SpProxy(const SpCol<eT>& A)
: Q(A) : Q(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
skipping to change at line 101 skipping to change at line 104
arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline uword get_n_elem() const { return Q.n_elem; }
arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } arma_inline uword get_n_nonzero() const { return Q.n_nonzero; }
arma_inline elem_type operator[](const uword i) const { return Q[i]; } arma_inline elem_type operator[](const uword i) const { return Q[i]; }
arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
arma_inline const eT* get_values() const { return Q.values; } arma_inline const eT* get_values() const { return Q.values; }
arma_inline const uword* get_row_indices() const { return Q.row_indices; } arma_inline const uword* get_row_indices() const { return Q.row_indices; }
arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; } arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; }
arma_inline const_iterator_type begin() const arma_inline const_iterator_type begin() co
{ return Q.begin(); } nst { return Q.begin(); }
arma_inline const_iterator_type begin_col(const uword col_num) const arma_inline const_iterator_type begin_col(const uword col_num) co
{ return Q.begin(); } nst { return Q.begin(); }
arma_inline const_row_iterator_type begin_row() const arma_inline const_row_iterator_type begin_row(const uword row_num = 0) co
{ return Q.begin_row(); } nst { return Q.begin_row(row_num); }
arma_inline const_iterator_type end() const { return Q.end(); arma_inline const_iterator_type end() const {
} return Q.end(); }
arma_inline const_row_iterator_type end_row() const { return Q.end_row( arma_inline const_row_iterator_type end_row() const {
); } return Q.end_row(); }
arma_inline const_row_iterator_type end_row(const uword row_num) const {
return Q.end_row(row_num); }
template<typename eT2> template<typename eT2>
arma_inline bool is_alias(const SpMat<eT2>& X) const { return (void_ptr(& Q) == void_ptr(&X)); } arma_inline bool is_alias(const SpMat<eT2>& X) const { return (void_ptr(& Q) == void_ptr(&X)); }
}; };
template<typename eT> template<typename eT>
class SpProxy< SpRow<eT> > class SpProxy< SpRow<eT> >
{ {
public: public:
typedef eT elem_type; typedef eT elem_type;
typedef typename get_pod_type<elem_type>::result pod_type; typedef typename get_pod_type<elem_type>::result pod_type;
typedef SpRow<eT> stored_type; typedef SpRow<eT> stored_type;
typedef typename SpRow<eT>::const_iterator const_iterator_type; typedef typename SpRow<eT>::const_iterator const_iterator_type;
typedef typename SpRow<eT>::const_row_iterator const_row_iterator_type; typedef typename SpRow<eT>::const_row_iterator const_row_iterator_type;
static const bool must_use_iterator = false; static const bool must_use_iterator = false;
static const bool Q_created_by_proxy = false;
static const bool is_row = true; static const bool is_row = true;
static const bool is_col = false; static const bool is_col = false;
arma_aligned const SpRow<eT>& Q; arma_aligned const SpRow<eT>& Q;
inline explicit SpProxy(const SpRow<eT>& A) inline explicit SpProxy(const SpRow<eT>& A)
: Q(A) : Q(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
skipping to change at line 149 skipping to change at line 154
arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline uword get_n_elem() const { return Q.n_elem; }
arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } arma_inline uword get_n_nonzero() const { return Q.n_nonzero; }
arma_inline elem_type operator[](const uword i) const { return Q[i]; } arma_inline elem_type operator[](const uword i) const { return Q[i]; }
arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
arma_inline const eT* get_values() const { return Q.values; } arma_inline const eT* get_values() const { return Q.values; }
arma_inline const uword* get_row_indices() const { return Q.row_indices; } arma_inline const uword* get_row_indices() const { return Q.row_indices; }
arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; } arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; }
arma_inline const_iterator_type begin() const arma_inline const_iterator_type begin() co
{ return Q.begin(); } nst { return Q.begin(); }
arma_inline const_iterator_type begin_col(const uword col_num) const arma_inline const_iterator_type begin_col(const uword col_num) co
{ return Q.begin_col(col_num); } nst { return Q.begin_col(col_num); }
arma_inline const_row_iterator_type begin_row() const arma_inline const_row_iterator_type begin_row(const uword row_num = 0) co
{ return Q.begin_row(); } nst { return Q.begin_row(row_num); }
arma_inline const_iterator_type end() const { return Q.end(); arma_inline const_iterator_type end() const {
} return Q.end(); }
arma_inline const_row_iterator_type end_row() const { return Q.end_row( arma_inline const_row_iterator_type end_row() const {
); } return Q.end_row(); }
arma_inline const_row_iterator_type end_row(const uword row_num) const {
return Q.end_row(row_num); }
template<typename eT2> template<typename eT2>
arma_inline bool is_alias(const SpMat<eT2>& X) const { return (void_ptr(& Q) == void_ptr(&X)); } arma_inline bool is_alias(const SpMat<eT2>& X) const { return (void_ptr(& Q) == void_ptr(&X)); }
}; };
template<typename eT> template<typename eT>
class SpProxy< SpSubview<eT> > class SpProxy< SpSubview<eT> >
{ {
public: public:
typedef eT elem_type; typedef eT elem_type;
typedef typename get_pod_type<elem_type>::result pod_type; typedef typename get_pod_type<elem_type>::result pod_type;
typedef SpSubview<eT> stored_type; typedef SpSubview<eT> stored_type;
typedef typename SpSubview<eT>::const_iterator const_iterator_type; typedef typename SpSubview<eT>::const_iterator const_iterator_type;
typedef typename SpSubview<eT>::const_row_iterator const_row_iterator_t ype; typedef typename SpSubview<eT>::const_row_iterator const_row_iterator_t ype;
static const bool must_use_iterator = true; static const bool must_use_iterator = true;
static const bool Q_created_by_proxy = false;
static const bool is_row = false; static const bool is_row = false;
static const bool is_col = false; static const bool is_col = false;
arma_aligned const SpSubview<eT>& Q; arma_aligned const SpSubview<eT>& Q;
inline explicit SpProxy(const SpSubview<eT>& A) inline explicit SpProxy(const SpSubview<eT>& A)
: Q(A) : Q(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
skipping to change at line 197 skipping to change at line 204
arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline uword get_n_elem() const { return Q.n_elem; }
arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } arma_inline uword get_n_nonzero() const { return Q.n_nonzero; }
arma_inline elem_type operator[](const uword i) const { return Q[i]; } arma_inline elem_type operator[](const uword i) const { return Q[i]; }
arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
arma_inline const eT* get_values() const { return Q.m.values; } arma_inline const eT* get_values() const { return Q.m.values; }
arma_inline const uword* get_row_indices() const { return Q.m.row_indices ; } arma_inline const uword* get_row_indices() const { return Q.m.row_indices ; }
arma_inline const uword* get_col_ptrs() const { return Q.m.col_ptrs; } arma_inline const uword* get_col_ptrs() const { return Q.m.col_ptrs; }
arma_inline const_iterator_type begin() const arma_inline const_iterator_type begin() co
{ return Q.begin(); } nst { return Q.begin(); }
arma_inline const_iterator_type begin_col(const uword col_num) const arma_inline const_iterator_type begin_col(const uword col_num) co
{ return Q.begin_col(col_num); } nst { return Q.begin_col(col_num); }
arma_inline const_row_iterator_type begin_row() const arma_inline const_row_iterator_type begin_row(const uword row_num = 0) co
{ return Q.begin_row(); } nst { return Q.begin_row(row_num); }
arma_inline const_iterator_type end() const { return Q.end(); arma_inline const_iterator_type end() const {
} return Q.end(); }
arma_inline const_row_iterator_type end_row() const { return Q.end_row( arma_inline const_row_iterator_type end_row() const {
); } return Q.end_row(); }
arma_inline const_row_iterator_type end_row(const uword row_num) const {
return Q.end_row(row_num); }
template<typename eT2> template<typename eT2>
arma_inline bool is_alias(const SpMat<eT2>& X) const { return (void_ptr(& Q.m) == void_ptr(&X)); } arma_inline bool is_alias(const SpMat<eT2>& X) const { return (void_ptr(& Q.m) == void_ptr(&X)); }
}; };
template<typename T1, typename spop_type> template<typename T1, typename spop_type>
class SpProxy< SpOp<T1, spop_type> > class SpProxy< SpOp<T1, spop_type> >
{ {
public: public:
typedef typename T1::elem_type elem_type; typedef typename T1::elem_type elem_type;
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
typedef typename get_pod_type<elem_type>::result pod_type; typedef typename get_pod_type<elem_type>::result pod_type;
typedef SpMat<eT> stored_type; typedef SpMat<eT> stored_type;
typedef typename SpMat<eT>::const_iterator const_iterator_type; typedef typename SpMat<eT>::const_iterator const_iterator_type;
typedef typename SpMat<eT>::const_row_iterator const_row_iterator_type; typedef typename SpMat<eT>::const_row_iterator const_row_iterator_type;
static const bool must_use_iterator = false; static const bool must_use_iterator = false;
static const bool Q_created_by_proxy = true;
static const bool is_row = SpOp<T1, spop_type>::is_row; static const bool is_row = SpOp<T1, spop_type>::is_row;
static const bool is_col = SpOp<T1, spop_type>::is_col; static const bool is_col = SpOp<T1, spop_type>::is_col;
arma_aligned const SpMat<eT> Q; arma_aligned const SpMat<eT> Q;
inline explicit SpProxy(const SpOp<T1, spop_type>& A) inline explicit SpProxy(const SpOp<T1, spop_type>& A)
: Q(A) : Q(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
skipping to change at line 246 skipping to change at line 255
arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline uword get_n_elem() const { return Q.n_elem; }
arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } arma_inline uword get_n_nonzero() const { return Q.n_nonzero; }
arma_inline elem_type operator[](const uword i) const { return Q[i]; } arma_inline elem_type operator[](const uword i) const { return Q[i]; }
arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
arma_inline const eT* get_values() const { return Q.values; } arma_inline const eT* get_values() const { return Q.values; }
arma_inline const uword* get_row_indices() const { return Q.row_indices; } arma_inline const uword* get_row_indices() const { return Q.row_indices; }
arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; } arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; }
arma_inline const_iterator_type begin() const arma_inline const_iterator_type begin() co
{ return Q.begin(); } nst { return Q.begin(); }
arma_inline const_iterator_type begin_col(const uword col_num) const arma_inline const_iterator_type begin_col(const uword col_num) co
{ return Q.begin_col(col_num); } nst { return Q.begin_col(col_num); }
arma_inline const_row_iterator_type begin_row() const arma_inline const_row_iterator_type begin_row(const uword row_num = 0) co
{ return Q.begin_row(); } nst { return Q.begin_row(row_num); }
arma_inline const_iterator_type end() const { return Q.end(); arma_inline const_iterator_type end() const {
} return Q.end(); }
arma_inline const_row_iterator_type end_row() const { return Q.end_row( arma_inline const_row_iterator_type end_row() const {
); } return Q.end_row(); }
arma_inline const_row_iterator_type end_row(const uword row_num) const {
return Q.end_row(row_num); }
template<typename eT2> template<typename eT2>
arma_inline bool is_alias(const SpMat<eT2>&) const { return false; } arma_inline bool is_alias(const SpMat<eT2>&) const { return false; }
}; };
template<typename T1, typename T2, typename spglue_type> template<typename T1, typename T2, typename spglue_type>
class SpProxy< SpGlue<T1, T2, spglue_type> > class SpProxy< SpGlue<T1, T2, spglue_type> >
{ {
public: public:
typedef typename T1::elem_type elem_type; typedef typename T1::elem_type elem_type;
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
typedef typename get_pod_type<elem_type>::result pod_type; typedef typename get_pod_type<elem_type>::result pod_type;
typedef SpMat<eT> stored_type; typedef SpMat<eT> stored_type;
typedef typename SpMat<eT>::const_iterator const_iterator_type; typedef typename SpMat<eT>::const_iterator const_iterator_type;
typedef typename SpMat<eT>::const_row_iterator const_row_iterator_type; typedef typename SpMat<eT>::const_row_iterator const_row_iterator_type;
static const bool must_use_iterator = false; static const bool must_use_iterator = false;
static const bool Q_created_by_proxy = true;
static const bool is_row = SpGlue<T1, T2, spglue_type>::is_row; static const bool is_row = SpGlue<T1, T2, spglue_type>::is_row;
static const bool is_col = SpGlue<T1, T2, spglue_type>::is_col; static const bool is_col = SpGlue<T1, T2, spglue_type>::is_col;
arma_aligned const SpMat<eT> Q; arma_aligned const SpMat<eT> Q;
inline explicit SpProxy(const SpGlue<T1, T2, spglue_type>& A) inline explicit SpProxy(const SpGlue<T1, T2, spglue_type>& A)
: Q(A) : Q(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
skipping to change at line 295 skipping to change at line 306
arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline uword get_n_elem() const { return Q.n_elem; }
arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } arma_inline uword get_n_nonzero() const { return Q.n_nonzero; }
arma_inline elem_type operator[](const uword i) const { return Q[i]; } arma_inline elem_type operator[](const uword i) const { return Q[i]; }
arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
arma_inline const eT* get_values() const { return Q.values; } arma_inline const eT* get_values() const { return Q.values; }
arma_inline const uword* get_row_indices() const { return Q.row_indices; } arma_inline const uword* get_row_indices() const { return Q.row_indices; }
arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; } arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; }
arma_inline const_iterator_type begin() const arma_inline const_iterator_type begin() co
{ return Q.begin(); } nst { return Q.begin(); }
arma_inline const_iterator_type begin_col(const uword col_num) const arma_inline const_iterator_type begin_col(const uword col_num) co
{ return Q.begin_col(col_num); } nst { return Q.begin_col(col_num); }
arma_inline const_row_iterator_type begin_row() const arma_inline const_row_iterator_type begin_row(const uword row_num = 0) co
{ return Q.begin_row(); } nst { return Q.begin_row(row_num); }
arma_inline const_iterator_type end() const {
return Q.end(); }
arma_inline const_row_iterator_type end_row() const {
return Q.end_row(); }
arma_inline const_row_iterator_type end_row(const uword row_num) const {
return Q.end_row(row_num); }
template<typename eT2>
arma_inline bool is_alias(const SpMat<eT2>&) const { return false; }
};
template<typename out_eT, typename T1, typename spop_type>
class SpProxy< mtSpOp<out_eT, T1, spop_type> >
{
public:
typedef out_eT elem_type;
typedef typename T1::elem_type eT;
typedef typename get_pod_type<elem_type>::result pod_type;
typedef SpMat<out_eT> stored_type;
typedef typename SpMat<out_eT>::const_iterator const_iterator_type;
typedef typename SpMat<out_eT>::const_row_iterator const_row_iterator_t
ype;
static const bool must_use_iterator = false;
static const bool Q_created_by_proxy = true;
static const bool is_row = mtSpOp<out_eT, T1, spop_type>::is_row;
static const bool is_col = mtSpOp<out_eT, T1, spop_type>::is_col;
arma_aligned const SpMat<out_eT> Q;
inline explicit SpProxy(const mtSpOp<out_eT, T1, spop_type>& A)
: Q(A)
{
arma_extra_debug_sigprint();
}
arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; }
arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; }
arma_inline uword get_n_elem() const { return Q.n_elem; }
arma_inline uword get_n_nonzero() const { return Q.n_nonzero; }
arma_inline elem_type operator[](const uword i) const
{ return Q[i]; }
arma_inline elem_type at (const uword row, const uword col) const
{ return Q.at(row, col); }
arma_inline const eT* get_values() const { return Q.values;
}
arma_inline const uword* get_row_indices() const { return Q.row_indices;
}
arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs;
}
arma_inline const_iterator_type end() const { return Q.end(); arma_inline const_iterator_type begin() co
} nst { return Q.begin(); }
arma_inline const_row_iterator_type end_row() const { return Q.end_row( arma_inline const_iterator_type begin_col(const uword col_num) co
); } nst { return Q.begin_col(col_num); }
arma_inline const_row_iterator_type begin_row(const uword row_num = 0) co
nst { return Q.begin_row(row_num); }
arma_inline const_iterator_type end() const {
return Q.end(); }
arma_inline const_row_iterator_type end_row() const {
return Q.end_row(); }
arma_inline const_row_iterator_type end_row(const uword row_num) const {
return Q.end_row(row_num); }
template<typename eT2> template<typename eT2>
arma_inline bool is_alias(const SpMat<eT2>&) const { return false; } arma_inline bool is_alias(const SpMat<eT2>&) const { return false; }
}; };
//! @} //! @}
 End of changes. 13 change blocks. 
71 lines changed or deleted 152 lines changed or added


 SpRow_bones.hpp   SpRow_bones.hpp 
skipping to change at line 74 skipping to change at line 74
inline void shed_col (const uword col_num); inline void shed_col (const uword col_num);
inline void shed_cols(const uword in_col1, const uword in_col2); inline void shed_cols(const uword in_col1, const uword in_col2);
// inline void insert_cols(const uword col_num, con st uword N, const bool set_to_zero = true); // inline void insert_cols(const uword col_num, con st uword N, const bool set_to_zero = true);
// template<typename T1> inline void insert_cols(const uword col_num, con st Base<eT,T1>& X); // template<typename T1> inline void insert_cols(const uword col_num, con st Base<eT,T1>& X);
typedef typename SpMat<eT>::iterator row_iterator; typedef typename SpMat<eT>::iterator row_iterator;
typedef typename SpMat<eT>::const_iterator const_row_iterator; typedef typename SpMat<eT>::const_iterator const_row_iterator;
inline row_iterator begin_row(); inline row_iterator begin_row(const uword row_num = 0);
inline const_row_iterator begin_row() const; inline const_row_iterator begin_row(const uword row_num = 0) const;
inline row_iterator end_row(); inline row_iterator end_row(const uword row_num = 0);
inline const_row_iterator end_row() const; inline const_row_iterator end_row(const uword row_num = 0) const;
#ifdef ARMA_EXTRA_SPROW_PROTO #ifdef ARMA_EXTRA_SPROW_PROTO
#include ARMA_INCFILE_WRAP(ARMA_EXTRA_SPROW_PROTO) #include ARMA_INCFILE_WRAP(ARMA_EXTRA_SPROW_PROTO)
#endif #endif
}; };
//! @} //! @}
 End of changes. 2 change blocks. 
4 lines changed or deleted 4 lines changed or added


 SpRow_meat.hpp   SpRow_meat.hpp 
skipping to change at line 451 skipping to change at line 451
// SpRow<eT>::insert_cols(const uword col_num, const Base<eT,T1>& X) // SpRow<eT>::insert_cols(const uword col_num, const Base<eT,T1>& X)
// { // {
// arma_extra_debug_sigprint(); // arma_extra_debug_sigprint();
// //
// SpMat<eT>::insert_cols(col_num, X); // SpMat<eT>::insert_cols(col_num, X);
// } // }
template<typename eT> template<typename eT>
inline inline
typename SpRow<eT>::row_iterator typename SpRow<eT>::row_iterator
SpRow<eT>::begin_row() SpRow<eT>::begin_row(const uword row_num)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
// Since this is a row, row_num can only be 0. But the option is provide
d for
// compatibility.
arma_debug_check((row_num >= 1), "SpRow::row(): invalid row index");
return SpMat<eT>::begin(); return SpMat<eT>::begin();
} }
template<typename eT> template<typename eT>
inline inline
typename SpRow<eT>::const_row_iterator typename SpRow<eT>::const_row_iterator
SpRow<eT>::begin_row() const SpRow<eT>::begin_row(const uword row_num) const
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
// Since this is a row, row_num can only be 0. But the option is provide
d for
// compatibility.
arma_debug_check((row_num >= 1), "SpRow::row(): invalid row index");
return SpMat<eT>::begin(); return SpMat<eT>::begin();
} }
template<typename eT> template<typename eT>
inline inline
typename SpRow<eT>::row_iterator typename SpRow<eT>::row_iterator
SpRow<eT>::end_row() SpRow<eT>::end_row(const uword row_num)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
// Since this is a row, row_num can only be 0. But the option is provide
d for
// compatibility.
arma_debug_check((row_num >= 1), "SpRow::row(): invalid row index");
return SpMat<eT>::end(); return SpMat<eT>::end();
} }
template<typename eT> template<typename eT>
inline inline
typename SpRow<eT>::const_row_iterator typename SpRow<eT>::const_row_iterator
SpRow<eT>::end_row() const SpRow<eT>::end_row(const uword row_num) const
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
// Since this is a row, row_num can only be 0. But the option is provide
d for
// compatibility.
arma_debug_check((row_num >= 1), "SpRow::row(): invalid row index");
return SpMat<eT>::end(); return SpMat<eT>::end();
} }
#ifdef ARMA_EXTRA_SPROW_MEAT #ifdef ARMA_EXTRA_SPROW_MEAT
#include ARMA_INCFILE_WRAP(ARMA_EXTRA_SPROW_MEAT) #include ARMA_INCFILE_WRAP(ARMA_EXTRA_SPROW_MEAT)
#endif #endif
//! @} //! @}
 End of changes. 8 change blocks. 
4 lines changed or deleted 24 lines changed or added


 SpSubview_bones.hpp   SpSubview_bones.hpp 
skipping to change at line 103 skipping to change at line 103
arma_hot inline SpValProxy<SpSubview<eT> > at(const uword i); arma_hot inline SpValProxy<SpSubview<eT> > at(const uword i);
arma_hot inline eT at(const uword i) const; arma_hot inline eT at(const uword i) const;
arma_hot inline SpValProxy<SpSubview<eT> > at(const uword in_row, const u word in_col); arma_hot inline SpValProxy<SpSubview<eT> > at(const uword in_row, const u word in_col);
arma_hot inline eT at(const uword in_row, const u word in_col) const; arma_hot inline eT at(const uword in_row, const u word in_col) const;
inline bool check_overlap(const SpSubview& x) const; inline bool check_overlap(const SpSubview& x) const;
inline bool is_vec() const; inline bool is_vec() const;
inline SpSubview row(const uword row_num);
inline const SpSubview row(const uword row_num) const;
inline SpSubview col(const uword col_num);
inline const SpSubview col(const uword col_num) const;
inline SpSubview rows(const uword in_row1, const uword in_row2);
inline const SpSubview rows(const uword in_row1, const uword in_row2) con
st;
inline SpSubview cols(const uword in_col1, const uword in_col2);
inline const SpSubview cols(const uword in_col1, const uword in_col2) con
st;
inline SpSubview submat(const uword in_row1, const uword in_col1, c
onst uword in_row2, const uword in_col2);
inline const SpSubview submat(const uword in_row1, const uword in_col1, c
onst uword in_row2, const uword in_col2) const;
inline SpSubview submat(const span& row_span, const span& col_span)
;
inline const SpSubview submat(const span& row_span, const span& col_span)
const;
inline SpSubview operator()(const uword row_num, const span& col_sp
an);
inline const SpSubview operator()(const uword row_num, const span& col_sp
an) const;
inline SpSubview operator()(const span& row_span, const uword col_n
um);
inline const SpSubview operator()(const span& row_span, const uword col_n
um) const;
inline SpSubview operator()(const span& row_span, const span& col_s
pan);
inline const SpSubview operator()(const span& row_span, const span& col_s
pan) const;
/* not yet /* not yet
inline SpSubview_row<eT> row(const uword row_num); inline SpSubview_row<eT> row(const uword row_num);
inline const SpSubview_row<eT> row(const uword row_num) const; inline const SpSubview_row<eT> row(const uword row_num) const;
inline SpSubview_row<eT> operator()(const uword row_num, const span& col_span); inline SpSubview_row<eT> operator()(const uword row_num, const span& col_span);
inline const SpSubview_row<eT> operator()(const uword row_num, const span& col_span) const; inline const SpSubview_row<eT> operator()(const uword row_num, const span& col_span) const;
inline SpSubview_col<eT> col(const uword col_num); inline SpSubview_col<eT> col(const uword col_num);
inline const SpSubview_col<eT> col(const uword col_num) const; inline const SpSubview_col<eT> col(const uword col_num) const;
skipping to change at line 141 skipping to change at line 168
inline SpSubview<eT> operator()(const span& row_span, const sp an& col_span); inline SpSubview<eT> operator()(const span& row_span, const sp an& col_span);
inline const SpSubview<eT> operator()(const span& row_span, const sp an& col_span) const; inline const SpSubview<eT> operator()(const span& row_span, const sp an& col_span) const;
inline diagview<eT> diag(const s32 in_id = 0); inline diagview<eT> diag(const s32 in_id = 0);
inline const diagview<eT> diag(const s32 in_id = 0) const; inline const diagview<eT> diag(const s32 in_id = 0) const;
*/ */
inline void swap_rows(const uword in_row1, const uword in_row2); inline void swap_rows(const uword in_row1, const uword in_row2);
inline void swap_cols(const uword in_col1, const uword in_col2); inline void swap_cols(const uword in_col1, const uword in_col2);
// Similar to SpMat iterators but automatically iterate over values not i // Forward declarations.
n the subview. class iterator_base;
class const_iterator;
class iterator;
class const_row_iterator;
class row_iterator;
// Similar to SpMat iterators but automatically iterates past and ignores
values not in the subview.
class iterator_base class iterator_base
{ {
public: public:
inline iterator_base(const SpSubview& in_M); inline iterator_base(const SpSubview& in_M);
inline iterator_base(const SpSubview& in_M, const uword col, const uwor d pos, const uword skip_pos); inline iterator_base(const SpSubview& in_M, const uword col, const uwor d pos, const uword skip_pos);
inline eT operator*() const; inline eT operator*() const;
inline bool operator!=(const iterator_base& rhs) const;
inline bool operator==(const iterator_base& rhs) const;
inline bool operator!=(const typename SpMat<eT>::iterator_base& rhs) co
nst;
inline bool operator==(const typename SpMat<eT>::iterator_base& rhs) co
nst;
// Don't hold location internally; call "dummy" methods to get that inf ormation. // Don't hold location internally; call "dummy" methods to get that inf ormation.
arma_inline uword row() const { return M.m.row_indices[internal_pos + s kip_pos] - M.aux_row1; } arma_inline uword row() const { return M.m.row_indices[internal_pos + s kip_pos] - M.aux_row1; }
arma_inline uword col() const { return internal_col; } arma_inline uword col() const { return internal_col; }
arma_inline uword pos() const { return internal_pos; } arma_inline uword pos() const { return internal_pos; }
arma_aligned const SpSubview& M; arma_aligned const SpSubview& M;
arma_aligned uword internal_col; arma_aligned uword internal_col;
arma_aligned uword internal_pos; arma_aligned uword internal_pos;
arma_aligned uword skip_pos; // not used in row_iterator or const_row_iterator arma_aligned uword skip_pos; // not used in row_iterator or const_row_iterator
// So that we satisfy the STL iterator types.
typedef std::bidirectional_iterator_tag iterator_category;
typedef eT value_type;
typedef uword difference_type; // not certain
on this one
typedef const eT* pointer;
typedef const eT& reference;
}; };
class const_iterator : public iterator_base class const_iterator : public iterator_base
{ {
public: public:
inline const_iterator(const SpSubview& in_M, uword initial_pos = 0); inline const_iterator(const SpSubview& in_M, uword initial_pos = 0);
inline const_iterator(const SpSubview& in_M, uword in_row, uword in_col ); inline const_iterator(const SpSubview& in_M, uword in_row, uword in_col );
inline const_iterator(const SpSubview& in_M, uword in_row, uword in_col , uword in_pos, uword skip_pos); inline const_iterator(const SpSubview& in_M, uword in_row, uword in_col , uword in_pos, uword skip_pos);
inline const_iterator(const const_iterator& other); inline const_iterator(const const_iterator& other);
inline const_iterator& operator++(); inline const_iterator& operator++();
inline void operator++(int); inline const_iterator operator++(int);
inline const_iterator& operator--(); inline const_iterator& operator--();
inline void operator--(int); inline const_iterator operator--(int);
inline bool operator!=(const const_iterator& rhs) const;
inline bool operator==(const const_iterator& rhs) const;
inline bool operator!=(const typename SpMat<eT>::const_iterator& rhs) c
onst;
inline bool operator==(const typename SpMat<eT>::const_iterator& rhs) c
onst;
inline bool operator!=(const const_row_iterator& rhs) const;
inline bool operator==(const const_row_iterator& rhs) const;
inline bool operator!=(const typename SpMat<eT>::const_row_iterator& rh
s) const;
inline bool operator==(const typename SpMat<eT>::const_row_iterator& rh
s) const;
}; };
class iterator : public const_iterator class iterator : public const_iterator
{ {
public: public:
inline iterator(SpSubview& in_M, const uword initial_pos = 0) : const_i terator(in_M, initial_pos) { } inline iterator(SpSubview& in_M, const uword initial_pos = 0) : const_i terator(in_M, initial_pos) { }
inline iterator(SpSubview& in_M, const uword in_row, const uword in_col ) : const_iterator(in_M, in_row, in_col) { } inline iterator(SpSubview& in_M, const uword in_row, const uword in_col ) : const_iterator(in_M, in_row, in_col) { }
inline iterator(SpSubview& in_M, const uword in_row, const uword in_col , const uword in_pos, const uword skip_pos) : const_iterator(in_M, in_row, in_col, in_pos, skip_pos) { } inline iterator(SpSubview& in_M, const uword in_row, const uword in_col , const uword in_pos, const uword skip_pos) : const_iterator(in_M, in_row, in_col, in_pos, skip_pos) { }
inline iterator(const iterator& other) : const_iterator(other) { } inline iterator(const iterator& other) : const_iterator(other) { }
inline SpValProxy<SpSubview<eT> > operator*(); inline SpValProxy<SpSubview<eT> > operator*();
// overloads needed for return type correctness // overloads needed for return type correctness
inline iterator& operator++(); inline iterator& operator++();
inline void operator++(int); inline iterator operator++(int);
inline iterator& operator--(); inline iterator& operator--();
inline void operator--(int); inline iterator operator--(int);
// This has a different value_type than iterator_base.
typedef SpValProxy<SpSubview<eT> > value_type;
typedef const SpValProxy<SpSubview<eT> >* pointer;
typedef const SpValProxy<SpSubview<eT> >& reference;
}; };
class const_row_iterator : public iterator_base class const_row_iterator : public iterator_base
{ {
public: public:
inline const_row_iterator(const SpSubview& in_M, uword initial_pos = 0) ; inline const_row_iterator(const SpSubview& in_M, uword initial_pos = 0) ;
inline const_row_iterator(const SpSubview& in_M, uword in_row, uword in _col); inline const_row_iterator(const SpSubview& in_M, uword in_row, uword in _col);
inline const_row_iterator(const const_row_iterator& other); inline const_row_iterator(const const_row_iterator& other);
inline const_row_iterator& operator++(); inline const_row_iterator& operator++();
inline void operator++(int); inline const_row_iterator operator++(int);
inline const_row_iterator& operator--(); inline const_row_iterator& operator--();
inline void operator--(int); inline const_row_iterator operator--(int);
uword internal_row; // Hold row internally because we use internal_pos differently. uword internal_row; // Hold row internally because we use internal_pos differently.
uword actual_pos; // Actual position in subview's parent matrix. uword actual_pos; // Actual position in subview's parent matrix.
arma_inline eT operator*() const { return iterator_base::M.m.values[act ual_pos]; } arma_inline eT operator*() const { return iterator_base::M.m.values[act ual_pos]; }
arma_inline uword row() const { return internal_row; } arma_inline uword row() const { return internal_row; }
inline bool operator!=(const const_iterator& rhs) const;
inline bool operator==(const const_iterator& rhs) const;
inline bool operator!=(const typename SpMat<eT>::const_iterator& rhs) c
onst;
inline bool operator==(const typename SpMat<eT>::const_iterator& rhs) c
onst;
inline bool operator!=(const const_row_iterator& rhs) const;
inline bool operator==(const const_row_iterator& rhs) const;
inline bool operator!=(const typename SpMat<eT>::const_row_iterator& rh
s) const;
inline bool operator==(const typename SpMat<eT>::const_row_iterator& rh
s) const;
}; };
class row_iterator : public const_row_iterator class row_iterator : public const_row_iterator
{ {
public: public:
inline row_iterator(SpSubview& in_M, uword initial_pos = 0) : const_row _iterator(in_M, initial_pos) { } inline row_iterator(SpSubview& in_M, uword initial_pos = 0) : const_row _iterator(in_M, initial_pos) { }
inline row_iterator(SpSubview& in_M, uword in_row, uword in_col) : cons t_row_iterator(in_M, in_row, in_col) { } inline row_iterator(SpSubview& in_M, uword in_row, uword in_col) : cons t_row_iterator(in_M, in_row, in_col) { }
inline row_iterator(const row_iterator& other) : const_row_iterator(oth er) { } inline row_iterator(const row_iterator& other) : const_row_iterator(oth er) { }
inline SpValProxy<SpSubview<eT> > operator*(); inline SpValProxy<SpSubview<eT> > operator*();
// overloads needed for return type correctness // overloads needed for return type correctness
inline row_iterator& operator++(); inline row_iterator& operator++();
inline void operator++(int); inline row_iterator operator++(int);
inline row_iterator& operator--(); inline row_iterator& operator--();
inline void operator--(int); inline row_iterator operator--(int);
// This has a different value_type than iterator_base.
typedef SpValProxy<SpSubview<eT> > value_type;
typedef const SpValProxy<SpSubview<eT> >* pointer;
typedef const SpValProxy<SpSubview<eT> >& reference;
}; };
inline iterator begin(); inline iterator begin();
inline const_iterator begin() const; inline const_iterator begin() const;
inline iterator begin_col(const uword col_num); inline iterator begin_col(const uword col_num);
inline const_iterator begin_col(const uword col_num) const; inline const_iterator begin_col(const uword col_num) const;
inline row_iterator begin_row(); inline row_iterator begin_row(const uword row_num = 0);
inline const_row_iterator begin_row() const; inline const_row_iterator begin_row(const uword row_num = 0) const;
inline iterator end(); inline iterator end();
inline const_iterator end() const; inline const_iterator end() const;
inline row_iterator end_row(); inline row_iterator end_row();
inline const_row_iterator end_row() const; inline const_row_iterator end_row() const;
inline row_iterator end_row(const uword row_num = 0);
inline const_row_iterator end_row(const uword row_num = 0) const;
private: private:
friend class SpMat<eT>; friend class SpMat<eT>;
SpSubview(); SpSubview();
// For use by SpValProxy. We just update n_nonzero and pass the call on to the matrix. // For use by SpValProxy. We just update n_nonzero and pass the call on to the matrix.
inline arma_hot arma_warn_unused eT& add_element(const uword in_row, con st uword in_col, const eT in_val = 0.0); inline arma_hot arma_warn_unused eT& add_element(const uword in_row, con st uword in_col, const eT in_val = 0.0);
inline arma_hot void delete_element(const uword in_row, const uword in_col); inline arma_hot void delete_element(const uword in_row, const uword in_col);
}; };
 End of changes. 15 change blocks. 
20 lines changed or deleted 111 lines changed or added


 SpSubview_iterators_meat.hpp   SpSubview_iterators_meat.hpp 
skipping to change at line 50 skipping to change at line 50
} }
template<typename eT> template<typename eT>
inline inline
eT eT
SpSubview<eT>::iterator_base::operator*() const SpSubview<eT>::iterator_base::operator*() const
{ {
return M.m.values[internal_pos + skip_pos]; return M.m.values[internal_pos + skip_pos];
} }
template<typename eT>
inline
bool
SpSubview<eT>::iterator_base::operator==(const iterator_base& rhs) const
{
return (rhs.row() == row()) && (rhs.col() == internal_col);
}
template<typename eT>
inline
bool
SpSubview<eT>::iterator_base::operator!=(const iterator_base& rhs) const
{
return (rhs.row() != row()) || (rhs.col() != internal_col);
}
template<typename eT>
inline
bool
SpSubview<eT>::iterator_base::operator==(const typename SpMat<eT>::iterator
_base& rhs) const
{
return (rhs.row() == row()) && (rhs.col() == internal_col);
}
template<typename eT>
inline
bool
SpSubview<eT>::iterator_base::operator!=(const typename SpMat<eT>::iterator
_base& rhs) const
{
return (rhs.row() != row()) || (rhs.col() != internal_col);
}
/////////////////////////////////////////////////////////////////////////// //// /////////////////////////////////////////////////////////////////////////// ////
// SpSubview::const_iterator implementation // // SpSubview::const_iterator implementation //
/////////////////////////////////////////////////////////////////////////// //// /////////////////////////////////////////////////////////////////////////// ////
template<typename eT> template<typename eT>
inline inline
SpSubview<eT>::const_iterator::const_iterator(const SpSubview<eT>& in_M, co nst uword initial_pos) SpSubview<eT>::const_iterator::const_iterator(const SpSubview<eT>& in_M, co nst uword initial_pos)
: iterator_base(in_M, 0, initial_pos, 0) : iterator_base(in_M, 0, initial_pos, 0)
{ {
// Corner case for empty subviews. // Corner case for empty subviews.
skipping to change at line 104 skipping to change at line 72
iterator_base::internal_col = in_M.n_cols; iterator_base::internal_col = in_M.n_cols;
iterator_base::skip_pos = in_M.m.n_nonzero; iterator_base::skip_pos = in_M.m.n_nonzero;
return; return;
} }
// Figure out the row and column of the position. // Figure out the row and column of the position.
// skip_pos holds the number of values which aren't part of this subview. // skip_pos holds the number of values which aren't part of this subview.
const uword aux_col = iterator_base::M.aux_col1; const uword aux_col = iterator_base::M.aux_col1;
const uword aux_row = iterator_base::M.aux_row1; const uword aux_row = iterator_base::M.aux_row1;
const uword n_rows = iterator_base::M.n_rows; const uword n_rows = iterator_base::M.n_rows;
const uword n_cols = iterator_base::M.n_cols;
uword cur_pos = 0; // off by one because we might be searching for pos 0 uword cur_pos = 0; // off by one because we might be searching for pos 0
uword skip_pos = iterator_base::M.m.col_ptrs[aux_col]; uword skip_pos = iterator_base::M.m.col_ptrs[aux_col];
uword cur_col = 0; uword cur_col = 0;
while(cur_pos < (iterator_base::internal_pos + 1)) while(cur_pos < (iterator_base::internal_pos + 1))
{ {
// Have we stepped forward a column (or multiple columns)? // Have we stepped forward a column (or multiple columns)?
while((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + aux _col + 1]) while(((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + au x_col + 1]) && (cur_col < n_cols))
{ {
++cur_col; ++cur_col;
} }
// See if the current position is in the subview. // See if the current position is in the subview.
const uword row_index = iterator_base::M.m.row_indices[cur_pos + skip_p os]; const uword row_index = iterator_base::M.m.row_indices[cur_pos + skip_p os];
if(row_index < aux_row) if(row_index < aux_row)
{ {
++skip_pos; // not valid ++skip_pos; // not valid
} }
skipping to change at line 144 skipping to change at line 113
iterator_base::internal_col = cur_col; iterator_base::internal_col = cur_col;
iterator_base::skip_pos = skip_pos; iterator_base::skip_pos = skip_pos;
} }
template<typename eT> template<typename eT>
inline inline
SpSubview<eT>::const_iterator::const_iterator(const SpSubview<eT>& in_M, co nst uword in_row, const uword in_col) SpSubview<eT>::const_iterator::const_iterator(const SpSubview<eT>& in_M, co nst uword in_row, const uword in_col)
: iterator_base(in_M, in_col, 0, 0) : iterator_base(in_M, in_col, 0, 0)
{ {
// Corner case for empty subviews.
if(in_M.n_nonzero == 0)
{
// We must be at the last position.
iterator_base::internal_col = in_M.n_cols;
iterator_base::skip_pos = in_M.m.n_nonzero;
return;
}
// We have a destination we want to be just after, but don't know what po sition that is. // We have a destination we want to be just after, but don't know what po sition that is.
// Because we have to count the points in this subview and not in this su bview, this becomes a little difficult and slow. // Because we have to count the points in this subview and not in this su bview, this becomes a little difficult and slow.
const uword aux_col = iterator_base::M.aux_col1; const uword aux_col = iterator_base::M.aux_col1;
const uword aux_row = iterator_base::M.aux_row1; const uword aux_row = iterator_base::M.aux_row1;
const uword n_rows = iterator_base::M.n_rows; const uword n_rows = iterator_base::M.n_rows;
const uword n_cols = iterator_base::M.n_cols;
uword cur_pos = 0; uword cur_pos = 0;
uword skip_pos = iterator_base::M.m.col_ptrs[aux_col]; uword skip_pos = iterator_base::M.m.col_ptrs[aux_col];
uword cur_col = 0; uword cur_col = 0;
while(cur_col < in_col) while(cur_col < in_col)
{ {
// See if the current position is in the subview. // See if the current position is in the subview.
const uword row_index = iterator_base::M.m.row_indices[cur_pos + skip_p os]; const uword row_index = iterator_base::M.m.row_indices[cur_pos + skip_p os];
if(row_index < aux_row) if(row_index < aux_row)
skipping to change at line 174 skipping to change at line 153
++cur_pos; ++cur_pos;
} }
else else
{ {
// skip to end of column // skip to end of column
const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_c ol + 1]; const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_c ol + 1];
skip_pos += (next_colptr - (cur_pos + skip_pos)); skip_pos += (next_colptr - (cur_pos + skip_pos));
} }
// Have we stepped forward a column (or multiple columns)? // Have we stepped forward a column (or multiple columns)?
while((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + aux _col + 1]) while(((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + au x_col + 1]) && (cur_col < n_cols))
{ {
++cur_col; ++cur_col;
} }
} }
// Now we are either on the right column or ahead of it. // Now we are either on the right column or ahead of it.
if(cur_col == in_col) if(cur_col == in_col)
{ {
// We have to find the right row index. // We have to find the right row index.
uword row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos]; uword row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos];
skipping to change at line 196 skipping to change at line 175
{ {
if(row_index < aux_row) if(row_index < aux_row)
{ {
++skip_pos; ++skip_pos;
} }
else else
{ {
++cur_pos; ++cur_pos;
} }
// Ensure we didn't step forward a column; if we did, we need to stop
.
while(((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col +
aux_col + 1]) && (cur_col < n_cols))
{
++cur_col;
}
if(cur_col != in_col)
{
break;
}
row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos]; row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos];
} }
} }
// Now we need to find the next valid position in the subview. // Now we need to find the next valid position in the subview.
uword row_index; uword row_index;
while(true) while(true)
{ {
const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]; const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col + 1];
row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos]; row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos];
// Are we at the last position?
if(cur_col >= n_cols)
{
cur_col = n_cols;
// Make sure we will be pointing at the last element in the parent ma
trix.
skip_pos = iterator_base::M.m.n_nonzero - iterator_base::M.n_nonzero;
break;
}
if(row_index < aux_row) if(row_index < aux_row)
{ {
++skip_pos; ++skip_pos;
} }
else if(row_index < (aux_row + n_rows)) else if(row_index < (aux_row + n_rows))
{ {
break; // found break; // found
} }
else else
{ {
skip_pos += (next_colptr - (cur_pos + skip_pos)); skip_pos += (next_colptr - (cur_pos + skip_pos));
} }
// Did we move any columns? // Did we move any columns?
while((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + aux _col + 1]) while(((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + au x_col + 1]) && (cur_col < n_cols))
{ {
++cur_col; ++cur_col;
} }
} }
// It is possible we have moved another column.
while(((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + aux_
col + 1]) && (cur_col < n_cols))
{
++cur_col;
}
iterator_base::internal_pos = cur_pos; iterator_base::internal_pos = cur_pos;
iterator_base::skip_pos = skip_pos; iterator_base::skip_pos = skip_pos;
iterator_base::internal_col = cur_col; iterator_base::internal_col = cur_col;
} }
template<typename eT> template<typename eT>
inline inline
SpSubview<eT>::const_iterator::const_iterator(const SpSubview<eT>& in_M, uw ord in_row, uword in_col, uword in_pos, uword skip_pos) SpSubview<eT>::const_iterator::const_iterator(const SpSubview<eT>& in_M, uw ord in_row, uword in_col, uword in_pos, uword skip_pos)
: iterator_base(in_M, in_col, in_pos, skip_pos) : iterator_base(in_M, in_col, in_pos, skip_pos)
{ {
skipping to change at line 306 skipping to change at line 311
iterator_base::internal_pos = cur_pos; iterator_base::internal_pos = cur_pos;
iterator_base::internal_col = cur_col; iterator_base::internal_col = cur_col;
iterator_base::skip_pos = skip_pos; iterator_base::skip_pos = skip_pos;
return *this; return *this;
} }
template<typename eT> template<typename eT>
inline inline
void typename SpSubview<eT>::const_iterator
SpSubview<eT>::const_iterator::operator++(int) SpSubview<eT>::const_iterator::operator++(int)
{ {
typename SpSubview<eT>::const_iterator tmp(*this);
++(*this); ++(*this);
return tmp;
} }
template<typename eT> template<typename eT>
inline inline
typename SpSubview<eT>::const_iterator& typename SpSubview<eT>::const_iterator&
SpSubview<eT>::const_iterator::operator--() SpSubview<eT>::const_iterator::operator--()
{ {
const uword aux_col = iterator_base::M.aux_col1; const uword aux_col = iterator_base::M.aux_col1;
const uword aux_row = iterator_base::M.aux_row1; const uword aux_row = iterator_base::M.aux_row1;
const uword n_rows = iterator_base::M.n_rows; const uword n_rows = iterator_base::M.n_rows;
skipping to change at line 369 skipping to change at line 378
iterator_base::internal_pos = cur_pos; iterator_base::internal_pos = cur_pos;
iterator_base::skip_pos = skip_pos; iterator_base::skip_pos = skip_pos;
iterator_base::internal_col = cur_col; iterator_base::internal_col = cur_col;
return *this; return *this;
} }
template<typename eT> template<typename eT>
inline inline
void typename SpSubview<eT>::const_iterator
SpSubview<eT>::const_iterator::operator--(int) SpSubview<eT>::const_iterator::operator--(int)
{ {
typename SpSubview<eT>::const_iterator tmp(*this);
--(*this); --(*this);
return tmp;
}
template<typename eT>
inline
bool
SpSubview<eT>::const_iterator::operator==(const const_iterator& rhs) const
{
return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::inter
nal_col);
}
template<typename eT>
inline
bool
SpSubview<eT>::const_iterator::operator!=(const const_iterator& rhs) const
{
return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::inter
nal_col);
}
template<typename eT>
inline
bool
SpSubview<eT>::const_iterator::operator==(const typename SpMat<eT>::const_i
terator& rhs) const
{
return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::inter
nal_col);
}
template<typename eT>
inline
bool
SpSubview<eT>::const_iterator::operator!=(const typename SpMat<eT>::const_i
terator& rhs) const
{
return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::inter
nal_col);
}
template<typename eT>
inline
bool
SpSubview<eT>::const_iterator::operator==(const const_row_iterator& rhs) co
nst
{
return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::inter
nal_col);
}
template<typename eT>
inline
bool
SpSubview<eT>::const_iterator::operator!=(const const_row_iterator& rhs) co
nst
{
return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::inter
nal_col);
}
template<typename eT>
inline
bool
SpSubview<eT>::const_iterator::operator==(const typename SpMat<eT>::const_r
ow_iterator& rhs) const
{
return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::inter
nal_col);
}
template<typename eT>
inline
bool
SpSubview<eT>::const_iterator::operator!=(const typename SpMat<eT>::const_r
ow_iterator& rhs) const
{
return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::inter
nal_col);
} }
/////////////////////////////////////////////////////////////////////////// //// /////////////////////////////////////////////////////////////////////////// ////
// SpSubview<eT>::iterator implementation // // SpSubview<eT>::iterator implementation //
/////////////////////////////////////////////////////////////////////////// //// /////////////////////////////////////////////////////////////////////////// ////
template<typename eT> template<typename eT>
inline inline
SpValProxy<SpSubview<eT> > SpValProxy<SpSubview<eT> >
SpSubview<eT>::iterator::operator*() SpSubview<eT>::iterator::operator*()
skipping to change at line 402 skipping to change at line 479
inline inline
typename SpSubview<eT>::iterator& typename SpSubview<eT>::iterator&
SpSubview<eT>::iterator::operator++() SpSubview<eT>::iterator::operator++()
{ {
const_iterator::operator++(); const_iterator::operator++();
return *this; return *this;
} }
template<typename eT> template<typename eT>
inline inline
void typename SpSubview<eT>::iterator
SpSubview<eT>::iterator::operator++(int) SpSubview<eT>::iterator::operator++(int)
{ {
typename SpSubview<eT>::iterator tmp(*this);
const_iterator::operator++(); const_iterator::operator++();
return tmp;
} }
template<typename eT> template<typename eT>
inline inline
typename SpSubview<eT>::iterator& typename SpSubview<eT>::iterator&
SpSubview<eT>::iterator::operator--() SpSubview<eT>::iterator::operator--()
{ {
const_iterator::operator--(); const_iterator::operator--();
return *this; return *this;
} }
template<typename eT> template<typename eT>
inline inline
void typename SpSubview<eT>::iterator
SpSubview<eT>::iterator::operator--(int) SpSubview<eT>::iterator::operator--(int)
{ {
typename SpSubview<eT>::iterator tmp(*this);
const_iterator::operator--(); const_iterator::operator--();
return tmp;
} }
/////////////////////////////////////////////////////////////////////////// //// /////////////////////////////////////////////////////////////////////////// ////
// SpSubview<eT>::const_row_iterator implementation // // SpSubview<eT>::const_row_iterator implementation //
/////////////////////////////////////////////////////////////////////////// //// /////////////////////////////////////////////////////////////////////////// ////
template<typename eT> template<typename eT>
inline inline
SpSubview<eT>::const_row_iterator::const_row_iterator(const SpSubview<eT>& in_M, uword initial_pos) SpSubview<eT>::const_row_iterator::const_row_iterator(const SpSubview<eT>& in_M, uword initial_pos)
: iterator_base(in_M, 0, initial_pos, 0) : iterator_base(in_M, 0, initial_pos, 0)
, internal_row(0) , internal_row(0)
, actual_pos(0) , actual_pos(0)
{ {
// Corner case for empty subviews. // Corner case for empty subviews.
if(in_M.n_nonzero == 0) if(in_M.n_nonzero == 0)
{ {
iterator_base::internal_col = in_M.n_cols; iterator_base::internal_col = 0;
internal_row = in_M.n_rows;
iterator_base::skip_pos = in_M.m.n_nonzero; iterator_base::skip_pos = in_M.m.n_nonzero;
return; return;
} }
const uword aux_col = iterator_base::M.aux_col1; const uword aux_col = iterator_base::M.aux_col1;
const uword aux_row = iterator_base::M.aux_row1; const uword aux_row = iterator_base::M.aux_row1;
const uword n_cols = iterator_base::M.n_cols; const uword n_cols = iterator_base::M.n_cols;
// We don't know where the elements are in each row. What we will do is // We don't know where the elements are in each row. What we will do is
// loop across all valid columns looking for elements in row 0 (and add t o // loop across all valid columns looking for elements in row 0 (and add t o
skipping to change at line 500 skipping to change at line 586
// Out of columns. Loop back to the beginning and look on the next r ow. // Out of columns. Loop back to the beginning and look on the next r ow.
cur_col = 0; cur_col = 0;
cur_row++; cur_row++;
} }
} }
} }
template<typename eT> template<typename eT>
inline inline
SpSubview<eT>::const_row_iterator::const_row_iterator(const SpSubview<eT>& in_M, uword in_row, uword in_col) SpSubview<eT>::const_row_iterator::const_row_iterator(const SpSubview<eT>& in_M, uword in_row, uword in_col)
: iterator_base(in_M, in_row, in_col, 0, 0) : iterator_base(in_M, in_col, 0, 0)
, internal_row(0) , internal_row(0)
, actual_pos(0) , actual_pos(0)
{ {
// We have a destination we want to be just after, but don't know what th at // We have a destination we want to be just after, but don't know what th at
// position is. Because we will have to loop over everything anyway, cre ate // position is. Because we will have to loop over everything anyway, cre ate
// another iterator and loop it until it is at the right place, then take its // another iterator and loop it until it is at the right place, then take its
// information. // information.
const_row_iterator it(in_M, 0); const_row_iterator it(in_M, 0);
while((it.row() < in_row) || ((it.row() == in_row) && (it.col() < in_col) )) while((it.row() < in_row) || ((it.row() == in_row) && (it.col() < in_col) ))
{ {
skipping to change at line 524 skipping to change at line 610
iterator_base::internal_col = it.col(); iterator_base::internal_col = it.col();
iterator_base::internal_pos = it.pos(); iterator_base::internal_pos = it.pos();
iterator_base::skip_pos = it.skip_pos; iterator_base::skip_pos = it.skip_pos;
internal_row = it.internal_row; internal_row = it.internal_row;
actual_pos = it.actual_pos; actual_pos = it.actual_pos;
} }
template<typename eT> template<typename eT>
inline inline
SpSubview<eT>::const_row_iterator::const_row_iterator(const const_row_itera tor& other) SpSubview<eT>::const_row_iterator::const_row_iterator(const const_row_itera tor& other)
: iterator_base(other) : iterator_base(other.M, other.internal_col, other.internal_pos, other.sk ip_pos)
, internal_row(other.internal_row) , internal_row(other.internal_row)
, actual_pos(other.actual_pos) , actual_pos(other.actual_pos)
{ {
// Nothing to do. // Nothing to do.
} }
template<typename eT> template<typename eT>
inline inline
typename SpSubview<eT>::const_row_iterator& typename SpSubview<eT>::const_row_iterator&
SpSubview<eT>::const_row_iterator::operator++() SpSubview<eT>::const_row_iterator::operator++()
skipping to change at line 589 skipping to change at line 675
iterator_base::internal_col = cur_col; iterator_base::internal_col = cur_col;
return *this; return *this;
} }
} }
} }
} }
template<typename eT> template<typename eT>
inline inline
void typename SpSubview<eT>::const_row_iterator
SpSubview<eT>::const_row_iterator::operator++(int) SpSubview<eT>::const_row_iterator::operator++(int)
{ {
typename SpSubview<eT>::const_row_iterator tmp(*this);
++(*this); ++(*this);
return tmp;
} }
template<typename eT> template<typename eT>
inline inline
typename SpSubview<eT>::const_row_iterator& typename SpSubview<eT>::const_row_iterator&
SpSubview<eT>::const_row_iterator::operator--() SpSubview<eT>::const_row_iterator::operator--()
{ {
// We just need to find the previous element. // We just need to find the previous element.
// if(iterator_base::pos == 0) // if(iterator_base::pos == 0)
// { // {
skipping to change at line 659 skipping to change at line 749
actual_pos = ind; actual_pos = ind;
return *this; return *this;
} }
} }
} }
} }
template<typename eT> template<typename eT>
inline inline
void typename SpSubview<eT>::const_row_iterator
SpSubview<eT>::const_row_iterator::operator--(int) SpSubview<eT>::const_row_iterator::operator--(int)
{ {
typename SpSubview<eT>::const_row_iterator tmp(*this);
--(*this); --(*this);
return tmp;
}
template<typename eT>
inline
bool
SpSubview<eT>::const_row_iterator::operator==(const const_iterator& rhs) co
nst
{
return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col)
;
}
template<typename eT>
inline
bool
SpSubview<eT>::const_row_iterator::operator!=(const const_iterator& rhs) co
nst
{
return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col)
;
}
template<typename eT>
inline
bool
SpSubview<eT>::const_row_iterator::operator==(const typename SpMat<eT>::con
st_iterator& rhs) const
{
return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col)
;
}
template<typename eT>
inline
bool
SpSubview<eT>::const_row_iterator::operator!=(const typename SpMat<eT>::con
st_iterator& rhs) const
{
return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col)
;
}
template<typename eT>
inline
bool
SpSubview<eT>::const_row_iterator::operator==(const const_row_iterator& rhs
) const
{
return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col)
;
}
template<typename eT>
inline
bool
SpSubview<eT>::const_row_iterator::operator!=(const const_row_iterator& rhs
) const
{
return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col)
;
}
template<typename eT>
inline
bool
SpSubview<eT>::const_row_iterator::operator==(const typename SpMat<eT>::con
st_row_iterator& rhs) const
{
return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col)
;
}
template<typename eT>
inline
bool
SpSubview<eT>::const_row_iterator::operator!=(const typename SpMat<eT>::con
st_row_iterator& rhs) const
{
return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col)
;
} }
/////////////////////////////////////////////////////////////////////////// //// /////////////////////////////////////////////////////////////////////////// ////
// SpSubview<eT>::row_iterator implementation // // SpSubview<eT>::row_iterator implementation //
/////////////////////////////////////////////////////////////////////////// //// /////////////////////////////////////////////////////////////////////////// ////
template<typename eT> template<typename eT>
inline inline
SpValProxy<SpSubview<eT> > SpValProxy<SpSubview<eT> >
SpSubview<eT>::row_iterator::operator*() SpSubview<eT>::row_iterator::operator*()
skipping to change at line 692 skipping to change at line 850
inline inline
typename SpSubview<eT>::row_iterator& typename SpSubview<eT>::row_iterator&
SpSubview<eT>::row_iterator::operator++() SpSubview<eT>::row_iterator::operator++()
{ {
const_row_iterator::operator++(); const_row_iterator::operator++();
return *this; return *this;
} }
template<typename eT> template<typename eT>
inline inline
void typename SpSubview<eT>::row_iterator
SpSubview<eT>::row_iterator::operator++(int) SpSubview<eT>::row_iterator::operator++(int)
{ {
typename SpSubview<eT>::row_iterator tmp(*this);
++(*this); ++(*this);
return tmp;
} }
template<typename eT> template<typename eT>
inline inline
typename SpSubview<eT>::row_iterator& typename SpSubview<eT>::row_iterator&
SpSubview<eT>::row_iterator::operator--() SpSubview<eT>::row_iterator::operator--()
{ {
const_row_iterator::operator--(); const_row_iterator::operator--();
return *this; return *this;
} }
template<typename eT> template<typename eT>
inline inline
void typename SpSubview<eT>::row_iterator
SpSubview<eT>::row_iterator::operator--(int) SpSubview<eT>::row_iterator::operator--(int)
{ {
typename SpSubview<eT>::row_iterator tmp(*this);
--(*this); --(*this);
return tmp;
} }
//! @} //! @}
 End of changes. 37 change blocks. 
48 lines changed or deleted 246 lines changed or added


 SpSubview_meat.hpp   SpSubview_meat.hpp 
skipping to change at line 928 skipping to change at line 928
template<typename eT> template<typename eT>
inline inline
bool bool
SpSubview<eT>::is_vec() const SpSubview<eT>::is_vec() const
{ {
return ( (n_rows == 1) || (n_cols == 1) ); return ( (n_rows == 1) || (n_cols == 1) );
} }
template<typename eT> template<typename eT>
inline inline
SpSubview<eT>
SpSubview<eT>::row(const uword row_num)
{
arma_extra_debug_sigprint();
arma_debug_check(row_num >= n_rows, "SpSubview::row(): out of bounds");
return submat(row_num, 0, row_num, n_cols - 1);
}
template<typename eT>
inline
const SpSubview<eT>
SpSubview<eT>::row(const uword row_num) const
{
arma_extra_debug_sigprint();
arma_debug_check(row_num >= n_rows, "SpSubview::row(): out of bounds");
return submat(row_num, 0, row_num, n_cols - 1);
}
template<typename eT>
inline
SpSubview<eT>
SpSubview<eT>::col(const uword col_num)
{
arma_extra_debug_sigprint();
arma_debug_check(col_num >= n_cols, "SpSubview::col(): out of bounds");
return submat(0, col_num, n_rows - 1, col_num);
}
template<typename eT>
inline
const SpSubview<eT>
SpSubview<eT>::col(const uword col_num) const
{
arma_extra_debug_sigprint();
arma_debug_check(col_num >= n_cols, "SpSubview::col(): out of bounds");
return submat(0, col_num, n_rows - 1, col_num);
}
template<typename eT>
inline
SpSubview<eT>
SpSubview<eT>::rows(const uword in_row1, const uword in_row2)
{
arma_extra_debug_sigprint();
arma_debug_check
(
(in_row1 > in_row2) || (in_row2 >= n_rows),
"SpSubview::rows(): indices out of bounds or incorrectly used"
);
return submat(in_row1, 0, in_row2, n_cols - 1);
}
template<typename eT>
inline
const SpSubview<eT>
SpSubview<eT>::rows(const uword in_row1, const uword in_row2) const
{
arma_extra_debug_sigprint();
arma_debug_check
(
(in_row1 > in_row2) || (in_row2 >= n_rows),
"SpSubview::rows(): indices out of bounds or incorrectly used"
);
return submat(in_row1, 0, in_row2, n_cols - 1);
}
template<typename eT>
inline
SpSubview<eT>
SpSubview<eT>::cols(const uword in_col1, const uword in_col2)
{
arma_extra_debug_sigprint();
arma_debug_check
(
(in_col1 > in_col2) || (in_col2 >= n_cols),
"SpSubview::cols(): indices out of bounds or incorrectly used"
);
return submat(0, in_col1, n_rows - 1, in_col2);
}
template<typename eT>
inline
const SpSubview<eT>
SpSubview<eT>::cols(const uword in_col1, const uword in_col2) const
{
arma_extra_debug_sigprint();
arma_debug_check
(
(in_col1 > in_col2) || (in_col2 >= n_cols),
"SpSubview::cols(): indices out of bounds or incorrectly used"
);
return submat(0, in_col1, n_rows - 1, in_col2);
}
template<typename eT>
inline
SpSubview<eT>
SpSubview<eT>::submat(const uword in_row1, const uword in_col1, const uword
in_row2, const uword in_col2)
{
arma_extra_debug_sigprint();
arma_debug_check
(
(in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (i
n_col2 >= n_cols),
"SpSubview::submat(): indices out of bounds or incorrectly used"
);
return access::rw(m).submat(in_row1 + aux_row1, in_col1 + aux_col1, in_ro
w2 + aux_row1, in_col2 + aux_col1);
}
template<typename eT>
inline
const SpSubview<eT>
SpSubview<eT>::submat(const uword in_row1, const uword in_col1, const uword
in_row2, const uword in_col2) const
{
arma_extra_debug_sigprint();
arma_debug_check
(
(in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (i
n_col2 >= n_cols),
"SpSubview::submat(): indices out of bounds or incorrectly used"
);
return m.submat(in_row1 + aux_row1, in_col1 + aux_col1, in_row2 + aux_row
1, in_col2 + aux_col1);
}
template<typename eT>
inline
SpSubview<eT>
SpSubview<eT>::submat(const span& row_span, const span& col_span)
{
arma_extra_debug_sigprint();
const bool row_all = row_span.whole;
const bool col_all = row_span.whole;
const uword in_row1 = row_all ? 0 : row_span.a;
const uword in_row2 = row_all ? n_rows : row_span.b;
const uword in_col1 = col_all ? 0 : col_span.a;
const uword in_col2 = col_all ? n_cols : col_span.b;
arma_debug_check
(
( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= n_rows)))
||
( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= n_cols))),
"SpSubview::submat(): indices out of bounds or incorrectly used"
);
return submat(in_row1, in_col1, in_row2, in_col2);
}
template<typename eT>
inline
const SpSubview<eT>
SpSubview<eT>::submat(const span& row_span, const span& col_span) const
{
arma_extra_debug_sigprint();
const bool row_all = row_span.whole;
const bool col_all = row_span.whole;
const uword in_row1 = row_all ? 0 : row_span.a;
const uword in_row2 = row_all ? n_rows - 1 : row_span.b;
const uword in_col1 = col_all ? 0 : col_span.a;
const uword in_col2 = col_all ? n_cols - 1 : col_span.b;
arma_debug_check
(
( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= n_rows)))
||
( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= n_cols))),
"SpSubview::submat(): indices out of bounds or incorrectly used"
);
return submat(in_row1, in_col1, in_row2, in_col2);
}
template<typename eT>
inline
SpSubview<eT>
SpSubview<eT>::operator()(const uword row_num, const span& col_span)
{
arma_extra_debug_sigprint();
return submat(span(row_num, row_num), col_span);
}
template<typename eT>
inline
const SpSubview<eT>
SpSubview<eT>::operator()(const uword row_num, const span& col_span) const
{
arma_extra_debug_sigprint();
return submat(span(row_num, row_num), col_span);
}
template<typename eT>
inline
SpSubview<eT>
SpSubview<eT>::operator()(const span& row_span, const uword col_num)
{
arma_extra_debug_sigprint();
return submat(row_span, span(col_num, col_num));
}
template<typename eT>
inline
const SpSubview<eT>
SpSubview<eT>::operator()(const span& row_span, const uword col_num) const
{
arma_extra_debug_sigprint();
return submat(row_span, span(col_num, col_num));
}
template<typename eT>
inline
SpSubview<eT>
SpSubview<eT>::operator()(const span& row_span, const span& col_span)
{
arma_extra_debug_sigprint();
return submat(row_span, col_span);
}
template<typename eT>
inline
const SpSubview<eT>
SpSubview<eT>::operator()(const span& row_span, const span& col_span) const
{
arma_extra_debug_sigprint();
return submat(row_span, col_span);
}
template<typename eT>
inline
void void
SpSubview<eT>::swap_rows(const uword in_row1, const uword in_row2) SpSubview<eT>::swap_rows(const uword in_row1, const uword in_row2)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_check((in_row1 >= n_rows) || (in_row2 >= n_rows), "SpSubview:: swap_rows(): invalid row index"); arma_debug_check((in_row1 >= n_rows) || (in_row2 >= n_rows), "SpSubview:: swap_rows(): invalid row index");
const uword start_col = aux_col1; const uword start_col = aux_col1;
const uword end_col = aux_col1 + n_cols; const uword end_col = aux_col1 + n_cols;
skipping to change at line 1001 skipping to change at line 1259
inline inline
typename SpSubview<eT>::const_iterator typename SpSubview<eT>::const_iterator
SpSubview<eT>::begin_col(const uword col_num) const SpSubview<eT>::begin_col(const uword col_num) const
{ {
return const_iterator(*this, 0, col_num); return const_iterator(*this, 0, col_num);
} }
template<typename eT> template<typename eT>
inline inline
typename SpSubview<eT>::row_iterator typename SpSubview<eT>::row_iterator
SpSubview<eT>::begin_row() SpSubview<eT>::begin_row(const uword row_num)
{ {
return row_iterator(*this); return row_iterator(*this, row_num, 0);
} }
template<typename eT> template<typename eT>
inline inline
typename SpSubview<eT>::const_row_iterator typename SpSubview<eT>::const_row_iterator
SpSubview<eT>::begin_row() const SpSubview<eT>::begin_row(const uword row_num) const
{ {
return const_row_iterator(*this); return const_row_iterator(*this, row_num, 0);
} }
template<typename eT> template<typename eT>
inline inline
typename SpSubview<eT>::iterator typename SpSubview<eT>::iterator
SpSubview<eT>::end() SpSubview<eT>::end()
{ {
return iterator(*this, 0, n_cols, n_nonzero, m.n_nonzero - n_nonzero); return iterator(*this, 0, n_cols, n_nonzero, m.n_nonzero - n_nonzero);
} }
skipping to change at line 1048 skipping to change at line 1306
template<typename eT> template<typename eT>
inline inline
typename SpSubview<eT>::const_row_iterator typename SpSubview<eT>::const_row_iterator
SpSubview<eT>::end_row() const SpSubview<eT>::end_row() const
{ {
return const_row_iterator(*this, n_nonzero); return const_row_iterator(*this, n_nonzero);
} }
template<typename eT> template<typename eT>
inline inline
typename SpSubview<eT>::row_iterator
SpSubview<eT>::end_row(const uword row_num)
{
return row_iterator(*this, row_num + 1, 0);
}
template<typename eT>
inline
typename SpSubview<eT>::const_row_iterator
SpSubview<eT>::end_row(const uword row_num) const
{
return const_row_iterator(*this, row_num + 1, 0);
}
template<typename eT>
inline
arma_hot arma_hot
arma_warn_unused arma_warn_unused
eT& eT&
SpSubview<eT>::add_element(const uword in_row, const uword in_col, const eT in_val) SpSubview<eT>::add_element(const uword in_row, const uword in_col, const eT in_val)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
// This may not actually add an element. // This may not actually add an element.
const uword old_n_nonzero = m.n_nonzero; const uword old_n_nonzero = m.n_nonzero;
eT& retval = access::rw(m).add_element(in_row + aux_row1, in_col + aux_co l1, in_val); eT& retval = access::rw(m).add_element(in_row + aux_row1, in_col + aux_co l1, in_val);
 End of changes. 6 change blocks. 
4 lines changed or deleted 284 lines changed or added


 arma_ostream_bones.hpp   arma_ostream_bones.hpp 
skipping to change at line 41 skipping to change at line 41
class arma_ostream class arma_ostream
{ {
public: public:
template<typename eT> inline static std::streamsize modify_stream(std::os tream& o, const eT* data, const uword n_elem); template<typename eT> inline static std::streamsize modify_stream(std::os tream& o, const eT* data, const uword n_elem);
template<typename T> inline static std::streamsize modify_stream(std::os tream& o, const std::complex<T>* data, const uword n_elem); template<typename T> inline static std::streamsize modify_stream(std::os tream& o, const std::complex<T>* data, const uword n_elem);
template<typename eT> inline static std::streamsize modify_stream(std::os tream& o, typename SpMat<eT>::const_iterator begin, const uword n_elem, con st typename arma_not_cx<eT>::result* junk = 0); template<typename eT> inline static std::streamsize modify_stream(std::os tream& o, typename SpMat<eT>::const_iterator begin, const uword n_elem, con st typename arma_not_cx<eT>::result* junk = 0);
template<typename T> inline static std::streamsize modify_stream(std::os tream& o, typename SpMat<T>::const_iterator begin, const uword n_elem, cons t typename arma_cx_only<T>::result* junk = 0); template<typename T> inline static std::streamsize modify_stream(std::os tream& o, typename SpMat<T>::const_iterator begin, const uword n_elem, cons t typename arma_cx_only<T>::result* junk = 0);
template<typename eT> inline static void print_elem_zero(std::ostream& o) ; template<typename eT> inline static void print_elem_zero(std::ostream& o, const bool modify);
template<typename eT> arma_inline static void print_elem(std::ostream& o, template<typename eT> arma_inline static void print_elem(std::ostream& o,
const eT& x); const eT& x, const bool modify);
template<typename T> inline static void print_elem(std::ostream& o, template<typename T> inline static void print_elem(std::ostream& o,
const std::complex<T>& x); const std::complex<T>& x, const bool modify);
template<typename eT> inline static void print(std::ostream& o, const Ma t<eT>& m, const bool modify); template<typename eT> inline static void print(std::ostream& o, const Ma t<eT>& m, const bool modify);
template<typename eT> inline static void print(std::ostream& o, const Cub e<eT>& m, const bool modify); template<typename eT> inline static void print(std::ostream& o, const Cub e<eT>& m, const bool modify);
template<typename oT> inline static void print(std::ostream& o, const fie ld<oT>& m); template<typename oT> inline static void print(std::ostream& o, const fie ld<oT>& m);
template<typename oT> inline static void print(std::ostream& o, const sub view_field<oT>& m); template<typename oT> inline static void print(std::ostream& o, const sub view_field<oT>& m);
template<typename eT> inline static void print_dense(std::ostream& o, con st SpMat<eT>& m, const bool modify); template<typename eT> inline static void print_dense(std::ostream& o, con st SpMat<eT>& m, const bool modify);
template<typename eT> inline static void print(std::ostream& o, const SpM at<eT>& m, const bool modify); template<typename eT> inline static void print(std::ostream& o, const SpM at<eT>& m, const bool modify);
}; };
 End of changes. 2 change blocks. 
5 lines changed or deleted 5 lines changed or added


 arma_ostream_meat.hpp   arma_ostream_meat.hpp 
skipping to change at line 251 skipping to change at line 251
o.precision(3); o.precision(3);
cell_width = 2 + 2*(1 + 3 + o.precision() + 5) + 1; cell_width = 2 + 2*(1 + 3 + o.precision() + 5) + 1;
return cell_width; return cell_width;
} }
template<typename eT> template<typename eT>
inline inline
void void
arma_ostream::print_elem_zero(std::ostream& o) arma_ostream::print_elem_zero(std::ostream& o, const bool modify)
{ {
const std::streamsize orig_precision = o.precision(); if(modify == true)
{
const std::streamsize orig_precision = o.precision();
o.precision(0); o.precision(0);
o << eT(0); o << eT(0);
o.precision(orig_precision); o.precision(orig_precision);
}
else
{
o << eT(0);
}
} }
//! Print an element to the specified stream //! Print an element to the specified stream
template<typename eT> template<typename eT>
arma_inline arma_inline
void void
arma_ostream::print_elem(std::ostream& o, const eT& x) arma_ostream::print_elem(std::ostream& o, const eT& x, const bool modify)
{ {
if(x != eT(0)) if(x != eT(0))
{ {
o << x; o << x;
} }
else else
{ {
arma_ostream::print_elem_zero<eT>(o); arma_ostream::print_elem_zero<eT>(o, modify);
} }
} }
//! Print a complex element to the specified stream //! Print a complex element to the specified stream
template<typename T> template<typename T>
inline inline
void void
arma_ostream::print_elem(std::ostream& o, const std::complex<T>& x) arma_ostream::print_elem(std::ostream& o, const std::complex<T>& x, const b ool modify)
{ {
if( (x.real() != T(0)) || (x.imag() != T(0)) ) if( (x.real() != T(0)) || (x.imag() != T(0)) || (modify == false) )
{ {
std::ostringstream ss; std::ostringstream ss;
ss.flags(o.flags()); ss.flags(o.flags());
//ss.imbue(o.getloc()); //ss.imbue(o.getloc());
ss.precision(o.precision()); ss.precision(o.precision());
ss << '(' << x.real() << ',' << x.imag() << ')'; ss << '(' << x.real() << ',' << x.imag() << ')';
o << ss.str(); o << ss.str();
} }
else else
skipping to change at line 328 skipping to change at line 335
{ {
if(cell_width > 0) if(cell_width > 0)
{ {
for(uword row=0; row < m_n_rows; ++row) for(uword row=0; row < m_n_rows; ++row)
{ {
for(uword col=0; col < m_n_cols; ++col) for(uword col=0; col < m_n_cols; ++col)
{ {
// the cell width appears to be reset after each element is pri nted, // the cell width appears to be reset after each element is pri nted,
// hence we need to restore it // hence we need to restore it
o.width(cell_width); o.width(cell_width);
arma_ostream::print_elem(o, m.at(row,col)); arma_ostream::print_elem(o, m.at(row,col), modify);
} }
o << '\n'; o << '\n';
} }
} }
else else
{ {
for(uword row=0; row < m_n_rows; ++row) for(uword row=0; row < m_n_rows; ++row)
{ {
for(uword col=0; col < m_n_cols-1; ++col) for(uword col=0; col < m_n_cols-1; ++col)
{ {
arma_ostream::print_elem(o, m.at(row,col)); arma_ostream::print_elem(o, m.at(row,col), modify);
o << ' '; o << ' ';
} }
arma_ostream::print_elem(o, m.at(row, m_n_cols-1)); arma_ostream::print_elem(o, m.at(row, m_n_cols-1), modify);
o << '\n'; o << '\n';
} }
} }
} }
} }
else else
{ {
o << "[matrix size: " << m_n_rows << 'x' << m_n_cols << "]\n"; o << "[matrix size: " << m_n_rows << 'x' << m_n_cols << "]\n";
} }
skipping to change at line 500 skipping to change at line 507
o.width(cell_width); o.width(cell_width);
eT val = eT(0); eT val = eT(0);
for(typename SpMat<eT>::const_iterator it = begin; it.pos() < m .n_nonzero; ++it) for(typename SpMat<eT>::const_iterator it = begin; it.pos() < m .n_nonzero; ++it)
{ {
if(it.row() == row && it.col() == col) if(it.row() == row && it.col() == col)
{ {
val = *it; val = *it;
break; break;
} }
} }
arma_ostream::print_elem(o,eT(val)); arma_ostream::print_elem(o,eT(val), modify);
} }
o << '\n'; o << '\n';
} }
} }
else else
{ {
// An efficient row_iterator would make this simpler and faster // An efficient row_iterator would make this simpler and faster
for(uword row=0; row < m_n_rows; ++row) for(uword row=0; row < m_n_rows; ++row)
{ {
skipping to change at line 522 skipping to change at line 529
{ {
eT val = eT(0); eT val = eT(0);
for(typename SpMat<eT>::const_iterator it = begin; it.pos() < m .n_nonzero; ++it) for(typename SpMat<eT>::const_iterator it = begin; it.pos() < m .n_nonzero; ++it)
{ {
if(it.row() == row && it.col() == col) if(it.row() == row && it.col() == col)
{ {
val = *it; val = *it;
break; break;
} }
} }
arma_ostream::print_elem(o,eT(val)); arma_ostream::print_elem(o,eT(val), modify);
o << ' '; o << ' ';
} }
o << '\n'; o << '\n';
} }
} }
} }
} }
else else
{ {
skipping to change at line 552 skipping to change at line 559
const std::streamsize cell_width = modify ? arma_ostream::modify_stre am(o, &tmp[0], 1) : o.width(); const std::streamsize cell_width = modify ? arma_ostream::modify_stre am(o, &tmp[0], 1) : o.width();
const uword m_n_rows = m.n_rows; const uword m_n_rows = m.n_rows;
const uword m_n_cols = m.n_cols; const uword m_n_cols = m.n_cols;
for(uword row=0; row < m_n_rows; ++row) for(uword row=0; row < m_n_rows; ++row)
{ {
for(uword col=0; col < m_n_cols; ++col) for(uword col=0; col < m_n_cols; ++col)
{ {
o.width(cell_width); o.width(cell_width);
arma_ostream::print_elem_zero<eT>(o);
arma_ostream::print_elem_zero<eT>(o, modify);
o << ' '; o << ' ';
} }
o << '\n'; o << '\n';
} }
} }
} }
o.flush(); o.flush();
stream_state.restore(o); stream_state.restore(o);
skipping to change at line 620 skipping to change at line 629
o << '(' << row << ", " << col << ") "; o << '(' << row << ", " << col << ") ";
if(col < 10) { o << " "; } if(col < 10) { o << " "; }
else if(col < 100) { o << " "; } else if(col < 100) { o << " "; }
else if(col < 1000) { o << " "; } else if(col < 1000) { o << " "; }
else if(col < 10000) { o << " "; } else if(col < 10000) { o << " "; }
else if(col < 100000) { o << ' '; } else if(col < 100000) { o << ' '; }
if(cell_width > 0) { o.width(cell_width); } if(cell_width > 0) { o.width(cell_width); }
arma_ostream::print_elem(o, eT(*begin)); arma_ostream::print_elem(o, eT(*begin), modify);
o << '\n'; o << '\n';
++begin; ++begin;
} }
o << '\n'; o << '\n';
} }
o.flush(); o.flush();
stream_state.restore(o); stream_state.restore(o);
 End of changes. 16 change blocks. 
16 lines changed or deleted 25 lines changed or added


 arma_version.hpp   arma_version.hpp 
skipping to change at line 17 skipping to change at line 17
// and/or modify it under the terms of the GNU // and/or modify it under the terms of the GNU
// Lesser General Public License (LGPL) as published // Lesser General Public License (LGPL) as published
// by the Free Software Foundation, either version 3 // by the Free Software Foundation, either version 3
// of the License or (at your option) any later version. // of the License or (at your option) any later version.
// (see http://www.opensource.org/licenses for more info) // (see http://www.opensource.org/licenses for more info)
//! \addtogroup arma_version //! \addtogroup arma_version
//! @{ //! @{
#define ARMA_VERSION_MAJOR 3 #define ARMA_VERSION_MAJOR 3
#define ARMA_VERSION_MINOR 4 #define ARMA_VERSION_MINOR 6
#define ARMA_VERSION_PATCH 5 #define ARMA_VERSION_PATCH 0
#define ARMA_VERSION_NAME "Ku De Ta" #define ARMA_VERSION_NAME "Piazza del Duomo"
struct arma_version struct arma_version
{ {
static const unsigned int major = ARMA_VERSION_MAJOR; static const unsigned int major = ARMA_VERSION_MAJOR;
static const unsigned int minor = ARMA_VERSION_MINOR; static const unsigned int minor = ARMA_VERSION_MINOR;
static const unsigned int patch = ARMA_VERSION_PATCH; static const unsigned int patch = ARMA_VERSION_PATCH;
static static
inline inline
std::string std::string
 End of changes. 1 change blocks. 
3 lines changed or deleted 3 lines changed or added


 armadillo   armadillo 
skipping to change at line 165 skipping to change at line 165
#include "armadillo_bits/Op_bones.hpp" #include "armadillo_bits/Op_bones.hpp"
#include "armadillo_bits/OpCube_bones.hpp" #include "armadillo_bits/OpCube_bones.hpp"
#include "armadillo_bits/SpOp_bones.hpp" #include "armadillo_bits/SpOp_bones.hpp"
#include "armadillo_bits/eOp_bones.hpp" #include "armadillo_bits/eOp_bones.hpp"
#include "armadillo_bits/eOpCube_bones.hpp" #include "armadillo_bits/eOpCube_bones.hpp"
#include "armadillo_bits/mtOp_bones.hpp" #include "armadillo_bits/mtOp_bones.hpp"
#include "armadillo_bits/mtOpCube_bones.hpp" #include "armadillo_bits/mtOpCube_bones.hpp"
#include "armadillo_bits/mtSpOp_bones.hpp"
#include "armadillo_bits/Glue_bones.hpp" #include "armadillo_bits/Glue_bones.hpp"
#include "armadillo_bits/eGlue_bones.hpp" #include "armadillo_bits/eGlue_bones.hpp"
#include "armadillo_bits/mtGlue_bones.hpp" #include "armadillo_bits/mtGlue_bones.hpp"
#include "armadillo_bits/SpGlue_bones.hpp" #include "armadillo_bits/SpGlue_bones.hpp"
#include "armadillo_bits/GlueCube_bones.hpp" #include "armadillo_bits/GlueCube_bones.hpp"
#include "armadillo_bits/eGlueCube_bones.hpp" #include "armadillo_bits/eGlueCube_bones.hpp"
#include "armadillo_bits/mtGlueCube_bones.hpp" #include "armadillo_bits/mtGlueCube_bones.hpp"
skipping to change at line 237 skipping to change at line 238
#include "armadillo_bits/glue_toeplitz_bones.hpp" #include "armadillo_bits/glue_toeplitz_bones.hpp"
#include "armadillo_bits/glue_hist_bones.hpp" #include "armadillo_bits/glue_hist_bones.hpp"
#include "armadillo_bits/glue_histc_bones.hpp" #include "armadillo_bits/glue_histc_bones.hpp"
#include "armadillo_bits/spop_max_bones.hpp" #include "armadillo_bits/spop_max_bones.hpp"
#include "armadillo_bits/spop_min_bones.hpp" #include "armadillo_bits/spop_min_bones.hpp"
#include "armadillo_bits/spop_sum_bones.hpp" #include "armadillo_bits/spop_sum_bones.hpp"
#include "armadillo_bits/spop_strans_bones.hpp" #include "armadillo_bits/spop_strans_bones.hpp"
#include "armadillo_bits/spop_htrans_bones.hpp" #include "armadillo_bits/spop_htrans_bones.hpp"
#include "armadillo_bits/spop_misc_bones.hpp" #include "armadillo_bits/spop_misc_bones.hpp"
#include "armadillo_bits/spop_mean_bones.hpp"
#include "armadillo_bits/spop_var_bones.hpp"
#include "armadillo_bits/spglue_plus_bones.hpp" #include "armadillo_bits/spglue_plus_bones.hpp"
#include "armadillo_bits/spglue_minus_bones.hpp" #include "armadillo_bits/spglue_minus_bones.hpp"
#include "armadillo_bits/spglue_times_bones.hpp" #include "armadillo_bits/spglue_times_bones.hpp"
// //
// debugging functions // debugging functions
#include "armadillo_bits/debug.hpp" #include "armadillo_bits/debug.hpp"
skipping to change at line 273 skipping to change at line 276
#include "armadillo_bits/diagmat_proxy.hpp" #include "armadillo_bits/diagmat_proxy.hpp"
#include "armadillo_bits/strip.hpp" #include "armadillo_bits/strip.hpp"
#include "armadillo_bits/Op_meat.hpp" #include "armadillo_bits/Op_meat.hpp"
#include "armadillo_bits/OpCube_meat.hpp" #include "armadillo_bits/OpCube_meat.hpp"
#include "armadillo_bits/SpOp_meat.hpp" #include "armadillo_bits/SpOp_meat.hpp"
#include "armadillo_bits/mtOp_meat.hpp" #include "armadillo_bits/mtOp_meat.hpp"
#include "armadillo_bits/mtOpCube_meat.hpp" #include "armadillo_bits/mtOpCube_meat.hpp"
#include "armadillo_bits/mtSpOp_meat.hpp"
#include "armadillo_bits/Glue_meat.hpp" #include "armadillo_bits/Glue_meat.hpp"
#include "armadillo_bits/GlueCube_meat.hpp" #include "armadillo_bits/GlueCube_meat.hpp"
#include "armadillo_bits/SpGlue_meat.hpp" #include "armadillo_bits/SpGlue_meat.hpp"
#include "armadillo_bits/eop_aux.hpp" #include "armadillo_bits/eop_aux.hpp"
#include "armadillo_bits/eOp_meat.hpp" #include "armadillo_bits/eOp_meat.hpp"
#include "armadillo_bits/eOpCube_meat.hpp" #include "armadillo_bits/eOpCube_meat.hpp"
skipping to change at line 503 skipping to change at line 507
#include "armadillo_bits/glue_toeplitz_meat.hpp" #include "armadillo_bits/glue_toeplitz_meat.hpp"
#include "armadillo_bits/glue_hist_meat.hpp" #include "armadillo_bits/glue_hist_meat.hpp"
#include "armadillo_bits/glue_histc_meat.hpp" #include "armadillo_bits/glue_histc_meat.hpp"
#include "armadillo_bits/spop_max_meat.hpp" #include "armadillo_bits/spop_max_meat.hpp"
#include "armadillo_bits/spop_min_meat.hpp" #include "armadillo_bits/spop_min_meat.hpp"
#include "armadillo_bits/spop_sum_meat.hpp" #include "armadillo_bits/spop_sum_meat.hpp"
#include "armadillo_bits/spop_strans_meat.hpp" #include "armadillo_bits/spop_strans_meat.hpp"
#include "armadillo_bits/spop_htrans_meat.hpp" #include "armadillo_bits/spop_htrans_meat.hpp"
#include "armadillo_bits/spop_misc_meat.hpp" #include "armadillo_bits/spop_misc_meat.hpp"
#include "armadillo_bits/spop_mean_meat.hpp"
#include "armadillo_bits/spop_var_meat.hpp"
#include "armadillo_bits/spglue_plus_meat.hpp" #include "armadillo_bits/spglue_plus_meat.hpp"
#include "armadillo_bits/spglue_minus_meat.hpp" #include "armadillo_bits/spglue_minus_meat.hpp"
#include "armadillo_bits/spglue_times_meat.hpp" #include "armadillo_bits/spglue_times_meat.hpp"
} }
#endif #endif
 End of changes. 4 change blocks. 
0 lines changed or deleted 6 lines changed or added


 compiler_setup.hpp   compiler_setup.hpp 
skipping to change at line 17 skipping to change at line 17
// and/or modify it under the terms of the GNU // and/or modify it under the terms of the GNU
// Lesser General Public License (LGPL) as published // Lesser General Public License (LGPL) as published
// by the Free Software Foundation, either version 3 // by the Free Software Foundation, either version 3
// of the License or (at your option) any later version. // of the License or (at your option) any later version.
// (see http://www.opensource.org/licenses for more info) // (see http://www.opensource.org/licenses for more info)
#define arma_hot #define arma_hot
#define arma_cold #define arma_cold
#define arma_pure #define arma_pure
#define arma_const #define arma_const
#define arma_inline inline
#define arma_aligned #define arma_aligned
#define arma_warn_unused #define arma_warn_unused
#define arma_deprecated #define arma_deprecated
#define arma_malloc
#define arma_inline inline
#define arma_ignore(variable) ((void)(variable)) #define arma_ignore(variable) ((void)(variable))
#if defined(ARMA_BLAS_UNDERSCORE) #if defined(ARMA_BLAS_UNDERSCORE)
#define arma_fortran2_noprefix(function) function##_ #define arma_fortran2_noprefix(function) function##_
#define arma_fortran2_prefix(function) wrapper_##function##_ #define arma_fortran2_prefix(function) wrapper_##function##_
#else #else
#define arma_fortran2_prefix(function) wrapper_##function #define arma_fortran2_prefix(function) wrapper_##function
#define arma_fortran2_noprefix(function) function #define arma_fortran2_noprefix(function) function
#endif #endif
skipping to change at line 68 skipping to change at line 69
#if (__GNUC__ < 4) #if (__GNUC__ < 4)
#error "*** Need a newer compiler ***" #error "*** Need a newer compiler ***"
#endif #endif
#define ARMA_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNU C_PATCHLEVEL__) #define ARMA_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNU C_PATCHLEVEL__)
#define ARMA_GOOD_COMPILER #define ARMA_GOOD_COMPILER
#undef ARMA_HAVE_STD_TR1 #undef ARMA_HAVE_STD_TR1
#undef arma_cold
#undef arma_pure #undef arma_pure
#undef arma_const #undef arma_const
#undef arma_inline
#undef arma_aligned #undef arma_aligned
#undef arma_warn_unused #undef arma_warn_unused
#undef arma_deprecated #undef arma_deprecated
#undef arma_malloc
#undef arma_inline
#define arma_cold __attribute__((__noinline__))
#define arma_pure __attribute__((__pure__))
#define arma_const __attribute__((__const__))
#define arma_aligned __attribute__((__aligned__))
#define arma_warn_unused __attribute__((__warn_unused_result__))
#define arma_deprecated __attribute__((__deprecated__))
#define arma_malloc __attribute__((__malloc__))
#define arma_inline inline __attribute__((__always_inline__))
#if (ARMA_GCC_VERSION >= 40300)
#undef arma_hot
#undef arma_cold
#define arma_pure __attribute__((pure)) #define arma_hot __attribute__((__hot__))
#define arma_const __attribute__((const)) #define arma_cold __attribute__((__cold__,__noinline__))
#define arma_inline inline __attribute__((always_inline)) #endif
#define arma_aligned __attribute__((aligned))
#define arma_warn_unused __attribute__((warn_unused_result))
#define arma_deprecated __attribute__((deprecated))
#if (ARMA_GCC_VERSION >= 40200) #if (ARMA_GCC_VERSION >= 40200)
#if defined(_GLIBCXX_USE_C99_MATH_TR1) && defined(_GLIBCXX_USE_C99_COMP LEX_TR1) #if defined(_GLIBCXX_USE_C99_MATH_TR1) && defined(_GLIBCXX_USE_C99_COMP LEX_TR1)
#define ARMA_HAVE_STD_TR1 #define ARMA_HAVE_STD_TR1
#endif #endif
#endif #endif
#if defined(__GXX_EXPERIMENTAL_CXX0X__) #if defined(__GXX_EXPERIMENTAL_CXX0X__)
#undef ARMA_HAVE_STD_TR1 #undef ARMA_HAVE_STD_TR1
#if !defined(ARMA_USE_CXX11) #if !defined(ARMA_USE_CXX11)
#define ARMA_USE_CXX11 #define ARMA_USE_CXX11
#endif #endif
#endif #endif
#if defined(__clang__) #if defined(__clang__)
#undef ARMA_HAVE_STD_TR1 #undef ARMA_HAVE_STD_TR1
//#undef ARMA_GOOD_COMPILER //#undef ARMA_GOOD_COMPILER
#endif #endif
#if (ARMA_GCC_VERSION >= 40300)
#undef arma_hot
#undef arma_cold
#define arma_hot __attribute__((hot))
#define arma_cold __attribute__((cold))
#endif
#if ( (ARMA_GCC_VERSION >= 40700) && (ARMA_GCC_VERSION <= 40701) ) #if ( (ARMA_GCC_VERSION >= 40700) && (ARMA_GCC_VERSION <= 40701) )
#define ARMA_GCC47_BUG #define ARMA_GCC47_BUG
#warning "*** Detected GCC 4.7.0 / 4.7.1, which has a regression (bug)" #warning "*** Detected GCC 4.7.0 / 4.7.1, which has a regression (bug)"
#warning "*** See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53549 " #warning "*** See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53549 "
#warning "*** A partial workaround for the bug has been activated, " #warning "*** A partial workaround for the bug has been activated, "
#warning "*** which reduces some functionality in fixed-size matrices " #warning "*** which reduces some functionality in fixed-size matrices "
#endif #endif
#undef ARMA_GCC_VERSION #undef ARMA_GCC_VERSION
 End of changes. 7 change blocks. 
16 lines changed or deleted 21 lines changed or added


 debug.hpp   debug.hpp 
skipping to change at line 80 skipping to change at line 80
get_stream_err2() get_stream_err2()
{ {
return arma_stream_err2<char>(NULL); return arma_stream_err2<char>(NULL);
} }
// //
// arma_stop // arma_stop
//! print a message to get_stream_err1() and/or throw a logic_error excepti on //! print a message to get_stream_err1() and/or throw a logic_error excepti on
template<typename T1> template<typename T1>
inline
void
arma_cold arma_cold
static
void
arma_stop(const T1& x) arma_stop(const T1& x)
{ {
#if defined(ARMA_PRINT_LOGIC_ERRORS) #if defined(ARMA_PRINT_LOGIC_ERRORS)
{ {
std::ostream& out = get_stream_err1(); std::ostream& out = get_stream_err1();
out.flush(); out.flush();
out << '\n'; out << '\n';
out << "error: " << x << '\n'; out << "error: " << x << '\n';
skipping to change at line 106 skipping to change at line 106
#else #else
{ {
arma_ignore(x); arma_ignore(x);
} }
#endif #endif
throw std::logic_error(""); throw std::logic_error("");
} }
template<typename T1> template<typename T1>
inline
void
arma_cold arma_cold
static
void
arma_stop_bad_alloc(const T1& x) arma_stop_bad_alloc(const T1& x)
{ {
std::ostream& out = get_stream_err1(); std::ostream& out = get_stream_err1();
out.flush(); out.flush();
out << '\n'; out << '\n';
out << "error: " << x << '\n'; out << "error: " << x << '\n';
out << '\n'; out << '\n';
out.flush(); out.flush();
throw std::bad_alloc(); throw std::bad_alloc();
} }
// //
// arma_bad // arma_bad
//! print a message to get_stream_err2() and/or throw a run-time error exce ption //! print a message to get_stream_err2() and/or throw a run-time error exce ption
template<typename T1> template<typename T1>
inline
void
arma_cold arma_cold
static
void
arma_bad(const T1& x, const bool hurl = true) arma_bad(const T1& x, const bool hurl = true)
{ {
#if defined(ARMA_PRINT_RUNTIME_ERRORS) #if defined(ARMA_PRINT_RUNTIME_ERRORS)
{ {
std::ostream& out = get_stream_err2(); std::ostream& out = get_stream_err2();
out.flush(); out.flush();
out << '\n'; out << '\n';
out << "error: " << x << '\n'; out << "error: " << x << '\n';
skipping to change at line 159 skipping to change at line 159
if(hurl == true) if(hurl == true)
{ {
throw std::runtime_error(""); throw std::runtime_error("");
} }
} }
// //
// arma_print // arma_print
arma_cold
inline inline
void void
arma_cold
arma_print() arma_print()
{ {
get_stream_err1() << std::endl; get_stream_err1() << std::endl;
} }
template<typename T1> template<typename T1>
inline
void
arma_cold arma_cold
static
void
arma_print(const T1& x) arma_print(const T1& x)
{ {
get_stream_err1() << x << std::endl; get_stream_err1() << x << std::endl;
} }
template<typename T1, typename T2> template<typename T1, typename T2>
inline
void
arma_cold arma_cold
static
void
arma_print(const T1& x, const T2& y) arma_print(const T1& x, const T2& y)
{ {
get_stream_err1() << x << y << std::endl; get_stream_err1() << x << y << std::endl;
} }
template<typename T1, typename T2, typename T3> template<typename T1, typename T2, typename T3>
inline
void
arma_cold arma_cold
static
void
arma_print(const T1& x, const T2& y, const T3& z) arma_print(const T1& x, const T2& y, const T3& z)
{ {
get_stream_err1() << x << y << z << std::endl; get_stream_err1() << x << y << z << std::endl;
} }
// //
// arma_sigprint // arma_sigprint
//! print a message the the log stream with a preceding @ character. //! print a message the the log stream with a preceding @ character.
//! by default the log stream is cout. //! by default the log stream is cout.
skipping to change at line 249 skipping to change at line 249
arma_thisprint(const void* this_ptr) arma_thisprint(const void* this_ptr)
{ {
get_stream_err1() << " [this = " << this_ptr << ']' << std::endl; get_stream_err1() << " [this = " << this_ptr << ']' << std::endl;
} }
// //
// arma_warn // arma_warn
//! print a message to the warn stream //! print a message to the warn stream
template<typename T1> template<typename T1>
inline
void
arma_cold arma_cold
static
void
arma_warn(const bool state, const T1& x) arma_warn(const bool state, const T1& x)
{ {
if(state==true) if(state==true)
{ {
get_stream_err2() << x << std::endl; get_stream_err2() << x << std::endl;
} }
} }
template<typename T1, typename T2> template<typename T1, typename T2>
inline
void
arma_cold arma_cold
static
void
arma_warn(const bool state, const T1& x, const T2& y) arma_warn(const bool state, const T1& x, const T2& y)
{ {
if(state==true) if(state==true)
{ {
get_stream_err2() << x << y << std::endl; get_stream_err2() << x << y << std::endl;
} }
} }
template<typename T1, typename T2, typename T3> template<typename T1, typename T2, typename T3>
inline
void
arma_cold arma_cold
static
void
arma_warn(const bool state, const T1& x, const T2& y, const T3& z) arma_warn(const bool state, const T1& x, const T2& y, const T3& z)
{ {
if(state==true) if(state==true)
{ {
get_stream_err2() << x << y << z << std::endl; get_stream_err2() << x << y << z << std::endl;
} }
} }
// //
// arma_check // arma_check
//! if state is true, abort program //! if state is true, abort program
template<typename T1> template<typename T1>
arma_hot
inline inline
void void
arma_hot
arma_check(const bool state, const T1& x) arma_check(const bool state, const T1& x)
{ {
if(state==true) if(state==true)
{ {
arma_stop(arma_boost::str_wrapper(x)); arma_stop(arma_boost::str_wrapper(x));
} }
} }
template<typename T1, typename T2> template<typename T1, typename T2>
arma_hot
inline inline
void void
arma_hot
arma_check(const bool state, const T1& x, const T2& y) arma_check(const bool state, const T1& x, const T2& y)
{ {
if(state==true) if(state==true)
{ {
arma_stop( std::string(x) + std::string(y) ); arma_stop( std::string(x) + std::string(y) );
} }
} }
template<typename T1> template<typename T1>
arma_hot
inline inline
void void
arma_hot
arma_check_bad_alloc(const bool state, const T1& x) arma_check_bad_alloc(const bool state, const T1& x)
{ {
if(state==true) if(state==true)
{ {
arma_stop_bad_alloc(x); arma_stop_bad_alloc(x);
} }
} }
// //
// arma_set_error // arma_set_error
arma_hot
arma_inline arma_inline
void void
arma_hot
arma_set_error(bool& err_state, char*& err_msg, const bool expression, cons t char* message) arma_set_error(bool& err_state, char*& err_msg, const bool expression, cons t char* message)
{ {
if(expression == true) if(expression == true)
{ {
err_state = true; err_state = true;
err_msg = const_cast<char*>(message); err_msg = const_cast<char*>(message);
} }
} }
// //
// functions for generating strings indicating size errors // functions for generating strings indicating size errors
inline
std::string
arma_cold arma_cold
static
std::string
arma_incompat_size_string(const uword A_n_rows, const uword A_n_cols, const uword B_n_rows, const uword B_n_cols, const char* x) arma_incompat_size_string(const uword A_n_rows, const uword A_n_cols, const uword B_n_rows, const uword B_n_cols, const char* x)
{ {
std::stringstream tmp; std::stringstream tmp;
tmp << x << ": incompatible matrix dimensions: " << A_n_rows << 'x' << A_ n_cols << " and " << B_n_rows << 'x' << B_n_cols; tmp << x << ": incompatible matrix dimensions: " << A_n_rows << 'x' << A_ n_cols << " and " << B_n_rows << 'x' << B_n_cols;
return tmp.str(); return tmp.str();
} }
inline
arma_cold arma_cold
static
std::string std::string
arma_incompat_size_string(const uword A_n_rows, const uword A_n_cols, const uword A_n_slices, const uword B_n_rows, const uword B_n_cols, const uword B_n_slices, const char* x) arma_incompat_size_string(const uword A_n_rows, const uword A_n_cols, const uword A_n_slices, const uword B_n_rows, const uword B_n_cols, const uword B_n_slices, const char* x)
{ {
std::stringstream tmp; std::stringstream tmp;
tmp << x << ": incompatible cube dimensions: " << A_n_rows << 'x' << A_n_ cols << 'x' << A_n_slices << " and " << B_n_rows << 'x' << B_n_cols << 'x' << B_n_slices; tmp << x << ": incompatible cube dimensions: " << A_n_rows << 'x' << A_n_ cols << 'x' << A_n_slices << " and " << B_n_rows << 'x' << B_n_cols << 'x' << B_n_slices;
return tmp.str(); return tmp.str();
} }
template<typename eT> template<typename eT>
inline
arma_cold arma_cold
static
std::string std::string
arma_incompat_size_string(const subview_cube<eT>& Q, const Mat<eT>& A, cons t char* x) arma_incompat_size_string(const subview_cube<eT>& Q, const Mat<eT>& A, cons t char* x)
{ {
std::stringstream tmp; std::stringstream tmp;
tmp << x tmp << x
<< ": interpreting matrix as cube with dimenensions: " << ": interpreting matrix as cube with dimenensions: "
<< A.n_rows << 'x' << A.n_cols << 'x' << 1 << A.n_rows << 'x' << A.n_cols << 'x' << 1
<< " or " << " or "
<< A.n_rows << 'x' << 1 << 'x' << A.n_cols << A.n_rows << 'x' << 1 << 'x' << A.n_cols
skipping to change at line 403 skipping to change at line 403
arma_assert_same_size(const uword A_n_rows, const uword A_n_cols, const uwo rd B_n_rows, const uword B_n_cols, const char* x) arma_assert_same_size(const uword A_n_rows, const uword A_n_cols, const uwo rd B_n_rows, const uword B_n_cols, const char* x)
{ {
if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
{ {
arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) ); arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) );
} }
} }
//! stop if given matrices have different sizes //! stop if given matrices have different sizes
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_same_size(const Mat<eT1>& A, const Mat<eT2>& B, const char* x) arma_assert_same_size(const Mat<eT1>& A, const Mat<eT2>& B, const char* x)
{ {
const uword A_n_rows = A.n_rows; const uword A_n_rows = A.n_rows;
const uword A_n_cols = A.n_cols; const uword A_n_cols = A.n_cols;
const uword B_n_rows = B.n_rows; const uword B_n_rows = B.n_rows;
const uword B_n_cols = B.n_cols; const uword B_n_cols = B.n_cols;
if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
{ {
arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) ); arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) );
} }
} }
//! stop if given proxies have different sizes //! stop if given proxies have different sizes
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_same_size(const Proxy<eT1>& A, const Proxy<eT2>& B, const char* x) arma_assert_same_size(const Proxy<eT1>& A, const Proxy<eT2>& B, const char* x)
{ {
const uword A_n_rows = A.get_n_rows(); const uword A_n_rows = A.get_n_rows();
const uword A_n_cols = A.get_n_cols(); const uword A_n_cols = A.get_n_cols();
const uword B_n_rows = B.get_n_rows(); const uword B_n_rows = B.get_n_rows();
const uword B_n_cols = B.get_n_cols(); const uword B_n_cols = B.get_n_cols();
if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
{ {
arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) ); arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) );
} }
} }
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_same_size(const subview<eT1>& A, const subview<eT2>& B, const c har* x) arma_assert_same_size(const subview<eT1>& A, const subview<eT2>& B, const c har* x)
{ {
const uword A_n_rows = A.n_rows; const uword A_n_rows = A.n_rows;
const uword A_n_cols = A.n_cols; const uword A_n_cols = A.n_cols;
const uword B_n_rows = B.n_rows; const uword B_n_rows = B.n_rows;
const uword B_n_cols = B.n_cols; const uword B_n_cols = B.n_cols;
if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
{ {
arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) ); arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) );
} }
} }
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_same_size(const Mat<eT1>& A, const subview<eT2>& B, const char* x) arma_assert_same_size(const Mat<eT1>& A, const subview<eT2>& B, const char* x)
{ {
const uword A_n_rows = A.n_rows; const uword A_n_rows = A.n_rows;
const uword A_n_cols = A.n_cols; const uword A_n_cols = A.n_cols;
const uword B_n_rows = B.n_rows; const uword B_n_rows = B.n_rows;
const uword B_n_cols = B.n_cols; const uword B_n_cols = B.n_cols;
if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
{ {
arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) ); arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) );
} }
} }
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_same_size(const subview<eT1>& A, const Mat<eT2>& B, const char* x) arma_assert_same_size(const subview<eT1>& A, const Mat<eT2>& B, const char* x)
{ {
const uword A_n_rows = A.n_rows; const uword A_n_rows = A.n_rows;
const uword A_n_cols = A.n_cols; const uword A_n_cols = A.n_cols;
const uword B_n_rows = B.n_rows; const uword B_n_rows = B.n_rows;
const uword B_n_cols = B.n_cols; const uword B_n_cols = B.n_cols;
if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
{ {
arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) ); arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) );
} }
} }
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_same_size(const Mat<eT1>& A, const Proxy<eT2>& B, const char* x ) arma_assert_same_size(const Mat<eT1>& A, const Proxy<eT2>& B, const char* x )
{ {
const uword A_n_rows = A.n_rows; const uword A_n_rows = A.n_rows;
const uword A_n_cols = A.n_cols; const uword A_n_cols = A.n_cols;
const uword B_n_rows = B.get_n_rows(); const uword B_n_rows = B.get_n_rows();
const uword B_n_cols = B.get_n_cols(); const uword B_n_cols = B.get_n_cols();
if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
{ {
arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) ); arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) );
} }
} }
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_same_size(const Proxy<eT1>& A, const Mat<eT2>& B, const char* x ) arma_assert_same_size(const Proxy<eT1>& A, const Mat<eT2>& B, const char* x )
{ {
const uword A_n_rows = A.get_n_rows(); const uword A_n_rows = A.get_n_rows();
const uword A_n_cols = A.get_n_cols(); const uword A_n_cols = A.get_n_cols();
const uword B_n_rows = B.n_rows; const uword B_n_rows = B.n_rows;
const uword B_n_cols = B.n_cols; const uword B_n_cols = B.n_cols;
if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
{ {
arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) ); arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) );
} }
} }
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_same_size(const Proxy<eT1>& A, const subview<eT2>& B, const cha r* x) arma_assert_same_size(const Proxy<eT1>& A, const subview<eT2>& B, const cha r* x)
{ {
const uword A_n_rows = A.get_n_rows(); const uword A_n_rows = A.get_n_rows();
const uword A_n_cols = A.get_n_cols(); const uword A_n_cols = A.get_n_cols();
const uword B_n_rows = B.n_rows; const uword B_n_rows = B.n_rows;
const uword B_n_cols = B.n_cols; const uword B_n_cols = B.n_cols;
if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
{ {
arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) ); arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) );
} }
} }
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_same_size(const subview<eT1>& A, const Proxy<eT2>& B, const cha r* x) arma_assert_same_size(const subview<eT1>& A, const Proxy<eT2>& B, const cha r* x)
{ {
const uword A_n_rows = A.n_rows; const uword A_n_rows = A.n_rows;
const uword A_n_cols = A.n_cols; const uword A_n_cols = A.n_cols;
const uword B_n_rows = B.get_n_rows(); const uword B_n_rows = B.get_n_rows();
const uword B_n_cols = B.get_n_cols(); const uword B_n_cols = B.get_n_cols();
if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) )
{ {
arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) ); arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) );
} }
} }
// //
// functions for checking whether two cubes have the same dimensions // functions for checking whether two cubes have the same dimensions
arma_hot
inline inline
void void
arma_hot
arma_assert_same_size(const uword A_n_rows, const uword A_n_cols, const uwo rd A_n_slices, const uword B_n_rows, const uword B_n_cols, const uword B_n_ slices, const char* x) arma_assert_same_size(const uword A_n_rows, const uword A_n_cols, const uwo rd A_n_slices, const uword B_n_rows, const uword B_n_cols, const uword B_n_ slices, const char* x)
{ {
if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_ n_slices) ) if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_ n_slices) )
{ {
arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, A_n_slices, B_ n_rows, B_n_cols, B_n_slices, x) ); arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, A_n_slices, B_ n_rows, B_n_cols, B_n_slices, x) );
} }
} }
//! stop if given cubes have different sizes //! stop if given cubes have different sizes
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_same_size(const Cube<eT1>& A, const Cube<eT2>& B, const char* x ) arma_assert_same_size(const Cube<eT1>& A, const Cube<eT2>& B, const char* x )
{ {
if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B. n_slices) ) if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B. n_slices) )
{ {
arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B. n_rows, B.n_cols, B.n_slices, x) ); arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B. n_rows, B.n_cols, B.n_slices, x) );
} }
} }
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_same_size(const Cube<eT1>& A, const subview_cube<eT2>& B, const char* x) arma_assert_same_size(const Cube<eT1>& A, const subview_cube<eT2>& B, const char* x)
{ {
if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B. n_slices) ) if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B. n_slices) )
{ {
arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B. n_rows, B.n_cols, B.n_slices, x) ); arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B. n_rows, B.n_cols, B.n_slices, x) );
} }
} }
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_same_size(const subview_cube<eT1>& A, const Cube<eT2>& B, const char* x) arma_assert_same_size(const subview_cube<eT1>& A, const Cube<eT2>& B, const char* x)
{ {
if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B. n_slices) ) if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B. n_slices) )
{ {
arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B. n_rows, B.n_cols, B.n_slices, x) ); arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B. n_rows, B.n_cols, B.n_slices, x) );
} }
} }
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_same_size(const subview_cube<eT1>& A, const subview_cube<eT2>& B, const char* x) arma_assert_same_size(const subview_cube<eT1>& A, const subview_cube<eT2>& B, const char* x)
{ {
if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B. n_slices)) if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B. n_slices))
{ {
arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B. n_rows, B.n_cols, B.n_slices, x) ); arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B. n_rows, B.n_cols, B.n_slices, x) );
} }
} }
//! stop if given cube proxies have different sizes //! stop if given cube proxies have different sizes
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_same_size(const ProxyCube<eT1>& A, const ProxyCube<eT2>& B, con st char* x) arma_assert_same_size(const ProxyCube<eT1>& A, const ProxyCube<eT2>& B, con st char* x)
{ {
const uword A_n_rows = A.get_n_rows(); const uword A_n_rows = A.get_n_rows();
const uword A_n_cols = A.get_n_cols(); const uword A_n_cols = A.get_n_cols();
const uword A_n_slices = A.get_n_slices(); const uword A_n_slices = A.get_n_slices();
const uword B_n_rows = B.get_n_rows(); const uword B_n_rows = B.get_n_rows();
const uword B_n_cols = B.get_n_cols(); const uword B_n_cols = B.get_n_cols();
const uword B_n_slices = B.get_n_slices(); const uword B_n_slices = B.get_n_slices();
if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_ n_slices)) if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_ n_slices))
{ {
arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, A_n_slices, B_ n_rows, B_n_cols, B_n_slices, x) ); arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, A_n_slices, B_ n_rows, B_n_cols, B_n_slices, x) );
} }
} }
// //
// functions for checking whether a cube or subcube can be interpreted as a matrix (i.e. single slice) // functions for checking whether a cube or subcube can be interpreted as a matrix (i.e. single slice)
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_same_size(const Cube<eT1>& A, const Mat<eT2>& B, const char* x) arma_assert_same_size(const Cube<eT1>& A, const Mat<eT2>& B, const char* x)
{ {
if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1) ) if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1) )
{ {
arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B. n_rows, B.n_cols, 1, x) ); arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B. n_rows, B.n_cols, 1, x) );
} }
} }
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_same_size(const Mat<eT1>& A, const Cube<eT2>& B, const char* x) arma_assert_same_size(const Mat<eT1>& A, const Cube<eT2>& B, const char* x)
{ {
if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices) ) if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices) )
{ {
arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B .n_cols, B.n_slices, x) ); arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B .n_cols, B.n_slices, x) );
} }
} }
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_same_size(const subview_cube<eT1>& A, const Mat<eT2>& B, const char* x) arma_assert_same_size(const subview_cube<eT1>& A, const Mat<eT2>& B, const char* x)
{ {
if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1) ) if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1) )
{ {
arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B. n_rows, B.n_cols, 1, x) ); arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B. n_rows, B.n_cols, 1, x) );
} }
} }
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_same_size(const Mat<eT1>& A, const subview_cube<eT2>& B, const char* x) arma_assert_same_size(const Mat<eT1>& A, const subview_cube<eT2>& B, const char* x)
{ {
if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices) ) if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices) )
{ {
arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B .n_cols, B.n_slices, x) ); arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B .n_cols, B.n_slices, x) );
} }
} }
template<typename eT, typename T1> template<typename eT, typename T1>
inline inline
skipping to change at line 850 skipping to change at line 850
arma_stop( tmp.str() ); arma_stop( tmp.str() );
} }
} }
} }
} }
} }
// //
// functions for checking whether two matrices have dimensions that are com patible with the matrix multiply operation // functions for checking whether two matrices have dimensions that are com patible with the matrix multiply operation
arma_hot
inline inline
void void
arma_hot
arma_assert_mul_size(const uword A_n_rows, const uword A_n_cols, const uwor d B_n_rows, const uword B_n_cols, const char* x) arma_assert_mul_size(const uword A_n_rows, const uword A_n_cols, const uwor d B_n_rows, const uword B_n_cols, const char* x)
{ {
if(A_n_cols != B_n_rows) if(A_n_cols != B_n_rows)
{ {
arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) ); arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_ cols, x) );
} }
} }
//! stop if given matrices are incompatible for multiplication //! stop if given matrices are incompatible for multiplication
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_mul_size(const Mat<eT1>& A, const Mat<eT2>& B, const char* x) arma_assert_mul_size(const Mat<eT1>& A, const Mat<eT2>& B, const char* x)
{ {
const uword A_n_cols = A.n_cols; const uword A_n_cols = A.n_cols;
const uword B_n_rows = B.n_rows; const uword B_n_rows = B.n_rows;
if(A_n_cols != B_n_rows) if(A_n_cols != B_n_rows)
{ {
arma_stop( arma_incompat_size_string(A.n_rows, A_n_cols, B_n_rows, B.n_ cols, x) ); arma_stop( arma_incompat_size_string(A.n_rows, A_n_cols, B_n_rows, B.n_ cols, x) );
} }
} }
//! stop if given matrices are incompatible for multiplication //! stop if given matrices are incompatible for multiplication
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_mul_size(const Mat<eT1>& A, const Mat<eT2>& B, const bool do_tr ans_A, const bool do_trans_B, const char* x) arma_assert_mul_size(const Mat<eT1>& A, const Mat<eT2>& B, const bool do_tr ans_A, const bool do_trans_B, const char* x)
{ {
const uword final_A_n_cols = (do_trans_A == false) ? A.n_cols : A.n_rows; const uword final_A_n_cols = (do_trans_A == false) ? A.n_cols : A.n_rows;
const uword final_B_n_rows = (do_trans_B == false) ? B.n_rows : B.n_cols; const uword final_B_n_rows = (do_trans_B == false) ? B.n_rows : B.n_cols;
if(final_A_n_cols != final_B_n_rows) if(final_A_n_cols != final_B_n_rows)
{ {
const uword final_A_n_rows = (do_trans_A == false) ? A.n_rows : A.n_col s; const uword final_A_n_rows = (do_trans_A == false) ? A.n_rows : A.n_col s;
const uword final_B_n_cols = (do_trans_B == false) ? B.n_cols : B.n_row s; const uword final_B_n_cols = (do_trans_B == false) ? B.n_cols : B.n_row s;
arma_stop( arma_incompat_size_string(final_A_n_rows, final_A_n_cols, fi nal_B_n_rows, final_B_n_cols, x) ); arma_stop( arma_incompat_size_string(final_A_n_rows, final_A_n_cols, fi nal_B_n_rows, final_B_n_cols, x) );
} }
} }
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_mul_size(const Mat<eT1>& A, const subview<eT2>& B, const char* x) arma_assert_mul_size(const Mat<eT1>& A, const subview<eT2>& B, const char* x)
{ {
if(A.n_cols != B.n_rows) if(A.n_cols != B.n_rows)
{ {
arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_ cols, x) ); arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_ cols, x) );
} }
} }
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_mul_size(const subview<eT1>& A, const Mat<eT2>& B, const char* x) arma_assert_mul_size(const subview<eT1>& A, const Mat<eT2>& B, const char* x)
{ {
if(A.n_cols != B.n_rows) if(A.n_cols != B.n_rows)
{ {
arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_ cols, x) ); arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_ cols, x) );
} }
} }
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
arma_hot
inline inline
void void
arma_hot
arma_assert_mul_size(const subview<eT1>& A, const subview<eT2>& B, const ch ar* x) arma_assert_mul_size(const subview<eT1>& A, const subview<eT2>& B, const ch ar* x)
{ {
if(A.n_cols != B.n_rows) if(A.n_cols != B.n_rows)
{ {
arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_ cols, x) ); arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_ cols, x) );
} }
} }
// //
// macros // macros
skipping to change at line 1002 skipping to change at line 1002
#if defined(ARMA_EXTRA_DEBUG) #if defined(ARMA_EXTRA_DEBUG)
namespace junk namespace junk
{ {
class arma_first_extra_debug_message class arma_first_extra_debug_message
{ {
public: public:
inline inline
arma_cold
arma_first_extra_debug_message() arma_first_extra_debug_message()
{ {
union union
{ {
unsigned short a; unsigned short a;
unsigned char b[sizeof(unsigned short)]; unsigned char b[sizeof(unsigned short)];
} endian_test; } endian_test;
endian_test.a = 1; endian_test.a = 1;
 End of changes. 85 change blocks. 
53 lines changed or deleted 52 lines changed or added


 diskio_bones.hpp   diskio_bones.hpp 
// Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // Copyright (C) 2008-2012 NICTA (www.nicta.com.au)
// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 Conrad Sanderson
// Copyright (C) 2009-2010 Ian Cullinan // Copyright (C) 2009-2010 Ian Cullinan
// Copyright (C) 2012 Matthew Amidon
// //
// This file is part of the Armadillo C++ library. // This file is part of the Armadillo C++ library.
// It is provided without any warranty of fitness // It is provided without any warranty of fitness
// for any purpose. You can redistribute this file // for any purpose. You can redistribute this file
// and/or modify it under the terms of the GNU // and/or modify it under the terms of the GNU
// Lesser General Public License (LGPL) as published // Lesser General Public License (LGPL) as published
// by the Free Software Foundation, either version 3 // by the Free Software Foundation, either version 3
// of the License or (at your option) any later version. // of the License or (at your option) any later version.
// (see http://www.opensource.org/licenses for more info) // (see http://www.opensource.org/licenses for more info)
skipping to change at line 26 skipping to change at line 25
//! @{ //! @{
//! class for saving and loading matrices and fields //! class for saving and loading matrices and fields
class diskio class diskio
{ {
public: public:
template<typename eT> inline static std::string gen_txt_header(const Mat< eT>& x); template<typename eT> inline static std::string gen_txt_header(const Mat< eT>& x);
template<typename eT> inline static std::string gen_bin_header(const Mat< eT>& x); template<typename eT> inline static std::string gen_bin_header(const Mat< eT>& x);
template<typename eT> inline static std::string gen_txt_header(const SpMa t<eT>& x);
template<typename eT> inline static std::string gen_bin_header(const SpMa t<eT>& x); template<typename eT> inline static std::string gen_bin_header(const SpMa t<eT>& x);
template<typename eT> inline static std::string gen_txt_header(const Cube <eT>& x); template<typename eT> inline static std::string gen_txt_header(const Cube <eT>& x);
template<typename eT> inline static std::string gen_bin_header(const Cube <eT>& x); template<typename eT> inline static std::string gen_bin_header(const Cube <eT>& x);
inline static file_type guess_file_type(std::istream& f); inline static file_type guess_file_type(std::istream& f);
inline static char conv_to_hex_char(const u8 x); inline static char conv_to_hex_char(const u8 x);
inline static void conv_to_hex(char* out, const u8 x); inline static void conv_to_hex(char* out, const u8 x);
inline static std::string gen_tmp_name(const std::string& x); inline static std::string gen_tmp_name(const std::string& x);
inline static bool safe_rename(const std::string& old_name, const std::st ring& new_name); inline static bool safe_rename(const std::string& old_name, const std::st ring& new_name);
template<typename eT> inline static bool convert_naninf(eT&
val, const std::string& token);
template<typename T> inline static bool convert_naninf(std::complex<T>&
val, const std::string& token);
// //
// matrix saving // matrix saving
template<typename eT> inline static bool save_raw_ascii (const Mat<eT>& x, const std::string& final_name); template<typename eT> inline static bool save_raw_ascii (const Mat<eT>& x, const std::string& final_name);
template<typename eT> inline static bool save_raw_binary (const Mat<eT>& x, const std::string& final_name); template<typename eT> inline static bool save_raw_binary (const Mat<eT>& x, const std::string& final_name);
template<typename eT> inline static bool save_arma_ascii (const Mat<eT>& x, const std::string& final_name); template<typename eT> inline static bool save_arma_ascii (const Mat<eT>& x, const std::string& final_name);
template<typename eT> inline static bool save_csv_ascii (const Mat<eT>& x, const std::string& final_name); template<typename eT> inline static bool save_csv_ascii (const Mat<eT>& x, const std::string& final_name);
template<typename eT> inline static bool save_arma_binary(const Mat<eT>& x, const std::string& final_name); template<typename eT> inline static bool save_arma_binary(const Mat<eT>& x, const std::string& final_name);
template<typename eT> inline static bool save_pgm_binary (const Mat<eT>& x, const std::string& final_name); template<typename eT> inline static bool save_pgm_binary (const Mat<eT>& x, const std::string& final_name);
template<typename T> inline static bool save_pgm_binary (const Mat< std: :complex<T> >& x, const std::string& final_name); template<typename T> inline static bool save_pgm_binary (const Mat< std: :complex<T> >& x, const std::string& final_name);
skipping to change at line 86 skipping to change at line 87
template<typename eT> inline static bool load_arma_ascii (Mat<eT>& x, std::istream& f, std::string& err_msg); template<typename eT> inline static bool load_arma_ascii (Mat<eT>& x, std::istream& f, std::string& err_msg);
template<typename eT> inline static bool load_csv_ascii (Mat<eT>& x, std::istream& f, std::string& err_msg); template<typename eT> inline static bool load_csv_ascii (Mat<eT>& x, std::istream& f, std::string& err_msg);
template<typename eT> inline static bool load_arma_binary(Mat<eT>& x, std::istream& f, std::string& err_msg); template<typename eT> inline static bool load_arma_binary(Mat<eT>& x, std::istream& f, std::string& err_msg);
template<typename eT> inline static bool load_pgm_binary (Mat<eT>& x, std::istream& is, std::string& err_msg); template<typename eT> inline static bool load_pgm_binary (Mat<eT>& x, std::istream& is, std::string& err_msg);
template<typename T> inline static bool load_pgm_binary (Mat< std::compl ex<T> >& x, std::istream& is, std::string& err_msg); template<typename T> inline static bool load_pgm_binary (Mat< std::compl ex<T> >& x, std::istream& is, std::string& err_msg);
template<typename eT> inline static bool load_auto_detect(Mat<eT>& x, std::istream& f, std::string& err_msg); template<typename eT> inline static bool load_auto_detect(Mat<eT>& x, std::istream& f, std::string& err_msg);
inline static void pnm_skip_comments(std::istream& f); inline static void pnm_skip_comments(std::istream& f);
// //
// sparse saving // sparse matrix saving
template<typename eT> inline static bool save_raw_ascii (const SpMat<eT>
& x, const std::string& final_name);
//template<typename eT> inline static bool save_raw_binary (const SpMat<e
T>& x, const std::string& final_name);
//template<typename eT> inline static bool save_arma_ascii (const SpMat<e
T>& x, const std::string& final_name);
//template<typename eT> inline static bool save_csv_ascii (const SpMat<e
T>& x, const std::string& final_name);
template<typename eT> inline static bool save_arma_binary(const SpMat<eT>
& x, const std::string& final_name);
//template<typename eT> inline static bool save_pgm_binary (const SpMat<e
T>& x, const std::string& final_name);
//template<typename T> inline static bool save_pgm_binary (const SpMat<s
td::complex<T> >& x, const std::string& final_name);
template<typename eT> inline static bool save_coord_ascii(const SpMat<eT> & x, const std::string& final_name); template<typename eT> inline static bool save_coord_ascii(const SpMat<eT> & x, const std::string& final_name);
template<typename eT> inline static bool save_arma_binary(const SpMat<eT> & x, const std::string& final_name);
template<typename eT> inline static bool save_raw_ascii (const SpMat<eT> template<typename eT> inline static bool save_coord_ascii(const SpMat<eT>
& x, std::ostream& f); & x, std::ostream& f);
//template<typename eT> inline static bool save_raw_binary (const SpMat<e template<typename T> inline static bool save_coord_ascii(const SpMat< st
T>& x, std::ostream& f); d::complex<T> >& x, std::ostream& f);
//template<typename eT> inline static bool save_arma_ascii (const SpMat<e template<typename eT> inline static bool save_arma_binary(const SpMat<eT>
T>& x, std::ostream& f); & x, std::ostream& f);
//template<typename eT> inline static bool save_csv_ascii (const SpMat<e
T>& x, std::ostream& f);
template<typename eT> inline static bool save_arma_binary(const SpMat<eT>
& x, std::ostream& f);
//template<typename eT> inline static bool save_pgm_binary (const SpMat<e
T>& x, std::ostream& f);
//template<typename T> inline static bool save_pgm_binary (const SpMat<s
td::complex<T> >& x, std::ostream& f);
template<typename eT> inline static bool save_coord_ascii(const SpMat<eT>
& x, std::ostream& f);
// //
// sparse loading // sparse matrix loading
template<typename eT> inline static bool load_raw_ascii (SpMat<eT>& x, c
onst std::string& name, std::string& err_msg);
//template<typename eT> inline static bool load_raw_binary (SpMat<eT>& x,
const std::string& name, std::string& err_msg);
//template<typename eT> inline static bool load_arma_ascii (SpMat<eT>& x,
const std::string& name, std::string& err_msg);
//template<typename eT> inline static bool load_csv_ascii (SpMat<eT>& x,
const std::string& name, std::string& err_msg);
template<typename eT> inline static bool load_arma_binary(SpMat<eT>& x, c
onst std::string& name, std::string& err_msg);
//template<typename eT> inline static bool load_pgm_binary (SpMat<eT>& x,
const std::string& name, std::string& err_msg);
//template<typename T> inline static bool load_pgm_binary (SpMat<std::co
mplex<T> >& x, const std::string& name, std::string& err_msg);
//template<typename eT> inline static bool load_auto_detect(SpMat<eT>& x,
const std::string& name, std::string& err_msg);
template<typename eT> inline static bool load_coord_ascii(SpMat<eT>& x, c onst std::string& name, std::string& err_msg); template<typename eT> inline static bool load_coord_ascii(SpMat<eT>& x, c onst std::string& name, std::string& err_msg);
template<typename eT> inline static bool load_arma_binary(SpMat<eT>& x, c onst std::string& name, std::string& err_msg);
template<typename eT> inline static bool load_raw_ascii (SpMat<eT>& x, s template<typename eT> inline static bool load_coord_ascii(SpMat<eT>& x,
td::istream& f, std::string& err_msg); std::istream& f, std::string& err_msg);
//template<typename eT> inline static bool load_raw_binary (SpMat<eT>& x, template<typename T> inline static bool load_coord_ascii(SpMat< std::com
std::istream& f, std::string& err_msg); plex<T> >& x, std::istream& f, std::string& err_msg);
//template<typename eT> inline static bool load_arma_ascii (SpMat<eT>& x, template<typename eT> inline static bool load_arma_binary(SpMat<eT>& x,
std::istream& f, std::string& err_msg); std::istream& f, std::string& err_msg);
//template<typename eT> inline static bool load_csv_ascii (SpMat<eT>& x,
std::istream& f, std::string& err_msg);
template<typename eT> inline static bool load_arma_binary(SpMat<eT>& x, s
td::istream& f, std::string& err_msg);
//template<typename eT> inline static bool load_pgm_binary (SpMat<eT>& x,
std::istream& is, std::string& err_msg);
//template<typename T> inline static bool load_pgm_binary (SpMat<std::co
mplex<T> >& x, std::istream& is, std::string& err_msg);
//template<typename eT> inline static bool load_auto_detect(SpMat<eT>& x,
std::istream& f, std::string& err_msg);
template<typename eT> inline static bool load_coord_ascii(SpMat<eT>& x, s
td::istream& f, std::string& err_msg);
// //
// cube saving // cube saving
template<typename eT> inline static bool save_raw_ascii (const Cube<eT>& x, const std::string& name); template<typename eT> inline static bool save_raw_ascii (const Cube<eT>& x, const std::string& name);
template<typename eT> inline static bool save_raw_binary (const Cube<eT>& x, const std::string& name); template<typename eT> inline static bool save_raw_binary (const Cube<eT>& x, const std::string& name);
template<typename eT> inline static bool save_arma_ascii (const Cube<eT>& x, const std::string& name); template<typename eT> inline static bool save_arma_ascii (const Cube<eT>& x, const std::string& name);
template<typename eT> inline static bool save_arma_binary(const Cube<eT>& x, const std::string& name); template<typename eT> inline static bool save_arma_binary(const Cube<eT>& x, const std::string& name);
template<typename eT> inline static bool save_raw_ascii (const Cube<eT>& x, std::ostream& f); template<typename eT> inline static bool save_raw_ascii (const Cube<eT>& x, std::ostream& f);
 End of changes. 11 change blocks. 
68 lines changed or deleted 21 lines changed or added


 diskio_meat.hpp   diskio_meat.hpp 
skipping to change at line 182 skipping to change at line 182
{ {
return std::string("ARMA_MAT_BIN_FC016"); return std::string("ARMA_MAT_BIN_FC016");
} }
else else
{ {
return std::string(); return std::string();
} }
} }
//! Generate the first line of the header used for saving matrices in text
format.
//! Format: "ARMA_SPM_TXT_ABXYZ".
//! A is one of: I (for integral types) or F (for floating point types).
//! B is one of: U (for unsigned types), S (for signed types), N (for not a
ppliable) or C (for complex types).
//! XYZ specifies the width of each element in terms of bytes, e.g. "008" i
ndicates eight bytes.
template<typename eT>
inline
std::string
diskio::gen_txt_header(const SpMat<eT>& x)
{
arma_type_check(( is_supported_elem_type<eT>::value == false ));
arma_ignore(x);
if(is_u8<eT>::value == true)
{
return std::string("ARMA_SPM_TXT_IU001");
}
else
if(is_s8<eT>::value == true)
{
return std::string("ARMA_SPM_TXT_IS001");
}
else
if(is_u16<eT>::value == true)
{
return std::string("ARMA_SPM_TXT_IU002");
}
else
if(is_s16<eT>::value == true)
{
return std::string("ARMA_SPM_TXT_IS002");
}
else
if(is_u32<eT>::value == true)
{
return std::string("ARMA_SPM_TXT_IU004");
}
else
if(is_s32<eT>::value == true)
{
return std::string("ARMA_SPM_TXT_IS004");
}
#if defined(ARMA_64BIT_WORD)
else
if(is_u64<eT>::value == true)
{
return std::string("ARMA_SPM_TXT_IU008");
}
else
if(is_s64<eT>::value == true)
{
return std::string("ARMA_SPM_TXT_IS008");
}
#endif
else
if(is_float<eT>::value == true)
{
return std::string("ARMA_SPM_TXT_FN004");
}
else
if(is_double<eT>::value == true)
{
return std::string("ARMA_SPM_TXT_FN008");
}
else
if(is_complex_float<eT>::value == true)
{
return std::string("ARMA_SPM_TXT_FC008");
}
else
if(is_complex_double<eT>::value == true)
{
return std::string("ARMA_SPM_TXT_FC016");
}
else
{
return std::string();
}
}
//! Generate the first line of the header used for saving matrices in binar y format. //! Generate the first line of the header used for saving matrices in binar y format.
//! Format: "ARMA_SPM_BIN_ABXYZ". //! Format: "ARMA_SPM_BIN_ABXYZ".
//! A is one of: I (for integral types) or F (for floating point types). //! A is one of: I (for integral types) or F (for floating point types).
//! B is one of: U (for unsigned types), S (for signed types), N (for not a ppliable) or C (for complex types). //! B is one of: U (for unsigned types), S (for signed types), N (for not a ppliable) or C (for complex types).
//! XYZ specifies the width of each element in terms of bytes, e.g. "008" i ndicates eight bytes. //! XYZ specifies the width of each element in terms of bytes, e.g. "008" i ndicates eight bytes.
template<typename eT> template<typename eT>
inline inline
std::string std::string
diskio::gen_bin_header(const SpMat<eT>& x) diskio::gen_bin_header(const SpMat<eT>& x)
{ {
skipping to change at line 541 skipping to change at line 460
unsigned char* ptr = data.memptr(); unsigned char* ptr = data.memptr();
f.clear(); f.clear();
f.read( reinterpret_cast<char*>(ptr), std::streamsize(N) ); f.read( reinterpret_cast<char*>(ptr), std::streamsize(N) );
const bool load_okay = f.good(); const bool load_okay = f.good();
f.clear(); f.clear();
f.seekg(pos1); f.seekg(pos1);
bool has_binary = false; bool has_binary = false;
bool has_comma = false; bool has_comma = false;
bool has_bracket = false;
if(load_okay == true) if(load_okay == true)
{ {
uword i = 0; uword i = 0;
uword j = (N >= 2) ? 1 : 0; uword j = (N >= 2) ? 1 : 0;
for(; j<N; i+=2, j+=2) for(; j<N; i+=2, j+=2)
{ {
const unsigned char val_i = ptr[i]; const unsigned char val_i = ptr[i];
const unsigned char val_j = ptr[j]; const unsigned char val_j = ptr[j];
skipping to change at line 564 skipping to change at line 484
// the range checking can be made more elaborate // the range checking can be made more elaborate
if( ((val_i <= 8) || (val_i >= 123)) || ((val_j <= 8) || (val_j >= 12 3)) ) if( ((val_i <= 8) || (val_i >= 123)) || ((val_j <= 8) || (val_j >= 12 3)) )
{ {
has_binary = true; has_binary = true;
break; break;
} }
if( (val_i == ',') || (val_j == ',') ) if( (val_i == ',') || (val_j == ',') )
{ {
has_comma = true; has_comma = true;
break; }
if( (val_i == '(') || (val_j == '(') || (val_i == ')') || (val_j == '
)') )
{
has_bracket = true;
} }
} }
} }
else else
{ {
return file_type_unknown; return file_type_unknown;
} }
if(has_binary) if(has_binary)
{ {
return raw_binary; return raw_binary;
} }
if(has_comma) if(has_comma && (has_bracket == false))
{ {
return csv_ascii; return csv_ascii;
} }
return raw_ascii; return raw_ascii;
} }
inline inline
char char
diskio::conv_to_hex_char(const u8 x) diskio::conv_to_hex_char(const u8 x)
skipping to change at line 716 skipping to change at line 640
std::remove(new_name.c_str()); std::remove(new_name.c_str());
const int mv_result = std::rename(old_name.c_str(), new_name.c_str()); const int mv_result = std::rename(old_name.c_str(), new_name.c_str());
save_okay = (mv_result == 0); save_okay = (mv_result == 0);
} }
return save_okay; return save_okay;
} }
template<typename eT>
inline
bool
diskio::convert_naninf(eT& val, const std::string& token)
{
// see if the token represents a NaN or Inf
if( (token.length() == 3) || (token.length() == 4) )
{
const bool neg = (token[0] == '-');
const bool pos = (token[0] == '+');
const size_t offset = ( (neg || pos) && (token.length() == 4) ) ? 1 : 0
;
const std::string token2 = token.substr(offset, 3);
if( (token2 == "inf") || (token2 == "Inf") || (token2 == "INF") )
{
val = neg ? -(Datum<eT>::inf) : Datum<eT>::inf;
return true;
}
else
if( (token2 == "nan") || (token2 == "Nan") || (token2 == "NaN") || (tok
en2 == "NAN") )
{
val = neg ? -(Datum<eT>::nan) : Datum<eT>::nan;
return true;
}
}
return false;
}
template<typename T>
inline
bool
diskio::convert_naninf(std::complex<T>& val, const std::string& token)
{
if( token.length() >= 5 )
{
std::stringstream ss( token.substr(1, token.length()-2) ); // strip '(
' at the start and ')' at the end
std::string token_real;
std::string token_imag;
std::getline(ss, token_real, ',');
std::getline(ss, token_imag);
std::stringstream ss_real(token_real);
std::stringstream ss_imag(token_imag);
T val_real = T(0);
T val_imag = T(0);
ss_real >> val_real;
ss_imag >> val_imag;
bool success_real = true;
bool success_imag = true;
if(ss_real.fail() == true)
{
success_real = diskio::convert_naninf( val_real, token_real );
}
if(ss_imag.fail() == true)
{
success_imag = diskio::convert_naninf( val_imag, token_imag );
}
val = std::complex<T>(val_real, val_imag);
return (success_real && success_imag);
}
return false;
}
//! Save a matrix as raw text (no header, human readable). //! Save a matrix as raw text (no header, human readable).
//! Matrices can be loaded in Matlab and Octave, as long as they don't have complex elements. //! Matrices can be loaded in Matlab and Octave, as long as they don't have complex elements.
template<typename eT> template<typename eT>
inline inline
bool bool
diskio::save_raw_ascii(const Mat<eT>& x, const std::string& final_name) diskio::save_raw_ascii(const Mat<eT>& x, const std::string& final_name)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const std::string tmp_name = diskio::gen_tmp_name(final_name); const std::string tmp_name = diskio::gen_tmp_name(final_name);
skipping to change at line 1240 skipping to change at line 1243
// work out the size // work out the size
uword f_n_rows = 0; uword f_n_rows = 0;
uword f_n_cols = 0; uword f_n_cols = 0;
bool f_n_cols_found = false; bool f_n_cols_found = false;
std::string line_string; std::string line_string;
std::string token; std::string token;
std::stringstream line_stream;
while( (f.good() == true) && (load_okay == true) ) while( (f.good() == true) && (load_okay == true) )
{ {
std::getline(f, line_string); std::getline(f, line_string);
if(line_string.size() == 0) if(line_string.size() == 0)
{ {
break; break;
} }
std::stringstream line_stream(line_string); line_stream.clear();
line_stream.str(line_string);
uword line_n_cols = 0; uword line_n_cols = 0;
while (line_stream >> token) while (line_stream >> token)
{ {
++line_n_cols; ++line_n_cols;
} }
if(f_n_cols_found == false) if(f_n_cols_found == false)
{ {
skipping to change at line 1282 skipping to change at line 1288
++f_n_rows; ++f_n_rows;
} }
if(load_okay == true) if(load_okay == true)
{ {
f.clear(); f.clear();
f.seekg(pos1); f.seekg(pos1);
x.set_size(f_n_rows, f_n_cols); x.set_size(f_n_rows, f_n_cols);
eT val; std::stringstream ss;
for(uword row=0; (row < x.n_rows) && (load_okay == true); ++row) for(uword row=0; (row < x.n_rows) && (load_okay == true); ++row)
{ {
for(uword col=0; (col < x.n_cols) && (load_okay == true); ++col) for(uword col=0; (col < x.n_cols) && (load_okay == true); ++col)
{ {
f >> val; f >> token;
if(f.fail() == false) ss.clear();
ss.str(token);
eT val = eT(0);
ss >> val;
if(ss.fail() == false)
{ {
x.at(row,col) = val; x.at(row,col) = val;
} }
else else
{ {
load_okay = false; const bool success = diskio::convert_naninf( x.at(row,col), token
err_msg = "couldn't interpret data in "; );
//break;
if(success == false)
{
load_okay = false;
err_msg = "couldn't interpret data in ";
}
} }
} }
} }
} }
// an empty file indicates an empty matrix // an empty file indicates an empty matrix
if( (f_n_cols_found == false) && (load_okay == true) ) if( (f_n_cols_found == false) && (load_okay == true) )
{ {
x.reset(); x.reset();
} }
skipping to change at line 1410 skipping to change at line 1426
std::string f_header; std::string f_header;
uword f_n_rows; uword f_n_rows;
uword f_n_cols; uword f_n_cols;
f >> f_header; f >> f_header;
f >> f_n_rows; f >> f_n_rows;
f >> f_n_cols; f >> f_n_cols;
if(f_header == diskio::gen_txt_header(x)) if(f_header == diskio::gen_txt_header(x))
{ {
x.set_size(f_n_rows, f_n_cols); x.zeros(f_n_rows, f_n_cols);
std::string token;
std::stringstream ss;
for(uword row=0; row < x.n_rows; ++row) for(uword row=0; row < x.n_rows; ++row)
{ {
for(uword col=0; col < x.n_cols; ++col) for(uword col=0; col < x.n_cols; ++col)
{ {
f >> x.at(row,col); f >> token;
ss.clear();
ss.str(token);
eT val = eT(0);
ss >> val;
if(ss.fail() == false)
{
x.at(row,col) = val;
}
else
{
diskio::convert_naninf( x.at(row,col), token );
}
} }
} }
load_okay = f.good(); load_okay = f.good();
} }
else else
{ {
load_okay = false; load_okay = false;
err_msg = "incorrect header in "; err_msg = "incorrect header in ";
} }
skipping to change at line 1475 skipping to change at line 1509
// //
// work out the size // work out the size
uword f_n_rows = 0; uword f_n_rows = 0;
uword f_n_cols = 0; uword f_n_cols = 0;
std::string line_string; std::string line_string;
std::string token; std::string token;
std::stringstream line_stream;
while( (f.good() == true) && (load_okay == true) ) while( (f.good() == true) && (load_okay == true) )
{ {
std::getline(f, line_string); std::getline(f, line_string);
if(line_string.size() == 0) if(line_string.size() == 0)
{ {
break; break;
} }
std::stringstream line_stream(line_string); line_stream.clear();
line_stream.str(line_string);
uword line_n_cols = 0; uword line_n_cols = 0;
while(line_stream.good() == true) while(line_stream.good() == true)
{ {
std::getline(line_stream, token, ','); std::getline(line_stream, token, ',');
++line_n_cols; ++line_n_cols;
} }
if(f_n_cols < line_n_cols) if(f_n_cols < line_n_cols)
skipping to change at line 1509 skipping to change at line 1546
++f_n_rows; ++f_n_rows;
} }
f.clear(); f.clear();
f.seekg(pos1); f.seekg(pos1);
x.zeros(f_n_rows, f_n_cols); x.zeros(f_n_rows, f_n_cols);
uword row = 0; uword row = 0;
std::stringstream ss;
while(f.good() == true) while(f.good() == true)
{ {
std::getline(f, line_string); std::getline(f, line_string);
if(line_string.size() == 0) if(line_string.size() == 0)
{ {
break; break;
} }
std::stringstream line_stream(line_string); line_stream.clear();
line_stream.str(line_string);
uword col = 0; uword col = 0;
while(line_stream.good() == true) while(line_stream.good() == true)
{ {
std::getline(line_stream, token, ','); std::getline(line_stream, token, ',');
eT val; ss.clear();
ss.str(token);
std::stringstream ss(token);
eT val = eT(0);
ss >> val; ss >> val;
if(ss.fail() == false) if(ss.fail() == false)
{ {
x.at(row,col) = val; x.at(row,col) = val;
} }
else
{
diskio::convert_naninf( x.at(row,col), token );
}
++col; ++col;
} }
++row; ++row;
} }
return load_okay; return load_okay;
} }
skipping to change at line 2001 skipping to change at line 2045
default: default:
err_msg = "unknown data in "; err_msg = "unknown data in ";
return false; return false;
} }
} }
return false; return false;
} }
//
// sparse matrices // sparse matrices
//
//! Save a matrix as raw text (no header, human readable). //! Save a matrix in ASCII coord format
//! Matrices can be loaded in Matlab and Octave, as long as they don't have
complex elements.
template<typename eT> template<typename eT>
inline inline
bool bool
diskio::save_raw_ascii(const SpMat<eT>& x, const std::string& final_name) diskio::save_coord_ascii(const SpMat<eT>& x, const std::string& final_name)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const std::string tmp_name = diskio::gen_tmp_name(final_name); const std::string tmp_name = diskio::gen_tmp_name(final_name);
std::fstream f(tmp_name.c_str(), std::fstream::out); std::ofstream f(tmp_name.c_str());
bool save_okay = f.is_open(); bool save_okay = f.is_open();
if(save_okay == true) if(save_okay == true)
{ {
save_okay = diskio::save_raw_ascii(x, f); save_okay = diskio::save_coord_ascii(x, f);
f.flush(); f.flush();
f.close(); f.close();
if(save_okay == true) if(save_okay == true)
{ {
save_okay = diskio::safe_rename(tmp_name, final_name); save_okay = diskio::safe_rename(tmp_name, final_name);
} }
} }
return save_okay; return save_okay;
} }
//! Save a matrix as raw text (no header, human readable). //! Save a matrix in ASCII coord format
//! Matrices can be loaded in Matlab and Octave, as long as they don't have
complex elements.
template<typename eT> template<typename eT>
inline inline
bool bool
diskio::save_raw_ascii(const SpMat<eT>& x, std::ostream& f) diskio::save_coord_ascii(const SpMat<eT>& x, std::ostream& f)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
uword cell_width; const ios::fmtflags orig_flags = f.flags();
// TODO: need sane values for complex numbers
if( (is_float<eT>::value == true) || (is_double<eT>::value == true) ) typename SpMat<eT>::const_iterator iter = x.begin();
{ typename SpMat<eT>::const_iterator iter_end = x.end();
f.setf(ios::scientific);
f.precision(10);
cell_width = 18;
}
for(uword row=0; row < x.n_rows; ++row) for(; iter != iter_end; ++iter)
{ {
for(uword col=0; col < x.n_cols; ++col) f.setf(ios::fixed);
{
f.put(' ');
if( (is_float<eT>::value == true) || (is_double<eT>::value == true) ) f << iter.row() << ' ' << iter.col() << ' ';
{
f.width(cell_width);
}
f << x.at(row,col); if( (is_float<eT>::value == true) || (is_double<eT>::value == true) )
{
f.setf(ios::scientific);
f.precision(10);
} }
f.put('\n'); f << (*iter) << '\n';
} }
return f.good(); // make sure it's possible to figure out the matrix size later
} if( (x.n_rows > 0) && (x.n_cols > 0) )
{
//// TODO: this function doesn't make sense for sparse matrices, as there i const uword max_row = (x.n_rows > 0) ? x.n_rows-1 : 0;
s no universal definition of a "raw" CSC file const uword max_col = (x.n_cols > 0) ? x.n_cols-1 : 0;
// //! Save a matrix as raw binary (no header)
// template<typename eT>
// inline
// bool
// diskio::save_raw_binary(const SpMat<eT>& x, const std::string& final_nam
e)
// {
// arma_extra_debug_sigprint();
//
//
// const std::string tmp_name = diskio::gen_tmp_name(final_name);
//
// std::ofstream f(tmp_name.c_str(), std::fstream::binary);
//
// bool save_okay = f.is_open();
//
// if(save_okay == true)
// {
// save_okay = diskio::save_raw_binary(x, f);
//
// f.flush();
// f.close();
//
// if(save_okay == true)
// {
// save_okay = diskio::safe_rename(tmp_name, final_name);
// }
// }
//
// return save_okay;
// }
//// TODO: this function doesn't make sense for sparse matrices, as there i if( x.at(max_row, max_col) == eT(0) )
s no universal definition of a "raw" CSC file {
// template<typename eT> f.setf(ios::fixed);
// inline
// bool
// diskio::save_raw_binary(const SpMat<eT>& x, std::ostream& f)
// {
// arma_extra_debug_sigprint();
//
//
// //Write the dims of the matrix first
// f.write( reinterpret_cast<const char*>(&x.n_rows), std::streamsize(siz
eof(uword)) );
// f.write( reinterpret_cast<const char*>(&x.n_cols), std::streamsize(siz
eof(uword)) );
// f.write( reinterpret_cast<const char*>(&x.n_nonzero), std::streamsize(
sizeof(uword)) );
//
// //Now write the data for the three vectors
// f.write( reinterpret_cast<const char*>(x.values), std::streamsize(x.n_
nonzero*sizeof(eT)) );
// f.write( reinterpret_cast<const char*>(x.row_indices), std::streamsize
(x.n_nonzero*sizeof(uword)) );
// f.write( reinterpret_cast<const char*>(x.col_ptrs), std::streamsize((x
.n_cols+1)*sizeof(uword)) );
//
// return f.good();
// }
//// TODO: this function needs to be reworked to save only non-zero element f << max_row << ' ' << max_col << " 0\n";
s; we can define our own format, or adapt an existing format }
// //! Save a matrix in text format (human readable), }
// //! with a header that indicates the matrix type as well as its dimensio
ns
// template<typename eT>
// inline
// bool
// diskio::save_arma_ascii(const SpMat<eT>& x, const std::string& final_nam
e)
// {
// arma_extra_debug_sigprint();
//
//
// const std::string tmp_name = diskio::gen_tmp_name(final_name);
//
// std::ofstream f(tmp_name.c_str());
//
// bool save_okay = f.is_open();
//
// if(save_okay == true)
// {
// save_okay = diskio::save_arma_ascii(x, f);
//
// f.flush();
// f.close();
//
// if(save_okay == true)
// {
// save_okay = diskio::safe_rename(tmp_name, final_name);
// }
// }
//
// return save_okay;
// }
//// TODO: this function needs to be reworked to save only non-zero element const bool save_okay = f.good();
s; we can define our own format, or adapt an existing format
// //! Save a matrix in text format (human readable),
// //! with a header that indicates the matrix type as well as its dimensio
ns
// template<typename eT>
// inline
// bool
// diskio::save_arma_ascii(const SpMat<eT>& x, std::ostream& f)
// {
// arma_extra_debug_sigprint();
//
//
// const ios::fmtflags orig_flags = f.flags();
//
// f << diskio::gen_txt_header(x) << '\n';
// f << x.n_rows << ' ' << x.n_cols << '\n';
//
// uword cell_width;
//
// // TODO: need sane values for complex numbers
//
// if( (is_float<eT>::value == true) || (is_double<eT>::value == true) )
// {
// f.setf(ios::scientific);
// f.precision(10);
// cell_width = 18;
// }
//
// for(uword row=0; row < x.n_rows; ++row)
// {
// for(uword col=0; col < x.n_cols; ++col)
// {
// f.put(' ');
//
// if( (is_float<eT>::value == true) || (is_double<eT>::value == true
) )
// {
// f.width(cell_width);
// }
//
// f << x.at(row,col);
// }
//
// f.put('\n');
// }
//
// const bool save_okay = f.good();
//
// f.flags(orig_flags);
//
// return save_okay;
// }
//// TODO: this function needs to be reworked to save only non-zero element f.flags(orig_flags);
s
// //! Save a matrix in CSV text format (human readable)
// template<typename eT>
// inline
// bool
// diskio::save_csv_ascii(const SpMat<eT>& x, const std::string& final_name
)
// {
// arma_extra_debug_sigprint();
//
//
// const std::string tmp_name = diskio::gen_tmp_name(final_name);
//
// std::ofstream f(tmp_name.c_str());
//
// bool save_okay = f.is_open();
//
// if(save_okay == true)
// {
// save_okay = diskio::save_csv_ascii(x, f);
//
// f.flush();
// f.close();
//
// if(save_okay == true)
// {
// save_okay = diskio::safe_rename(tmp_name, final_name);
// }
// }
//
// return save_okay;
// }
//// TODO: this function needs to be reworked to save only non-zero element return save_okay;
s }
// //! Save a matrix in CSV text format (human readable)
// template<typename eT>
// inline
// bool
// diskio::save_csv_ascii(const SpMat<eT>& x, std::ostream& f)
// {
// arma_extra_debug_sigprint();
//
//
// const ios::fmtflags orig_flags = f.flags();
//
// // TODO: need sane values for complex numbers
//
// if( (is_float<eT>::value == true) || (is_double<eT>::value == true) )
// {
// f.setf(ios::scientific);
// f.precision(10);
// }
//
// uword x_n_rows = x.n_rows;
// uword x_n_cols = x.n_cols;
//
// for(uword row=0; row < x_n_rows; ++row)
// {
// for(uword col=0; col < x_n_cols; ++col)
// {
// f << x.at(row,col);
//
// if( col < (x_n_cols-1) )
// {
// f.put(',');
// }
// }
//
// f.put('\n');
// }
//
// const bool save_okay = f.good();
//
// f.flags(orig_flags);
//
// return save_okay;
// }
//! Save a matrix in binary format, //! Save a matrix in ASCII coord format (complex numbers)
//! with a header that stores the matrix type as well as its dimensions template<typename T>
template<typename eT>
inline inline
bool bool
diskio::save_arma_binary(const SpMat<eT>& x, const std::string& final_name) diskio::save_coord_ascii(const SpMat< std::complex<T> >& x, std::ostream& f )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const std::string tmp_name = diskio::gen_tmp_name(final_name); const ios::fmtflags orig_flags = f.flags();
std::ofstream f(tmp_name.c_str(), std::fstream::binary); typedef typename std::complex<T> eT;
bool save_okay = f.is_open(); typename SpMat<eT>::const_iterator iter = x.begin();
typename SpMat<eT>::const_iterator iter_end = x.end();
if(save_okay == true) for(; iter != iter_end; ++iter)
{ {
save_okay = diskio::save_arma_binary(x, f); f.setf(ios::fixed);
f.flush(); f << iter.row() << ' ' << iter.col() << ' ';
f.close();
if(save_okay == true) if( (is_float<T>::value == true) || (is_double<T>::value == true) )
{ {
save_okay = diskio::safe_rename(tmp_name, final_name); f.setf(ios::scientific);
f.precision(10);
} }
const eT val = (*iter);
f << val.real() << ' ' << val.imag() << '\n';
} }
return save_okay; // make sure it's possible to figure out the matrix size later
} if( (x.n_rows > 0) && (x.n_cols > 0) )
{
const uword max_row = (x.n_rows > 0) ? x.n_rows-1 : 0;
const uword max_col = (x.n_cols > 0) ? x.n_cols-1 : 0;
//! Save a matrix in binary format, if( x.at(max_row, max_col) == eT(0) )
//! with a header that stores the matrix type as well as its dimensions {
template<typename eT> f.setf(ios::fixed);
inline
bool
diskio::save_arma_binary(const SpMat<eT>& x, std::ostream& f)
{
arma_extra_debug_sigprint();
//Write the dims of the matrix first
f << diskio::gen_bin_header(x) << '\n';
f << x.n_rows << ' ' << x.n_cols << ' ' << x.n_nonzero << '\n';
//Now write the data for the three vectors
f.write( reinterpret_cast<const char*>(x.values), std::streamsize(x.n_non
zero*sizeof(eT)) );
f.write( reinterpret_cast<const char*>(x.row_indices), std::streamsize(x.
n_nonzero*sizeof(uword)) );
f.write( reinterpret_cast<const char*>(x.col_ptrs), std::streamsize((x.n_
cols+1)*sizeof(uword)) );
return f.good();
}
// //! Save a matrix as a PGM greyscale image f << max_row << ' ' << max_col << " 0 0\n";
// template<typename eT> }
// inline }
// bool
// diskio::save_pgm_binary(const SpMat<eT>& x, const std::string& final_nam
e)
// {
// arma_extra_debug_sigprint();
//
//
// const std::string tmp_name = diskio::gen_tmp_name(final_name);
//
// std::fstream f(tmp_name.c_str(), std::fstream::out | std::fstream::bin
ary);
//
// bool save_okay = f.is_open();
//
// if(save_okay == true)
// {
// save_okay = diskio::save_pgm_binary(x, f);
//
// f.flush();
// f.close();
//
// if(save_okay == true)
// {
// save_okay = diskio::safe_rename(tmp_name, final_name);
// }
// }
//
// return save_okay;
// }
// //! Save a matrix as a PGM greyscale image const bool save_okay = f.good();
// template<typename eT>
// inline
// bool
// diskio::save_pgm_binary(const SpMat<eT>& x, std::ostream& f)
// {
// arma_extra_debug_sigprint();
//
//
// f << "P5" << '\n';
// f << x.n_cols << ' ' << x.n_rows << ' ' << x.n_cols*x.n_rows << '\n';
// f << 255 << '\n';
//
// const uword n_elem = x.n_nonzero;
// podarray<u8> tmp(n_elem);
//
// uword i = 0;
//
// for(uword row=0; row < x.n_rows; ++row)
// {
// for(uword col=0; col < x.n_cols; ++col)
// {
// tmp[i] = u8( x.at(row,col) ); // TODO: add round() ?
// ++i;
// }
// }
//
// f.write(reinterpret_cast<const char*>(tmp.mem), std::streamsize(x.n_ro
ws*x.n_cols) );
//
// return f.good();
// }
// //! Save a matrix as a PGM greyscale image f.flags(orig_flags);
// template<typename T>
// inline
// bool
// diskio::save_pgm_binary(const SpMat< std::complex<T> >& x, const std::st
ring& final_name)
// {
// arma_extra_debug_sigprint();
//
// const uchar_mat tmp = conv_to<uchar_mat>::from(x);
//
// return diskio::save_pgm_binary(tmp, final_name);
// }
// //! Save a matrix as a PGM greyscale image return save_okay;
// template<typename T> }
// inline
// bool
// diskio::save_pgm_binary(const SpMat< std::complex<T> >& x, std::ostream&
f)
// {
// arma_extra_debug_sigprint();
//
// const uchar_mat tmp = conv_to<uchar_mat>::from(x);
//
// return diskio::save_pgm_binary(tmp, f);
// }
//! Save a matrix in ASCII coord format //! Save a matrix in binary format,
//! with a header that stores the matrix type as well as its dimensions
template<typename eT> template<typename eT>
inline inline
bool bool
diskio::save_coord_ascii(const SpMat<eT>& x, const std::string& final_name) diskio::save_arma_binary(const SpMat<eT>& x, const std::string& final_name)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const std::string tmp_name = diskio::gen_tmp_name(final_name); const std::string tmp_name = diskio::gen_tmp_name(final_name);
std::ofstream f(tmp_name.c_str()); std::ofstream f(tmp_name.c_str(), std::fstream::binary);
bool save_okay = f.is_open(); bool save_okay = f.is_open();
if(save_okay == true) if(save_okay == true)
{ {
save_okay = diskio::save_coord_ascii(x, f); save_okay = diskio::save_arma_binary(x, f);
f.flush(); f.flush();
f.close(); f.close();
if(save_okay == true) if(save_okay == true)
{ {
save_okay = diskio::safe_rename(tmp_name, final_name); save_okay = diskio::safe_rename(tmp_name, final_name);
} }
} }
return save_okay; return save_okay;
} }
//! Save a matrix in ASCII coord format //! Save a matrix in binary format,
//! with a header that stores the matrix type as well as its dimensions
template<typename eT> template<typename eT>
inline inline
bool bool
diskio::save_coord_ascii(const SpMat<eT>& x, std::ostream& f) diskio::save_arma_binary(const SpMat<eT>& x, std::ostream& f)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
uword x_n_rows = x.n_rows; f << diskio::gen_bin_header(x) << '\n';
uword x_n_cols = x.n_cols; f << x.n_rows << ' ' << x.n_cols << ' ' << x.n_nonzero << '\n';
uword x_n_nonzero = x.n_nonzero;
//Put down the header
f << x_n_rows << " " << x_n_cols << " " << x_n_nonzero << endl;
typename SpMat<eT>::const_iterator iter = x.begin();
for(; iter != x.end(); iter++)
f << iter.row() << " " << iter.col() << " " << *iter << endl;
const bool save_okay = f.good(); f.write( reinterpret_cast<const char*>(x.values), std::streamsize(x.
n_nonzero*sizeof(eT)) );
f.write( reinterpret_cast<const char*>(x.row_indices), std::streamsize(x.
n_nonzero*sizeof(uword)) );
f.write( reinterpret_cast<const char*>(x.col_ptrs), std::streamsize((x
.n_cols+1)*sizeof(uword)) );
return save_okay; return f.good();
} }
//! Load a matrix as raw text (no header, human readable).
//! Can read matrices saved as text in Matlab and Octave.
//! NOTE: this is much slower than reading a file with a header.
template<typename eT> template<typename eT>
inline inline
bool bool
diskio::load_raw_ascii(SpMat<eT>& x, const std::string& name, std::string& err_msg) diskio::load_coord_ascii(SpMat<eT>& x, const std::string& name, std::string & err_msg)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
std::fstream f; std::fstream f;
f.open(name.c_str(), std::fstream::in); f.open(name.c_str(), std::fstream::in | std::fstream::binary);
bool load_okay = f.is_open(); bool load_okay = f.is_open();
if(load_okay == true) if(load_okay == true)
{ {
load_okay = diskio::load_raw_ascii(x, f, err_msg); load_okay = diskio::load_coord_ascii(x, f, err_msg);
f.close(); f.close();
} }
return load_okay; return load_okay;
} }
//! Load a matrix as raw text (no header, human readable).
//! Can read matrices saved as text in Matlab and Octave.
//! NOTE: this is much slower than reading a file with a header.
template<typename eT> template<typename eT>
inline inline
bool bool
diskio::load_raw_ascii(SpMat<eT>& x, std::istream& f, std::string& err_msg) diskio::load_coord_ascii(SpMat<eT>& x, std::istream& f, std::string& err_ms g)
{ {
arma_extra_debug_sigprint();
bool load_okay = f.good(); bool load_okay = f.good();
f.clear(); f.clear();
const std::fstream::pos_type pos1 = f.tellg(); const std::fstream::pos_type pos1 = f.tellg();
// //
// work out the size // work out the size
uword f_n_rows = 0; uword f_n_rows = 0;
uword f_n_cols = 0; uword f_n_cols = 0;
uword f_n_nz = 0;
bool f_n_cols_found = false; bool size_found = false;
std::string line_string; std::string line_string;
std::string token; std::string token;
std::stringstream line_stream;
std::stringstream ss;
uword last_line_row = 0;
uword last_line_col = 0;
bool first_line = true;
bool weird_format = false;
while( (f.good() == true) && (load_okay == true) ) while( (f.good() == true) && (load_okay == true) )
{ {
std::getline(f, line_string); std::getline(f, line_string);
if(line_string.size() == 0) if(line_string.size() == 0)
{ {
break; break;
} }
std::stringstream line_stream(line_string); line_stream.clear();
line_stream.str(line_string);
uword line_n_cols = 0; uword line_row = 0;
uword line_col = 0;
while (line_stream >> token) // a valid line in co-ord format has at least 2 entries
line_stream >> line_row;
if(line_stream.good() == false)
{ {
++line_n_cols; load_okay = false;
break;
} }
if(f_n_cols_found == false) line_stream >> line_col;
size_found = true;
if(f_n_rows < line_row) f_n_rows = line_row;
if(f_n_cols < line_col) f_n_cols = line_col;
if(first_line == true)
{ {
f_n_cols = line_n_cols; first_line = false;
f_n_cols_found = true;
} }
else else
{ {
if(line_n_cols != f_n_cols) if( (line_col < last_line_col) || ((line_row <= last_line_row) && (li ne_col <= last_line_col)) )
{ {
err_msg = "inconsistent number of columns in "; weird_format = true;
load_okay = false;
} }
} }
++f_n_rows; last_line_row = line_row;
last_line_col = line_col;
if(line_stream.good() == true)
{
eT final_val = eT(0);
line_stream >> token;
if(line_stream.fail() == false)
{
eT val = eT(0);
ss.clear();
ss.str(token);
ss >> val;
if(ss.fail() == false)
{
final_val = val;
}
else
{
val = eT(0);
const bool success = diskio::convert_naninf( val, token );
if(success == true)
{
final_val = val;
}
}
}
if(final_val != eT(0))
{
++f_n_nz;
}
}
}
if(size_found == true)
{
// take into account that indices start at 0
f_n_rows++;
f_n_cols++;
} }
if(load_okay == true) if(load_okay == true)
{ {
f.clear(); f.clear();
f.seekg(pos1); f.seekg(pos1);
x.set_size(f_n_rows, f_n_cols); x.set_size(f_n_rows, f_n_cols);
eT val; if(weird_format == false)
{
x.mem_resize(f_n_nz);
}
for(uword row=0; (row < x.n_rows) && (load_okay == true); ++row) uword pos = 0;
while(f.good() == true)
{ {
for(uword col=0; (col < x.n_cols) && (load_okay == true); ++col) std::getline(f, line_string);
if(line_string.size() == 0)
{
break;
}
line_stream.clear();
line_stream.str(line_string);
uword line_row = 0;
uword line_col = 0;
line_stream >> line_row;
line_stream >> line_col;
eT final_val = eT(0);
line_stream >> token;
if(line_stream.fail() == false)
{ {
f >> val; eT val = eT(0);
if(f.fail() == false)
ss.clear();
ss.str(token);
ss >> val;
if(ss.fail() == false)
{ {
x.at(row,col) = val; final_val = val;
}
else
{
val = eT(0);
const bool success = diskio::convert_naninf( val, token );
if(success == true)
{
final_val = val;
}
}
}
if(final_val != eT(0))
{
if(weird_format == false)
{
access::rw(x.row_indices[pos]) = line_row;
access::rw(x.values[pos]) = final_val;
++access::rw(x.col_ptrs[line_col + 1]);
++pos;
} }
else else
{ {
load_okay = false; x.at(line_row,line_col) = final_val;
err_msg = "couldn't interpret data in ";
//break;
} }
} }
} }
}
// an empty file indicates an empty matrix if(weird_format == false)
if( (f_n_cols_found == false) && (load_okay == true) ) {
{ for(uword c = 1; c <= f_n_cols; ++c)
x.reset(); {
access::rw(x.col_ptrs[c]) += x.col_ptrs[c - 1];
}
}
} }
return load_okay; return load_okay;
} }
//TODO: this function doesn't make sense for sparse matrices, as there is n template<typename T>
o universal definition of a "raw" CSC file inline
// //! Load a matrix in binary format (no header); bool
// //! the matrix is assumed to have one column diskio::load_coord_ascii(SpMat< std::complex<T> >& x, std::istream& f, std:
// template<typename eT> :string& err_msg)
// inline {
// bool typedef std::complex<T> eT;
// diskio::load_raw_binary(SpMat<eT>& x, const std::string& name, std::stri
ng& err_msg)
// {
// arma_extra_debug_sigprint();
//
//
// std::ifstream f;
// f.open(name.c_str(), std::fstream::binary);
//
// bool load_okay = f.is_open();
//
// if(load_okay == true)
// {
// load_okay = diskio::load_raw_binary(x, f, err_msg);
// f.close();
// }
//
// return load_okay;
// }
//// TODO: this function doesn't make sense for sparse matrices, as there i bool load_okay = f.good();
s no universal definition of a "raw" CSC file
// template<typename eT>
// inline
// bool
// diskio::load_raw_binary(SpMat<eT>& x, std::istream& f, std::string& err_
msg)
// {
// arma_extra_debug_sigprint();
// arma_ignore(err_msg);
//
//
// //Make sure we are at top of file.
// f.clear();
//
// //Read the dimensions of the matrix
// f.read( (char*) &access::rw(x.n_rows), std::streamsize(sizeof(uword))
);
// f.read( (char*) &access::rw(x.n_cols), std::streamsize(sizeof(uword))
);
// f.read( (char*) &access::rw(x.n_nonzero), std::streamsize(sizeof(uword
)) );
// access::rw(x.n_elem) = x.n_rows * x.n_cols;
//
// //Allocate appropriate memory, then fill it.
// eT* in_values = memory::acquire<eT>(x.n_nonzero); // TODO: BUG. use
acquire_chunked
// uword* in_row_indices = memory::acquire<uword>(x.n_nonzero); // TODO:
BUG. use acquire_chunked
// uword* in_col_ptrs = memory::acquire<uword>(x.n_cols + 1);
//
// f.read( reinterpret_cast<char*>(in_values), std::streamsize(x.n_nonzer
o * sizeof(eT)) );
// f.read( reinterpret_cast<char*>(in_row_indices), std::streamsize(x.n_n
onzero * sizeof(uword)) );
// f.read( reinterpret_cast<char*>(in_col_ptrs), std::streamsize((x.n_col
s + 1) * sizeof(uword)) );
//
// //Replace the current data in the sparse matrix
// if(x.n_nonzero > 0)
// {
// memory::release(x.values);
// memory::release(x.row_indices);
// }
//
// memory::release(x.col_ptrs);
//
// access::rwp(x.values) = in_values;
// access::rwp(x.row_indices) = in_row_indices;
// access::rwp(x.col_ptrs) = in_col_ptrs;
//
// return f.good();
// }
//// TODO: this function needs to be reworked to save only non-zero element f.clear();
s; we can define our own format, or adapt an existing format const std::fstream::pos_type pos1 = f.tellg();
// //! Load a matrix in text format (human readable),
// //! with a header that indicates the matrix type as well as its dimensio
ns
// template<typename eT>
// inline
// bool
// diskio::load_arma_ascii(SpMat<eT>& x, const std::string& name, std::stri
ng& err_msg)
// {
// arma_extra_debug_sigprint();
//
//
// std::ifstream f(name.c_str());
//
// bool load_okay = f.is_open();
//
// if(load_okay == true)
// {
// load_okay = diskio::load_arma_ascii(x, f, err_msg);
// f.close();
// }
//
// return load_okay;
// }
//// TODO: this function needs to be reworked to save only non-zero element //
s; we can define our own format, or adapt an existing format // work out the size
// //! Load a matrix in text format (human readable),
// //! with a header that indicates the matrix type as well as its dimensio
ns
// template<typename eT>
// inline
// bool
// diskio::load_arma_ascii(SpMat<eT>& x, std::istream& f, std::string& err_
msg)
// {
// arma_extra_debug_sigprint();
//
//
// bool load_okay = true;
//
// eT tmp;
// std::string f_header;
// uword f_n_rows;
// uword f_n_cols;
//
// f >> f_header;
// f >> f_n_rows;
// f >> f_n_cols;
//
// if(f_header == diskio::gen_txt_header(x))
// {
// x.set_size(f_n_rows, f_n_cols);
//
// for(uword row=0; row < x.n_rows; ++row)
// {
// for(uword col=0; col < x.n_cols; ++col)
// {
// f >> tmp;
// x.at(row,col) = tmp;
// }
// }
//
// load_okay = f.good();
// }
// else
// {
// load_okay = false;
// err_msg = "incorrect header in ";
// }
//
// return load_okay;
// }
// //! Load a matrix in CSV text format (human readable) uword f_n_rows = 0;
// template<typename eT> uword f_n_cols = 0;
// inline uword f_n_nz = 0;
// bool
// diskio::load_csv_ascii(SpMat<eT>& x, const std::string& name, std::strin
g& err_msg)
// {
// arma_extra_debug_sigprint();
//
// std::fstream f;
// f.open(name.c_str(), std::fstream::in);
//
// bool load_okay = f.is_open();
//
// if(load_okay == true)
// {
// load_okay = diskio::load_csv_ascii(x, f, err_msg);
// f.close();
// }
//
// return load_okay;
// }
// //! Load a matrix in CSV text format (human readable) bool size_found = false;
// template<typename eT>
// inline
// bool
// diskio::load_csv_ascii(SpMat<eT>& x, std::istream& f, std::string& err_m
sg)
// {
// arma_extra_debug_sigprint();
//
// bool load_okay = f.good();
//
// f.clear();
// const std::fstream::pos_type pos1 = f.tellg();
//
// //
// // work out the size
//
// uword f_n_rows = 0;
// uword f_n_cols = 0;
//
// std::string line_string;
// std::string token;
//
// while( (f.good() == true) && (load_okay == true) )
// {
// std::getline(f, line_string);
//
// if(line_string.size() == 0)
// {
// break;
// }
//
// std::stringstream line_stream(line_string);
//
// uword line_n_cols = 0;
//
// while(line_stream.good() == true)
// {
// std::getline(line_stream, token, ',');
// ++line_n_cols;
// }
//
// if(f_n_cols < line_n_cols)
// {
// f_n_cols = line_n_cols;
// }
//
// ++f_n_rows;
// }
//
// f.clear();
// f.seekg(pos1);
// x.zeros(f_n_rows, f_n_cols);
//
// uword row = 0;
//
// while(f.good() == true)
// {
// std::getline(f, line_string);
//
// if(line_string.size() == 0)
// {
// break;
// }
//
// std::stringstream line_stream(line_string);
//
// uword col = 0;
//
// while(line_stream.good() == true)
// {
// std::getline(line_stream, token, ',');
//
// eT val;
//
// std::stringstream ss(token);
//
// ss >> val;
//
// if(ss.fail() == false)
// {
// x.at(row,col) = val;
// }
//
// ++col;
// }
//
// ++row;
// }
//
// return load_okay;
// }
//! Load a matrix in binary format, std::string line_string;
//! with a header that indicates the matrix type as well as its dimensions std::string token_real;
template<typename eT> std::string token_imag;
inline
bool
diskio::load_arma_binary(SpMat<eT>& x, const std::string& name, std::string
& err_msg)
{
arma_extra_debug_sigprint();
std::ifstream f; std::stringstream line_stream;
f.open(name.c_str(), std::fstream::binary); std::stringstream ss;
bool load_okay = f.is_open(); uword last_line_row = 0;
uword last_line_col = 0;
if(load_okay == true) bool first_line = true;
bool weird_format = false;
while( (f.good() == true) && (load_okay == true) )
{ {
load_okay = diskio::load_arma_binary(x, f, err_msg); std::getline(f, line_string);
f.close();
}
return load_okay; if(line_string.size() == 0)
} {
break;
}
template<typename eT> line_stream.clear();
inline line_stream.str(line_string);
bool
diskio::load_arma_binary(SpMat<eT>& x, std::istream& f, std::string& err_ms
g)
{
arma_extra_debug_sigprint();
bool load_okay = true; uword line_row = 0;
uword line_col = 0;
std::string f_header; // a valid line in co-ord format has at least 2 entries
f >> f_header; line_stream >> line_row;
f >> access::rw(x.n_rows);
f >> access::rw(x.n_cols);
f >> access::rw(x.n_nonzero);
access::rw(x.n_elem) = x.n_rows*x.n_cols;
if(f_header == diskio::gen_bin_header(x)) if(line_stream.good() == false)
{ {
//f.seekg(1, ios::cur); // NOTE: this may not be portable, as on a Win load_okay = false;
dows machine a newline could be two characters break;
f.get(); }
//Allocate memory for the incoming data line_stream >> line_col;
eT* in_values = memory::acquire_chunked<eT> (x.n_nonzero);
uword* in_row_indices = memory::acquire_chunked<uword>(x.n_nonzero);
uword* in_col_ptrs = memory::acquire<uword> (x.n_cols + 1);
f.read((char*) in_values, std::streamsize(x.n_nonzero * sizeof(eT)) ); size_found = true;
f.read((char*) in_row_indices, std::streamsize(x.n_nonzero * sizeof(uwo
rd)) );
f.read((char*) in_col_ptrs, std::streamsize((x.n_cols + 1) * sizeof(uwo
rd)) );
//Stick new data into sparse matrix if(f_n_rows < line_row) f_n_rows = line_row;
if (x.n_nonzero > 0) if(f_n_cols < line_col) f_n_cols = line_col;
if(first_line == true)
{ {
memory::release(x.values); first_line = false;
memory::release(x.row_indices);
} }
else
{
if( (line_col < last_line_col) || ((line_row <= last_line_row) && (li
ne_col <= last_line_col)) )
{
weird_format = true;
}
}
last_line_row = line_row;
last_line_col = line_col;
memory::release(x.col_ptrs); if(line_stream.good() == true)
{
T final_val_real = T(0);
T final_val_imag = T(0);
access::rw(x.values) = in_values; line_stream >> token_real;
access::rw(x.row_indices) = in_row_indices;
access::rw(x.col_ptrs) = in_col_ptrs;
load_okay = f.good(); if(line_stream.fail() == false)
{
T val_real = T(0);
ss.clear();
ss.str(token_real);
ss >> val_real;
if(ss.fail() == false)
{
final_val_real = val_real;
}
else
{
val_real = T(0);
const bool success = diskio::convert_naninf( val_real, token_real
);
if(success == true)
{
final_val_real = val_real;
}
}
}
line_stream >> token_imag;
if(line_stream.fail() == false)
{
T val_imag = T(0);
ss.clear();
ss.str(token_imag);
ss >> val_imag;
if(ss.fail() == false)
{
final_val_imag = val_imag;
}
else
{
val_imag = T(0);
const bool success = diskio::convert_naninf( val_imag, token_imag
);
if(success == true)
{
final_val_imag = val_imag;
}
}
}
if( (final_val_real != T(0)) || (final_val_imag != T(0)) )
{
++f_n_nz;
}
}
} }
else
if(size_found == true)
{ {
load_okay = false; // take into account that indices start at 0
err_msg = "incorrect header in "; f_n_rows++;
f_n_cols++;
} }
return load_okay; if(load_okay == true)
} {
f.clear();
f.seekg(pos1);
// //! Load a PGM greyscale image as a matrix x.set_size(f_n_rows, f_n_cols);
// template<typename eT>
// inline
// bool
// diskio::load_pgm_binary(SpMat<eT>& x, const std::string& name, std::stri
ng& err_msg)
// {
// arma_extra_debug_sigprint();
//
//
// std::fstream f;
// f.open(name.c_str(), std::fstream::in | std::fstream::binary);
//
// bool load_okay = f.is_open();
//
// if(load_okay == true)
// {
// load_okay = diskio::load_pgm_binary(x, f, err_msg);
// f.close();
// }
//
// return load_okay;
// }
////! Load a PGM greyscale image as a matrix if(weird_format == false)
// template<typename eT> {
// inline x.mem_resize(f_n_nz);
// bool }
// diskio::load_pgm_binary(SpMat<eT>& x, std::istream& f, std::string& err_
msg)
// {
// bool load_okay = true;
//
//
// std::string f_header;
// f >> f_header;
//
// if(f_header == "P5")
// {
// uword f_n_rows = 0;
// uword f_n_cols = 0;
// int f_maxval = 0;
//
// diskio::pnm_skip_comments(f);
//
// f >> f_n_cols;
// diskio::pnm_skip_comments(f);
//
// f >> f_n_rows;
// diskio::pnm_skip_comments(f);
//
// f >> f_maxval; //grabing a redundant size value
//
// f >> f_maxval;
// f.get();
//
// if( (f_maxval > 0) || (f_maxval <= 65535) )
// {
// x.set_size(f_n_rows,f_n_cols);
//
// if(f_maxval <= 255)
// {
// const uword n_elem = f_n_cols*f_n_rows;
// podarray<u8> tmp(n_elem);
//
// f.read( reinterpret_cast<char*>(tmp.memptr()), std::streamsize(n
_elem) );
//
// uword i = 0;
//
// //cout << "f_n_cols = " << f_n_cols << endl;
// //cout << "f_n_rows = " << f_n_rows << endl;
//
//
// for(uword row=0; row < f_n_rows; ++row)
// {
// for(uword col=0; col < f_n_cols; ++col)
// {
// x.at(row,col) = eT(tmp[i]);
// ++i;
// }
// }
//
// }
// else
// {
// const uword n_elem = f_n_cols*f_n_rows;
// podarray<u16> tmp(n_elem);
//
// f.read( reinterpret_cast<char *>(tmp.memptr()), std::streamsize(
n_elem*2) );
//
// uword i = 0;
//
// for(uword row=0; row < f_n_rows; ++row)
// {
// for(uword col=0; col < f_n_cols; ++col)
// {
// x.at(row,col) = eT(tmp[i]);
// ++i;
// }
// }
//
// }
//
// }
// else
// {
// load_okay = false;
// err_msg = "currently no code available to handle loading ";
// }
//
// if(f.good() == false)
// {
// load_okay = false;
// }
// }
// else
// {
// load_okay = false;
// err_msg = "unsupported header in ";
// }
//
// return load_okay;
// }
// //! Load a PGM greyscale image as a matrix uword pos = 0;
// template<typename T>
// inline
// bool
// diskio::load_pgm_binary(SpMat< std::complex<T> >& x, const std::string&
name, std::string& err_msg)
// {
// arma_extra_debug_sigprint();
//
// uchar_mat tmp;
// const bool load_okay = diskio::load_pgm_binary(tmp, name, err_msg);
//
// x = conv_to< Mat< std::complex<T> > >::from(tmp); // TODO: BUG
//
// return load_okay;
// }
// //! Load a PGM greyscale image as a matrix while(f.good() == true)
// template<typename T> {
// inline std::getline(f, line_string);
// bool
// diskio::load_pgm_binary(SpMat< std::complex<T> >& x, std::istream& is, s
td::string& err_msg)
// {
// arma_extra_debug_sigprint();
//
// uchar_mat tmp;
// const bool load_okay = diskio::load_pgm_binary(tmp, is, err_msg);
//
// x = conv_to< Mat< std::complex<T> > >::from(tmp); // TODO: BUG
//
// return load_okay;
// }
// //! Try to load a matrix by automatically determining its type if(line_string.size() == 0)
// template<typename eT> {
// inline break;
// bool }
// diskio::load_auto_detect(SpMat<eT>& x, const std::string& name, std::str
ing& err_msg)
// {
// arma_extra_debug_sigprint();
//
// std::fstream f;
// f.open(name.c_str(), std::fstream::in | std::fstream::binary);
//
// bool load_okay = f.is_open();
//
// if(load_okay == true)
// {
// load_okay = diskio::load_auto_detect(x, f, err_msg);
// f.close();
// }
//
// return load_okay;
// }
// //! Try to load a matrix by automatically determining its type line_stream.clear();
// template<typename eT> line_stream.str(line_string);
// inline
// bool uword line_row = 0;
// diskio::load_auto_detect(SpMat<eT>& x, std::istream& f, std::string& err uword line_col = 0;
_msg)
// {
// arma_extra_debug_sigprint();
//
// static const std::string ARMA_SPM_TXT = "ARMA_SPM_TXT";
// static const std::string ARMA_SPM_BIN = "ARMA_SPM_BIN";
// static const std::string P5 = "P5";
//
// podarray<char> raw_header(ARMA_SPM_TXT.length() + 1);
//
// std::streampos pos = f.tellg();
//
// f.read( raw_header.memptr(), std::streamsize(ARMA_SPM_TXT.length()) );
// raw_header[ARMA_SPM_TXT.length()] = '\0';
//
// f.clear();
// f.seekg(pos);
//
// const std::string header = raw_header.mem;
//
// if(ARMA_SPM_TXT == header.substr(0,ARMA_SPM_TXT.length()))
// {
// return load_arma_ascii(x, f, err_msg);
// }
// else
// if(ARMA_SPM_BIN == header.substr(0,ARMA_SPM_BIN.length()))
// {
// return load_arma_binary(x, f, err_msg);
// }
// else
// if(P5 == header.substr(0,P5.length()))
// {
// return load_pgm_binary(x, f, err_msg);
// }
// else
// {
// const file_type ft = guess_file_type(f);
//
// switch(ft)
// {
// case csv_ascii:
// return load_csv_ascii(x, f, err_msg);
// break;
//
// case raw_binary:
// return load_raw_binary(x, f, err_msg);
// break;
//
// case raw_ascii:
// return load_raw_ascii(x, f, err_msg);
// break;
//
// default:
// err_msg = "unknown data in ";
// return false;
// }
// }
//
// return false;
// }
line_stream >> line_row;
line_stream >> line_col;
T final_val_real = T(0);
T final_val_imag = T(0);
line_stream >> token_real;
if(line_stream.fail() == false)
{
T val_real = T(0);
ss.clear();
ss.str(token_real);
ss >> val_real;
if(ss.fail() == false)
{
final_val_real = val_real;
}
else
{
val_real = T(0);
const bool success = diskio::convert_naninf( val_real, token_real
);
if(success == true)
{
final_val_real = val_real;
}
}
}
line_stream >> token_imag;
if(line_stream.fail() == false)
{
T val_imag = T(0);
ss.clear();
ss.str(token_imag);
ss >> val_imag;
if(ss.fail() == false)
{
final_val_imag = val_imag;
}
else
{
val_imag = T(0);
const bool success = diskio::convert_naninf( val_imag, token_imag
);
if(success == true)
{
final_val_imag = val_imag;
}
}
}
if( (final_val_real != T(0)) || (final_val_imag != T(0)) )
{
if(weird_format == false)
{
access::rw(x.row_indices[pos]) = line_row;
access::rw(x.values[pos]) = std::complex<T>(final_val_real,
final_val_imag);
++access::rw(x.col_ptrs[line_col + 1]);
++pos;
}
else
{
x.at(line_row,line_col) = std::complex<T>(final_val_real, final_v
al_imag);
}
}
}
if(weird_format == false)
{
for(uword c = 1; c <= f_n_cols; ++c)
{
access::rw(x.col_ptrs[c]) += x.col_ptrs[c - 1];
}
}
}
return load_okay;
}
//! Load a matrix in binary format,
//! with a header that indicates the matrix type as well as its dimensions
template<typename eT> template<typename eT>
inline inline
bool bool
diskio::load_coord_ascii(SpMat<eT>& x, const std::string& name, std::string & err_msg) diskio::load_arma_binary(SpMat<eT>& x, const std::string& name, std::string & err_msg)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
std::fstream f; std::ifstream f;
f.open(name.c_str(), std::fstream::in | std::fstream::binary); f.open(name.c_str(), std::fstream::binary);
bool load_okay = f.is_open(); bool load_okay = f.is_open();
if(load_okay == true) if(load_okay == true)
{ {
load_okay = diskio::load_coord_ascii(x, f, err_msg); load_okay = diskio::load_arma_binary(x, f, err_msg);
f.close(); f.close();
} }
return load_okay; return load_okay;
} }
template<typename eT> template<typename eT>
inline inline
bool bool
diskio::load_coord_ascii(SpMat<eT>& x, std::istream& f, std::string& err_ms g) diskio::load_arma_binary(SpMat<eT>& x, std::istream& f, std::string& err_ms g)
{ {
uword r,c,nz; arma_extra_debug_sigprint();
f >> r; f >> c; f >> nz; //Grab the header bool load_okay = true;
x.set_size(r,c);
for(size_t i = 0; i < nz; i++) std::string f_header;
f >> f_header;
if(f_header == diskio::gen_bin_header(x))
{ {
eT data; uword f_n_rows;
uword row, col; uword f_n_cols;
uword f_n_nz;
f >> row; f >> col; f >> data; f >> f_n_rows;
f >> f_n_cols;
f >> f_n_nz;
x.at(row,col) = data; //f.seekg(1, ios::cur); // NOTE: this may not be portable, as on a Win
dows machine a newline could be two characters
f.get();
x.set_size(f_n_rows, f_n_cols);
x.mem_resize(f_n_nz);
f.read( reinterpret_cast<char*>(access::rwp(x.values)), std::strea
msize(x.n_nonzero*sizeof(eT)) );
f.read( reinterpret_cast<char*>(access::rwp(x.row_indices)), std::strea
msize(x.n_nonzero*sizeof(uword)) );
f.read( reinterpret_cast<char*>(access::rwp(x.col_ptrs)), std::strea
msize((x.n_cols+1)*sizeof(uword)) );
load_okay = f.good();
}
else
{
load_okay = false;
err_msg = "incorrect header in ";
} }
return f.good(); return load_okay;
} }
// cubes // cubes
//! Save a cube as raw text (no header, human readable). //! Save a cube as raw text (no header, human readable).
template<typename eT> template<typename eT>
inline inline
bool bool
diskio::save_raw_ascii(const Cube<eT>& x, const std::string& final_name) diskio::save_raw_ascii(const Cube<eT>& x, const std::string& final_name)
{ {
 End of changes. 140 change blocks. 
1131 lines changed or deleted 676 lines changed or added


 eglue_core_meat.hpp   eglue_core_meat.hpp 
skipping to change at line 48 skipping to change at line 48
if(i < n_elem)\ if(i < n_elem)\
{\ {\
out_mem[i] operatorA P1[i] operatorB P2[i];\ out_mem[i] operatorA P1[i] operatorB P2[i];\
}\ }\
} }
#define arma_applier_2(operatorA, operatorB) \ #define arma_applier_2(operatorA, operatorB) \
{\ {\
if(n_rows != 1)\ if(n_rows != 1)\
{\ {\
uword count = 0;\
\
for(uword col=0; col<n_cols; ++col)\ for(uword col=0; col<n_cols; ++col)\
{\ {\
uword i,j;\ uword i,j;\
\ \
for(i=0, j=1; j<n_rows; i+=2, j+=2, count+=2)\ for(i=0, j=1; j<n_rows; i+=2, j+=2)\
{\ {\
eT tmp_i = P1.at(i,col);\ eT tmp_i = P1.at(i,col);\
eT tmp_j = P1.at(j,col);\ eT tmp_j = P1.at(j,col);\
\ \
tmp_i operatorB##= P2.at(i,col);\ tmp_i operatorB##= P2.at(i,col);\
tmp_j operatorB##= P2.at(j,col);\ tmp_j operatorB##= P2.at(j,col);\
\ \
out_mem[count ] operatorA tmp_i;\ *out_mem operatorA tmp_i; out_mem++; \
out_mem[count+1] operatorA tmp_j;\ *out_mem operatorA tmp_j; out_mem++; \
}\ }\
\ \
if(i < n_rows)\ if(i < n_rows)\
{\ {\
out_mem[count] operatorA P1.at(i,col) operatorB P2.at(i,col);\ *out_mem operatorA P1.at(i,col) operatorB P2.at(i,col); out_mem++;
++count;\ \
}\ }\
}\ }\
}\ }\
else\ else\
{\ {\
uword i,j;\ uword i,j;\
for(i=0, j=1; j < n_cols; i+=2, j+=2)\ for(i=0, j=1; j < n_cols; i+=2, j+=2)\
{\ {\
eT tmp_i = P1.at(0,i);\ eT tmp_i = P1.at(0,i);\
eT tmp_j = P1.at(0,j);\ eT tmp_j = P1.at(0,j);\
skipping to change at line 97 skipping to change at line 94
\ \
if(i < n_cols)\ if(i < n_cols)\
{\ {\
out_mem[i] operatorA P1.at(0,i) operatorB P2.at(0,i);\ out_mem[i] operatorA P1.at(0,i) operatorB P2.at(0,i);\
}\ }\
}\ }\
} }
#define arma_applier_3(operatorA, operatorB) \ #define arma_applier_3(operatorA, operatorB) \
{\ {\
uword count = 0;\
\
for(uword slice=0; slice<n_slices; ++slice)\ for(uword slice=0; slice<n_slices; ++slice)\
{\ {\
for(uword col=0; col<n_cols; ++col)\ for(uword col=0; col<n_cols; ++col)\
{\ {\
uword i,j;\ uword i,j;\
\ \
for(i=0, j=1; j<n_rows; i+=2, j+=2, count+=2)\ for(i=0, j=1; j<n_rows; i+=2, j+=2)\
{\ {\
eT tmp_i = P1.at(i,col,slice);\ eT tmp_i = P1.at(i,col,slice);\
eT tmp_j = P1.at(j,col,slice);\ eT tmp_j = P1.at(j,col,slice);\
\ \
tmp_i operatorB##= P2.at(i,col,slice);\ tmp_i operatorB##= P2.at(i,col,slice);\
tmp_j operatorB##= P2.at(j,col,slice);\ tmp_j operatorB##= P2.at(j,col,slice);\
\ \
out_mem[count ] operatorA tmp_i;\ *out_mem operatorA tmp_i; out_mem++; \
out_mem[count+1] operatorA tmp_j;\ *out_mem operatorA tmp_j; out_mem++; \
}\ }\
\ \
if(i < n_rows)\ if(i < n_rows)\
{\ {\
out_mem[count] operatorA P1.at(i,col,slice) operatorB P2.at(i,col,s *out_mem operatorA P1.at(i,col,slice) operatorB P2.at(i,col,slice);
lice);\ out_mem++; \
++count;\
}\ }\
}\ }\
}\ }\
} }
// //
// matrices // matrices
template<typename eglue_type> template<typename eglue_type>
template<typename T1, typename T2> template<typename T1, typename T2>
 End of changes. 8 change blocks. 
15 lines changed or deleted 10 lines changed or added


 eop_core_meat.hpp   eop_core_meat.hpp 
skipping to change at line 47 skipping to change at line 47
if(i < n_elem)\ if(i < n_elem)\
{\ {\
out_mem[i] operatorA eop_core<eop_type>::process(P[i], k);\ out_mem[i] operatorA eop_core<eop_type>::process(P[i], k);\
}\ }\
} }
#define arma_applier_2(operatorA) \ #define arma_applier_2(operatorA) \
{\ {\
if(n_rows != 1)\ if(n_rows != 1)\
{\ {\
uword count = 0;\
\
for(uword col=0; col<n_cols; ++col)\ for(uword col=0; col<n_cols; ++col)\
{\ {\
uword i,j;\ uword i,j;\
\ \
for(i=0, j=1; j<n_rows; i+=2, j+=2, count+=2)\ for(i=0, j=1; j<n_rows; i+=2, j+=2)\
{\ {\
eT tmp_i = P.at(i,col);\ eT tmp_i = P.at(i,col);\
eT tmp_j = P.at(j,col);\ eT tmp_j = P.at(j,col);\
\ \
tmp_i = eop_core<eop_type>::process(tmp_i, k);\ tmp_i = eop_core<eop_type>::process(tmp_i, k);\
tmp_j = eop_core<eop_type>::process(tmp_j, k);\ tmp_j = eop_core<eop_type>::process(tmp_j, k);\
\ \
out_mem[count ] operatorA tmp_i;\ *out_mem operatorA tmp_i; out_mem++;\
out_mem[count+1] operatorA tmp_j;\ *out_mem operatorA tmp_j; out_mem++;\
}\ }\
\ \
if(i < n_rows)\ if(i < n_rows)\
{\ {\
out_mem[count] operatorA eop_core<eop_type>::process(P.at(i,col), k *out_mem operatorA eop_core<eop_type>::process(P.at(i,col), k); ou
);\ t_mem++;\
++count;\
}\ }\
}\ }\
}\ }\
else\ else\
{\ {\
for(uword count=0; count < n_cols; ++count)\ for(uword count=0; count < n_cols; ++count)\
{\ {\
out_mem[count] operatorA eop_core<eop_type>::process(P.at(0,count), k );\ out_mem[count] operatorA eop_core<eop_type>::process(P.at(0,count), k );\
}\ }\
}\ }\
} }
#define arma_applier_3(operatorA) \ #define arma_applier_3(operatorA) \
{\ {\
uword count = 0;\
\
for(uword slice=0; slice<n_slices; ++slice)\ for(uword slice=0; slice<n_slices; ++slice)\
{\ {\
for(uword col=0; col<n_cols; ++col)\ for(uword col=0; col<n_cols; ++col)\
{\ {\
uword i,j;\ uword i,j;\
\ \
for(i=0, j=1; j<n_rows; i+=2, j+=2, count+=2)\ for(i=0, j=1; j<n_rows; i+=2, j+=2)\
{\ {\
eT tmp_i = P.at(i,col,slice);\ eT tmp_i = P.at(i,col,slice);\
eT tmp_j = P.at(j,col,slice);\ eT tmp_j = P.at(j,col,slice);\
\ \
tmp_i = eop_core<eop_type>::process(tmp_i, k);\ tmp_i = eop_core<eop_type>::process(tmp_i, k);\
tmp_j = eop_core<eop_type>::process(tmp_j, k);\ tmp_j = eop_core<eop_type>::process(tmp_j, k);\
\ \
out_mem[count ] operatorA tmp_i;\ *out_mem operatorA tmp_i; out_mem++; \
out_mem[count+1] operatorA tmp_j;\ *out_mem operatorA tmp_j; out_mem++; \
}\ }\
\ \
if(i < n_rows)\ if(i < n_rows)\
{\ {\
out_mem[count] operatorA eop_core<eop_type>::process(P.at(i,col,sli *out_mem operatorA eop_core<eop_type>::process(P.at(i,col,slice), k
ce), k);\ ); out_mem++; \
++count;\
}\ }\
}\ }\
}\ }\
} }
// //
// matrices // matrices
template<typename eop_type> template<typename eop_type>
template<typename T1> template<typename T1>
 End of changes. 8 change blocks. 
16 lines changed or deleted 10 lines changed or added


 fn_accu.hpp   fn_accu.hpp 
skipping to change at line 300 skipping to change at line 300
const SpProxy<T1> p(x); const SpProxy<T1> p(x);
if(SpProxy<T1>::must_use_iterator == false) if(SpProxy<T1>::must_use_iterator == false)
{ {
// direct counting // direct counting
return arrayops::accumulate(p.get_values(), p.get_n_nonzero()); return arrayops::accumulate(p.get_values(), p.get_n_nonzero());
} }
else else
{ {
typename SpProxy<T1>::const_iterator_type it = p.begin(); typename SpProxy<T1>::const_iterator_type it = p.begin();
typename SpProxy<T1>::const_iterator_type it_end = p.end();
eT result = eT(0); eT result = eT(0);
while(it != p.end()) while(it != it_end)
{ {
result += (*it); result += (*it);
++it; ++it;
} }
return result; return result;
} }
} }
//! @} //! @}
 End of changes. 2 change blocks. 
2 lines changed or deleted 3 lines changed or added


 fn_elem.hpp   fn_elem.hpp 
skipping to change at line 134 skipping to change at line 134
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return mtOpCube<typename T1::pod_type, T1, op_imag>( X.get_ref() ); return mtOpCube<typename T1::pod_type, T1, op_imag>( X.get_ref() );
} }
// //
// log // log
template<typename T1> template<typename T1>
arma_inline arma_inline
const eOp<T1, eop_log> typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_log> >::res
log(const Base<typename T1::elem_type,T1>& A) ult
log(const T1& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return eOp<T1, eop_log>(A.get_ref()); return eOp<T1, eop_log>(A);
} }
template<typename T1> template<typename T1>
arma_inline arma_inline
const eOpCube<T1, eop_log> const eOpCube<T1, eop_log>
log(const BaseCube<typename T1::elem_type,T1>& A) log(const BaseCube<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return eOpCube<T1, eop_log>(A.get_ref()); return eOpCube<T1, eop_log>(A.get_ref());
skipping to change at line 203 skipping to change at line 203
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return eOpCube<T1, eop_log10>(A.get_ref()); return eOpCube<T1, eop_log10>(A.get_ref());
} }
// //
// exp // exp
template<typename T1> template<typename T1>
arma_inline arma_inline
const eOp<T1, eop_exp> typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_exp> >::res
exp(const Base<typename T1::elem_type,T1>& A) ult
exp(const T1& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return eOp<T1, eop_exp>(A.get_ref()); return eOp<T1, eop_exp>(A);
} }
template<typename T1> template<typename T1>
arma_inline arma_inline
const eOpCube<T1, eop_exp> const eOpCube<T1, eop_exp>
exp(const BaseCube<typename T1::elem_type,T1>& A) exp(const BaseCube<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return eOpCube<T1, eop_exp>(A.get_ref()); return eOpCube<T1, eop_exp>(A.get_ref());
skipping to change at line 270 skipping to change at line 270
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return eOpCube<T1, eop_exp10>(A.get_ref()); return eOpCube<T1, eop_exp10>(A.get_ref());
} }
// //
// abs // abs
template<typename T1> template<typename T1>
arma_inline arma_inline
const eOp<T1, eop_abs> typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_abs> >::res
abs(const Base<typename T1::elem_type,T1>& X, const typename arma_not_cx<ty ult
pename T1::elem_type>::result* junk = 0) abs(const T1& X, const typename arma_not_cx<typename T1::elem_type>::result
* junk = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_ignore(junk); arma_ignore(junk);
return eOp<T1, eop_abs>(X.get_ref()); return eOp<T1, eop_abs>(X);
} }
template<typename T1> template<typename T1>
arma_inline arma_inline
const eOpCube<T1, eop_abs> const eOpCube<T1, eop_abs>
abs(const BaseCube<typename T1::elem_type,T1>& X, const typename arma_not_c x<typename T1::elem_type>::result* junk = 0) abs(const BaseCube<typename T1::elem_type,T1>& X, const typename arma_not_c x<typename T1::elem_type>::result* junk = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_ignore(junk); arma_ignore(junk);
skipping to change at line 316 skipping to change at line 316
const mtOpCube<typename T1::pod_type, T1, op_abs> const mtOpCube<typename T1::pod_type, T1, op_abs>
abs(const BaseCube< std::complex<typename T1::pod_type>,T1>& X, const typen ame arma_cx_only<typename T1::elem_type>::result* junk = 0) abs(const BaseCube< std::complex<typename T1::pod_type>,T1>& X, const typen ame arma_cx_only<typename T1::elem_type>::result* junk = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_ignore(junk); arma_ignore(junk);
return mtOpCube<typename T1::pod_type, T1, op_abs>( X.get_ref() ); return mtOpCube<typename T1::pod_type, T1, op_abs>( X.get_ref() );
} }
template<typename T1>
arma_inline
const SpOp<T1, spop_abs>
abs(const SpBase<typename T1::elem_type,T1>& X, const typename arma_not_cx<
typename T1::elem_type>::result* junk = 0)
{
arma_extra_debug_sigprint();
arma_ignore(junk);
return SpOp<T1, spop_abs>(X.get_ref());
}
template<typename T1>
arma_inline
const mtSpOp<typename T1::pod_type, T1, spop_cx_abs>
abs(const SpBase< std::complex<typename T1::pod_type>, T1>& X, const typena
me arma_cx_only<typename T1::elem_type>::result* junk = 0)
{
arma_extra_debug_sigprint();
arma_ignore(junk);
return mtSpOp<typename T1::pod_type, T1, spop_cx_abs>(X.get_ref());
}
// //
// square // square
template<typename T1> template<typename T1>
arma_inline arma_inline
const eOp<T1, eop_square> typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_square> >::
square(const Base<typename T1::elem_type,T1>& A) result
square(const T1& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return eOp<T1, eop_square>(A.get_ref()); return eOp<T1, eop_square>(A);
} }
template<typename T1> template<typename T1>
arma_inline arma_inline
const eOpCube<T1, eop_square> const eOpCube<T1, eop_square>
square(const BaseCube<typename T1::elem_type,T1>& A) square(const BaseCube<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return eOpCube<T1, eop_square>(A.get_ref()); return eOpCube<T1, eop_square>(A.get_ref());
skipping to change at line 354 skipping to change at line 376
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return SpOp<T1, spop_square>(A.get_ref()); return SpOp<T1, spop_square>(A.get_ref());
} }
// //
// sqrt // sqrt
template<typename T1> template<typename T1>
arma_inline arma_inline
const eOp<T1, eop_sqrt> typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_sqrt> >::re
sqrt(const Base<typename T1::elem_type,T1>& A) sult
sqrt(const T1& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return eOp<T1, eop_sqrt>(A.get_ref()); return eOp<T1, eop_sqrt>(A);
} }
template<typename T1> template<typename T1>
arma_inline arma_inline
const eOpCube<T1, eop_sqrt> const eOpCube<T1, eop_sqrt>
sqrt(const BaseCube<typename T1::elem_type,T1>& A) sqrt(const BaseCube<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return eOpCube<T1, eop_sqrt>(A.get_ref()); return eOpCube<T1, eop_sqrt>(A.get_ref());
} }
template<typename T1>
arma_inline
const SpOp<T1, spop_sqrt>
sqrt(const SpBase<typename T1::elem_type,T1>& A)
{
arma_extra_debug_sigprint();
return SpOp<T1, spop_sqrt>(A.get_ref());
}
// //
// conj // conj
template<typename T1> template<typename T1>
arma_inline arma_inline
const T1& const T1&
conj(const Base<typename T1::pod_type,T1>& A) conj(const Base<typename T1::pod_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
 End of changes. 12 change blocks. 
16 lines changed or deleted 55 lines changed or added


 fn_mean.hpp   fn_mean.hpp 
skipping to change at line 104 skipping to change at line 104
template<typename T> template<typename T>
arma_inline arma_inline
arma_warn_unused arma_warn_unused
const typename arma_scalar_only<T>::result & const typename arma_scalar_only<T>::result &
mean(const T& x) mean(const T& x)
{ {
return x; return x;
} }
template<typename T1>
inline
arma_warn_unused
const SpOp<T1, spop_mean>
mean
(
const T1& X,
const uword dim = 0,
const typename enable_if< is_arma_sparse_type<T1>::value == true >
::result* junk1 = 0,
const typename enable_if< resolves_to_sparse_vector<T1>::value == false >
::result* junk2 = 0
)
{
arma_extra_debug_sigprint();
arma_ignore(junk1);
arma_ignore(junk2);
return SpOp<T1, spop_mean>(X, dim, 0);
}
template<typename T1>
inline
arma_warn_unused
const SpOp<T1, spop_mean>
mean
(
const T1& X,
const uword dim,
const typename enable_if< resolves_to_sparse_vector<T1>::value == true >:
:result* junk1 = 0
)
{
arma_extra_debug_sigprint();
arma_ignore(junk1);
return SpOp<T1, spop_mean>(X, dim, 0);
}
template<typename T1>
inline
arma_warn_unused
typename T1::elem_type
mean
(
const T1& X,
const arma_empty_class junk1 = arma_empty_class(),
const typename enable_if< resolves_to_sparse_vector<T1>::value == true >:
:result* junk2 = 0
)
{
arma_extra_debug_sigprint();
arma_ignore(junk1);
arma_ignore(junk2);
return spop_mean::mean_all(X);
}
template<typename T1>
inline
arma_warn_unused
typename T1::elem_type
mean(const SpOp<T1, spop_mean>& in)
{
arma_extra_debug_sigprint();
arma_extra_debug_print("mean(): two consecutive mean() calls detected");
return spop_mean::mean_all(in.m);
}
//! @} //! @}
 End of changes. 1 change blocks. 
0 lines changed or deleted 72 lines changed or added


 fn_norm.hpp   fn_norm.hpp 
skipping to change at line 459 skipping to change at line 459
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
// TODO: this can be sped up with a dedicated implementation // TODO: this can be sped up with a dedicated implementation
return as_scalar( max( sum(abs(P.Q), 1), 0) ); return as_scalar( max( sum(abs(P.Q), 1), 0) );
} }
template<typename T1> template<typename T1>
inline inline
arma_warn_unused arma_warn_unused
typename T1::pod_type typename enable_if2< is_arma_type<T1>::value, typename T1::pod_type >::resu lt
norm norm
( (
const Base<typename T1::elem_type,T1>& X, const T1& X,
const uword k, const uword k,
const typename arma_float_or_cx_only<typename T1::elem_type>::result* jun k = 0 const typename arma_float_or_cx_only<typename T1::elem_type>::result* jun k = 0
) )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_ignore(junk); arma_ignore(junk);
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
typedef typename T1::pod_type T; typedef typename T1::pod_type T;
const Proxy<T1> P(X.get_ref()); const Proxy<T1> P(X);
if(P.get_n_elem() == 0) if(P.get_n_elem() == 0)
{ {
return T(0); return T(0);
} }
const bool is_vec = (P.get_n_rows() == 1) || (P.get_n_cols() == 1); const bool is_vec = (P.get_n_rows() == 1) || (P.get_n_cols() == 1);
if(is_vec == true) if(is_vec == true)
{ {
skipping to change at line 523 skipping to change at line 523
default: default:
arma_stop("norm(): unsupported matrix norm type"); arma_stop("norm(): unsupported matrix norm type");
return T(0); return T(0);
} }
} }
} }
template<typename T1> template<typename T1>
inline inline
arma_warn_unused arma_warn_unused
typename T1::pod_type typename enable_if2< is_arma_type<T1>::value, typename T1::pod_type >::resu lt
norm norm
( (
const Base<typename T1::elem_type,T1>& X, const T1& X,
const char* method, const char* method,
const typename arma_float_or_cx_only<typename T1::elem_type>::result* jun k = 0 const typename arma_float_or_cx_only<typename T1::elem_type>::result* jun k = 0
) )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_ignore(junk); arma_ignore(junk);
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
typedef typename T1::pod_type T; typedef typename T1::pod_type T;
const Proxy<T1> P(X.get_ref()); const Proxy<T1> P(X);
if(P.get_n_elem() == 0) if(P.get_n_elem() == 0)
{ {
return T(0); return T(0);
} }
const char sig = method[0]; const char sig = method[0];
const bool is_vec = (P.get_n_rows() == 1) || (P.get_n_cols() == 1); const bool is_vec = (P.get_n_rows() == 1) || (P.get_n_cols() == 1);
if(is_vec == true) if(is_vec == true)
skipping to change at line 588 skipping to change at line 588
return arma_vec_norm_2(P); return arma_vec_norm_2(P);
} }
else else
{ {
arma_stop("norm(): unsupported matrix norm type"); arma_stop("norm(): unsupported matrix norm type");
return T(0); return T(0);
} }
} }
} }
//
// norms for sparse matrices
template<typename T1>
inline
typename T1::pod_type
arma_mat_norm_1(const SpProxy<T1>& P)
{
arma_extra_debug_sigprint();
// TODO: this can be sped up with a dedicated implementation
return as_scalar( max( sum(abs(P.Q), 0), 1) );
}
// template<typename T1>
// inline
// typename T1::pod_type
// arma_mat_norm_2(const SpProxy<T1>& P)
// {
// arma_extra_debug_sigprint();
//
// // TODO: norm = sqrt( largest eigenvalue of (A^H)*A ), where ^H is the
conjugate transpose
// // TODO: can use ARPACK or directly implement the Arnoldi iteration
// // http://math.stackexchange.com/questions/4368/computing-the-largest-
eigenvalue-of-a-very-large-sparse-matrix
// }
template<typename T1>
inline
typename T1::pod_type
arma_mat_norm_inf(const SpProxy<T1>& P)
{
arma_extra_debug_sigprint();
// TODO: this can be sped up with a dedicated implementation
return as_scalar( max( sum(abs(P.Q), 1), 0) );
}
template<typename T1>
inline
arma_warn_unused
typename enable_if2< is_arma_sparse_type<T1>::value, typename T1::pod_type
>::result
norm
(
const T1& X,
const uword k,
const typename arma_float_or_cx_only<typename T1::elem_type>::result* jun
k = 0
)
{
arma_extra_debug_sigprint();
arma_ignore(junk);
typedef typename T1::elem_type eT;
typedef typename T1::pod_type T;
const SpProxy<T1> P(X);
if(P.get_n_nonzero() == 0)
{
return T(0);
}
const bool is_vec = (P.get_n_rows() == 1) || (P.get_n_cols() == 1);
if(is_vec == true)
{
const unwrap_spmat<typename SpProxy<T1>::stored_type> tmp(P.Q);
const SpMat<eT>& A = tmp.M;
// create a fake dense vector to allow reuse of code for dense vectors
Col<eT> fake_vector( access::rwp(A.values), A.n_nonzero, false );
const Proxy< Col<eT> > P_fake_vector(fake_vector);
switch(k)
{
case 1:
return arma_vec_norm_1(P_fake_vector);
break;
case 2:
return arma_vec_norm_2(P_fake_vector);
break;
default:
{
arma_debug_check( (k == 0), "norm(): k must be greater than zero"
);
return arma_vec_norm_k(P_fake_vector, int(k));
}
}
}
else
{
switch(k)
{
case 1:
return arma_mat_norm_1(P);
break;
// case 2:
// return arma_mat_norm_2(P);
// break;
default:
arma_stop("norm(): unsupported or unimplemented norm type for spars
e matrices");
return T(0);
}
}
}
template<typename T1>
inline
arma_warn_unused
typename enable_if2< is_arma_sparse_type<T1>::value, typename T1::pod_type
>::result
norm
(
const T1& X,
const char* method,
const typename arma_float_or_cx_only<typename T1::elem_type>::result* jun
k = 0
)
{
arma_extra_debug_sigprint();
arma_ignore(junk);
typedef typename T1::elem_type eT;
typedef typename T1::pod_type T;
const SpProxy<T1> P(X);
if(P.get_n_nonzero() == 0)
{
return T(0);
}
const unwrap_spmat<typename SpProxy<T1>::stored_type> tmp(P.Q);
const SpMat<eT>& A = tmp.M;
// create a fake dense vector to allow reuse of code for dense vectors
Col<eT> fake_vector( access::rwp(A.values), A.n_nonzero, false );
const Proxy< Col<eT> > P_fake_vector(fake_vector);
const char sig = method[0];
const bool is_vec = (P.get_n_rows() == 1) || (P.get_n_cols() == 1);
if(is_vec == true)
{
if( (sig == 'i') || (sig == 'I') || (sig == '+') ) // max norm
{
return arma_vec_norm_max(P_fake_vector);
}
else
if(sig == '-') // min norm
{
const T val = arma_vec_norm_min(P_fake_vector);
if( P.get_n_nonzero() < P.get_n_elem() )
{
return (std::min)(T(0), val);
}
else
{
return val;
}
}
else
if( (sig == 'f') || (sig == 'F') )
{
return arma_vec_norm_2(P_fake_vector);
}
else
{
arma_stop("norm(): unsupported vector norm type");
return T(0);
}
}
else
{
if( (sig == 'i') || (sig == 'I') || (sig == '+') ) // inf norm
{
return arma_mat_norm_inf(P);
}
else
if( (sig == 'f') || (sig == 'F') )
{
return arma_vec_norm_2(P_fake_vector);
}
else
{
arma_stop("norm(): unsupported matrix norm type");
return T(0);
}
}
}
//! @} //! @}
 End of changes. 7 change blocks. 
6 lines changed or deleted 208 lines changed or added


 fn_sort.hpp   fn_sort.hpp 
// Copyright (C) 2008-2010 NICTA (www.nicta.com.au) // Copyright (C) 2008-2010 NICTA (www.nicta.com.au)
// Copyright (C) 2008-2010 Conrad Sanderson // Copyright (C) 2008-2012 Conrad Sanderson
// //
// This file is part of the Armadillo C++ library. // This file is part of the Armadillo C++ library.
// It is provided without any warranty of fitness // It is provided without any warranty of fitness
// for any purpose. You can redistribute this file // for any purpose. You can redistribute this file
// and/or modify it under the terms of the GNU // and/or modify it under the terms of the GNU
// Lesser General Public License (LGPL) as published // Lesser General Public License (LGPL) as published
// by the Free Software Foundation, either version 3 // by the Free Software Foundation, either version 3
// of the License or (at your option) any later version. // of the License or (at your option) any later version.
// (see http://www.opensource.org/licenses for more info) // (see http://www.opensource.org/licenses for more info)
//! \addtogroup fn_sort //! \addtogroup fn_sort
//! @{ //! @{
template<typename T1> template<typename T1>
arma_inline arma_inline
const Op<T1, op_sort> typename
sort(const Base<typename T1::elem_type,T1>& X, const uword sort_type = 0, c enable_if2
onst uword dim = 0) <
( (is_arma_type<T1>::value == true) && (resolves_to_vector<T1>::value ==
false) ),
const Op<T1, op_sort>
>::result
sort
(
const T1& X,
const uword sort_type = 0,
const uword dim = 0
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_sort>(X.get_ref(), sort_type, dim); return Op<T1, op_sort>(X, sort_type, dim);
} }
template<typename eT> template<typename T1>
arma_inline
const Op<Col<eT>, op_sort>
sort(const Col<eT>& X, const uword sort_type = 0)
{
arma_extra_debug_sigprint();
const uword dim = 0;
return Op<Col<eT>, op_sort>(X, sort_type, dim);
}
template<typename eT>
arma_inline arma_inline
const Op<Row<eT>, op_sort> typename
sort(const Row<eT>& X, const uword sort_type = 0) enable_if2
<
( (is_arma_type<T1>::value == true) && (resolves_to_vector<T1>::value ==
true) ),
const Op<T1, op_sort>
>::result
sort
(
const T1& X,
const uword sort_type = 0
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const uword dim = 1; const uword dim = (T1::is_col) ? 0 : 1;
return Op<Row<eT>, op_sort>(X, sort_type, dim); return Op<T1, op_sort>(X, sort_type, dim);
} }
//! @} //! @}
 End of changes. 7 change blocks. 
22 lines changed or deleted 30 lines changed or added


 fn_sort_index.hpp   fn_sort_index.hpp 
skipping to change at line 17 skipping to change at line 17
// and/or modify it under the terms of the GNU // and/or modify it under the terms of the GNU
// Lesser General Public License (LGPL) as published // Lesser General Public License (LGPL) as published
// by the Free Software Foundation, either version 3 // by the Free Software Foundation, either version 3
// of the License or (at your option) any later version. // of the License or (at your option) any later version.
// (see http://www.opensource.org/licenses for more info) // (see http://www.opensource.org/licenses for more info)
//! \addtogroup fn_sort_index //! \addtogroup fn_sort_index
//! @{ //! @{
template<typename T1, typename T2> template<typename T1, typename T2>
struct arma_sort_index_packet_ascend struct arma_sort_index_packet
{ {
T1 val; T1 val;
T2 index; T2 index;
}; };
template<typename T1, typename T2> class arma_sort_index_helper_ascend
struct arma_sort_index_packet_descend
{ {
T1 val; public:
T2 index;
template<typename T1, typename T2>
arma_inline
bool
operator() (const arma_sort_index_packet<T1,T2>& A, const arma_sort_index
_packet<T1,T2>& B) const
{
return (A.val < B.val);
}
}; };
template<typename T1, typename T2> class arma_sort_index_helper_descend
inline
bool
operator< (const arma_sort_index_packet_ascend<T1,T2>& A, const arma_sort_i
ndex_packet_ascend<T1,T2>& B)
{ {
return A.val < B.val; public:
}
template<typename T1, typename T2> template<typename T1, typename T2>
inline arma_inline
bool bool
operator< (const arma_sort_index_packet_descend<T1,T2>& A, const arma_sort_ operator() (const arma_sort_index_packet<T1,T2>& A, const arma_sort_index
index_packet_descend<T1,T2>& B) _packet<T1,T2>& B) const
{ {
return A.val > B.val; return (A.val > B.val);
} }
};
template<typename umat_elem_type, typename packet_type, typename eT> template<typename umat_elem_type, typename eT, const uword sort_direction, const uword sort_type>
void void
inline inline
sort_index_helper(umat_elem_type* out_mem, std::vector<packet_type>& packet _vec, const eT* in_mem) sort_index_helper(umat_elem_type* out_mem, const eT* in_mem, const uword n_ elem)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const uword n_elem = packet_vec.size(); std::vector< arma_sort_index_packet<eT, umat_elem_type> > packet_vec(n_el em);
for(uword i=0; i<n_elem; ++i) for(uword i=0; i<n_elem; ++i)
{ {
packet_vec[i].val = in_mem[i]; packet_vec[i].val = in_mem[i];
packet_vec[i].index = i; packet_vec[i].index = i;
} }
std::sort( packet_vec.begin(), packet_vec.end() ); if(sort_direction == 0)
{
// ascend
arma_sort_index_helper_ascend comparator;
if(sort_type == 0)
{
std::sort( packet_vec.begin(), packet_vec.end(), comparator );
}
else
{
std::stable_sort( packet_vec.begin(), packet_vec.end(), comparator );
}
}
else
{
// descend
arma_sort_index_helper_descend comparator;
if(sort_type == 0)
{
std::sort( packet_vec.begin(), packet_vec.end(), comparator );
}
else
{
std::stable_sort( packet_vec.begin(), packet_vec.end(), comparator );
}
}
for(uword i=0; i<n_elem; ++i) for(uword i=0; i<n_elem; ++i)
{ {
out_mem[i] = packet_vec[i].index; out_mem[i] = packet_vec[i].index;
} }
} }
template<typename T1> template<typename T1>
inline inline
umat umat
sort_index sort_index
( (
const Base<typename T1::elem_type,T1>& X, const Base<typename T1::elem_type,T1>& X,
const uword sort_type = 0, const uword sort_direction = 0,
const typename arma_not_cx<typename T1::elem_type>::result* junk = 0 const typename arma_not_cx<typename T1::elem_type>::result* junk = 0
) )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_ignore(junk);
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
const unwrap<T1> tmp(X.get_ref()); const unwrap<T1> tmp(X.get_ref());
const Mat<eT>& A = tmp.M; const Mat<eT>& A = tmp.M;
if(A.is_empty() == true) if(A.is_empty() == true)
{ {
return umat(); return umat();
} }
arma_debug_check( (A.is_vec() == false), "sort_index(): currently only ha ndles vectors"); arma_debug_check( (A.is_vec() == false), "sort_index(): currently only ha ndles vectors");
typedef typename umat::elem_type out_elem_type; typedef typename umat::elem_type out_elem_type;
umat out(A.n_rows, A.n_cols); umat out(A.n_rows, A.n_cols);
if(sort_type == 0) if(sort_direction == 0)
{ {
std::vector< arma_sort_index_packet_ascend<eT,out_elem_type> > packet_v sort_index_helper<out_elem_type, eT, 0, 0>(out.memptr(), A.mem, A.n_ele
ec(A.n_elem); m);
sort_index_helper(out.memptr(), packet_vec, A.mem);
} }
else else
{ {
std::vector< arma_sort_index_packet_descend<eT,out_elem_type> > packet_ sort_index_helper<out_elem_type, eT, 1, 0>(out.memptr(), A.mem, A.n_ele
vec(A.n_elem); m);
}
return out;
}
sort_index_helper(out.memptr(), packet_vec, A.mem); template<typename T1>
inline
umat
stable_sort_index
(
const Base<typename T1::elem_type,T1>& X,
const uword sort_direction = 0,
const typename arma_not_cx<typename T1::elem_type>::result* junk = 0
)
{
arma_extra_debug_sigprint();
arma_ignore(junk);
typedef typename T1::elem_type eT;
const unwrap<T1> tmp(X.get_ref());
const Mat<eT>& A = tmp.M;
if(A.is_empty() == true)
{
return umat();
}
arma_debug_check( (A.is_vec() == false), "stable_sort_index(): currently
only handles vectors");
typedef typename umat::elem_type out_elem_type;
umat out(A.n_rows, A.n_cols);
if(sort_direction == 0)
{
sort_index_helper<out_elem_type, eT, 0, 1>(out.memptr(), A.mem, A.n_ele
m);
}
else
{
sort_index_helper<out_elem_type, eT, 1, 1>(out.memptr(), A.mem, A.n_ele
m);
} }
return out; return out;
} }
//! @} //! @}
 End of changes. 16 change blocks. 
33 lines changed or deleted 106 lines changed or added


 fn_strans.hpp   fn_strans.hpp 
skipping to change at line 69 skipping to change at line 69
arma_extra_debug_print("strans(): removing op_strans"); arma_extra_debug_print("strans(): removing op_strans");
return X.m; return X.m;
} }
// //
// handling of sparse matrices // handling of sparse matrices
template<typename T1> template<typename T1>
inline inline
const SpOp<T1,spop_strans> typename
strans(const SpBase<typename T1::elem_type, T1>& x) enable_if2
<
is_arma_sparse_type<T1>::value,
const SpOp<T1,spop_strans>
>::result
strans(const T1& x)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return SpOp<T1,spop_strans>( x.get_ref() ); return SpOp<T1,spop_strans>(x);
} }
//! @} //! @}
 End of changes. 2 change blocks. 
3 lines changed or deleted 8 lines changed or added


 fn_trans.hpp   fn_trans.hpp 
skipping to change at line 74 skipping to change at line 74
arma_extra_debug_print("htrans(): removing op_htrans"); arma_extra_debug_print("htrans(): removing op_htrans");
return X.m; return X.m;
} }
// //
// handling of sparse matrices // handling of sparse matrices
template<typename T1> template<typename T1>
inline inline
const SpOp<T1,spop_strans> typename
enable_if2
<
is_arma_sparse_type<T1>::value,
const SpOp<T1,spop_strans>
>::result
trans trans
( (
const SpBase<typename T1::elem_type, T1>& x, const T1& x,
const typename arma_not_cx<typename T1::elem_type>::result* junk = 0 const typename arma_not_cx<typename T1::elem_type>::result* junk = 0
) )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_ignore(junk); arma_ignore(junk);
return SpOp<T1,spop_strans>( x.get_ref() ); return SpOp<T1,spop_strans>(x);
} }
template<typename T1> template<typename T1>
inline inline
const SpOp<T1,spop_htrans> typename
enable_if2
<
is_arma_sparse_type<T1>::value,
const SpOp<T1,spop_htrans>
>::result
trans trans
( (
const SpBase<typename T1::elem_type, T1>& x, const T1& x,
const typename arma_cx_only<typename T1::elem_type>::result* junk = 0 const typename arma_cx_only<typename T1::elem_type>::result* junk = 0
) )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_ignore(junk); arma_ignore(junk);
return SpOp<T1,spop_htrans>( x.get_ref() ); return SpOp<T1,spop_htrans>(x);
} }
template<typename T1> template<typename T1>
inline inline
const SpOp<T1,spop_strans> typename
enable_if2
<
is_arma_sparse_type<T1>::value,
const SpOp<T1,spop_strans>
>::result
htrans htrans
( (
const SpBase<typename T1::elem_type, T1>& x, const T1& x,
const typename arma_not_cx<typename T1::elem_type>::result* junk = 0 const typename arma_not_cx<typename T1::elem_type>::result* junk = 0
) )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_ignore(junk); arma_ignore(junk);
return SpOp<T1,spop_strans>( x.get_ref() ); return SpOp<T1,spop_strans>(x);
} }
template<typename T1> template<typename T1>
inline inline
const SpOp<T1,spop_htrans> typename
enable_if2
<
is_arma_sparse_type<T1>::value,
const SpOp<T1,spop_htrans>
>::result
htrans htrans
( (
const SpBase<typename T1::elem_type, T1>& x, const T1& x,
const typename arma_cx_only<typename T1::elem_type>::result* junk = 0 const typename arma_cx_only<typename T1::elem_type>::result* junk = 0
) )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_ignore(junk); arma_ignore(junk);
return SpOp<T1,spop_htrans>( x.get_ref() ); return SpOp<T1,spop_htrans>(x);
} }
//! @} //! @}
 End of changes. 12 change blocks. 
12 lines changed or deleted 32 lines changed or added


 fn_trunc_exp.hpp   fn_trunc_exp.hpp 
// Copyright (C) 2008-2010 NICTA (www.nicta.com.au) // Copyright (C) 2008-2010 NICTA (www.nicta.com.au)
// Copyright (C) 2008-2010 Conrad Sanderson // Copyright (C) 2008-2012 Conrad Sanderson
// //
// This file is part of the Armadillo C++ library. // This file is part of the Armadillo C++ library.
// It is provided without any warranty of fitness // It is provided without any warranty of fitness
// for any purpose. You can redistribute this file // for any purpose. You can redistribute this file
// and/or modify it under the terms of the GNU // and/or modify it under the terms of the GNU
// Lesser General Public License (LGPL) as published // Lesser General Public License (LGPL) as published
// by the Free Software Foundation, either version 3 // by the Free Software Foundation, either version 3
// of the License or (at your option) any later version. // of the License or (at your option) any later version.
// (see http://www.opensource.org/licenses for more info) // (see http://www.opensource.org/licenses for more info)
skipping to change at line 42 skipping to change at line 42
template<typename eT> template<typename eT>
inline inline
static static
typename arma_integral_only<eT>::result typename arma_integral_only<eT>::result
trunc_exp(const eT x) trunc_exp(const eT x)
{ {
return eT( trunc_exp( double(x) ) ); return eT( trunc_exp( double(x) ) );
} }
template<typename T> template<typename T>
arma_inline inline
static static
std::complex<T> std::complex<T>
trunc_exp(const std::complex<T>& x) trunc_exp(const std::complex<T>& x)
{ {
return std::exp(x); return std::polar( trunc_exp( x.real() ), x.imag() );
} }
template<typename T1> template<typename T1>
arma_inline arma_inline
const eOp<T1, eop_trunc_exp> const eOp<T1, eop_trunc_exp>
trunc_exp(const Base<typename T1::elem_type,T1>& A) trunc_exp(const Base<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return eOp<T1, eop_trunc_exp>(A.get_ref()); return eOp<T1, eop_trunc_exp>(A.get_ref());
 End of changes. 3 change blocks. 
3 lines changed or deleted 3 lines changed or added


 fn_trunc_log.hpp   fn_trunc_log.hpp 
// Copyright (C) 2008-2010 NICTA (www.nicta.com.au) // Copyright (C) 2008-2010 NICTA (www.nicta.com.au)
// Copyright (C) 2008-2010 Conrad Sanderson // Copyright (C) 2008-2012 Conrad Sanderson
// //
// This file is part of the Armadillo C++ library. // This file is part of the Armadillo C++ library.
// It is provided without any warranty of fitness // It is provided without any warranty of fitness
// for any purpose. You can redistribute this file // for any purpose. You can redistribute this file
// and/or modify it under the terms of the GNU // and/or modify it under the terms of the GNU
// Lesser General Public License (LGPL) as published // Lesser General Public License (LGPL) as published
// by the Free Software Foundation, either version 3 // by the Free Software Foundation, either version 3
// of the License or (at your option) any later version. // of the License or (at your option) any later version.
// (see http://www.opensource.org/licenses for more info) // (see http://www.opensource.org/licenses for more info)
skipping to change at line 54 skipping to change at line 54
{ {
return eT( trunc_log( double(x) ) ); return eT( trunc_log( double(x) ) );
} }
template<typename T> template<typename T>
inline inline
static static
std::complex<T> std::complex<T>
trunc_log(const std::complex<T>& x) trunc_log(const std::complex<T>& x)
{ {
return std::log(x); return std::complex<T>( trunc_log( std::abs(x) ), std::arg(x) );
} }
template<typename T1> template<typename T1>
arma_inline arma_inline
const eOp<T1, eop_trunc_log> const eOp<T1, eop_trunc_log>
trunc_log(const Base<typename T1::elem_type,T1>& A) trunc_log(const Base<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return eOp<T1, eop_trunc_log>(A.get_ref()); return eOp<T1, eop_trunc_log>(A.get_ref());
 End of changes. 2 change blocks. 
2 lines changed or deleted 2 lines changed or added


 fn_var.hpp   fn_var.hpp 
skipping to change at line 80 skipping to change at line 80
template<typename T> template<typename T>
arma_inline arma_inline
arma_warn_unused arma_warn_unused
const typename arma_scalar_only<T>::result const typename arma_scalar_only<T>::result
var(const T&) var(const T&)
{ {
return T(0); return T(0);
} }
template<typename T1>
inline
const mtSpOp<typename T1::pod_type, T1, spop_var>
var
(
const T1& X,
const uword norm_type = 0,
const uword dim = 0,
const typename enable_if< is_arma_sparse_type<T1>::value == true >
::result* junk1 = 0,
const typename enable_if< resolves_to_sparse_vector<T1>::value == false >
::result* junk2 = 0
)
{
arma_extra_debug_sigprint();
arma_ignore(junk1);
arma_ignore(junk2);
return mtSpOp<typename T1::pod_type, T1, spop_var>(X, norm_type, dim);
}
template<typename T1>
inline
const mtSpOp<typename T1::pod_type, T1, spop_var>
var
(
const T1& X,
const uword norm_type,
const uword dim = 0,
const typename enable_if<resolves_to_sparse_vector<T1>::value == true>::r
esult* junk1 = 0
)
{
arma_extra_debug_sigprint();
arma_ignore(junk1);
return mtSpOp<typename T1::pod_type, T1, spop_var>(X, norm_type, dim);
}
template<typename T1>
inline
typename T1::pod_type
var
(
const T1& X,
const uword norm_type = 0,
const arma_empty_class junk1 = arma_empty_class(),
const typename enable_if<resolves_to_sparse_vector<T1>::value == true>::r
esult* junk2 = 0
)
{
arma_extra_debug_sigprint();
arma_ignore(junk1);
arma_ignore(junk2);
return spop_var::var_vec(X, norm_type);
}
//! @} //! @}
 End of changes. 1 change blocks. 
0 lines changed or deleted 58 lines changed or added


 forward_bones.hpp   forward_bones.hpp 
skipping to change at line 150 skipping to change at line 150
class spglue_plus; class spglue_plus;
class spglue_plus2; class spglue_plus2;
class spglue_minus; class spglue_minus;
class spglue_minus2; class spglue_minus2;
class spglue_times; class spglue_times;
class spglue_times2; class spglue_times2;
template<typename T1, typename spop_type > class SpOp; template< typename T1, typename spop_type> class SpOp;
template<typename out_eT, typename T1, typename spop_type> class mtSpOp;
template<typename T1, typename T2, typename spglue_type> class SpGlue; template<typename T1, typename T2, typename spglue_type> class SpGlue;
template<typename T1> class SpProxy; template<typename T1> class SpProxy;
struct arma_vec_indicator {}; struct arma_vec_indicator {};
struct arma_fixed_indicator {}; struct arma_fixed_indicator {};
//! \addtogroup injector //! \addtogroup injector
//! @{ //! @{
skipping to change at line 175 skipping to change at line 177
//!< similar conceptual meaning to std::endl //!< similar conceptual meaning to std::endl
//! @} //! @}
//! \addtogroup diskio //! \addtogroup diskio
//! @{ //! @{
enum file_type enum file_type
{ {
file_type_unknown, file_type_unknown,
auto_detect, //!< Automatically detect the file type (file must be one o f the following types) auto_detect, //!< Automatically detect the file type
raw_ascii, //!< ASCII format (text), without any other information. raw_ascii, //!< ASCII format (text), without any other information.
arma_ascii, //!< Armadillo ASCII format (text), with information about matrix type and size arma_ascii, //!< Armadillo ASCII format (text), with information about matrix type and size
csv_ascii, //!< comma separated values (CSV), without any other inform ation csv_ascii, //!< comma separated values (CSV), without any other inform ation
raw_binary, //!< raw binary format, without any other information. raw_binary, //!< raw binary format, without any other information.
arma_binary, //!< Armadillo binary format, with information about matrix type and size arma_binary, //!< Armadillo binary format, with information about matrix type and size
pgm_binary, //!< Portable Grey Map (greyscale image) pgm_binary, //!< Portable Grey Map (greyscale image)
ppm_binary, //!< Portable Pixel Map (colour image), used by the field a nd cube classes ppm_binary, //!< Portable Pixel Map (colour image), used by the field a nd cube classes
hdf5_binary //!< Open binary format, not specific to Armadillo, which c hdf5_binary, //!< Open binary format, not specific to Armadillo, which c
an store arbitrary data an store arbitrary data
coord_ascii //!< simple co-ordinate format for sparse matrices
}; };
//! @} //! @}
 End of changes. 3 change blocks. 
4 lines changed or deleted 7 lines changed or added


 glue_relational_meat.hpp   glue_relational_meat.hpp 
skipping to change at line 66 skipping to change at line 66
{\ {\
if(n_rows == 1)\ if(n_rows == 1)\
{\ {\
for(uword count=0; count < n_cols; ++count)\ for(uword count=0; count < n_cols; ++count)\
{\ {\
out_mem[count] = (P1.at(0,count) operator_rel P2.at(0,count)) ? u word(1) : uword(0);\ out_mem[count] = (P1.at(0,count) operator_rel P2.at(0,count)) ? u word(1) : uword(0);\
}\ }\
}\ }\
else\ else\
{\ {\
uword count = 0;\
\
for(uword col=0; col<n_cols; ++col)\ for(uword col=0; col<n_cols; ++col)\
for(uword row=0; row<n_rows; ++row, ++count)\ for(uword row=0; row<n_rows; ++row)\
{\ {\
out_mem[count] = (P1.at(row,col) operator_rel P2.at(row,col)) ? u *out_mem = (P1.at(row,col) operator_rel P2.at(row,col)) ? uword(1
word(1) : uword(0);\ ) : uword(0);\
out_mem++;\
}\ }\
}\ }\
}\ }\
}\ }\
else\ else\
{\ {\
const unwrap_check<typename Proxy<T1>::stored_type> tmp1(P1.Q, P1.is_al ias(out));\ const unwrap_check<typename Proxy<T1>::stored_type> tmp1(P1.Q, P1.is_al ias(out));\
const unwrap_check<typename Proxy<T2>::stored_type> tmp2(P2.Q, P2.is_al ias(out));\ const unwrap_check<typename Proxy<T2>::stored_type> tmp2(P2.Q, P2.is_al ias(out));\
\ \
out = (tmp1.M) operator_rel (tmp2.M);\ out = (tmp1.M) operator_rel (tmp2.M);\
skipping to change at line 121 skipping to change at line 120
\ \
const uword n_elem = out.n_elem;\ const uword n_elem = out.n_elem;\
\ \
for(uword i=0; i<n_elem; ++i)\ for(uword i=0; i<n_elem; ++i)\
{\ {\
out_mem[i] = (A[i] operator_rel B[i]) ? uword(1) : uword(0);\ out_mem[i] = (A[i] operator_rel B[i]) ? uword(1) : uword(0);\
}\ }\
}\ }\
else\ else\
{\ {\
uword count = 0;\
\
for(uword slice = 0; slice < n_slices; ++slice)\ for(uword slice = 0; slice < n_slices; ++slice)\
for(uword col = 0; col < n_cols; ++col)\ for(uword col = 0; col < n_cols; ++col )\
for(uword row = 0; row < n_rows; ++row, ++count)\ for(uword row = 0; row < n_rows; ++row )\
{\ {\
out_mem[count] = (P1.at(row,col,slice) operator_rel P2.at(row,col,s *out_mem = (P1.at(row,col,slice) operator_rel P2.at(row,col,slice))
lice)) ? uword(1) : uword(0);\ ? uword(1) : uword(0);\
out_mem++;\
}\ }\
}\ }\
}\ }\
else\ else\
{\ {\
const unwrap_cube<typename ProxyCube<T1>::stored_type> tmp1(P1.Q);\ const unwrap_cube<typename ProxyCube<T1>::stored_type> tmp1(P1.Q);\
const unwrap_cube<typename ProxyCube<T2>::stored_type> tmp2(P2.Q);\ const unwrap_cube<typename ProxyCube<T2>::stored_type> tmp2(P2.Q);\
\ \
out = (tmp1.M) operator_rel (tmp2.M);\ out = (tmp1.M) operator_rel (tmp2.M);\
}\ }\
 End of changes. 6 change blocks. 
11 lines changed or deleted 9 lines changed or added


 hdf5_misc.hpp   hdf5_misc.hpp 
skipping to change at line 316 skipping to change at line 316
for (uword i = 0; i < str.length(); ++i) for (uword i = 0; i < str.length(); ++i)
{ {
if (str[i] == '/') { ++count; } if (str[i] == '/') { ++count; }
} }
// If we are asking for more slashes than we have, this can't be a ma tch. // If we are asking for more slashes than we have, this can't be a ma tch.
// Skip to below, where we decide whether or not to keep it anyway ba sed // Skip to below, where we decide whether or not to keep it anyway ba sed
// on the exactness condition of the search. // on the exactness condition of the search.
if (count <= name_count) if (count <= name_count)
{ {
uword start_pos = (count == 0) ? 0 : std::string::npos; size_t start_pos = (count == 0) ? 0 : std::string::npos;
while (count > 0) while (count > 0)
{ {
// Move pointer to previous slash. // Move pointer to previous slash.
start_pos = str.rfind('/', start_pos); start_pos = str.rfind('/', start_pos);
// Break if we've run out of slashes. // Break if we've run out of slashes.
if (start_pos == std::string::npos) { break; } if (start_pos == std::string::npos) { break; }
--count; --count;
} }
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 memory.hpp   memory.hpp 
skipping to change at line 20 skipping to change at line 20
// of the License or (at your option) any later version. // of the License or (at your option) any later version.
// (see http://www.opensource.org/licenses for more info) // (see http://www.opensource.org/licenses for more info)
//! \addtogroup memory //! \addtogroup memory
//! @{ //! @{
class memory class memory
{ {
public: public:
arma_inline static uword enlarge_to_mult_of_chunksi ze(const uword n_elem); arma_inline static uword enlarge_to_mul t_of_chunksize(const uword n_elem);
template<typename eT> arma_inline static eT* acquire(const uword n_elem ); template<typename eT> arma_inline arma_malloc static eT* acquire(const uword n_elem);
template<typename eT> arma_inline static eT* acquire_chunked(const uwor d n_elem); template<typename eT> arma_inline arma_malloc static eT* acquire_chunke d(const uword n_elem);
template<typename eT> arma_inline static void release(eT* mem); template<typename eT> arma_inline static void release(eT* me m);
}; };
arma_inline arma_inline
uword uword
memory::enlarge_to_mult_of_chunksize(const uword n_elem) memory::enlarge_to_mult_of_chunksize(const uword n_elem)
{ {
const uword chunksize = arma_config::spmat_chunksize; const uword chunksize = arma_config::spmat_chunksize;
// this relies on integer division // this relies on integer division
const uword n_elem_mod = ((n_elem % chunksize) != 0) ? ((n_elem / chunksi ze) + 1) * chunksize : n_elem; const uword n_elem_mod = ((n_elem % chunksize) != 0) ? ((n_elem / chunksi ze) + 1) * chunksize : n_elem;
return n_elem_mod; return n_elem_mod;
} }
template<typename eT> template<typename eT>
arma_inline arma_inline
arma_malloc
eT* eT*
memory::acquire(const uword n_elem) memory::acquire(const uword n_elem)
{ {
#if defined(ARMA_USE_TBB_ALLOC) #if defined(ARMA_USE_TBB_ALLOC)
{ {
return ( (eT *) scalable_malloc( sizeof(eT)*n_elem) ); return ( (eT *) scalable_malloc( sizeof(eT)*n_elem) );
} }
#elif defined(ARMA_USE_MKL_ALLOC) #elif defined(ARMA_USE_MKL_ALLOC)
{ {
return ( (eT *) mkl_malloc( sizeof(eT)*n_elem, 128 ) ); return ( (eT *) mkl_malloc( sizeof(eT)*n_elem, 128 ) );
skipping to change at line 64 skipping to change at line 65
#else #else
{ {
return ( new(std::nothrow) eT[n_elem] ); return ( new(std::nothrow) eT[n_elem] );
} }
#endif #endif
} }
//! get memory in multiples of chunks, holding at least n_elem //! get memory in multiples of chunks, holding at least n_elem
template<typename eT> template<typename eT>
arma_inline arma_inline
arma_malloc
eT* eT*
memory::acquire_chunked(const uword n_elem) memory::acquire_chunked(const uword n_elem)
{ {
const uword n_elem_mod = memory::enlarge_to_mult_of_chunksize(n_elem); const uword n_elem_mod = memory::enlarge_to_mult_of_chunksize(n_elem);
return memory::acquire<eT>(n_elem_mod); return memory::acquire<eT>(n_elem_mod);
} }
template<typename eT> template<typename eT>
arma_inline arma_inline
 End of changes. 6 change blocks. 
4 lines changed or deleted 6 lines changed or added


 op_median_bones.hpp   op_median_bones.hpp 
skipping to change at line 19 skipping to change at line 19
// by the Free Software Foundation, either version 3 // by the Free Software Foundation, either version 3
// of the License or (at your option) any later version. // of the License or (at your option) any later version.
// (see http://www.opensource.org/licenses for more info) // (see http://www.opensource.org/licenses for more info)
//! \addtogroup op_median //! \addtogroup op_median
//! @{ //! @{
template<typename T> template<typename T>
struct arma_cx_median_packet struct arma_cx_median_packet
{ {
T val; T val;
uword index; uword index;
}; };
template<typename T> template<typename T>
arma_inline arma_inline
bool bool
operator< (const arma_cx_median_packet<T>& A, const arma_cx_median_packet<T >& B) operator< (const arma_cx_median_packet<T>& A, const arma_cx_median_packet<T >& B)
{ {
return A.val < B.val; return A.val < B.val;
} }
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 op_misc_meat.hpp   op_misc_meat.hpp 
skipping to change at line 48 skipping to change at line 48
const uword n_elem = P.get_n_elem(); const uword n_elem = P.get_n_elem();
ea_type A = P.get_ea(); ea_type A = P.get_ea();
for(uword i=0; i < n_elem; ++i) for(uword i=0; i < n_elem; ++i)
{ {
out_mem[i] = std::real( A[i] ); out_mem[i] = std::real( A[i] );
} }
} }
else else
{ {
uword count = 0;
for(uword col=0; col < n_cols; ++col) for(uword col=0; col < n_cols; ++col)
for(uword row=0; row < n_rows; ++row, ++count) for(uword row=0; row < n_rows; ++row)
{ {
out_mem[count] = std::real( P.at(row,col) ); *out_mem = std::real( P.at(row,col) );
out_mem++;
} }
} }
} }
template<typename T1> template<typename T1>
inline inline
void void
op_real::apply( Cube<typename T1::pod_type>& out, const mtOpCube<typename T 1::pod_type, T1, op_real>& X ) op_real::apply( Cube<typename T1::pod_type>& out, const mtOpCube<typename T 1::pod_type, T1, op_real>& X )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::pod_type T; typedef typename T1::pod_type T;
const ProxyCube<T1> A(X.m); const ProxyCube<T1> P(X.m);
const uword n_rows = P.get_n_rows();
const uword n_cols = P.get_n_cols();
const uword n_slices = P.get_n_slices();
out.set_size(n_rows, n_cols, n_slices);
out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices()); T* out_mem = out.memptr();
if(ProxyCube<T1>::prefer_at_accessor == false)
{
typedef typename ProxyCube<T1>::ea_type ea_type;
const uword n_elem = out.n_elem; const uword n_elem = P.get_n_elem();
T* out_mem = out.memptr(); ea_type A = P.get_ea();
for(uword i=0; i<n_elem; ++i) for(uword i=0; i < n_elem; ++i)
{
out_mem[i] = std::real( A[i] );
}
}
else
{ {
out_mem[i] = std::real(A[i]); 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 = std::real( P.at(row,col,slice) );
out_mem++;
}
} }
} }
template<typename T1> template<typename T1>
inline inline
void void
op_imag::apply( Mat<typename T1::pod_type>& out, const mtOp<typename T1::po d_type, T1, op_imag>& X ) op_imag::apply( Mat<typename T1::pod_type>& out, const mtOp<typename T1::po d_type, T1, op_imag>& X )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
skipping to change at line 112 skipping to change at line 132
const uword n_elem = P.get_n_elem(); const uword n_elem = P.get_n_elem();
ea_type A = P.get_ea(); ea_type A = P.get_ea();
for(uword i=0; i < n_elem; ++i) for(uword i=0; i < n_elem; ++i)
{ {
out_mem[i] = std::imag( A[i] ); out_mem[i] = std::imag( A[i] );
} }
} }
else else
{ {
uword count = 0;
for(uword col=0; col < n_cols; ++col) for(uword col=0; col < n_cols; ++col)
for(uword row=0; row < n_rows; ++row, ++count) for(uword row=0; row < n_rows; ++row)
{ {
out_mem[count] = std::imag( P.at(row,col) ); *out_mem = std::imag( P.at(row,col) );
out_mem++;
} }
} }
} }
template<typename T1> template<typename T1>
inline inline
void void
op_imag::apply( Cube<typename T1::pod_type>& out, const mtOpCube<typename T 1::pod_type, T1, op_imag>& X ) op_imag::apply( Cube<typename T1::pod_type>& out, const mtOpCube<typename T 1::pod_type, T1, op_imag>& X )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::pod_type T; typedef typename T1::pod_type T;
const ProxyCube<T1> A(X.m); const ProxyCube<T1> P(X.m);
const uword n_rows = P.get_n_rows();
const uword n_cols = P.get_n_cols();
const uword n_slices = P.get_n_slices();
out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices()); out.set_size(n_rows, n_cols, n_slices);
const uword n_elem = out.n_elem; T* out_mem = out.memptr();
T* out_mem = out.memptr();
if(ProxyCube<T1>::prefer_at_accessor == false)
{
typedef typename ProxyCube<T1>::ea_type ea_type;
const uword n_elem = P.get_n_elem();
ea_type A = P.get_ea();
for(uword i=0; i<n_elem; ++i) for(uword i=0; i < n_elem; ++i)
{
out_mem[i] = std::imag( A[i] );
}
}
else
{ {
out_mem[i] = std::imag(A[i]); 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 = std::imag( P.at(row,col,slice) );
out_mem++;
}
} }
} }
template<typename T1> template<typename T1>
inline inline
void void
op_abs::apply( Mat<typename T1::pod_type>& out, const mtOp<typename T1::pod _type, T1, op_abs>& X ) op_abs::apply( Mat<typename T1::pod_type>& out, const mtOp<typename T1::pod _type, T1, op_abs>& X )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
skipping to change at line 176 skipping to change at line 216
const uword n_elem = P.get_n_elem(); const uword n_elem = P.get_n_elem();
ea_type A = P.get_ea(); ea_type A = P.get_ea();
for(uword i=0; i < n_elem; ++i) for(uword i=0; i < n_elem; ++i)
{ {
out_mem[i] = std::abs( A[i] ); out_mem[i] = std::abs( A[i] );
} }
} }
else else
{ {
uword count = 0;
for(uword col=0; col < n_cols; ++col) for(uword col=0; col < n_cols; ++col)
for(uword row=0; row < n_rows; ++row, ++count) for(uword row=0; row < n_rows; ++row)
{ {
out_mem[count] = std::abs( P.at(row,col) ); *out_mem = std::abs( P.at(row,col) );
out_mem++;
} }
} }
} }
template<typename T1> template<typename T1>
inline inline
void void
op_abs::apply( Cube<typename T1::pod_type>& out, const mtOpCube<typename T1 ::pod_type, T1, op_abs>& X ) op_abs::apply( Cube<typename T1::pod_type>& out, const mtOpCube<typename T1 ::pod_type, T1, op_abs>& X )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::pod_type T; typedef typename T1::pod_type T;
const ProxyCube<T1> A(X.m); const ProxyCube<T1> P(X.m);
const uword n_rows = P.get_n_rows();
const uword n_cols = P.get_n_cols();
const uword n_slices = P.get_n_slices();
out.set_size(n_rows, n_cols, n_slices);
T* out_mem = out.memptr();
out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices()); if(ProxyCube<T1>::prefer_at_accessor == false)
{
typedef typename ProxyCube<T1>::ea_type ea_type;
const uword n_elem = out.n_elem; const uword n_elem = P.get_n_elem();
T* out_mem = out.memptr(); ea_type A = P.get_ea();
for(uword i=0; i<n_elem; ++i) for(uword i=0; i < n_elem; ++i)
{
out_mem[i] = std::abs( A[i] );
}
}
else
{ {
out_mem[i] = std::abs(A[i]); 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 = std::abs( P.at(row,col,slice) );
out_mem++;
}
} }
} }
template<typename T1> template<typename T1>
inline inline
void void
op_sympd::apply( Mat<typename T1::elem_type>& out, const Op<T1, op_sympd>& X ) op_sympd::apply( Mat<typename T1::elem_type>& out, const Op<T1, op_sympd>& X )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
 End of changes. 24 change blocks. 
30 lines changed or deleted 90 lines changed or added


 op_relational_meat.hpp   op_relational_meat.hpp 
skipping to change at line 65 skipping to change at line 65
{\ {\
if(n_rows == 1)\ if(n_rows == 1)\
{\ {\
for(uword count=0; count < n_cols; ++count)\ for(uword count=0; count < n_cols; ++count)\
{\ {\
out_mem[count] = (val operator_rel P.at(0,count)) ? uword(1) : uw ord(0);\ out_mem[count] = (val operator_rel P.at(0,count)) ? uword(1) : uw ord(0);\
}\ }\
}\ }\
else\ else\
{\ {\
uword count = 0;\
\
for(uword col=0; col < n_cols; ++col)\ for(uword col=0; col < n_cols; ++col)\
for(uword row=0; row < n_rows; ++row, ++count)\ for(uword row=0; row < n_rows; ++row)\
{\ {\
out_mem[count] = (val operator_rel P.at(row,col)) ? uword(1) : uw *out_mem = (val operator_rel P.at(row,col)) ? uword(1) : uword(0)
ord(0);\ ;\
out_mem++;\
}\ }\
}\ }\
}\ }\
}\ }\
else\ else\
{\ {\
const Mat<eT> tmp(P.Q);\ const Mat<eT> tmp(P.Q);\
\ \
out = (val) operator_rel (tmp);\ out = (val) operator_rel (tmp);\
}\ }\
skipping to change at line 124 skipping to change at line 123
{\ {\
if(n_rows == 1)\ if(n_rows == 1)\
{\ {\
for(uword count=0; count < n_cols; ++count)\ for(uword count=0; count < n_cols; ++count)\
{\ {\
out_mem[count] = (P.at(0,count) operator_rel val) ? uword(1) : uw ord(0);\ out_mem[count] = (P.at(0,count) operator_rel val) ? uword(1) : uw ord(0);\
}\ }\
}\ }\
else\ else\
{\ {\
uword count = 0;\
\
for(uword col=0; col < n_cols; ++col)\ for(uword col=0; col < n_cols; ++col)\
for(uword row=0; row < n_rows; ++row, ++count)\ for(uword row=0; row < n_rows; ++row)\
{\ {\
out_mem[count] = (P.at(row,col) operator_rel val) ? uword(1) : uw *out_mem = (P.at(row,col) operator_rel val) ? uword(1) : uword(0)
ord(0);\ ;\
out_mem++;\
}\ }\
}\ }\
}\ }\
}\ }\
else\ else\
{\ {\
const Mat<eT> tmp(P.Q);\ const Mat<eT> tmp(P.Q);\
\ \
out = (tmp) operator_rel (val);\ out = (tmp) operator_rel (val);\
}\ }\
skipping to change at line 175 skipping to change at line 173
ea_type PA = P.get_ea();\ ea_type PA = P.get_ea();\
const uword n_elem = out.n_elem;\ const uword n_elem = out.n_elem;\
\ \
for(uword i=0; i<n_elem; ++i)\ for(uword i=0; i<n_elem; ++i)\
{\ {\
out_mem[i] = (val operator_rel PA[i]) ? uword(1) : uword(0);\ out_mem[i] = (val operator_rel PA[i]) ? uword(1) : uword(0);\
}\ }\
}\ }\
else\ else\
{\ {\
uword count = 0;\
\
for(uword slice=0; slice < n_slices; ++slice)\ for(uword slice=0; slice < n_slices; ++slice)\
for(uword col=0; col < n_cols; ++col)\ for(uword col=0; col < n_cols; ++col )\
for(uword row=0; row < n_rows; ++row, ++count)\ for(uword row=0; row < n_rows; ++row )\
{\ {\
out_mem[count] = (val operator_rel P.at(row,col,slice)) ? uword(1) *out_mem = (val operator_rel P.at(row,col,slice)) ? uword(1) : uwor
: uword(0);\ d(0);\
out_mem++;\
}\ }\
}\ }\
}\ }\
else\ else\
{\ {\
const unwrap_cube<typename ProxyCube<T1>::stored_type> tmp(P.Q);\ const unwrap_cube<typename ProxyCube<T1>::stored_type> tmp(P.Q);\
\ \
out = (val) operator_rel (tmp.M);\ out = (val) operator_rel (tmp.M);\
}\ }\
} }
skipping to change at line 226 skipping to change at line 223
ea_type PA = P.get_ea();\ ea_type PA = P.get_ea();\
const uword n_elem = out.n_elem;\ const uword n_elem = out.n_elem;\
\ \
for(uword i=0; i<n_elem; ++i)\ for(uword i=0; i<n_elem; ++i)\
{\ {\
out_mem[i] = (PA[i] operator_rel val) ? uword(1) : uword(0);\ out_mem[i] = (PA[i] operator_rel val) ? uword(1) : uword(0);\
}\ }\
}\ }\
else\ else\
{\ {\
uword count = 0;\
\
for(uword slice=0; slice < n_slices; ++slice)\ for(uword slice=0; slice < n_slices; ++slice)\
for(uword col=0; col < n_cols; ++col)\ for(uword col=0; col < n_cols; ++col )\
for(uword row=0; row < n_rows; ++row, ++count)\ for(uword row=0; row < n_rows; ++row )\
{\ {\
out_mem[count] = (P.at(row,col,slice) operator_rel val) ? uword(1) *out_mem = (P.at(row,col,slice) operator_rel val) ? uword(1) : uwor
: uword(0);\ d(0);\
out_mem++;\
}\ }\
}\ }\
}\ }\
else\ else\
{\ {\
const unwrap_cube<typename ProxyCube<T1>::stored_type> tmp(P.Q);\ const unwrap_cube<typename ProxyCube<T1>::stored_type> tmp(P.Q);\
\ \
out = (tmp.M) operator_rel (val);\ out = (tmp.M) operator_rel (val);\
}\ }\
} }
 End of changes. 12 change blocks. 
22 lines changed or deleted 18 lines changed or added


 op_shuffle_meat.hpp   op_shuffle_meat.hpp 
skipping to change at line 34 skipping to change at line 34
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
const unwrap<T1> tmp(in.m); const unwrap<T1> tmp(in.m);
const Mat<eT>& X = tmp.M; const Mat<eT>& X = tmp.M;
if(X.is_empty()) { out.copy_size(X); return; } if(X.is_empty()) { out.copy_size(X); return; }
const uword dim = in.aux_uword_a; const uword dim = in.aux_uword_a;
const uword N = (dim == 0) ? X.n_rows : X.n_cols; const uword N = (dim == 0) ? X.n_rows : X.n_cols;
// see "fn_sort_index.hpp" for the definition of "arma_sort_index_packet_ // see "fn_sort_index.hpp" for the definition of "arma_sort_index_packet"
ascend" // and the associated comparison functor
// and the associated "operator<" std::vector< arma_sort_index_packet<int,uword> > packet_vec(N);
std::vector< arma_sort_index_packet_ascend<int,uword> > packet_vec(N);
for(uword i=0; i<N; ++i) for(uword i=0; i<N; ++i)
{ {
packet_vec[i].val = std::rand(); packet_vec[i].val = std::rand();
packet_vec[i].index = i; packet_vec[i].index = i;
} }
std::sort( packet_vec.begin(), packet_vec.end() ); arma_sort_index_helper_ascend comparator;
std::sort( packet_vec.begin(), packet_vec.end(), comparator );
const bool is_alias = (&out == &X); const bool is_alias = (&out == &X);
if(X.is_vec() == false) if(X.is_vec() == false)
{ {
if(is_alias == false) if(is_alias == false)
{ {
arma_extra_debug_print("op_shuffle::apply(): matrix"); arma_extra_debug_print("op_shuffle::apply(): matrix");
out.copy_size(X); out.copy_size(X);
 End of changes. 2 change blocks. 
5 lines changed or deleted 6 lines changed or added


 spop_max_meat.hpp   spop_max_meat.hpp 
skipping to change at line 25 skipping to change at line 25
template<typename T1> template<typename T1>
inline inline
void void
spop_max::apply(SpMat<typename T1::elem_type>& out, const SpOp<T1,spop_max> & in) spop_max::apply(SpMat<typename T1::elem_type>& out, const SpOp<T1,spop_max> & in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
const uword dim = in.aux_uword_a;
arma_debug_check((dim > 1), "max(): incorrect usage. dim must be 0 or 1")
;
const SpProxy<T1> p(in.m); const SpProxy<T1> p(in.m);
if(p.is_alias(out) == false) if(p.is_alias(out) == false)
{ {
spop_max::apply_noalias(out, p, in.aux_uword_a); spop_max::apply_noalias(out, p, dim);
} }
else else
{ {
SpMat<eT> tmp; SpMat<eT> tmp;
spop_max::apply_noalias(tmp, p, in.aux_uword_a); spop_max::apply_noalias(tmp, p, dim);
out.steal_mem(tmp); out.steal_mem(tmp);
} }
} }
template<typename T1> template<typename T1>
inline inline
void void
spop_max::apply_noalias spop_max::apply_noalias
( (
skipping to change at line 57 skipping to change at line 60
const SpProxy<T1>& p, const SpProxy<T1>& p,
const uword dim, const uword dim,
const typename arma_not_cx<typename T1::elem_type>::result* junk const typename arma_not_cx<typename T1::elem_type>::result* junk
) )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_ignore(junk); arma_ignore(junk);
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
if(p.get_n_nonzero() == 0)
{
return;
}
if(dim == 0) if(dim == 0)
{ {
// maximum in each column // maximum in each column
result.set_size(1, p.get_n_cols()); result.set_size(1, p.get_n_cols());
if(p.get_n_nonzero() == 0)
{
return;
}
typename SpProxy<T1>::const_iterator_type it = p.begin(); typename SpProxy<T1>::const_iterator_type it = p.begin();
uword cur_col = it.col(); uword cur_col = it.col();
uword elem_in_col = 1; uword elem_in_col = 1;
eT cur_max = (*it); eT cur_max = (*it);
++it; ++it;
while(it != p.end()) while(it != p.end())
{ {
if(it.col() != cur_col) if(it.col() != cur_col)
skipping to change at line 115 skipping to change at line 118
else else
{ {
result.at(0, cur_col) = std::max(eT(0), cur_max); result.at(0, cur_col) = std::max(eT(0), cur_max);
} }
} }
else else
{ {
// maximum in each row // maximum in each row
result.set_size(p.get_n_rows(), 1); result.set_size(p.get_n_rows(), 1);
if(p.get_n_nonzero() == 0)
{
return;
}
typename SpProxy<T1>::const_row_iterator_type it = p.begin_row(); typename SpProxy<T1>::const_row_iterator_type it = p.begin_row();
uword cur_row = it.row(); uword cur_row = it.row();
uword elem_in_row = 1; uword elem_in_row = 1;
eT cur_max = (*it); eT cur_max = (*it);
++it; ++it;
while(it.pos() < p.get_n_nonzero()) while(it.pos() < p.get_n_nonzero())
{ {
if(it.row() != cur_row) if(it.row() != cur_row)
skipping to change at line 177 skipping to change at line 185
const uword dim, const uword dim,
const typename arma_cx_only<typename T1::elem_type>::result* junk const typename arma_cx_only<typename T1::elem_type>::result* junk
) )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_ignore(junk); arma_ignore(junk);
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
typedef typename get_pod_type<eT>::result T; typedef typename get_pod_type<eT>::result T;
if(p.get_n_nonzero() == 0)
{
return;
}
if(dim == 0) if(dim == 0)
{ {
// maximum in each column // maximum in each column
result.set_size(1, p.get_n_cols()); result.set_size(1, p.get_n_cols());
if(p.get_n_nonzero() == 0)
{
return;
}
typename SpProxy<T1>::const_iterator_type it = p.begin(); typename SpProxy<T1>::const_iterator_type it = p.begin();
uword cur_col = it.col(); uword cur_col = it.col();
uword elem_in_col = 1; uword elem_in_col = 1;
eT cur_max_orig = *it; eT cur_max_orig = *it;
T cur_max_abs = std::abs(cur_max_orig); T cur_max_abs = std::abs(cur_max_orig);
++it; ++it;
skipping to change at line 251 skipping to change at line 259
eT val1 = eT(0); eT val1 = eT(0);
result.at(0, cur_col) = ( std::abs(val1) >= cur_max_abs ) ? val1 : cu r_max_orig; result.at(0, cur_col) = ( std::abs(val1) >= cur_max_abs ) ? val1 : cu r_max_orig;
} }
} }
else else
{ {
// maximum in each row // maximum in each row
result.set_size(p.get_n_rows(), 1); result.set_size(p.get_n_rows(), 1);
if(p.get_n_nonzero() == 0)
{
return;
}
typename SpProxy<T1>::const_row_iterator_type it = p.begin_row(); typename SpProxy<T1>::const_row_iterator_type it = p.begin_row();
uword cur_row = it.row(); uword cur_row = it.row();
uword elem_in_row = 1; uword elem_in_row = 1;
eT cur_max_orig = *it; eT cur_max_orig = *it;
T cur_max_abs = std::abs(cur_max_orig); T cur_max_abs = std::abs(cur_max_orig);
++it; ++it;
 End of changes. 9 change blocks. 
12 lines changed or deleted 26 lines changed or added


 spop_min_meat.hpp   spop_min_meat.hpp 
skipping to change at line 25 skipping to change at line 25
template<typename T1> template<typename T1>
inline inline
void void
spop_min::apply(SpMat<typename T1::elem_type>& out, const SpOp<T1,spop_min> & in) spop_min::apply(SpMat<typename T1::elem_type>& out, const SpOp<T1,spop_min> & in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
const uword dim = in.aux_uword_a;
arma_debug_check((dim > 1), "min(): incorrect usage. dim must be 0 or 1")
;
const SpProxy<T1> p(in.m); const SpProxy<T1> p(in.m);
if(p.is_alias(out) == false) if(p.is_alias(out) == false)
{ {
spop_min::apply_noalias(out, p, in.aux_uword_a); spop_min::apply_noalias(out, p, dim);
} }
else else
{ {
SpMat<eT> tmp; SpMat<eT> tmp;
spop_min::apply_noalias(tmp, p, in.aux_uword_a); spop_min::apply_noalias(tmp, p, dim);
out.steal_mem(tmp); out.steal_mem(tmp);
} }
} }
template<typename T1> template<typename T1>
inline inline
void void
spop_min::apply_noalias spop_min::apply_noalias
( (
skipping to change at line 57 skipping to change at line 60
const SpProxy<T1>& p, const SpProxy<T1>& p,
const uword dim, const uword dim,
const typename arma_not_cx<typename T1::elem_type>::result* junk const typename arma_not_cx<typename T1::elem_type>::result* junk
) )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_ignore(junk); arma_ignore(junk);
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
if(p.get_n_nonzero() == 0)
{
return;
}
if(dim == 0) if(dim == 0)
{ {
// minimum in each column // minimum in each column
result.set_size(1, p.get_n_cols()); result.set_size(1, p.get_n_cols());
if(p.get_n_nonzero() == 0)
{
return;
}
typename SpProxy<T1>::const_iterator_type it = p.begin(); typename SpProxy<T1>::const_iterator_type it = p.begin();
uword cur_col = it.col(); uword cur_col = it.col();
uword elem_in_col = 1; uword elem_in_col = 1;
eT cur_min = (*it); eT cur_min = (*it);
++it; ++it;
while(it != p.end()) while(it != p.end())
{ {
if(it.col() != cur_col) if(it.col() != cur_col)
skipping to change at line 115 skipping to change at line 118
else else
{ {
result.at(0, cur_col) = std::min(eT(0), cur_min); result.at(0, cur_col) = std::min(eT(0), cur_min);
} }
} }
else else
{ {
// minimum in each row // minimum in each row
result.set_size(p.get_n_rows(), 1); result.set_size(p.get_n_rows(), 1);
if(p.get_n_nonzero() == 0)
{
return;
}
typename SpProxy<T1>::const_row_iterator_type it = p.begin_row(); typename SpProxy<T1>::const_row_iterator_type it = p.begin_row();
uword cur_row = it.row(); uword cur_row = it.row();
uword elem_in_row = 1; uword elem_in_row = 1;
eT cur_min = (*it); eT cur_min = (*it);
++it; ++it;
while(it.pos() < p.get_n_nonzero()) while(it.pos() < p.get_n_nonzero())
{ {
if(it.row() != cur_row) if(it.row() != cur_row)
skipping to change at line 177 skipping to change at line 185
const uword dim, const uword dim,
const typename arma_cx_only<typename T1::elem_type>::result* junk const typename arma_cx_only<typename T1::elem_type>::result* junk
) )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_ignore(junk); arma_ignore(junk);
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
typedef typename get_pod_type<eT>::result T; typedef typename get_pod_type<eT>::result T;
if(p.get_n_nonzero() == 0)
{
return;
}
if(dim == 0) if(dim == 0)
{ {
// minimum in each column // minimum in each column
result.set_size(1, p.get_n_cols()); result.set_size(1, p.get_n_cols());
if(p.get_n_nonzero() == 0)
{
return;
}
typename SpProxy<T1>::const_iterator_type it = p.begin(); typename SpProxy<T1>::const_iterator_type it = p.begin();
uword cur_col = it.col(); uword cur_col = it.col();
uword elem_in_col = 1; uword elem_in_col = 1;
eT cur_min_orig = *it; eT cur_min_orig = *it;
T cur_min_abs = std::abs(cur_min_orig); T cur_min_abs = std::abs(cur_min_orig);
++it; ++it;
skipping to change at line 251 skipping to change at line 259
eT val1 = eT(0); eT val1 = eT(0);
result.at(0, cur_col) = ( std::abs(val1) < cur_min_abs ) ? val1 : cur _min_orig; result.at(0, cur_col) = ( std::abs(val1) < cur_min_abs ) ? val1 : cur _min_orig;
} }
} }
else else
{ {
// minimum in each row // minimum in each row
result.set_size(p.get_n_rows(), 1); result.set_size(p.get_n_rows(), 1);
if(p.get_n_nonzero() == 0)
{
return;
}
typename SpProxy<T1>::const_row_iterator_type it = p.begin_row(); typename SpProxy<T1>::const_row_iterator_type it = p.begin_row();
uword cur_row = it.row(); uword cur_row = it.row();
uword elem_in_row = 1; uword elem_in_row = 1;
eT cur_min_orig = *it; eT cur_min_orig = *it;
T cur_min_abs = std::abs(cur_min_orig); T cur_min_abs = std::abs(cur_min_orig);
++it; ++it;
 End of changes. 9 change blocks. 
12 lines changed or deleted 26 lines changed or added


 spop_misc_bones.hpp   spop_misc_bones.hpp 
skipping to change at line 31 skipping to change at line 31
}; };
class spop_square class spop_square
{ {
public: public:
template<typename T1> template<typename T1>
arma_hot inline static void apply(SpMat<typename T1::elem_type>& out, con st SpOp<T1, spop_square>& in); arma_hot inline static void apply(SpMat<typename T1::elem_type>& out, con st SpOp<T1, spop_square>& in);
}; };
class spop_sqrt
{
public:
template<typename T1>
arma_hot inline static void apply(SpMat<typename T1::elem_type>& out, con
st SpOp<T1, spop_sqrt>& in);
};
class spop_abs
{
public:
template<typename T1>
arma_hot inline static void apply(SpMat<typename T1::elem_type>& out, con
st SpOp<T1, spop_abs>& in);
};
class spop_cx_abs
{
public:
template<typename T1>
arma_hot inline static void apply(SpMat<typename T1::pod_type>& out, cons
t mtSpOp<typename T1::pod_type, T1, spop_cx_abs>& in);
};
//! @} //! @}
 End of changes. 1 change blocks. 
0 lines changed or deleted 27 lines changed or added


 spop_misc_meat.hpp   spop_misc_meat.hpp 
skipping to change at line 15 skipping to change at line 15
// for any purpose. You can redistribute this file // for any purpose. You can redistribute this file
// and/or modify it under the terms of the GNU // and/or modify it under the terms of the GNU
// Lesser General Public License (LGPL) as published // Lesser General Public License (LGPL) as published
// by the Free Software Foundation, either version 3 // by the Free Software Foundation, either version 3
// of the License or (at your option) any later version. // of the License or (at your option) any later version.
// (see http://www.opensource.org/licenses for more info) // (see http://www.opensource.org/licenses for more info)
//! \addtogroup spop_misc //! \addtogroup spop_misc
//! @{ //! @{
namespace priv
{
template<typename eT>
struct functor_scalar_times
{
const eT k;
functor_scalar_times(const eT in_k) : k(in_k) {}
arma_inline eT operator()(const eT val) const { return val * k; }
};
}
template<typename T1> template<typename T1>
arma_hot
inline inline
void void
spop_scalar_times::apply(SpMat<typename T1::elem_type>& out, const SpOp<T1, spop_scalar_times>& in) spop_scalar_times::apply(SpMat<typename T1::elem_type>& out, const SpOp<T1, spop_scalar_times>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
out = in.m; typedef typename T1::elem_type eT;
out *= in.aux; out.init_xform(in.m, priv::functor_scalar_times<eT>(in.aux));
}
namespace priv
{
struct functor_square
{
template<typename eT>
arma_inline eT operator()(const eT val) const { return val*val; }
};
} }
template<typename T1> template<typename T1>
arma_hot
inline inline
void void
spop_square::apply(SpMat<typename T1::elem_type>& out, const SpOp<T1,spop_s quare>& in) spop_square::apply(SpMat<typename T1::elem_type>& out, const SpOp<T1,spop_s quare>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; out.init_xform(in.m, priv::functor_square());
}
out = in.m; namespace priv
{
struct functor_sqrt
{
template<typename eT>
arma_inline eT operator()(const eT val) const { return eop_aux::sqrt(va
l); }
};
}
eT* values = access::rwp(out.values); template<typename T1>
inline
void
spop_sqrt::apply(SpMat<typename T1::elem_type>& out, const SpOp<T1,spop_sqr
t>& in)
{
arma_extra_debug_sigprint();
const uword n_nz = out.n_nonzero; out.init_xform(in.m, priv::functor_sqrt());
}
uword i,j; namespace priv
for(i=0, j=1; j < n_nz; i+=2, j+=2) {
struct functor_abs
{ {
const eT tmp_i = values[i]; template<typename eT>
const eT tmp_j = values[j]; arma_inline eT operator()(const eT val) const { return eop_aux::arma_ab
s(val); }
};
}
values[i] = tmp_i*tmp_i; template<typename T1>
values[j] = tmp_j*tmp_j; inline
} void
spop_abs::apply(SpMat<typename T1::elem_type>& out, const SpOp<T1,spop_abs>
& in)
{
arma_extra_debug_sigprint();
if(i < n_nz) out.init_xform(in.m, priv::functor_abs());
}
namespace priv
{
struct functor_cx_abs
{ {
const eT tmp_i = values[i]; template<typename T>
arma_inline T operator()(const std::complex<T>& val) const { return std
::abs(val); }
};
}
template<typename T1>
inline
void
spop_cx_abs::apply(SpMat<typename T1::pod_type>& out, const mtSpOp<typename
T1::pod_type, T1, spop_cx_abs>& in)
{
arma_extra_debug_sigprint();
values[i] = tmp_i*tmp_i; out.init_xform_mt(in.m, priv::functor_cx_abs());
}
} }
//! @} //! @}
 End of changes. 15 change blocks. 
19 lines changed or deleted 79 lines changed or added


 spop_sum_bones.hpp   spop_sum_bones.hpp 
skipping to change at line 21 skipping to change at line 21
//! \addtogroup spop_sum //! \addtogroup spop_sum
//! @{ //! @{
class spop_sum class spop_sum
{ {
public: public:
template<typename T1> template<typename T1>
arma_hot inline static void apply(SpMat<typename T1::elem_type>& out, con st SpOp<T1, spop_sum>& in); arma_hot inline static void apply(SpMat<typename T1::elem_type>& out, con st SpOp<T1, spop_sum>& in);
template<typename T1>
arma_hot inline static void apply_noalias(SpMat<typename T1::elem_type>&
out, const SpProxy<T1>& p, const uword dim);
}; };
//! @} //! @}
 End of changes. 1 change blocks. 
0 lines changed or deleted 4 lines changed or added


 spop_sum_meat.hpp   spop_sum_meat.hpp 
skipping to change at line 27 skipping to change at line 27
arma_hot arma_hot
inline inline
void void
spop_sum::apply(SpMat<typename T1::elem_type>& out, const SpOp<T1,spop_sum> & in) spop_sum::apply(SpMat<typename T1::elem_type>& out, const SpOp<T1,spop_sum> & in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
const uword dim = in.aux_uword_a; const uword dim = in.aux_uword_a;
arma_debug_check((dim > 1), "sum(): incorrect usage. dim must be 0 or 1") ;
const SpProxy<T1> p(in.m); const SpProxy<T1> p(in.m);
if(p.is_alias(out) == false) if(p.is_alias(out) == false)
{ {
if(dim == 0) // find the sum in each column spop_sum::apply_noalias(out, p, dim);
{ }
out.zeros(1, p.get_n_cols()); else
{
SpMat<eT> tmp;
typename SpProxy<T1>::const_iterator_type it = p.begin(); spop_sum::apply_noalias(tmp, p, dim);
while(it != p.end()) out.steal_mem(tmp);
{ }
out.at(0, it.col()) += (*it); }
++it;
} template<typename T1>
} arma_hot
else // find the sum in each row inline
{ void
out.zeros(p.get_n_rows(), 1); spop_sum::apply_noalias(SpMat<typename T1::elem_type>& out, const SpProxy<T
1>& p, const uword dim)
{
arma_extra_debug_sigprint();
if(dim == 0) // find the sum in each column
{
out.zeros(1, p.get_n_cols());
typename SpProxy<T1>::const_iterator_type it = p.begin(); typename SpProxy<T1>::const_iterator_type it = p.begin();
typename SpProxy<T1>::const_iterator_type it_end = p.end();
while(it != p.end()) while(it != it_end)
{ {
out.at(it.row(), 0) += (*it); out.at(0, it.col()) += (*it);
++it; ++it;
}
} }
} }
else else // find the sum in each row
{ {
if(dim == 0) // find the sum in each column out.zeros(p.get_n_rows(), 1);
{
SpMat<eT> result(1, p.get_n_cols());
typename SpProxy<T1>::const_iterator_type it = p.begin();
while(it != p.end()) typename SpProxy<T1>::const_iterator_type it = p.begin();
{ typename SpProxy<T1>::const_iterator_type it_end = p.end();
result.at(0, it.col()) += (*it);
++it;
}
out.steal_mem(result); while(it != it_end)
}
else // find the sum in each row
{ {
SpMat<eT> result(p.get_n_rows(), 1); out.at(it.row(), 0) += (*it);
++it;
typename SpProxy<T1>::const_iterator_type it = p.begin();
while(it != p.end())
{
result.at(it.row(), 0) += (*it);
++it;
}
out.steal_mem(result);
} }
} }
} }
//! @} //! @}
 End of changes. 11 change blocks. 
44 lines changed or deleted 36 lines changed or added


 traits.hpp   traits.hpp 
skipping to change at line 611 skipping to change at line 611
{ static const bool value = true; }; { static const bool value = true; };
template<typename T> template<typename T>
struct is_SpGlue struct is_SpGlue
{ static const bool value = false; }; { static const bool value = false; };
template<typename T1, typename T2, typename glue_type> template<typename T1, typename T2, typename glue_type>
struct is_SpGlue< SpGlue<T1,T2,glue_type> > struct is_SpGlue< SpGlue<T1,T2,glue_type> >
{ static const bool value = true; }; { static const bool value = true; };
template<typename T>
struct is_mtSpOp
{ static const bool value = false; };
template<typename eT, typename T1, typename spop_type>
struct is_mtSpOp< mtSpOp<eT, T1, spop_type> >
{ static const bool value = true; };
template<typename T1> template<typename T1>
struct is_arma_sparse_type struct is_arma_sparse_type
{ {
static const bool value static const bool value
= is_SpMat<T1>::value = is_SpMat<T1>::value
|| is_SpSubview<T1>::value || is_SpSubview<T1>::value
|| is_SpOp<T1>::value || is_SpOp<T1>::value
|| is_SpGlue<T1>::value || is_SpGlue<T1>::value
|| is_mtSpOp<T1>::value
; ;
}; };
// //
// //
// //
template<typename T1, typename T2> template<typename T1, typename T2>
struct is_same_type struct is_same_type
{ static const bool value = false; }; { static const bool value = false; };
skipping to change at line 927 skipping to change at line 936
template<> struct is_op_mixed_elem<op_rel_lt_post> { stat ic const bool value = true; }; template<> struct is_op_mixed_elem<op_rel_lt_post> { stat ic const bool value = true; };
template<> struct is_op_mixed_elem<op_rel_gt_pre> { stat ic const bool value = true; }; template<> struct is_op_mixed_elem<op_rel_gt_pre> { stat ic const bool value = true; };
template<> struct is_op_mixed_elem<op_rel_gt_post> { stat ic const bool value = true; }; template<> struct is_op_mixed_elem<op_rel_gt_post> { stat ic const bool value = true; };
template<> struct is_op_mixed_elem<op_rel_lteq_pre> { stat ic const bool value = true; }; template<> struct is_op_mixed_elem<op_rel_lteq_pre> { stat ic const bool value = true; };
template<> struct is_op_mixed_elem<op_rel_lteq_post> { stat ic const bool value = true; }; template<> struct is_op_mixed_elem<op_rel_lteq_post> { stat ic const bool value = true; };
template<> struct is_op_mixed_elem<op_rel_gteq_pre> { stat ic const bool value = true; }; template<> struct is_op_mixed_elem<op_rel_gteq_pre> { stat ic const bool value = true; };
template<> struct is_op_mixed_elem<op_rel_gteq_post> { stat ic const bool value = true; }; template<> struct is_op_mixed_elem<op_rel_gteq_post> { stat ic const bool value = true; };
template<> struct is_op_mixed_elem<op_rel_eq> { stat ic const bool value = true; }; template<> struct is_op_mixed_elem<op_rel_eq> { stat ic const bool value = true; };
template<> struct is_op_mixed_elem<op_rel_noteq> { stat ic const bool value = true; }; template<> struct is_op_mixed_elem<op_rel_noteq> { stat ic const bool value = true; };
template<typename spop_type> struct is_spop_elem { stati
c const bool value = false; };
template<> struct is_spop_elem<spop_scalar_times> { stati
c const bool value = true; };
template<typename spglue_type> struct is_spglue_elem { stati
c const bool value = false; };
template<> struct is_spglue_elem<spglue_plus> { stati
c const bool value = true; };
template<> struct is_spglue_elem<spglue_plus2> { stati
c const bool value = true; };
template<> struct is_spglue_elem<spglue_minus> { stati
c const bool value = true; };
template<> struct is_spglue_elem<spglue_minus2> { stati
c const bool value = true; };
template<typename spglue_type> struct is_spglue_times { stati
c const bool value = false; };
template<> struct is_spglue_times<spglue_times> { stati
c const bool value = true; };
template<typename spglue_type> struct is_spglue_times2 { stat
ic const bool value = false; };
template<> struct is_spglue_times<spglue_times2> { stat
ic const bool value = true; };
//! @} //! @}
 End of changes. 3 change blocks. 
0 lines changed or deleted 35 lines changed or added


 unwrap_spmat.hpp   unwrap_spmat.hpp 
skipping to change at line 100 skipping to change at line 100
inline inline
unwrap_spmat(const SpGlue<T1, T2, spglue_type>& A) unwrap_spmat(const SpGlue<T1, T2, spglue_type>& A)
: M(A) : M(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
const SpMat<eT> M; const SpMat<eT> M;
}; };
template<typename out_eT, typename T1, typename spop_type>
struct unwrap_spmat< mtSpOp<out_eT, T1, spop_type> >
{
inline
unwrap_spmat(const mtSpOp<out_eT, T1, spop_type>& A)
: M(A)
{
arma_extra_debug_sigprint();
}
const SpMat<out_eT> M;
};
//! @} //! @}
 End of changes. 1 change blocks. 
0 lines changed or deleted 13 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/