Base.hpp   Base.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 BaseCube.hpp   BaseCube.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 Col_meat.hpp   Col_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 438 skipping to change at line 439
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
Mat<eT>::operator*=(X); Mat<eT>::operator*=(X);
arma_debug_check( (Mat<eT>::n_cols > 1), "Col::operator=(): incompatible dimensions" ); arma_debug_check( (Mat<eT>::n_cols > 1), "Col::operator=(): incompatible dimensions" );
return *this; return *this;
} }
template<typename eT>
template<typename T1, typename eop_type>
inline
Col<eT>::Col(const eOp<T1, eop_type>& X)
: Mat<eT>(X)
{
arma_extra_debug_sigprint();
arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
);
}
template<typename eT>
template<typename T1, typename eop_type>
inline
const Col<eT>&
Col<eT>::operator=(const eOp<T1, eop_type>& X)
{
arma_extra_debug_sigprint();
Mat<eT>::operator=(X);
arma_debug_check( (Mat<eT>::n_cols > 1), "Col::operator=(): given matrix
can't be interpreted as a column vector" );
return *this;
}
template<typename eT>
template<typename T1, typename eop_type>
inline
const Col<eT>&
Col<eT>::operator*=(const eOp<T1, eop_type>& X)
{
arma_extra_debug_sigprint();
Mat<eT>::operator*=(X);
arma_debug_check( (Mat<eT>::n_cols > 1), "Col::operator=(): incompatible
dimensions" );
return *this;
}
//! construct a column vector from Glue, i.e. run the previously delayed op erations; the result of the operations must have exactly one column //! construct a column vector from Glue, i.e. run the previously delayed op erations; the result of the operations must have exactly one column
template<typename eT> template<typename eT>
template<typename T1, typename T2, typename glue_type> template<typename T1, typename T2, typename glue_type>
inline inline
Col<eT>::Col(const Glue<T1, T2, glue_type>& X) Col<eT>::Col(const Glue<T1, T2, glue_type>& X)
: Mat<eT>(X) : Mat<eT>(X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" ); arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" );
skipping to change at line 481 skipping to change at line 521
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
Mat<eT>::operator*=(X); Mat<eT>::operator*=(X);
arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" ); arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" );
return *this; return *this;
} }
template<typename eT>
template<typename T1, typename T2, typename eglue_type>
inline
Col<eT>::Col(const eGlue<T1, T2, eglue_type>& X)
: Mat<eT>(X)
{
arma_extra_debug_sigprint();
arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
);
}
template<typename eT>
template<typename T1, typename T2, typename eglue_type>
inline
const Col<eT>&
Col<eT>::operator=(const eGlue<T1, T2, eglue_type>& X)
{
arma_extra_debug_sigprint();
Mat<eT>::operator=(X);
arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
);
return *this;
}
template<typename eT>
template<typename T1, typename T2, typename eglue_type>
inline
const Col<eT>&
Col<eT>::operator*=(const eGlue<T1, T2, eglue_type>& X)
{
arma_extra_debug_sigprint();
Mat<eT>::operator*=(X);
arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
);
return *this;
}
//! change the number of rows //! change the number of rows
template<typename eT> template<typename eT>
inline inline
void void
Col<eT>::set_size(const u32 in_n_elem) Col<eT>::set_size(const u32 in_n_elem)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
Mat<eT>::set_size(in_n_elem,1); Mat<eT>::set_size(in_n_elem,1);
} }
//! change the number of rows (this function re-implements mat::set_size() in order to check the number of columns) //! change the number of n_rows (this function re-implements mat::set_size () in order to check the number of columns)
template<typename eT> template<typename eT>
inline inline
void void
Col<eT>::set_size(const u32 in_n_rows, const u32 in_n_cols) Col<eT>::set_size(const u32 in_n_rows, const u32 in_n_cols)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
// min() is used in case in_n_cols is zero // min() is used in case in_n_cols is zero
Mat<eT>::set_size( in_n_rows, (std::min)( u32(1), in_n_cols ) ); Mat<eT>::set_size( in_n_rows, (std::min)( u32(1), in_n_cols ) );
arma_debug_check( (in_n_cols > 1), "Col::set_size(): incompatible dimensi ons" ); arma_debug_check( (in_n_cols > 1), "Col::set_size(): incompatible dimensi ons" );
} }
//! change the number of rows (this function re-implements mat::copy_size( ) in order to check the number of columns) //! change the number of n_rows (this function re-implements mat::copy_siz e() in order to check the number of columns)
template<typename eT> template<typename eT>
template<typename eT2> template<typename eT2>
inline inline
void void
Col<eT>::copy_size(const Mat<eT2>& x) Col<eT>::copy_size(const Mat<eT2>& x)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
// min() is used in case x.n_cols is zero // min() is used in case x.n_cols is zero
Mat<eT>::set_size( x.n_rows, (std::min)( u32(1), x.n_cols ) ); Mat<eT>::set_size( x.n_rows, (std::min)( u32(1), x.n_cols ) );
skipping to change at line 599 skipping to change at line 680
void void
Col<eT>::load(const std::string name, const file_type type) Col<eT>::load(const std::string name, const file_type type)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
Mat<eT>::load(name,type); Mat<eT>::load(name,type);
arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" ); arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" );
} }
template<typename eT>
inline
void
Col<eT>::load(std::istream& is, const file_type type)
{
arma_extra_debug_sigprint();
Mat<eT>::load(is, type);
arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions"
);
}
//! @} //! @}
 End of changes. 6 change blocks. 
3 lines changed or deleted 103 lines changed or added


 Col_proto.hpp   Col_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 25 skipping to change at line 26
//! \addtogroup Col //! \addtogroup Col
//! @{ //! @{
//! Class for column vectors (matrices with only column) //! Class for column vectors (matrices with only column)
template<typename eT> template<typename eT>
class Col : public Mat<eT>, public BaseVec< eT, Col<eT> > class Col : public Mat<eT>, public BaseVec< eT, Col<eT> >
{ {
public: public:
typedef eT elem_type; typedef eT elem_type;
typedef typename get_pod_type<elem_type>::pod_type pod_type; typedef typename get_pod_type<eT>::result pod_type;
inline Col(); inline Col();
inline explicit Col(const u32 n_elem); inline explicit Col(const u32 n_elem);
inline Col(const u32 in_rows, const u32 in_cols); inline Col(const u32 in_rows, const u32 in_cols);
inline Col(const char* text); inline Col(const char* text);
inline const Col& operator=(const char* text); inline const Col& operator=(const char* text);
inline Col(const std::string& text); inline Col(const std::string& text);
inline const Col& operator=(const std::string& text); inline const Col& operator=(const std::string& text);
skipping to change at line 76 skipping to change at line 77
arma_inline eT& row(const u32 row_num); arma_inline eT& row(const u32 row_num);
arma_inline eT row(const u32 row_num) const; arma_inline eT row(const u32 row_num) const;
arma_inline subview_col<eT> rows(const u32 in_row1, const u32 in_ro w2); arma_inline subview_col<eT> rows(const u32 in_row1, const u32 in_ro w2);
arma_inline const subview_col<eT> rows(const u32 in_row1, const u32 in_ro w2) const; arma_inline const subview_col<eT> rows(const u32 in_row1, const u32 in_ro w2) const;
template<typename T1, typename op_type> inline Col(cons t Op<T1, op_type>& X); template<typename T1, typename op_type> inline Col(cons t Op<T1, op_type>& X);
template<typename T1, typename op_type> inline const Col& operator=(cons t Op<T1, op_type>& X); template<typename T1, typename op_type> inline const Col& operator=(cons t Op<T1, op_type>& X);
template<typename T1, typename op_type> inline const Col& operator*=(cons t Op<T1, op_type>& X); template<typename T1, typename op_type> inline const Col& operator*=(cons t Op<T1, op_type>& X);
template<typename T1, typename eop_type> inline Col(con
st eOp<T1, eop_type>& X);
template<typename T1, typename eop_type> inline const Col& operator=(con
st eOp<T1, eop_type>& X);
template<typename T1, typename eop_type> inline const Col& operator*=(con
st eOp<T1, eop_type>& X);
template<typename T1, typename T2, typename glue_type> inline Col(const Glue<T1, T2, glue_type>& X); template<typename T1, typename T2, typename glue_type> inline Col(const Glue<T1, T2, glue_type>& X);
template<typename T1, typename T2, typename glue_type> inline const Col& operator=(const Glue<T1, T2, glue_type>& X); template<typename T1, typename T2, typename glue_type> inline const Col& operator=(const Glue<T1, T2, glue_type>& X);
template<typename T1, typename T2, typename glue_type> inline const Col& operator*=(const Glue<T1, T2, glue_type>& X); template<typename T1, typename T2, typename glue_type> inline const Col& operator*=(const Glue<T1, T2, glue_type>& X);
template<typename T1, typename T2, typename eglue_type> inline
Col(const eGlue<T1, T2, eglue_type>& X);
template<typename T1, typename T2, typename eglue_type> inline const Col&
operator=(const eGlue<T1, T2, eglue_type>& X);
template<typename T1, typename T2, typename eglue_type> inline const Col&
operator*=(const eGlue<T1, T2, eglue_type>& X);
inline void set_size(const u32 n_elem); inline void set_size(const u32 n_elem);
inline void set_size(const u32 n_rows, const u32 n_cols); inline void set_size(const u32 n_rows, const u32 n_cols);
template<typename eT2> template<typename eT2>
inline void copy_size(const Mat<eT2>& m); inline void copy_size(const Mat<eT2>& m);
inline void zeros(); inline void zeros();
inline void zeros(const u32 n_elem); inline void zeros(const u32 n_elem);
inline void zeros(const u32 n_rows, const u32 n_cols); inline void zeros(const u32 n_rows, const u32 n_cols);
inline void ones(); inline void ones();
inline void ones(const u32 n_elem); inline void ones(const u32 n_elem);
inline void ones(const u32 n_rows, const u32 n_cols); inline void ones(const u32 n_rows, const u32 n_cols);
inline void load(const std::string name, const file_type type = auto_dete inline void load(const std::string name, const file_type type = auto_de
ct); tect);
inline void load( std::istream& is, const file_type type = auto_de
tect);
}; };
//! @} //! @}
 End of changes. 5 change blocks. 
5 lines changed or deleted 22 lines changed or added


 Cube_meat.hpp   Cube_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 332 skipping to change at line 333
template<typename eT> template<typename eT>
inline inline
Cube<eT>::Cube(eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols, con st u32 aux_n_slices, const bool copy_aux_mem) Cube<eT>::Cube(eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols, con st u32 aux_n_slices, const bool copy_aux_mem)
: n_rows (copy_aux_mem ? 0 : aux_n_rows ) : n_rows (copy_aux_mem ? 0 : aux_n_rows )
, n_cols (copy_aux_mem ? 0 : aux_n_cols ) , n_cols (copy_aux_mem ? 0 : aux_n_cols )
, n_elem_slice(copy_aux_mem ? 0 : aux_n_rows*aux_n_cols ) , n_elem_slice(copy_aux_mem ? 0 : aux_n_rows*aux_n_cols )
, n_slices (copy_aux_mem ? 0 : aux_n_slices ) , n_slices (copy_aux_mem ? 0 : aux_n_slices )
, n_elem (copy_aux_mem ? 0 : aux_n_rows*aux_n_cols*aux_n_slices) , n_elem (copy_aux_mem ? 0 : aux_n_rows*aux_n_cols*aux_n_slices)
, use_aux_mem (copy_aux_mem ? false : true ) , use_aux_mem (copy_aux_mem ? false : true )
, mat_ptrs (mat_ptrs )
, mem (copy_aux_mem ? mem : aux_mem ) , mem (copy_aux_mem ? mem : aux_mem )
{ {
arma_extra_debug_sigprint_this(this); arma_extra_debug_sigprint_this(this);
if(copy_aux_mem == true) if(copy_aux_mem == true)
{ {
init(aux_n_rows, aux_n_cols, aux_n_slices); init(aux_n_rows, aux_n_cols, aux_n_slices);
syslib::copy_elem( memptr(), aux_mem, n_elem ); syslib::copy_elem( memptr(), aux_mem, n_elem );
} }
else
{
create_mat();
}
} }
//! construct a cube from a given auxiliary read-only array of eTs. //! construct a cube from a given auxiliary read-only array of eTs.
//! the array is copied. //! the array is copied.
template<typename eT> template<typename eT>
inline inline
Cube<eT>::Cube(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_col s, const u32 aux_n_slices) Cube<eT>::Cube(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_col s, const u32 aux_n_slices)
: n_rows(0) : n_rows(0)
, n_cols(0) , n_cols(0)
, n_elem_slice(0) , n_elem_slice(0)
skipping to change at line 371 skipping to change at line 377
} }
//! in-place cube addition //! in-place cube addition
template<typename eT> template<typename eT>
inline inline
const Cube<eT>& const Cube<eT>&
Cube<eT>::operator+=(const Cube<eT>& m) Cube<eT>::operator+=(const Cube<eT>& m)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
glue_cube_plus::apply_inplace(*this, m); arma_debug_assert_same_size(*this, m, "cube addition");
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
const u32 local_n_elem = m.n_elem;
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] += m_mem[i];
}
return *this; return *this;
} }
//! in-place cube subtraction //! in-place cube subtraction
template<typename eT> template<typename eT>
inline inline
const Cube<eT>& const Cube<eT>&
Cube<eT>::operator-=(const Cube<eT>& m) Cube<eT>::operator-=(const Cube<eT>& m)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
glue_cube_minus::apply_inplace(*this, m); arma_debug_assert_same_size(*this, m, "cube subtraction");
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
const u32 local_n_elem = m.n_elem;
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] -= m_mem[i];
}
return *this; return *this;
} }
//! in-place element-wise cube multiplication //! in-place element-wise cube multiplication
template<typename eT> template<typename eT>
inline inline
const Cube<eT>& const Cube<eT>&
Cube<eT>::operator%=(const Cube<eT>& m) Cube<eT>::operator%=(const Cube<eT>& m)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
glue_cube_schur::apply_inplace(*this, m); arma_debug_assert_same_size(*this, m, "element-wise cube multiplication")
;
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
const u32 local_n_elem = m.n_elem;
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] *= m_mem[i];
}
return *this; return *this;
} }
//! in-place element-wise cube division //! in-place element-wise cube division
template<typename eT> template<typename eT>
inline inline
const Cube<eT>& const Cube<eT>&
Cube<eT>::operator/=(const Cube<eT>& m) Cube<eT>::operator/=(const Cube<eT>& m)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
glue_cube_div::apply_inplace(*this, m); arma_debug_assert_same_size(*this, m, "element-wise cube division");
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
const u32 local_n_elem = m.n_elem;
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] /= m_mem[i];
}
return *this; return *this;
} }
//! 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
Cube<eT>::Cube Cube<eT>::Cube
( (
const BaseCube<typename Cube<eT>::pod_type,T1>& A, const BaseCube<typename Cube<eT>::pod_type,T1>& A,
skipping to change at line 641 skipping to change at line 687
(in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2 ) || (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2 ) ||
(in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices) , (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices) ,
"Cube::subcube(): indices out of bounds or incorrectly used" "Cube::subcube(): indices out of bounds or incorrectly used"
); );
return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, in_row2, in_c ol2, in_slice2); return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, in_row2, in_c ol2, in_slice2);
} }
//! create a cube from OpCube, i.e. run the previously delayed unary operat ions //! create a cube from OpCube, i.e. run the previously delayed unary operat ions
template<typename eT> template<typename eT>
template<typename T1, typename op_cube_type> template<typename T1, typename op_type>
inline inline
Cube<eT>::Cube(const OpCube<T1, op_cube_type>& X) Cube<eT>::Cube(const OpCube<T1, op_type>& X)
: n_rows(0) : n_rows(0)
, n_cols(0) , n_cols(0)
, n_elem_slice(0) , n_elem_slice(0)
, n_slices(0) , n_slices(0)
, n_elem(0) , n_elem(0)
, use_aux_mem(false) , use_aux_mem(false)
, mat_ptrs(mat_ptrs) , mat_ptrs(mat_ptrs)
, mem(mem) , mem(mem)
{ {
arma_extra_debug_sigprint_this(this); arma_extra_debug_sigprint_this(this);
isnt_same_type<eT, typename T1::elem_type>::check(); isnt_same_type<eT, typename T1::elem_type>::check();
op_cube_type::apply(*this, X); op_type::apply(*this, X);
} }
//! create a cube from OpCube, i.e. run the previously delayed unary operat ions //! create a cube from OpCube, i.e. run the previously delayed unary operat ions
template<typename eT> template<typename eT>
template<typename T1, typename op_cube_type> template<typename T1, typename op_type>
inline inline
const Cube<eT>& const Cube<eT>&
Cube<eT>::operator=(const OpCube<T1, op_cube_type>& X) Cube<eT>::operator=(const OpCube<T1, op_type>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check(); isnt_same_type<eT, typename T1::elem_type>::check();
op_cube_type::apply(*this, X); op_type::apply(*this, X);
return *this; return *this;
} }
//! in-place cube addition, with the right-hand-side operand having delayed operations //! in-place cube addition, with the right-hand-side operand having delayed operations
template<typename eT> template<typename eT>
template<typename T1, typename op_cube_type> template<typename T1, typename op_type>
inline inline
const Cube<eT>& const Cube<eT>&
Cube<eT>::operator+=(const OpCube<T1, op_cube_type>& X) Cube<eT>::operator+=(const OpCube<T1, op_type>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check(); isnt_same_type<eT, typename T1::elem_type>::check();
glue_cube_plus::apply_inplace(*this, X); const Cube<eT> m(X);
arma_debug_assert_same_size(*this, m, "cube addition");
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
const u32 local_n_elem = m.n_elem;
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] += m_mem[i];
}
return *this; return *this;
} }
//! in-place cube subtraction, with the right-hand-side operand having dela yed operations //! in-place cube subtraction, with the right-hand-side operand having dela yed operations
template<typename eT> template<typename eT>
template<typename T1, typename op_cube_type> template<typename T1, typename op_type>
inline inline
const Cube<eT>& const Cube<eT>&
Cube<eT>::operator-=(const OpCube<T1, op_cube_type>& X) Cube<eT>::operator-=(const OpCube<T1, op_type>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check(); isnt_same_type<eT, typename T1::elem_type>::check();
glue_cube_minus::apply_inplace(*this, X); const Cube<eT> m(X);
arma_debug_assert_same_size(*this, m, "cube subtraction");
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
const u32 local_n_elem = m.n_elem;
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] -= m_mem[i];
}
return *this; return *this;
} }
//! in-place cube element-wise multiplication, with the right-hand-side ope rand having delayed operations //! in-place cube element-wise multiplication, with the right-hand-side ope rand having delayed operations
template<typename eT> template<typename eT>
template<typename T1, typename op_cube_type> template<typename T1, typename op_type>
inline inline
const Cube<eT>& const Cube<eT>&
Cube<eT>::operator%=(const OpCube<T1, op_cube_type>& X) Cube<eT>::operator%=(const OpCube<T1, op_type>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check(); isnt_same_type<eT, typename T1::elem_type>::check();
glue_cube_schur::apply_inplace(*this, X);
const Cube<eT> m(X);
arma_debug_assert_same_size(*this, m, "element-wise cube multiplication")
;
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
const u32 local_n_elem = m.n_elem;
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] *= m_mem[i];
}
return *this; return *this;
} }
//! in-place cube element-wise division, with the right-hand-side operand h aving delayed operations //! in-place cube element-wise division, with the right-hand-side operand h aving delayed operations
template<typename eT> template<typename eT>
template<typename T1, typename op_cube_type> template<typename T1, typename op_type>
inline inline
const Cube<eT>& const Cube<eT>&
Cube<eT>::operator/=(const OpCube<T1, op_cube_type>& X) Cube<eT>::operator/=(const OpCube<T1, op_type>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check(); isnt_same_type<eT, typename T1::elem_type>::check();
glue_cube_div::apply_inplace(*this, X);
const Cube<eT> m(X);
arma_debug_assert_same_size(*this, m, "element-wise cube division");
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
const u32 local_n_elem = m.n_elem;
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] /= m_mem[i];
}
return *this;
}
//! create a cube from eOpCube, i.e. run the previously delayed unary opera
tions
template<typename eT>
template<typename T1, typename eop_type>
inline
Cube<eT>::Cube(const eOpCube<T1, eop_type>& X)
: n_rows(0)
, n_cols(0)
, n_elem_slice(0)
, n_slices(0)
, n_elem(0)
, use_aux_mem(false)
, mat_ptrs(mat_ptrs)
, mem(mem)
{
arma_extra_debug_sigprint_this(this);
isnt_same_type<eT, typename T1::elem_type>::check();
eop_type::apply(*this, X);
}
//! create a cube from eOpCube, i.e. run the previously delayed unary opera
tions
template<typename eT>
template<typename T1, typename eop_type>
inline
const Cube<eT>&
Cube<eT>::operator=(const eOpCube<T1, eop_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
eop_type::apply(*this, X);
return *this;
}
//! in-place cube addition, with the right-hand-side operand having delayed
operations
template<typename eT>
template<typename T1, typename eop_type>
inline
const Cube<eT>&
Cube<eT>::operator+=(const eOpCube<T1, eop_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
eop_type::apply_inplace_plus(*this, X);
return *this;
}
//! in-place cube subtraction, with the right-hand-side operand having dela
yed operations
template<typename eT>
template<typename T1, typename eop_type>
inline
const Cube<eT>&
Cube<eT>::operator-=(const eOpCube<T1, eop_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
eop_type::apply_inplace_minus(*this, X);
return *this;
}
//! in-place cube element-wise multiplication, with the right-hand-side ope
rand having delayed operations
template<typename eT>
template<typename T1, typename eop_type>
inline
const Cube<eT>&
Cube<eT>::operator%=(const eOpCube<T1, eop_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
eop_type::apply_inplace_schur(*this, X);
return *this;
}
//! in-place cube element-wise division, with the right-hand-side operand h
aving delayed operations
template<typename eT>
template<typename T1, typename eop_type>
inline
const Cube<eT>&
Cube<eT>::operator/=(const eOpCube<T1, eop_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
eop_type::apply_inplace_div(*this, X);
return *this; return *this;
} }
//! create a cube from Glue, i.e. run the previously delayed binary operati ons //! create a cube from Glue, i.e. run the previously delayed binary operati ons
template<typename eT> template<typename eT>
template<typename T1, typename T2, typename glue_cube_type> template<typename T1, typename T2, typename glue_type>
inline inline
Cube<eT>::Cube(const GlueCube<T1, T2, glue_cube_type>& X) Cube<eT>::Cube(const GlueCube<T1, T2, glue_type>& X)
: n_rows(0) : n_rows(0)
, n_cols(0) , n_cols(0)
, n_elem_slice(0) , n_elem_slice(0)
, n_slices(0) , n_slices(0)
, n_elem(0) , n_elem(0)
, use_aux_mem(false) , use_aux_mem(false)
, mat_ptrs(mat_ptrs) , mat_ptrs(mat_ptrs)
, mem(mem) , mem(mem)
{ {
arma_extra_debug_sigprint_this(this); arma_extra_debug_sigprint_this(this);
this->operator=(X); this->operator=(X);
} }
//! create a cube from Glue, i.e. run the previously delayed binary operati ons //! create a cube from Glue, i.e. run the previously delayed binary operati ons
template<typename eT> template<typename eT>
template<typename T1, typename T2, typename glue_cube_type> template<typename T1, typename T2, typename glue_type>
inline inline
const Cube<eT>& const Cube<eT>&
Cube<eT>::operator=(const GlueCube<T1, T2, glue_cube_type>& X) Cube<eT>::operator=(const GlueCube<T1, T2, glue_type>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check(); isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check(); isnt_same_type<eT, typename T2::elem_type>::check();
glue_cube_type::apply(*this, X); glue_type::apply(*this, X);
return *this; return *this;
} }
//! in-place cube addition, with the right-hand-side operands having delaye d operations //! in-place cube addition, with the right-hand-side operands having delaye d operations
template<typename eT> template<typename eT>
template<typename T1, typename T2, typename glue_cube_type> template<typename T1, typename T2, typename glue_type>
inline inline
const Cube<eT>& const Cube<eT>&
Cube<eT>::operator+=(const GlueCube<T1, T2, glue_cube_type>& X) Cube<eT>::operator+=(const GlueCube<T1, T2, glue_type>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check(); isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check(); isnt_same_type<eT, typename T2::elem_type>::check();
glue_cube_plus::apply_inplace(*this, X); const Cube<eT> m(X);
arma_debug_assert_same_size(*this, m, "cube addition");
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
const u32 local_n_elem = m.n_elem;
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] += m_mem[i];
}
return *this; return *this;
} }
//! in-place cube subtraction, with the right-hand-side operands having del ayed operations //! in-place cube subtraction, with the right-hand-side operands having del ayed operations
template<typename eT> template<typename eT>
template<typename T1, typename T2, typename glue_cube_type> template<typename T1, typename T2, typename glue_type>
inline inline
const Cube<eT>& const Cube<eT>&
Cube<eT>::operator-=(const GlueCube<T1, T2, glue_cube_type>& X) Cube<eT>::operator-=(const GlueCube<T1, T2, glue_type>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check(); isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check(); isnt_same_type<eT, typename T2::elem_type>::check();
glue_cube_minus::apply_inplace(*this, X); const Cube<eT> m(X);
arma_debug_assert_same_size(*this, m, "cube subtraction");
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
const u32 local_n_elem = m.n_elem;
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] -= m_mem[i];
}
return *this; return *this;
} }
//! in-place cube element-wise multiplication, with the right-hand-side ope rands having delayed operations //! in-place cube element-wise multiplication, with the right-hand-side ope rands having delayed operations
template<typename eT> template<typename eT>
template<typename T1, typename T2, typename glue_cube_type> template<typename T1, typename T2, typename glue_type>
inline inline
const Cube<eT>& const Cube<eT>&
Cube<eT>::operator%=(const GlueCube<T1, T2, glue_cube_type>& X) Cube<eT>::operator%=(const GlueCube<T1, T2, glue_type>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check(); isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check(); isnt_same_type<eT, typename T2::elem_type>::check();
glue_cube_schur::apply_inplace(*this, X); const Cube<eT> m(X);
arma_debug_assert_same_size(*this, m, "element-wise cube multiplication")
;
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
const u32 local_n_elem = m.n_elem;
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] *= m_mem[i];
}
return *this; return *this;
} }
//! in-place cube element-wise division, with the right-hand-side operands having delayed operations //! in-place cube element-wise division, with the right-hand-side operands having delayed operations
template<typename eT> template<typename eT>
template<typename T1, typename T2, typename glue_cube_type> template<typename T1, typename T2, typename glue_type>
inline inline
const Cube<eT>& const Cube<eT>&
Cube<eT>::operator/=(const GlueCube<T1, T2, glue_cube_type>& X) Cube<eT>::operator/=(const GlueCube<T1, T2, glue_type>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check(); isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check(); isnt_same_type<eT, typename T2::elem_type>::check();
glue_cube_div::apply_inplace(*this, X); const Cube<eT> m(X);
arma_debug_assert_same_size(*this, m, "element-wise cube division");
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
const u32 local_n_elem = m.n_elem;
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] /= m_mem[i];
}
return *this;
}
//! create a cube from eGlue, i.e. run the previously delayed binary operat
ions
template<typename eT>
template<typename T1, typename T2, typename eglue_type>
inline
Cube<eT>::Cube(const eGlueCube<T1, T2, eglue_type>& X)
: n_rows(0)
, n_cols(0)
, n_elem_slice(0)
, n_slices(0)
, n_elem(0)
, use_aux_mem(false)
, mat_ptrs(mat_ptrs)
, mem(mem)
{
arma_extra_debug_sigprint_this(this);
this->operator=(X);
}
//! create a cube from Glue, i.e. run the previously delayed binary operati
ons
template<typename eT>
template<typename T1, typename T2, typename eglue_type>
inline
const Cube<eT>&
Cube<eT>::operator=(const eGlueCube<T1, T2, eglue_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check();
eglue_type::apply(*this, X);
return *this;
}
//! in-place cube addition, with the right-hand-side operands having delaye
d operations
template<typename eT>
template<typename T1, typename T2, typename eglue_type>
inline
const Cube<eT>&
Cube<eT>::operator+=(const eGlueCube<T1, T2, eglue_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check();
eglue_type::apply_inplace_plus(*this, X);
return *this;
}
//! in-place cube subtraction, with the right-hand-side operands having del
ayed operations
template<typename eT>
template<typename T1, typename T2, typename eglue_type>
inline
const Cube<eT>&
Cube<eT>::operator-=(const eGlueCube<T1, T2, eglue_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check();
eglue_type::apply_inplace_minus(*this, X);
return *this;
}
//! in-place cube element-wise multiplication, with the right-hand-side ope
rands having delayed operations
template<typename eT>
template<typename T1, typename T2, typename eglue_type>
inline
const Cube<eT>&
Cube<eT>::operator%=(const eGlueCube<T1, T2, eglue_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check();
eglue_type::apply_inplace_schur(*this, X);
return *this;
}
//! in-place cube element-wise division, with the right-hand-side operands
having delayed operations
template<typename eT>
template<typename T1, typename T2, typename eglue_type>
inline
const Cube<eT>&
Cube<eT>::operator/=(const eGlueCube<T1, T2, eglue_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check();
eglue_type::apply_inplace_div(*this, X);
return *this; return *this;
} }
//! linear element accessor (treats the cube as a vector); bounds checking not done when ARMA_NO_DEBUG is defined //! linear element accessor (treats the cube as a vector); bounds checking not done when ARMA_NO_DEBUG is defined
template<typename eT> template<typename eT>
arma_inline arma_inline
eT& eT&
Cube<eT>::operator() (const u32 i) Cube<eT>::operator() (const u32 i)
{ {
arma_debug_check( (i >= n_elem), "Cube::operator(): index out of bounds") ; arma_debug_check( (i >= n_elem), "Cube::operator(): index out of bounds") ;
skipping to change at line 1237 skipping to change at line 1579
case ppm_binary: case ppm_binary:
diskio::save_ppm_binary(*this, name); diskio::save_ppm_binary(*this, name);
break; break;
default: default:
arma_stop("Cube::save(): unsupported file type"); arma_stop("Cube::save(): unsupported file type");
} }
} }
//! save the cube to a stream
template<typename eT>
inline
void
Cube<eT>::save(std::ostream& os, const file_type type) const
{
arma_extra_debug_sigprint();
switch(type)
{
case raw_ascii:
diskio::save_raw_ascii(*this, "[ostream]", os);
break;
case arma_ascii:
diskio::save_arma_ascii(*this, "[ostream]", os);
break;
case arma_binary:
diskio::save_arma_binary(*this, "[ostream]", os);
break;
case ppm_binary:
diskio::save_ppm_binary(*this, "[ostream]", os);
break;
default:
arma_stop("Cube::save(): unsupported file type");
}
}
//! load a cube from a file //! load a cube from a file
template<typename eT> template<typename eT>
inline inline
void void
Cube<eT>::load(const std::string name, const file_type type) Cube<eT>::load(const std::string name, const file_type type)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
switch(type) switch(type)
{ {
skipping to change at line 1273 skipping to change at line 1647
case ppm_binary: case ppm_binary:
diskio::load_ppm_binary(*this, name); diskio::load_ppm_binary(*this, name);
break; break;
default: default:
arma_stop("Cube::load(): unsupported file type"); arma_stop("Cube::load(): unsupported file type");
} }
} }
//! load a cube from a stream
template<typename eT>
inline
void
Cube<eT>::load(std::istream& is, const file_type type)
{
arma_extra_debug_sigprint();
switch(type)
{
case auto_detect:
diskio::load_auto_detect(*this, "[istream]", is);
break;
case raw_ascii:
diskio::load_raw_ascii(*this, "[istream]", is);
break;
case arma_ascii:
diskio::load_arma_ascii(*this, "[istream]", is);
break;
case arma_binary:
diskio::load_arma_binary(*this, "[istream]", is);
break;
case ppm_binary:
diskio::load_ppm_binary(*this, "[istream]", is);
break;
default:
arma_stop("Cube::load(): unsupported file type");
}
}
//! prefix ++ //! prefix ++
template<typename eT> template<typename eT>
arma_inline arma_inline
void void
Cube_aux::prefix_pp(Cube<eT>& x) Cube_aux::prefix_pp(Cube<eT>& x)
{ {
eT* memptr = x.memptr(); eT* memptr = x.memptr();
const u32 n_elem = x.n_elem; const u32 n_elem = x.n_elem;
for(u32 i=0; i<n_elem; ++i) for(u32 i=0; i<n_elem; ++i)
 End of changes. 44 change blocks. 
40 lines changed or deleted 465 lines changed or added


 Cube_proto.hpp   Cube_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 25 skipping to change at line 26
//! \addtogroup Cube //! \addtogroup Cube
//! @{ //! @{
//! Dense cube class //! Dense cube class
template<typename eT> template<typename eT>
class Cube : public BaseCube< eT, Cube<eT> > class Cube : public BaseCube< eT, Cube<eT> >
{ {
public: public:
typedef eT elem_type; //!< the type of elements stored in the cube typedef eT elem_type; //!< the type of ele
ments stored in the cube
typedef typename get_pod_type<elem_type>::pod_type pod_type; typedef typename get_pod_type<eT>::result pod_type; //!< if eT is non-co
//!< if eT is std::complex, pod_type is the underlying type used by std:: mplex, pod_type is same as eT. otherwise, pod_type is the underlying type u
complex. sed by std::complex
//!< otherwise pod_type is the same as elem_type
const u32 n_rows; //!< number of rows in each slice (read-only) const u32 n_rows; //!< number of rows in each slice (read-only)
const u32 n_cols; //!< number of columns in each slice (read-only) const u32 n_cols; //!< number of columns in each slice (read-only)
const u32 n_elem_slice; //!< number of elements in each slice (read-only ) const u32 n_elem_slice; //!< number of elements in each slice (read-only )
const u32 n_slices; //!< number of slices in the cube (read-only) const u32 n_slices; //!< number of slices in the cube (read-only)
const u32 n_elem; //!< number of elements in the cube (read-only) const u32 n_elem; //!< number of elements in the cube (read-only)
const bool use_aux_mem; //!< true if externally managed memory is being used (read-only) const bool use_aux_mem; //!< true if externally managed memory is being used (read-only)
arma_aligned const Mat<eT>** const mat_ptrs; //!< pointer to an array con taining pointers to Mat instances (one for each slice) arma_aligned const Mat<eT>** const mat_ptrs; //!< pointer to an array con taining pointers to Mat instances (one for each slice)
arma_aligned const eT* const mem; //!< pointer to the memory u sed by the cube (memory is read-only) arma_aligned const eT* const mem; //!< pointer to the memory u sed by the cube (memory is read-only)
skipping to change at line 87 skipping to change at line 85
arma_inline Mat<eT>& slice(const u32 in_slice); arma_inline Mat<eT>& slice(const u32 in_slice);
arma_inline const Mat<eT>& slice(const u32 in_slice) const; arma_inline const Mat<eT>& slice(const u32 in_slice) const;
arma_inline subview_cube<eT> slices(const u32 in_slice1, const u32 in_slice2); arma_inline subview_cube<eT> slices(const u32 in_slice1, const u32 in_slice2);
arma_inline const subview_cube<eT> slices(const u32 in_slice1, const u32 in_slice2) const; arma_inline const subview_cube<eT> slices(const u32 in_slice1, const u32 in_slice2) const;
arma_inline subview_cube<eT> subcube(const u32 in_row1, const u32 i n_col1, const u32 in_slice1, const u32 in_row2, const u32 in_col2, const u3 2 in_slice2); arma_inline subview_cube<eT> subcube(const u32 in_row1, const u32 i n_col1, const u32 in_slice1, const u32 in_row2, const u32 in_col2, const u3 2 in_slice2);
arma_inline const subview_cube<eT> subcube(const u32 in_row1, const u32 i n_col1, const u32 in_slice1, const u32 in_row2, const u32 in_col2, const u3 2 in_slice2) const; arma_inline const subview_cube<eT> subcube(const u32 in_row1, const u32 i n_col1, const u32 in_slice1, const u32 in_row2, const u32 in_col2, const u3 2 in_slice2) const;
template<typename T1, typename op_cube_type> inline Cub template<typename T1, typename op_type> inline Cube(con
e(const OpCube<T1, op_cube_type>& X); st OpCube<T1, op_type>& X);
template<typename T1, typename op_cube_type> inline const Cube& operator template<typename T1, typename op_type> inline const Cube& operator=(con
=(const OpCube<T1, op_cube_type>& X); st OpCube<T1, op_type>& X);
template<typename T1, typename op_cube_type> inline const Cube& operator+ template<typename T1, typename op_type> inline const Cube& operator+=(con
=(const OpCube<T1, op_cube_type>& X); st OpCube<T1, op_type>& X);
template<typename T1, typename op_cube_type> inline const Cube& operator- template<typename T1, typename op_type> inline const Cube& operator-=(con
=(const OpCube<T1, op_cube_type>& X); st OpCube<T1, op_type>& X);
template<typename T1, typename op_cube_type> inline const Cube& operator% template<typename T1, typename op_type> inline const Cube& operator%=(con
=(const OpCube<T1, op_cube_type>& X); st OpCube<T1, op_type>& X);
template<typename T1, typename op_cube_type> inline const Cube& operator/ template<typename T1, typename op_type> inline const Cube& operator/=(con
=(const OpCube<T1, op_cube_type>& X); st OpCube<T1, op_type>& X);
template<typename T1, typename T2, typename glue_cube_type> inline template<typename T1, typename eop_type> inline Cube(co
Cube(const GlueCube<T1, T2, glue_cube_type>& X); nst eOpCube<T1, eop_type>& X);
template<typename T1, typename T2, typename glue_cube_type> inline const template<typename T1, typename eop_type> inline const Cube& operator=(co
Cube& operator=(const GlueCube<T1, T2, glue_cube_type>& X); nst eOpCube<T1, eop_type>& X);
template<typename T1, typename T2, typename glue_cube_type> inline const template<typename T1, typename eop_type> inline const Cube& operator+=(co
Cube& operator+=(const GlueCube<T1, T2, glue_cube_type>& X); nst eOpCube<T1, eop_type>& X);
template<typename T1, typename T2, typename glue_cube_type> inline const template<typename T1, typename eop_type> inline const Cube& operator-=(co
Cube& operator-=(const GlueCube<T1, T2, glue_cube_type>& X); nst eOpCube<T1, eop_type>& X);
template<typename T1, typename T2, typename glue_cube_type> inline const template<typename T1, typename eop_type> inline const Cube& operator%=(co
Cube& operator%=(const GlueCube<T1, T2, glue_cube_type>& X); nst eOpCube<T1, eop_type>& X);
template<typename T1, typename T2, typename glue_cube_type> inline const template<typename T1, typename eop_type> inline const Cube& operator/=(co
Cube& operator/=(const GlueCube<T1, T2, glue_cube_type>& X); nst eOpCube<T1, eop_type>& X);
template<typename T1, typename T2, typename glue_type> inline
Cube(const GlueCube<T1, T2, glue_type>& X);
template<typename T1, typename T2, typename glue_type> inline const Cube&
operator=(const GlueCube<T1, T2, glue_type>& X);
template<typename T1, typename T2, typename glue_type> inline const Cube&
operator+=(const GlueCube<T1, T2, glue_type>& X);
template<typename T1, typename T2, typename glue_type> inline const Cube&
operator-=(const GlueCube<T1, T2, glue_type>& X);
template<typename T1, typename T2, typename glue_type> inline const Cube&
operator%=(const GlueCube<T1, T2, glue_type>& X);
template<typename T1, typename T2, typename glue_type> inline const Cube&
operator/=(const GlueCube<T1, T2, glue_type>& X);
template<typename T1, typename T2, typename eglue_type> inline
Cube(const eGlueCube<T1, T2, eglue_type>& X);
template<typename T1, typename T2, typename eglue_type> inline const Cube
& operator=(const eGlueCube<T1, T2, eglue_type>& X);
template<typename T1, typename T2, typename eglue_type> inline const Cube
& operator+=(const eGlueCube<T1, T2, eglue_type>& X);
template<typename T1, typename T2, typename eglue_type> inline const Cube
& operator-=(const eGlueCube<T1, T2, eglue_type>& X);
template<typename T1, typename T2, typename eglue_type> inline const Cube
& operator%=(const eGlueCube<T1, T2, eglue_type>& X);
template<typename T1, typename T2, typename eglue_type> inline const Cube
& operator/=(const eGlueCube<T1, T2, eglue_type>& X);
arma_inline eT& operator[] (const u32 i); arma_inline eT& operator[] (const u32 i);
arma_inline eT operator[] (const u32 i) const; arma_inline eT operator[] (const u32 i) const;
arma_inline eT& operator() (const u32 i); arma_inline eT& operator() (const u32 i);
arma_inline eT operator() (const u32 i) const; arma_inline eT operator() (const u32 i) const;
arma_inline eT& at (const u32 in_row, const u32 in_col, const u32 in_slice); arma_inline eT& at (const u32 in_row, const u32 in_col, const u32 in_slice);
arma_inline eT at (const u32 in_row, const u32 in_col, const u32 in_slice) const; arma_inline eT at (const u32 in_row, const u32 in_col, const u32 in_slice) const;
arma_inline eT& operator() (const u32 in_row, const u32 in_col, const u32 in_slice); arma_inline eT& operator() (const u32 in_row, const u32 in_col, const u32 in_slice);
arma_inline eT operator() (const u32 in_row, const u32 in_col, const u32 in_slice) const; arma_inline eT operator() (const u32 in_row, const u32 in_col, const u32 in_slice) const;
skipping to change at line 148 skipping to change at line 160
inline void fill(const eT val); inline void fill(const eT val);
inline void zeros(); inline void zeros();
inline void zeros(const u32 in_rows, const u32 in_cols, const u32 in_slic es); inline void zeros(const u32 in_rows, const u32 in_cols, const u32 in_slic es);
inline void ones(); inline void ones();
inline void ones(const u32 in_rows, const u32 in_cols, const u32 in_slice s); inline void ones(const u32 in_rows, const u32 in_cols, const u32 in_slice s);
inline void reset(); inline void reset();
inline void save(const std::string name, const file_type type = arma_bina inline void save(const std::string name, const file_type type = arma_bi
ry) const; nary) const;
inline void load(const std::string name, const file_type type = auto_dete inline void save( std::ostream& os, const file_type type = arma_bi
ct); nary) const;
inline void load(const std::string name, const file_type type = auto_de
tect);
inline void load( std::istream& is, const file_type type = auto_de
tect);
protected: protected:
inline void init(const u32 in_rows, const u32 in_cols, const u32 in_slice s); inline void init(const u32 in_rows, const u32 in_cols, const u32 in_slice s);
inline void init(const Cube& x); inline void init(const Cube& x);
inline void delete_mat(); inline void delete_mat();
inline void create_mat(); inline void create_mat();
}; };
 End of changes. 4 change blocks. 
36 lines changed or deleted 67 lines changed or added


 GlueCube_meat.hpp   GlueCube_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 GlueCube_proto.hpp   GlueCube_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 24 skipping to change at line 25
//! \addtogroup GlueCube //! \addtogroup GlueCube
//! @{ //! @{
//! analog of the Glue class, intended for Cube objects //! analog of the Glue class, intended for Cube objects
template<typename T1, typename T2, typename glue_type> template<typename T1, typename T2, typename glue_type>
class GlueCube : public BaseCube<typename T1::elem_type, GlueCube<T1, T2, g lue_type> > class GlueCube : public BaseCube<typename T1::elem_type, GlueCube<T1, T2, g lue_type> >
{ {
public: public:
typedef typename T1::elem_type elem_type; typedef typename T1::elem_type elem_type;
typedef typename get_pod_type<elem_type>::pod_type pod_type; typedef typename get_pod_type<elem_type>::result pod_type;
//! deliberately requiring the elem_type to be the same for both argument
s (experimental)
//! TODO:MAT the original Glue class should also have this restriction
arma_inline GlueCube(const BaseCube<typename T1::elem_type, T1>& in_A, c onst BaseCube<typename T1::elem_type, T2>& in_B); arma_inline GlueCube(const BaseCube<typename T1::elem_type, T1>& in_A, c onst BaseCube<typename T1::elem_type, T2>& in_B);
arma_inline ~GlueCube(); arma_inline ~GlueCube();
const T1& A; //!< first operand const T1& A; //!< first operand
const T2& B; //!< second operand const T2& B; //!< second operand
}; };
//! @} //! @}
 End of changes. 3 change blocks. 
6 lines changed or deleted 4 lines changed or added


 Glue_meat.hpp   Glue_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 26 skipping to change at line 27
//! @{ //! @{
template<typename T1, typename T2, typename glue_type> template<typename T1, typename T2, typename glue_type>
inline inline
Glue<T1,T2,glue_type>::Glue(const T1& in_A, const T2& in_B) Glue<T1,T2,glue_type>::Glue(const T1& in_A, const T2& in_B)
: A(in_A) : A(in_A)
, B(in_B) , B(in_B)
, aux_u32(aux_u32) , aux_u32(aux_u32)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<typename T1::elem_type, typename T2::elem_type>::check();
} }
template<typename T1, typename T2, typename glue_type> template<typename T1, typename T2, typename glue_type>
inline inline
Glue<T1,T2,glue_type>::Glue(const T1& in_A, const T2& in_B, const u32 in_au x_u32) Glue<T1,T2,glue_type>::Glue(const T1& in_A, const T2& in_B, const u32 in_au x_u32)
: A(in_A) : A(in_A)
, B(in_B) , B(in_B)
, aux_u32(in_aux_u32) , aux_u32(in_aux_u32)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<typename T1::elem_type, typename T2::elem_type>::check();
} }
template<typename T1, typename T2, typename glue_type> template<typename T1, typename T2, typename glue_type>
inline inline
Glue<T1,T2,glue_type>::~Glue() Glue<T1,T2,glue_type>::~Glue()
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
//! @} //! @}
 End of changes. 3 change blocks. 
5 lines changed or deleted 2 lines changed or added


 Glue_proto.hpp   Glue_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 25 skipping to change at line 26
//! \addtogroup Glue //! \addtogroup Glue
//! @{ //! @{
//! Class for storing data required for delayed binary operations, //! Class for storing data required for delayed binary operations,
//! such as the operands (e.g. two matrices) and the binary operator (e.g. addition). //! such as the operands (e.g. two matrices) and the binary operator (e.g. addition).
//! The operands are stored as references (which can be optimised away), //! The operands are stored as references (which can be optimised away),
//! while the operator is "stored" through the template definition (glue_ty pe). //! while the operator is "stored" through the template definition (glue_ty pe).
//! The operands can be 'Mat', 'Row', 'Col', 'Op', and 'Glue'. //! The operands can be 'Mat', 'Row', 'Col', 'Op', and 'Glue'.
//! Note that as 'Glue' can be one of the operands, more than two matrices can be stored. //! Note that as 'Glue' can be one of the operands, more than two matrices can be stored.
//! //!
//! For example, we could have: Glue< Glue<Mat, Mat, glue_times>, Mat, glue _plus> //! For example, we could have: Glue<Mat, Mat, glue_times>
//! //!
//! Another example is: Glue< Op<Mat, op_trans>, Op<Mat, op_inv>, glue_time s > //! Another example is: Glue< Op<Mat, op_trans>, Op<Mat, op_inv>, glue_time s >
//!
//! More complicated example: Glue< Op< Glue<Mat, Mat, glue_plus>, op_trans
>, Op<Mat, op_inv>, glue_times >
//!
template<typename T1, typename T2, typename glue_type> template<typename T1, typename T2, typename glue_type>
class Glue : public Base<typename T1::elem_type, Glue<T1, T2, glue_type> > class Glue : public Base<typename T1::elem_type, Glue<T1, T2, glue_type> >
{ {
public: public:
typedef typename T1::elem_type elem_type; typedef typename T1::elem_type elem_type;
typedef typename get_pod_type<elem_type>::pod_type pod_type; typedef typename get_pod_type<elem_type>::result pod_type;
arma_inline Glue(const T1& in_A, const T2& in_B); arma_inline Glue(const T1& in_A, const T2& in_B);
arma_inline Glue(const T1& in_A, const T2& in_B, const u32 in_aux_u32); arma_inline Glue(const T1& in_A, const T2& in_B, const u32 in_aux_u32);
arma_inline ~Glue(); arma_inline ~Glue();
const T1& A; //!< first operand const T1& A; //!< first operand
const T2& B; //!< second operand const T2& B; //!< second operand
const u32 aux_u32; //!< storage of auxiliary data, u32 format const u32 aux_u32; //!< storage of auxiliary data, u32 format
}; };
 End of changes. 4 change blocks. 
8 lines changed or deleted 5 lines changed or added


 Mat_meat.hpp   Mat_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 463 skipping to change at line 464
} }
//! in-place matrix addition //! in-place matrix addition
template<typename eT> template<typename eT>
inline inline
const Mat<eT>& const Mat<eT>&
Mat<eT>::operator+=(const Mat<eT>& m) Mat<eT>::operator+=(const Mat<eT>& m)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
glue_plus::apply_inplace(*this, m); arma_debug_assert_same_size(*this, m, "matrix addition");
const u32 local_n_elem = m.n_elem;
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] += m_mem[i];
}
return *this; return *this;
} }
//! in-place matrix subtraction //! in-place matrix subtraction
template<typename eT> template<typename eT>
inline inline
const Mat<eT>& const Mat<eT>&
Mat<eT>::operator-=(const Mat<eT>& m) Mat<eT>::operator-=(const Mat<eT>& m)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
glue_minus::apply_inplace(*this, m); arma_debug_assert_same_size(*this, m, "matrix subtraction");
const u32 local_n_elem = m.n_elem;
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] -= m_mem[i];
}
return *this; return *this;
} }
//! in-place matrix multiplication //! in-place matrix multiplication
template<typename eT> template<typename eT>
inline inline
const Mat<eT>& const Mat<eT>&
Mat<eT>::operator*=(const Mat<eT>& m) Mat<eT>::operator*=(const Mat<eT>& m)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
skipping to change at line 499 skipping to change at line 522
} }
//! in-place element-wise matrix multiplication //! in-place element-wise matrix multiplication
template<typename eT> template<typename eT>
inline inline
const Mat<eT>& const Mat<eT>&
Mat<eT>::operator%=(const Mat<eT>& m) Mat<eT>::operator%=(const Mat<eT>& m)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
glue_schur::apply_inplace(*this, m); arma_debug_assert_same_size(*this, m, "element-wise matrix multplication"
);
const u32 local_n_elem = m.n_elem;
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] *= m_mem[i];
}
return *this; return *this;
} }
//! in-place element-wise matrix division //! in-place element-wise matrix division
template<typename eT> template<typename eT>
inline inline
const Mat<eT>& const Mat<eT>&
Mat<eT>::operator/=(const Mat<eT>& m) Mat<eT>::operator/=(const Mat<eT>& m)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
glue_div::apply_inplace(*this, m); arma_debug_assert_same_size(*this, m, "element-wise matrix division");
const u32 local_n_elem = m.n_elem;
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] /= m_mem[i];
}
return *this; return *this;
} }
//! for constructing a complex matrix out of two non-complex matrices //! for constructing a complex matrix out of two non-complex matrices
template<typename eT> template<typename eT>
template<typename T1, typename T2> template<typename T1, typename T2>
inline inline
Mat<eT>::Mat Mat<eT>::Mat
( (
const Base<typename Mat<eT>::pod_type,T1>& A, const Base<typename Mat<eT>::pod_type,T1>& A,
skipping to change at line 619 skipping to change at line 664
} }
//! in-place matrix mutiplication (using a submatrix on the right-hand-side ) //! in-place matrix mutiplication (using a submatrix on the right-hand-side )
template<typename eT> template<typename eT>
inline inline
const Mat<eT>& const Mat<eT>&
Mat<eT>::operator*=(const subview<eT>& X) Mat<eT>::operator*=(const subview<eT>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
subview<eT>::times_inplace(*this, X); glue_times::apply_inplace(*this, X);
return *this; return *this;
} }
//! in-place element-wise matrix mutiplication (using a submatrix on the ri ght-hand-side) //! in-place element-wise matrix mutiplication (using a submatrix on the ri ght-hand-side)
template<typename eT> template<typename eT>
inline inline
const Mat<eT>& const Mat<eT>&
Mat<eT>::operator%=(const subview<eT>& X) Mat<eT>::operator%=(const subview<eT>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
skipping to change at line 764 skipping to change at line 809
inline inline
const Mat<eT>& const Mat<eT>&
Mat<eT>::operator=(const diagview<eT>& X) Mat<eT>::operator=(const diagview<eT>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
diagview<eT>::extract(*this, X); diagview<eT>::extract(*this, X);
return *this; return *this;
} }
//! in-place matrix addition (using a diagview on the right-hand-side)
template<typename eT>
inline
const Mat<eT>&
Mat<eT>::operator+=(const diagview<eT>& X)
{
arma_extra_debug_sigprint();
diagview<eT>::plus_inplace(*this, X);
return *this;
}
//! in-place matrix subtraction (using a diagview on the right-hand-side)
template<typename eT>
inline
const Mat<eT>&
Mat<eT>::operator-=(const diagview<eT>& X)
{
arma_extra_debug_sigprint();
diagview<eT>::minus_inplace(*this, X);
return *this;
}
//! in-place matrix mutiplication (using a diagview on the right-hand-side)
template<typename eT>
inline
const Mat<eT>&
Mat<eT>::operator*=(const diagview<eT>& X)
{
arma_extra_debug_sigprint();
glue_times::apply_inplace(*this, X);
return *this;
}
//! in-place element-wise matrix mutiplication (using a diagview on the rig
ht-hand-side)
template<typename eT>
inline
const Mat<eT>&
Mat<eT>::operator%=(const diagview<eT>& X)
{
arma_extra_debug_sigprint();
diagview<eT>::schur_inplace(*this, X);
return *this;
}
//! in-place element-wise matrix division (using a diagview on the right-ha
nd-side)
template<typename eT>
inline
const Mat<eT>&
Mat<eT>::operator/=(const diagview<eT>& X)
{
arma_extra_debug_sigprint();
diagview<eT>::div_inplace(*this, X);
return *this;
}
//! creation of subview (row vector) //! creation of subview (row vector)
template<typename eT> template<typename eT>
arma_inline arma_inline
subview_row<eT> subview_row<eT>
Mat<eT>::row(const u32 row_num) Mat<eT>::row(const u32 row_num)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_check( row_num >= n_rows, "Mat::row(): row out of bounds" ); arma_debug_check( row_num >= n_rows, "Mat::row(): row out of bounds" );
skipping to change at line 932 skipping to change at line 1037
Mat<eT>::diag(const s32 in_id) Mat<eT>::diag(const s32 in_id)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const u32 row_offset = (in_id < 0) ? -in_id : 0; const u32 row_offset = (in_id < 0) ? -in_id : 0;
const u32 col_offset = (in_id > 0) ? in_id : 0; const u32 col_offset = (in_id > 0) ? in_id : 0;
arma_debug_check arma_debug_check
( (
(row_offset >= n_rows) || (col_offset >= n_cols), (row_offset >= n_rows) || (col_offset >= n_cols),
"Mat::diag(): out of bounds" "Mat::diag(): requested diagonal out of bounds"
); );
const u32 len = (std::min)(n_rows - row_offset, n_cols - col_offset); const u32 len = (std::min)(n_rows - row_offset, n_cols - col_offset);
return diagview<eT>(*this, row_offset, col_offset, len); return diagview<eT>(*this, row_offset, col_offset, len);
} }
//! creation of diagview (diagonal) //! creation of diagview (diagonal)
template<typename eT> template<typename eT>
arma_inline arma_inline
skipping to change at line 954 skipping to change at line 1059
Mat<eT>::diag(const s32 in_id) const Mat<eT>::diag(const s32 in_id) const
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const u32 row_offset = (in_id < 0) ? -in_id : 0; const u32 row_offset = (in_id < 0) ? -in_id : 0;
const u32 col_offset = (in_id > 0) ? in_id : 0; const u32 col_offset = (in_id > 0) ? in_id : 0;
arma_debug_check arma_debug_check
( (
(row_offset >= n_rows) || (col_offset >= n_cols), (row_offset >= n_rows) || (col_offset >= n_cols),
"Mat::diag(): out of bounds" "Mat::diag(): requested diagonal out of bounds"
); );
const u32 len = (std::min)(n_rows - row_offset, n_cols - col_offset); const u32 len = (std::min)(n_rows - row_offset, n_cols - col_offset);
return diagview<eT>(*this, row_offset, col_offset, len); return diagview<eT>(*this, row_offset, col_offset, len);
} }
template<typename eT> template<typename eT>
inline inline
void void
skipping to change at line 1059 skipping to change at line 1164
template<typename eT> template<typename eT>
template<typename T1, typename op_type> template<typename T1, typename op_type>
inline inline
const Mat<eT>& const Mat<eT>&
Mat<eT>::operator+=(const Op<T1, op_type>& X) Mat<eT>::operator+=(const Op<T1, op_type>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check(); isnt_same_type<eT, typename T1::elem_type>::check();
glue_plus::apply_inplace(*this, X); const Mat<eT> m(X);
arma_debug_assert_same_size(*this, m, "matrix addition");
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
const u32 local_n_elem = m.n_elem;
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] += m_mem[i];
}
return *this; return *this;
} }
//! in-place matrix subtraction, with the right-hand-side operand having de layed operations //! in-place matrix subtraction, with the right-hand-side operand having de layed operations
template<typename eT> template<typename eT>
template<typename T1, typename op_type> template<typename T1, typename op_type>
inline inline
const Mat<eT>& const Mat<eT>&
Mat<eT>::operator-=(const Op<T1, op_type>& X) Mat<eT>::operator-=(const Op<T1, op_type>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check(); isnt_same_type<eT, typename T1::elem_type>::check();
glue_minus::apply_inplace(*this, X); const Mat<eT> m(X);
arma_debug_assert_same_size(*this, m, "matrix subtraction");
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
const u32 local_n_elem = m.n_elem;
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] -= m_mem[i];
}
return *this; return *this;
} }
//! in-place matrix multiplication, with the right-hand-side operand having delayed operations //! in-place matrix multiplication, with the right-hand-side operand having delayed operations
template<typename eT> template<typename eT>
template<typename T1, typename op_type> template<typename T1, typename op_type>
inline inline
const Mat<eT>& const Mat<eT>&
Mat<eT>::operator*=(const Op<T1, op_type>& X) Mat<eT>::operator*=(const Op<T1, op_type>& X)
skipping to change at line 1106 skipping to change at line 1233
//! in-place matrix element-wise multiplication, with the right-hand-side o perand having delayed operations //! in-place matrix element-wise multiplication, with the right-hand-side o perand having delayed operations
template<typename eT> template<typename eT>
template<typename T1, typename op_type> template<typename T1, typename op_type>
inline inline
const Mat<eT>& const Mat<eT>&
Mat<eT>::operator%=(const Op<T1, op_type>& X) Mat<eT>::operator%=(const Op<T1, op_type>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check(); isnt_same_type<eT, typename T1::elem_type>::check();
glue_schur::apply_inplace(*this, X);
const Mat<eT> m(X);
arma_debug_assert_same_size(*this, m, "element-wise matrix multiplication
");
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
const u32 local_n_elem = m.n_elem;
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] *= m_mem[i];
}
return *this; return *this;
} }
//! in-place matrix element-wise division, with the right-hand-side operand having delayed operations //! in-place matrix element-wise division, with the right-hand-side operand having delayed operations
template<typename eT> template<typename eT>
template<typename T1, typename op_type> template<typename T1, typename op_type>
inline inline
const Mat<eT>& const Mat<eT>&
Mat<eT>::operator/=(const Op<T1, op_type>& X) Mat<eT>::operator/=(const Op<T1, op_type>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check(); isnt_same_type<eT, typename T1::elem_type>::check();
glue_div::apply_inplace(*this, X);
const Mat<eT> m(X);
arma_debug_assert_same_size(*this, m, "element-wise matrix division");
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
const u32 local_n_elem = m.n_elem;
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] /= m_mem[i];
}
return *this;
}
//! create a matrix from eOp, i.e. run the previously delayed unary operati
ons
template<typename eT>
template<typename T1, typename eop_type>
inline
Mat<eT>::Mat(const eOp<T1, eop_type>& X)
: n_rows(0)
, n_cols(0)
, n_elem(0)
, use_aux_mem(false)
//, mem(0)
, mem(mem)
{
arma_extra_debug_sigprint_this(this);
isnt_same_type<eT, typename T1::elem_type>::check();
eop_type::apply(*this, X);
}
//! create a matrix from eOp, i.e. run the previously delayed unary operati
ons
template<typename eT>
template<typename T1, typename eop_type>
inline
const Mat<eT>&
Mat<eT>::operator=(const eOp<T1, eop_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
eop_type::apply(*this, X);
return *this;
}
template<typename eT>
template<typename T1, typename eop_type>
inline
const Mat<eT>&
Mat<eT>::operator+=(const eOp<T1, eop_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
eop_type::apply_inplace_plus(*this, X);
return *this;
}
template<typename eT>
template<typename T1, typename eop_type>
inline
const Mat<eT>&
Mat<eT>::operator-=(const eOp<T1, eop_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
eop_type::apply_inplace_minus(*this, X);
return *this;
}
template<typename eT>
template<typename T1, typename eop_type>
inline
const Mat<eT>&
Mat<eT>::operator*=(const eOp<T1, eop_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
glue_times::apply_inplace(*this, X);
return *this;
}
template<typename eT>
template<typename T1, typename eop_type>
inline
const Mat<eT>&
Mat<eT>::operator%=(const eOp<T1, eop_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
eop_type::apply_inplace_schur(*this, X);
return *this;
}
template<typename eT>
template<typename T1, typename eop_type>
inline
const Mat<eT>&
Mat<eT>::operator/=(const eOp<T1, eop_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
eop_type::apply_inplace_div(*this, X);
return *this; return *this;
} }
//! create a matrix from Glue, i.e. run the previously delayed binary opera tions //! create a matrix from Glue, i.e. run the previously delayed binary opera tions
template<typename eT> template<typename eT>
template<typename T1, typename T2, typename glue_type> template<typename T1, typename T2, typename glue_type>
inline inline
Mat<eT>::Mat(const Glue<T1, T2, glue_type>& X) Mat<eT>::Mat(const Glue<T1, T2, glue_type>& X)
: n_rows(0) : n_rows(0)
, n_cols(0) , n_cols(0)
, n_elem(0) , n_elem(0)
, use_aux_mem(false) , use_aux_mem(false)
//, mem(0) //, mem(0)
, mem(mem) , mem(mem)
{ {
arma_extra_debug_sigprint_this(this); arma_extra_debug_sigprint_this(this);
this->operator=(X);
isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check();
glue_type::apply(*this, X);
} }
//! create a matrix from Glue, i.e. run the previously delayed binary opera tions //! create a matrix from Glue, i.e. run the previously delayed binary opera tions
template<typename eT> template<typename eT>
template<typename T1, typename T2, typename glue_type> template<typename T1, typename T2, typename glue_type>
inline inline
const Mat<eT>& const Mat<eT>&
Mat<eT>::operator=(const Glue<T1, T2, glue_type>& X) Mat<eT>::operator=(const Glue<T1, T2, glue_type>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
// TODO:
// it may be simpler to pass the two objects (currently wrapped in X)
// directly to the apply function.
// (many adjustments throughout the source code will be required)
isnt_same_type<eT, typename T1::elem_type>::check(); isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check(); isnt_same_type<eT, typename T2::elem_type>::check();
glue_type::apply(*this, X); glue_type::apply(*this, X);
return *this; return *this;
} }
//! in-place matrix addition, with the right-hand-side operands having dela yed operations //! in-place matrix addition, with the right-hand-side operands having dela yed operations
template<typename eT> template<typename eT>
template<typename T1, typename T2, typename glue_type> template<typename T1, typename T2, typename glue_type>
inline inline
const Mat<eT>& const Mat<eT>&
Mat<eT>::operator+=(const Glue<T1, T2, glue_type>& X) Mat<eT>::operator+=(const Glue<T1, T2, glue_type>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check(); isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check(); isnt_same_type<eT, typename T2::elem_type>::check();
glue_plus::apply_inplace(*this, X); const Mat<eT> m(X);
arma_debug_assert_same_size(*this, m, "matrix addition");
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
const u32 local_n_elem = m.n_elem;
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] += m_mem[i];
}
return *this; return *this;
} }
//! in-place matrix subtraction, with the right-hand-side operands having d elayed operations //! in-place matrix subtraction, with the right-hand-side operands having d elayed operations
template<typename eT> template<typename eT>
template<typename T1, typename T2, typename glue_type> template<typename T1, typename T2, typename glue_type>
inline inline
const Mat<eT>& const Mat<eT>&
Mat<eT>::operator-=(const Glue<T1, T2, glue_type>& X) Mat<eT>::operator-=(const Glue<T1, T2, glue_type>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check(); isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check(); isnt_same_type<eT, typename T2::elem_type>::check();
glue_minus::apply_inplace(*this, X); const Mat<eT> m(X);
arma_debug_assert_same_size(*this, m, "matrix subtraction");
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
const u32 local_n_elem = m.n_elem;
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] -= m_mem[i];
}
return *this; return *this;
} }
//! in-place matrix multiplications, with the right-hand-side operands havi ng delayed operations //! in-place matrix multiplications, with the right-hand-side operands havi ng delayed operations
template<typename eT> template<typename eT>
template<typename T1, typename T2, typename glue_type> template<typename T1, typename T2, typename glue_type>
inline inline
const Mat<eT>& const Mat<eT>&
Mat<eT>::operator*=(const Glue<T1, T2, glue_type>& X) Mat<eT>::operator*=(const Glue<T1, T2, glue_type>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check(); isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check(); isnt_same_type<eT, typename T2::elem_type>::check();
glue_times::apply_inplace(*this, X); glue_times::apply_inplace(*this, X);
return *this; return *this;
} }
//! in-place matrix element-wise multiplication, with the right-hand-side o perands having delayed operations //! in-place matrix element-wise multiplication, with the right-hand-side o perands having delayed operations
template<typename eT> template<typename eT>
template<typename T1, typename T2, typename glue_type> template<typename T1, typename T2, typename glue_type>
inline inline
const Mat<eT>& const Mat<eT>&
Mat<eT>::operator%=(const Glue<T1, T2, glue_type>& X) Mat<eT>::operator%=(const Glue<T1, T2, glue_type>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check(); isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check(); isnt_same_type<eT, typename T2::elem_type>::check();
glue_schur::apply_inplace(*this, X); const Mat<eT> m(X);
arma_debug_assert_same_size(*this, m, "element-wise matrix multiplication
");
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
const u32 local_n_elem = m.n_elem;
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] *= m_mem[i];
}
return *this; return *this;
} }
//! in-place matrix element-wise division, with the right-hand-side operand s having delayed operations //! in-place matrix element-wise division, with the right-hand-side operand s having delayed operations
template<typename eT> template<typename eT>
template<typename T1, typename T2, typename glue_type> template<typename T1, typename T2, typename glue_type>
inline inline
const Mat<eT>& const Mat<eT>&
Mat<eT>::operator/=(const Glue<T1, T2, glue_type>& X) Mat<eT>::operator/=(const Glue<T1, T2, glue_type>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check(); isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check(); isnt_same_type<eT, typename T2::elem_type>::check();
glue_div::apply_inplace(*this, X); const Mat<eT> m(X);
arma_debug_assert_same_size(*this, m, "element-wise matrix division");
eT* out_mem = (*this).memptr();
const eT* m_mem = m.memptr();
const u32 local_n_elem = m.n_elem;
for(u32 i=0; i<local_n_elem; ++i)
{
out_mem[i] /= m_mem[i];
}
return *this;
}
template<typename eT>
template<typename T1, typename T2>
inline
const Mat<eT>&
Mat<eT>::operator+=(const Glue<T1, T2, glue_times>& X)
{
arma_extra_debug_sigprint();
glue_times::apply_inplace_plus(*this, X, s32(+1));
return *this;
}
template<typename eT>
template<typename T1, typename T2>
inline
const Mat<eT>&
Mat<eT>::operator-=(const Glue<T1, T2, glue_times>& X)
{
arma_extra_debug_sigprint();
glue_times::apply_inplace_plus(*this, X, s32(-1));
return *this;
}
//! create a matrix from eGlue, i.e. run the previously delayed binary oper
ations
template<typename eT>
template<typename T1, typename T2, typename eglue_type>
inline
Mat<eT>::Mat(const eGlue<T1, T2, eglue_type>& X)
: n_rows(0)
, n_cols(0)
, n_elem(0)
, use_aux_mem(false)
//, mem(0)
, mem(mem)
{
arma_extra_debug_sigprint_this(this);
isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check();
eglue_type::apply(*this, X);
}
//! create a matrix from eGlue, i.e. run the previously delayed binary oper
ations
template<typename eT>
template<typename T1, typename T2, typename eglue_type>
inline
const Mat<eT>&
Mat<eT>::operator=(const eGlue<T1, T2, eglue_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check();
eglue_type::apply(*this, X);
return *this;
}
//! in-place matrix addition, with the right-hand-side operands having dela
yed operations
template<typename eT>
template<typename T1, typename T2, typename eglue_type>
inline
const Mat<eT>&
Mat<eT>::operator+=(const eGlue<T1, T2, eglue_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check();
eglue_type::apply_inplace_plus(*this, X);
return *this;
}
//! in-place matrix subtraction, with the right-hand-side operands having d
elayed operations
template<typename eT>
template<typename T1, typename T2, typename eglue_type>
inline
const Mat<eT>&
Mat<eT>::operator-=(const eGlue<T1, T2, eglue_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check();
eglue_type::apply_inplace_minus(*this, X);
return *this;
}
template<typename eT>
template<typename T1, typename T2, typename eglue_type>
inline
const Mat<eT>&
Mat<eT>::operator*=(const eGlue<T1, T2, eglue_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check();
glue_times::apply_inplace(*this, X);
return *this;
}
template<typename eT>
template<typename T1, typename T2, typename eglue_type>
inline
const Mat<eT>&
Mat<eT>::operator%=(const eGlue<T1, T2, eglue_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check();
eglue_type::apply_inplace_schur(*this, X);
return *this;
}
template<typename eT>
template<typename T1, typename T2, typename eglue_type>
inline
const Mat<eT>&
Mat<eT>::operator/=(const eGlue<T1, T2, eglue_type>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<eT, typename T1::elem_type>::check();
isnt_same_type<eT, typename T2::elem_type>::check();
eglue_type::apply_inplace_div(*this, X);
return *this; return *this;
} }
//! linear element accessor (treats the matrix as a vector); bounds checkin g not done when ARMA_NO_DEBUG is defined //! linear element accessor (treats the matrix as a vector); bounds checkin g not done when ARMA_NO_DEBUG is defined
template<typename eT> template<typename eT>
arma_inline arma_inline
eT& eT&
Mat<eT>::operator() (const u32 i) Mat<eT>::operator() (const u32 i)
{ {
arma_debug_check( (i >= n_elem), "Mat::operator(): index out of bounds"); arma_debug_check( (i >= n_elem), "Mat::operator(): out of bounds");
return access::rw(mem[i]); return access::rw(mem[i]);
} }
//! linear element accessor (treats the matrix as a vector); bounds checkin g not done when ARMA_NO_DEBUG is defined //! linear element accessor (treats the matrix as a vector); bounds checkin g not done when ARMA_NO_DEBUG is defined
template<typename eT> template<typename eT>
arma_inline arma_inline
eT eT
Mat<eT>::operator() (const u32 i) const Mat<eT>::operator() (const u32 i) const
{ {
arma_debug_check( (i >= n_elem), "Mat::operator(): index out of bounds"); arma_debug_check( (i >= n_elem), "Mat::operator(): out of bounds");
return mem[i]; return mem[i];
} }
//! linear element accessor (treats the matrix as a vector); no bounds chec k. //! linear element accessor (treats the matrix as a vector); no bounds chec k.
template<typename eT> template<typename eT>
arma_inline arma_inline
eT& eT&
Mat<eT>::operator[] (const u32 i) Mat<eT>::operator[] (const u32 i)
{ {
return access::rw(mem[i]); return access::rw(mem[i]);
skipping to change at line 1290 skipping to change at line 1739
{ {
return mem[i]; return mem[i];
} }
//! element accessor; bounds checking not done when ARMA_NO_DEBUG is define d //! element accessor; bounds checking not done when ARMA_NO_DEBUG is define d
template<typename eT> template<typename eT>
arma_inline arma_inline
eT& eT&
Mat<eT>::operator() (const u32 in_row, const u32 in_col) Mat<eT>::operator() (const u32 in_row, const u32 in_col)
{ {
arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "Mat::opera tor(): index out of bounds"); arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "Mat::opera tor(): out of bounds");
return access::rw(mem[in_row + in_col*n_rows]); return access::rw(mem[in_row + in_col*n_rows]);
} }
//! element accessor; bounds checking not done when ARMA_NO_DEBUG is define d //! element accessor; bounds checking not done when ARMA_NO_DEBUG is define d
template<typename eT> template<typename eT>
arma_inline arma_inline
eT eT
Mat<eT>::operator() (const u32 in_row, const u32 in_col) const Mat<eT>::operator() (const u32 in_row, const u32 in_col) const
{ {
arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "Mat::opera tor(): index out of bounds"); arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "Mat::opera tor(): out of bounds");
return mem[in_row + in_col*n_rows]; return mem[in_row + in_col*n_rows];
} }
//! element accessor; no bounds check //! element accessor; no bounds check
template<typename eT> template<typename eT>
arma_inline arma_inline
eT& eT&
Mat<eT>::at(const u32 in_row, const u32 in_col) Mat<eT>::at(const u32 in_row, const u32 in_col)
{ {
return access::rw( mem[in_row + in_col*n_rows] ); return access::rw( mem[in_row + in_col*n_rows] );
skipping to change at line 1712 skipping to change at line 2161
case pgm_binary: case pgm_binary:
diskio::save_pgm_binary(*this, name); diskio::save_pgm_binary(*this, name);
break; break;
default: default:
arma_stop("Mat::save(): unsupported file type"); arma_stop("Mat::save(): unsupported file type");
} }
} }
//! save the matrix to a stream
template<typename eT>
inline
void
Mat<eT>::save(std::ostream& os, const file_type type) const
{
arma_extra_debug_sigprint();
switch(type)
{
case raw_ascii:
diskio::save_raw_ascii(*this, "[ostream]", os);
break;
case arma_ascii:
diskio::save_arma_ascii(*this, "[ostream]", os);
break;
case arma_binary:
diskio::save_arma_binary(*this, "[ostream]", os);
break;
case pgm_binary:
diskio::save_pgm_binary(*this, "[ostream]", os);
break;
default:
arma_stop("Mat::save(): unsupported file type");
}
}
//! load a matrix from a file //! load a matrix from a file
template<typename eT> template<typename eT>
inline inline
void void
Mat<eT>::load(const std::string name, const file_type type) Mat<eT>::load(const std::string name, const file_type type)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
switch(type) switch(type)
{ {
skipping to change at line 1748 skipping to change at line 2229
case pgm_binary: case pgm_binary:
diskio::load_pgm_binary(*this, name); diskio::load_pgm_binary(*this, name);
break; break;
default: default:
arma_stop("Mat::load(): unsupported file type"); arma_stop("Mat::load(): unsupported file type");
} }
} }
//! load a matrix from a stream
template<typename eT>
inline
void
Mat<eT>::load(std::istream& is, const file_type type)
{
arma_extra_debug_sigprint();
switch(type)
{
case auto_detect:
diskio::load_auto_detect(*this, "[istream]", is);
break;
case raw_ascii:
diskio::load_raw_ascii(*this, "[istream]", is);
break;
case arma_ascii:
diskio::load_arma_ascii(*this, "[istream]", is);
break;
case arma_binary:
diskio::load_arma_binary(*this, "[istream]", is);
break;
case pgm_binary:
diskio::load_pgm_binary(*this, "[istream]", is);
break;
default:
arma_stop("Mat::load(): unsupported file type");
}
}
//! prefix ++ //! prefix ++
template<typename eT> template<typename eT>
arma_inline arma_inline
void void
Mat_aux::prefix_pp(Mat<eT>& x) Mat_aux::prefix_pp(Mat<eT>& x)
{ {
eT* memptr = x.memptr(); eT* memptr = x.memptr();
const u32 n_elem = x.n_elem; const u32 n_elem = x.n_elem;
for(u32 i=0; i<n_elem; ++i) for(u32 i=0; i<n_elem; ++i)
 End of changes. 26 change blocks. 
26 lines changed or deleted 554 lines changed or added


 Mat_proto.hpp   Mat_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 25 skipping to change at line 26
//! \addtogroup Mat //! \addtogroup Mat
//! @{ //! @{
//! Dense matrix class //! Dense matrix class
template<typename eT> template<typename eT>
class Mat : public Base< eT, Mat<eT> > class Mat : public Base< eT, Mat<eT> >
{ {
public: public:
typedef eT elem_type; //!< the type of elements stored in the matrix typedef eT elem_type; //!< the typ
e of elements stored in the matrix
typedef typename get_pod_type<elem_type>::pod_type pod_type; typedef typename get_pod_type<elem_type>::result pod_type; //!< if eT i
//!< if eT is std::complex, pod_type is the underlying type used by std:: s non-complex, pod_type is same as eT. otherwise, pod_type is the underlyin
complex. g type used by std::complex
//!< otherwise pod_type is the same as elem_type
const u32 n_rows; //!< number of rows in the matrix (read-only) const u32 n_rows; //!< number of rows in the matrix (read-only)
const u32 n_cols; //!< number of columns in the matrix (read-only) const u32 n_cols; //!< number of columns in the matrix (read-only)
const u32 n_elem; //!< number of elements in the matrix (read-only) const u32 n_elem; //!< number of elements in the matrix (read-only)
const bool use_aux_mem; //!< true if externally managed memory is being u sed (read-only) const bool use_aux_mem; //!< true if externally managed memory is being u sed (read-only)
arma_aligned const eT* const mem; //!< pointer to the memory used by the matrix (memory is read-only) arma_aligned const eT* const mem; //!< pointer to the memory used by the matrix (memory is read-only)
protected: protected:
arma_aligned eT mem_local[ 16 ]; arma_aligned eT mem_local[ 16 ];
skipping to change at line 93 skipping to change at line 91
inline const Mat& operator=(const subview_cube<eT>& X); inline const Mat& operator=(const subview_cube<eT>& X);
inline const Mat& operator+=(const subview_cube<eT>& X); inline const Mat& operator+=(const subview_cube<eT>& X);
inline const Mat& operator-=(const subview_cube<eT>& X); inline const Mat& operator-=(const subview_cube<eT>& X);
inline const Mat& operator*=(const subview_cube<eT>& X); inline const Mat& operator*=(const subview_cube<eT>& X);
inline const Mat& operator%=(const subview_cube<eT>& X); inline const Mat& operator%=(const subview_cube<eT>& X);
inline const Mat& operator/=(const subview_cube<eT>& X); inline const Mat& operator/=(const subview_cube<eT>& X);
//inline explicit Mat(const diagview<eT>& X); //inline explicit Mat(const diagview<eT>& X);
inline Mat(const diagview<eT>& X); inline Mat(const diagview<eT>& X);
inline const Mat& operator=(const diagview<eT>& X); inline const Mat& operator=(const diagview<eT>& X);
inline const Mat& operator+=(const diagview<eT>& X);
inline const Mat& operator-=(const diagview<eT>& X);
inline const Mat& operator*=(const diagview<eT>& X);
inline const Mat& operator%=(const diagview<eT>& X);
inline const Mat& operator/=(const diagview<eT>& X);
arma_inline subview_row<eT> row(const u32 row_num); arma_inline subview_row<eT> row(const u32 row_num);
arma_inline const subview_row<eT> row(const u32 row_num) const; arma_inline const subview_row<eT> row(const u32 row_num) const;
arma_inline subview_col<eT> col(const u32 col_num); arma_inline subview_col<eT> col(const u32 col_num);
arma_inline const subview_col<eT> col(const u32 col_num) const; arma_inline const subview_col<eT> col(const u32 col_num) const;
arma_inline subview<eT> rows(const u32 in_row1, const u32 in_row2); arma_inline subview<eT> rows(const u32 in_row1, const u32 in_row2);
arma_inline const subview<eT> rows(const u32 in_row1, const u32 in_row2) const; arma_inline const subview<eT> rows(const u32 in_row1, const u32 in_row2) const;
skipping to change at line 123 skipping to change at line 126
inline void swap_cols(const u32 in_col1, const u32 in_col2); inline void swap_cols(const u32 in_col1, const u32 in_col2);
template<typename T1, typename op_type> inline Mat(cons t Op<T1, op_type>& X); template<typename T1, typename op_type> inline Mat(cons t Op<T1, op_type>& X);
template<typename T1, typename op_type> inline const Mat& operator=(cons t Op<T1, op_type>& X); template<typename T1, typename op_type> inline const Mat& operator=(cons t Op<T1, op_type>& X);
template<typename T1, typename op_type> inline const Mat& operator+=(cons t Op<T1, op_type>& X); template<typename T1, typename op_type> inline const Mat& operator+=(cons t Op<T1, op_type>& X);
template<typename T1, typename op_type> inline const Mat& operator-=(cons t Op<T1, op_type>& X); template<typename T1, typename op_type> inline const Mat& operator-=(cons t Op<T1, op_type>& X);
template<typename T1, typename op_type> inline const Mat& operator*=(cons t Op<T1, op_type>& X); template<typename T1, typename op_type> inline const Mat& operator*=(cons t Op<T1, op_type>& X);
template<typename T1, typename op_type> inline const Mat& operator%=(cons t Op<T1, op_type>& X); template<typename T1, typename op_type> inline const Mat& operator%=(cons t Op<T1, op_type>& X);
template<typename T1, typename op_type> inline const Mat& operator/=(cons t Op<T1, op_type>& X); template<typename T1, typename op_type> inline const Mat& operator/=(cons t Op<T1, op_type>& X);
template<typename T1, typename eop_type> inline Mat(con
st eOp<T1, eop_type>& X);
template<typename T1, typename eop_type> inline const Mat& operator=(con
st eOp<T1, eop_type>& X);
template<typename T1, typename eop_type> inline const Mat& operator+=(con
st eOp<T1, eop_type>& X);
template<typename T1, typename eop_type> inline const Mat& operator-=(con
st eOp<T1, eop_type>& X);
template<typename T1, typename eop_type> inline const Mat& operator*=(con
st eOp<T1, eop_type>& X);
template<typename T1, typename eop_type> inline const Mat& operator%=(con
st eOp<T1, eop_type>& X);
template<typename T1, typename eop_type> inline const Mat& operator/=(con
st eOp<T1, eop_type>& X);
template<typename T1, typename T2, typename glue_type> inline Mat(const Glue<T1, T2, glue_type>& X); template<typename T1, typename T2, typename glue_type> inline Mat(const Glue<T1, T2, glue_type>& X);
template<typename T1, typename T2, typename glue_type> inline const Mat& operator=(const Glue<T1, T2, glue_type>& X); template<typename T1, typename T2, typename glue_type> inline const Mat& operator=(const Glue<T1, T2, glue_type>& X);
template<typename T1, typename T2, typename glue_type> inline const Mat& operator+=(const Glue<T1, T2, glue_type>& X); template<typename T1, typename T2, typename glue_type> inline const Mat& operator+=(const Glue<T1, T2, glue_type>& X);
template<typename T1, typename T2, typename glue_type> inline const Mat& operator-=(const Glue<T1, T2, glue_type>& X); template<typename T1, typename T2, typename glue_type> inline const Mat& operator-=(const Glue<T1, T2, glue_type>& X);
template<typename T1, typename T2, typename glue_type> inline const Mat& operator*=(const Glue<T1, T2, glue_type>& X); template<typename T1, typename T2, typename glue_type> inline const Mat& operator*=(const Glue<T1, T2, glue_type>& X);
template<typename T1, typename T2, typename glue_type> inline const Mat& operator%=(const Glue<T1, T2, glue_type>& X); template<typename T1, typename T2, typename glue_type> inline const Mat& operator%=(const Glue<T1, T2, glue_type>& X);
template<typename T1, typename T2, typename glue_type> inline const Mat& operator/=(const Glue<T1, T2, glue_type>& X); template<typename T1, typename T2, typename glue_type> inline const Mat& operator/=(const Glue<T1, T2, glue_type>& X);
template<typename T1, typename T2> inline const Mat&
operator+=(const Glue<T1, T2, glue_times>& X);
template<typename T1, typename T2> inline const Mat&
operator-=(const Glue<T1, T2, glue_times>& X);
template<typename T1, typename T2, typename eglue_type> inline
Mat(const eGlue<T1, T2, eglue_type>& X);
template<typename T1, typename T2, typename eglue_type> inline const Mat&
operator=(const eGlue<T1, T2, eglue_type>& X);
template<typename T1, typename T2, typename eglue_type> inline const Mat&
operator+=(const eGlue<T1, T2, eglue_type>& X);
template<typename T1, typename T2, typename eglue_type> inline const Mat&
operator-=(const eGlue<T1, T2, eglue_type>& X);
template<typename T1, typename T2, typename eglue_type> inline const Mat&
operator*=(const eGlue<T1, T2, eglue_type>& X);
template<typename T1, typename T2, typename eglue_type> inline const Mat&
operator%=(const eGlue<T1, T2, eglue_type>& X);
template<typename T1, typename T2, typename eglue_type> inline const Mat&
operator/=(const eGlue<T1, T2, eglue_type>& X);
arma_inline eT& operator[] (const u32 i); arma_inline eT& operator[] (const u32 i);
arma_inline eT operator[] (const u32 i) const; arma_inline eT operator[] (const u32 i) const;
arma_inline eT& operator() (const u32 i); arma_inline eT& operator() (const u32 i);
arma_inline eT operator() (const u32 i) const; arma_inline eT operator() (const u32 i) const;
arma_inline eT& at (const u32 in_row, const u32 in_col); arma_inline eT& at (const u32 in_row, const u32 in_col);
arma_inline eT at (const u32 in_row, const u32 in_col) const; arma_inline eT at (const u32 in_row, const u32 in_col) const;
arma_inline eT& operator() (const u32 in_row, const u32 in_col); arma_inline eT& operator() (const u32 in_row, const u32 in_col);
arma_inline eT operator() (const u32 in_row, const u32 in_col) const; arma_inline eT operator() (const u32 in_row, const u32 in_col) const;
skipping to change at line 184 skipping to change at line 206
inline void fill(const eT val); inline void fill(const eT val);
inline void zeros(); inline void zeros();
inline void zeros(const u32 in_rows, const u32 in_cols); inline void zeros(const u32 in_rows, const u32 in_cols);
inline void ones(); inline void ones();
inline void ones(const u32 in_rows, const u32 in_cols); inline void ones(const u32 in_rows, const u32 in_cols);
inline void reset(); inline void reset();
inline void save(const std::string name, const file_type type = arma_bina inline void save(const std::string name, const file_type type = arma_bi
ry) const; nary) const;
inline void load(const std::string name, const file_type type = auto_dete inline void save( std::ostream& os, const file_type type = arma_bi
ct); nary) const;
inline void load(const std::string name, const file_type type = auto_de
tect);
inline void load( std::istream& is, const file_type type = auto_de
tect);
protected: protected:
inline void init(const u32 in_rows, const u32 in_cols); inline void init(const u32 in_rows, const u32 in_cols);
inline void init(const std::string& text); inline void init(const std::string& text);
inline void init(const Mat& x); inline void init(const Mat& x);
inline Mat(const char junk, const eT* aux_mem, const u32 aux_n_rows, cons t u32 aux_n_cols); inline Mat(const char junk, const eT* aux_mem, const u32 aux_n_rows, cons t u32 aux_n_cols);
friend class Cube<eT>; friend class Cube<eT>;
 End of changes. 6 change blocks. 
11 lines changed or deleted 56 lines changed or added


 OpCube_meat.hpp   OpCube_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 OpCube_proto.hpp   OpCube_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 25 skipping to change at line 26
//! \addtogroup OpCube //! \addtogroup OpCube
//! @{ //! @{
//! Analog of the Op class, intended for cubes //! Analog of the Op class, intended for cubes
template<typename T1, typename op_type> template<typename T1, typename op_type>
class OpCube : public BaseCube<typename T1::elem_type, OpCube<T1, op_type> > class OpCube : public BaseCube<typename T1::elem_type, OpCube<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>::pod_type pod_type; typedef typename get_pod_type<elem_type>::result pod_type;
inline explicit OpCube(const BaseCube<typename T1::elem_type, T1>& in_m); inline explicit OpCube(const BaseCube<typename T1::elem_type, T1>& in_m);
inline OpCube(const BaseCube<typename T1::elem_type, T1>& in_m, const elem_type in_aux); inline OpCube(const BaseCube<typename T1::elem_type, T1>& in_m, const elem_type in_aux);
inline OpCube(const BaseCube<typename T1::elem_type, T1>& in_m, const u32 in_aux_u32_a, const u32 in_aux_u32_b); inline OpCube(const BaseCube<typename T1::elem_type, T1>& in_m, const u32 in_aux_u32_a, const u32 in_aux_u32_b);
inline OpCube(const BaseCube<typename T1::elem_type, T1>& in_m, const u32 in_aux_u32_a, const u32 in_aux_u32_b, const u32 in_aux_u32_c); inline OpCube(const BaseCube<typename T1::elem_type, T1>& in_m, const u32 in_aux_u32_a, const u32 in_aux_u32_b, const u32 in_aux_u32_c);
inline OpCube(const BaseCube<typename T1::elem_type, T1>& in_m, const elem_type in_aux, const u32 in_aux_u32_a, const u32 in_aux_u32_b, con st u32 in_aux_u32_c); inline OpCube(const BaseCube<typename T1::elem_type, T1>& in_m, const elem_type in_aux, const u32 in_aux_u32_a, const u32 in_aux_u32_b, con st u32 in_aux_u32_c);
inline OpCube(const u32 in_aux_u32_a, const u32 in_aux_u32_b, co nst u32 in_aux_u32_c); inline OpCube(const u32 in_aux_u32_a, const u32 in_aux_u32_b, co nst u32 in_aux_u32_c);
inline ~OpCube(); inline ~OpCube();
// TODO:MAT: if the restriction to inputs of type BaseCube works, the use
of the "junk" parameter may no longer be necessary
const T1& m; //!< storage of reference to the operand (e.g . a cube) const T1& m; //!< storage of reference to the operand (e.g . a cube)
const elem_type aux; //!< storage of auxiliary data, user defined format const elem_type aux; //!< storage of auxiliary data, user defined format
const u32 aux_u32_a; //!< storage of auxiliary data, u32 format const u32 aux_u32_a; //!< storage of auxiliary data, u32 format
const u32 aux_u32_b; //!< storage of auxiliary data, u32 format const u32 aux_u32_b; //!< storage of auxiliary data, u32 format
const u32 aux_u32_c; //!< storage of auxiliary data, u32 format const u32 aux_u32_c; //!< storage of auxiliary data, u32 format
}; };
//! @} //! @}
 End of changes. 3 change blocks. 
6 lines changed or deleted 4 lines changed or added


 Op_meat.hpp   Op_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 59 skipping to change at line 60
Op<T1, op_type>::Op(const T1& in_m, const typename T1::elem_type in_aux, co nst u32 in_aux_u32_a, const u32 in_aux_u32_b) Op<T1, op_type>::Op(const T1& in_m, const typename T1::elem_type in_aux, co nst u32 in_aux_u32_a, const u32 in_aux_u32_b)
: m(in_m) : m(in_m)
, aux(in_aux) , aux(in_aux)
, aux_u32_a(in_aux_u32_a) , aux_u32_a(in_aux_u32_a)
, aux_u32_b(in_aux_u32_b) , aux_u32_b(in_aux_u32_b)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
template<typename T1, typename op_type> template<typename T1, typename op_type>
Op<T1, op_type>::Op(const u32 in_aux_u32_a, const u32 in_aux_u32_b, const c
har junk)
: m(m)
, aux(aux)
, aux_u32_a(in_aux_u32_a)
, aux_u32_b(in_aux_u32_b)
{
arma_extra_debug_sigprint();
}
template<typename T1, typename op_type>
Op<T1, op_type>::~Op() Op<T1, op_type>::~Op()
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
//! @} //! @}
 End of changes. 2 change blocks. 
12 lines changed or deleted 2 lines changed or added


 Op_proto.hpp   Op_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 33 skipping to change at line 34
//! Note that as 'Glue' can be one of the operands, more than one matrix ca n be stored. //! Note that as 'Glue' can be one of the operands, more than one matrix ca n be stored.
//! //!
//! For example, we could have: //! For example, we could have:
//! Op< Glue< Mat, Mat, glue_times >, op_trans > //! Op< Glue< Mat, Mat, glue_times >, op_trans >
template<typename T1, typename op_type> template<typename T1, typename op_type>
class Op : public Base<typename T1::elem_type, Op<T1, op_type> > class Op : public Base<typename T1::elem_type, Op<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>::pod_type pod_type; typedef typename get_pod_type<elem_type>::result pod_type;
inline explicit Op(const T1& in_m); inline explicit Op(const T1& in_m);
inline Op(const T1& in_m, const elem_type in_aux); inline Op(const T1& in_m, const elem_type in_aux);
inline Op(const T1& in_m, const u32 in_aux_u32_a, const u32 in_a ux_u32_b); inline Op(const T1& in_m, const u32 in_aux_u32_a, const u32 in_a ux_u32_b);
inline Op(const T1& in_m, const elem_type in_aux, const u32 in_a ux_u32_a, const u32 in_aux_u32_b); inline Op(const T1& in_m, const elem_type in_aux, const u32 in_a ux_u32_a, const u32 in_aux_u32_b);
inline Op(const u32 in_aux_u32_a, const u32 in_aux_u32_b, const char junk);
inline ~Op(); inline ~Op();
const T1& m; //!< storage of reference to the operand (e.g . a matrix) const T1& m; //!< storage of reference to the operand (e.g . a matrix)
const elem_type aux; //!< storage of auxiliary data, user defined format const elem_type aux; //!< storage of auxiliary data, user defined format
const u32 aux_u32_a; //!< storage of auxiliary data, u32 format const u32 aux_u32_a; //!< storage of auxiliary data, u32 format
const u32 aux_u32_b; //!< storage of auxiliary data, u32 format const u32 aux_u32_b; //!< storage of auxiliary data, u32 format
}; };
//! @} //! @}
 End of changes. 3 change blocks. 
4 lines changed or deleted 4 lines changed or added


 Row_meat.hpp   Row_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 413 skipping to change at line 414
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
Mat<eT>::operator*=(X); Mat<eT>::operator*=(X);
arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" ); arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
return *this; return *this;
} }
template<typename eT> template<typename eT>
template<typename T1, typename eop_type>
inline
Row<eT>::Row(const eOp<T1, eop_type>& X)
: Mat<eT>(X)
{
arma_extra_debug_sigprint();
arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
);
}
template<typename eT>
template<typename T1, typename eop_type>
inline
const Row<eT>&
Row<eT>::operator=(const eOp<T1, eop_type>& X)
{
arma_extra_debug_sigprint();
Mat<eT>::operator=(X);
arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
);
return *this;
}
template<typename eT>
template<typename T1, typename eop_type>
inline
const Row<eT>&
Row<eT>::operator*=(const eOp<T1, eop_type>& X)
{
arma_extra_debug_sigprint();
Mat<eT>::operator*=(X);
arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
);
return *this;
}
template<typename eT>
template<typename T1, typename T2, typename glue_type> template<typename T1, typename T2, typename glue_type>
inline inline
Row<eT>::Row(const Glue<T1, T2, glue_type>& X) Row<eT>::Row(const Glue<T1, T2, glue_type>& X)
: Mat<eT>(X) : Mat<eT>(X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" ); arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
} }
skipping to change at line 454 skipping to change at line 496
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
Mat<eT>::operator*=(X); Mat<eT>::operator*=(X);
arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" ); arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
return *this; return *this;
} }
template<typename eT> template<typename eT>
template<typename T1, typename T2, typename eglue_type>
inline
Row<eT>::Row(const eGlue<T1, T2, eglue_type>& X)
: Mat<eT>(X)
{
arma_extra_debug_sigprint();
arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
);
}
template<typename eT>
template<typename T1, typename T2, typename eglue_type>
inline
const Row<eT>&
Row<eT>::operator=(const eGlue<T1, T2, eglue_type>& X)
{
arma_extra_debug_sigprint();
Mat<eT>::operator=(X);
arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
);
return *this;
}
template<typename eT>
template<typename T1, typename T2, typename eglue_type>
inline
const Row<eT>&
Row<eT>::operator*=(const eGlue<T1, T2, eglue_type>& X)
{
arma_extra_debug_sigprint();
Mat<eT>::operator*=(X);
arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
);
return *this;
}
template<typename eT>
inline inline
void void
Row<eT>::set_size(const u32 in_n_elem) Row<eT>::set_size(const u32 in_n_elem)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
Mat<eT>::set_size(1,in_n_elem); Mat<eT>::set_size(1,in_n_elem);
} }
template<typename eT> template<typename eT>
skipping to change at line 568 skipping to change at line 651
void void
Row<eT>::load(const std::string name, const file_type type) Row<eT>::load(const std::string name, const file_type type)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
Mat<eT>::load(name,type); Mat<eT>::load(name,type);
arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" ); arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
} }
template<typename eT>
inline
void
Row<eT>::load(std::istream& is, const file_type type)
{
arma_extra_debug_sigprint();
Mat<eT>::load(is, type);
arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions"
);
}
//! @} //! @}
 End of changes. 4 change blocks. 
1 lines changed or deleted 103 lines changed or added


 Row_proto.hpp   Row_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 25 skipping to change at line 26
//! \addtogroup Row //! \addtogroup Row
//! @{ //! @{
//! Class for row vectors (matrices with only one row) //! Class for row vectors (matrices with only one row)
template<typename eT> template<typename eT>
class Row : public Mat<eT>, public BaseVec< eT, Row<eT> > class Row : public Mat<eT>, public BaseVec< eT, Row<eT> >
{ {
public: public:
typedef eT elem_type; typedef eT elem_type;
typedef typename get_pod_type<elem_type>::pod_type pod_type; typedef typename get_pod_type<elem_type>::result pod_type;
inline Row(); inline Row();
inline explicit Row(const u32 N); inline explicit Row(const u32 N);
inline Row(const u32 in_rows, const u32 in_cols); inline Row(const u32 in_rows, const u32 in_cols);
inline Row(const char* text); inline Row(const char* text);
inline const Row& operator=(const char* text); inline const Row& operator=(const char* text);
inline Row(const std::string& text); inline Row(const std::string& text);
inline const Row& operator=(const std::string& text); inline const Row& operator=(const std::string& text);
skipping to change at line 77 skipping to change at line 78
arma_inline eT& col(const u32 col_num); arma_inline eT& col(const u32 col_num);
arma_inline eT col(const u32 col_num) const; arma_inline eT col(const u32 col_num) const;
arma_inline subview_row<eT> cols(const u32 in_col1, const u32 in_co l2); arma_inline subview_row<eT> cols(const u32 in_col1, const u32 in_co l2);
arma_inline const subview_row<eT> cols(const u32 in_col1, const u32 in_co l2) const; arma_inline const subview_row<eT> cols(const u32 in_col1, const u32 in_co l2) const;
template<typename T1, typename op_type> inline Row(cons t Op<T1, op_type> &X); template<typename T1, typename op_type> inline Row(cons t Op<T1, op_type> &X);
template<typename T1, typename op_type> inline const Row& operator=(cons t Op<T1, op_type> &X); template<typename T1, typename op_type> inline const Row& operator=(cons t Op<T1, op_type> &X);
template<typename T1, typename op_type> inline const Row& operator*=(cons t Op<T1, op_type> &X); template<typename T1, typename op_type> inline const Row& operator*=(cons t Op<T1, op_type> &X);
template<typename T1, typename eop_type> inline Row(con
st eOp<T1, eop_type> &X);
template<typename T1, typename eop_type> inline const Row& operator=(con
st eOp<T1, eop_type> &X);
template<typename T1, typename eop_type> inline const Row& operator*=(con
st eOp<T1, eop_type> &X);
template<typename T1, typename T2, typename glue_type> inline Row(const Glue<T1, T2, glue_type> &X); template<typename T1, typename T2, typename glue_type> inline Row(const Glue<T1, T2, glue_type> &X);
template<typename T1, typename T2, typename glue_type> inline const Row& operator=(const Glue<T1, T2, glue_type> &X); template<typename T1, typename T2, typename glue_type> inline const Row& operator=(const Glue<T1, T2, glue_type> &X);
template<typename T1, typename T2, typename glue_type> inline const Row& operator*=(const Glue<T1, T2, glue_type> &X); template<typename T1, typename T2, typename glue_type> inline const Row& operator*=(const Glue<T1, T2, glue_type> &X);
template<typename T1, typename T2, typename eglue_type> inline
Row(const eGlue<T1, T2, eglue_type> &X);
template<typename T1, typename T2, typename eglue_type> inline const Row&
operator=(const eGlue<T1, T2, eglue_type> &X);
template<typename T1, typename T2, typename eglue_type> inline const Row&
operator*=(const eGlue<T1, T2, eglue_type> &X);
inline void set_size(const u32 N); inline void set_size(const u32 N);
inline void set_size(const u32 n_rows, const u32 n_cols); inline void set_size(const u32 n_rows, const u32 n_cols);
template<typename eT2> template<typename eT2>
inline void copy_size(const Mat<eT2>& m); inline void copy_size(const Mat<eT2>& m);
inline void zeros(); inline void zeros();
inline void zeros(const u32 N); inline void zeros(const u32 N);
inline void zeros(const u32 n_rows, const u32 n_cols); inline void zeros(const u32 n_rows, const u32 n_cols);
inline void ones(); inline void ones();
inline void ones(const u32 N); inline void ones(const u32 N);
inline void ones(const u32 n_rows, const u32 n_cols); inline void ones(const u32 n_rows, const u32 n_cols);
inline void load(const std::string name, const file_type type = auto_dete inline void load(const std::string name, const file_type type = auto_de
ct); tect);
inline void load( std::istream& is, const file_type type = auto_de
tect);
}; };
//! @} //! @}
 End of changes. 5 change blocks. 
5 lines changed or deleted 22 lines changed or added


 access.hpp   access.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 23 skipping to change at line 24
// (see http://www.opensource.org/licenses for more info) // (see http://www.opensource.org/licenses for more info)
//! \addtogroup access //! \addtogroup access
//! @{ //! @{
class access class access
{ {
public: public:
//! internal function to allow modification of data declared as read-only //! internal function to allow modification of data declared as read-only
template<typename T1> template<typename T1> arma_inline static T1& rw(const T1& x) { return con
arma_inline st_cast<T1&>(x); }
static
T1& rw(const T1& x) { return const_cast<T1&>(x); } //! internal function to obtain the real part of either a plain number or
a complex number
template<typename eT> arma_inline static const eT& tmp_real(const eT&
X) { return X; }
template<typename T> arma_inline static const T tmp_real(const std::co
mplex<T>& X) { return X.real(); }
}; };
//! @} //! @}
 End of changes. 2 change blocks. 
5 lines changed or deleted 11 lines changed or added


 arma_ostream_meat.hpp   arma_ostream_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 82 skipping to change at line 83
(val >= eT(+10)) || ( (is_signed<eT>::value == true) && (val <= eT(-1 0)) ) (val >= eT(+10)) || ( (is_signed<eT>::value == true) && (val <= eT(-1 0)) )
) )
{ {
use_layout_B = true; use_layout_B = true;
} }
} }
if(use_layout_C == true) if(use_layout_C == true)
{ {
o.setf(ios::scientific); o.setf(ios::scientific);
o.setf(ios::right);
o.unsetf(ios::fixed); o.unsetf(ios::fixed);
o.precision(4); o.precision(4);
cell_width = 13; cell_width = 13;
} }
else else
if(use_layout_B == true) if(use_layout_B == true)
{ {
o.unsetf(ios::scientific); o.unsetf(ios::scientific);
o.setf(ios::right);
o.setf(ios::fixed); o.setf(ios::fixed);
o.precision(4); o.precision(4);
cell_width = 10; cell_width = 10;
} }
else else
{ {
o.unsetf(ios::scientific); o.unsetf(ios::scientific);
o.setf(ios::right);
o.setf(ios::fixed); o.setf(ios::fixed);
o.precision(4); o.precision(4);
cell_width = 9; cell_width = 9;
} }
return cell_width; return cell_width;
} }
//! "better than nothing" settings for complex numbers //! "better than nothing" settings for complex numbers
template<typename T> template<typename T>
inline inline
u32 u32
arma_ostream::modify_stream(std::ostream& o, const std::complex<T>* data, c onst u32 n_elem) arma_ostream::modify_stream(std::ostream& o, const std::complex<T>* data, c onst u32 n_elem)
{ {
o.unsetf(ios::showbase); o.unsetf(ios::showbase);
o.unsetf(ios::uppercase); o.unsetf(ios::uppercase);
o.fill(' '); o.fill(' ');
o.setf(ios::scientific); o.setf(ios::scientific);
o.setf(ios::showpos); o.setf(ios::showpos);
o.setf(ios::right);
o.unsetf(ios::fixed); o.unsetf(ios::fixed);
u32 cell_width; u32 cell_width;
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;
} }
//! 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)
{ {
o << x; if(x != eT(0))
{
o << x;
}
else
{
const std::streamsize orig_precision = o.precision();
o.precision(0);
o << eT(0);
o.precision(orig_precision);
}
} }
//! Print a complex element to the specified stream //! Print a complex element to the specified stream
//! EXPERIMENTAL ! //! EXPERIMENTAL !
template<typename T> template<typename T>
arma_inline arma_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)
{ {
std::ostringstream ss; if( (x.real() != T(0)) || (x.imag() != T(0)) )
ss.flags(o.flags()); {
//ss.imbue(o.getloc()); std::ostringstream ss;
ss.precision(o.precision()); ss.flags(o.flags());
//ss.imbue(o.getloc());
ss << '(' << x.real() << ',' << x.imag() << ')'; ss.precision(o.precision());
o << ss.str(); ss << '(' << x.real() << ',' << x.imag() << ')';
o << ss.str();
}
else
{
o << "(0,0)";
}
} }
//! Print a matrix to the specified stream //! Print a matrix to the specified stream
template<typename eT> template<typename eT>
inline inline
void void
arma_ostream::print(std::ostream& o, const Mat<eT>& m, const bool modify) arma_ostream::print(std::ostream& o, const Mat<eT>& m, const bool modify)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
 End of changes. 8 change blocks. 
9 lines changed or deleted 33 lines changed or added


 arma_ostream_proto.hpp   arma_ostream_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 armadillo   armadillo 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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)
#ifndef ARMA_INCLUDES #ifndef ARMA_INCLUDES
#define ARMA_INCLUDES #define ARMA_INCLUDES
#define arma_hot
#define arma_pure
#define arma_const
#define arma_inline inline
#define arma_aligned
#if defined(__GNUG__)
#if (__GNUC__ < 4)
#error "*** Need a newer compiler ***"
#endif
#if (__GNUC_MINOR__ >= 3)
#undef arma_hot
#define arma_hot __attribute__((hot))
#endif
#undef arma_pure
#undef arma_const
#undef arma_inline
#undef arma_aligned
#define arma_pure __attribute__((pure))
#define arma_const __attribute__((const))
#define arma_inline inline __attribute__((always_inline))
#define arma_aligned __attribute__((aligned))
#define ARMA_GOOD_COMPILER
#elif defined(__INTEL_COMPILER)
#if (__INTEL_COMPILER < 1000)
#error "*** Need a newer compiler ***"
#endif
#define ARMA_GOOD_COMPILER
#elif defined(_MSC_VER)
#pragma message ("*** WARNING: This compiler may have an incomplete imple
mentation of the C++ standard ***")
#undef ARMA_GOOD_COMPILER
#endif
#include "armadillo_bits/config.hpp" #include "armadillo_bits/config.hpp"
#include "armadillo_bits/compiler_setup.hpp"
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <climits> #include <climits>
#include <cmath> #include <cmath>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
skipping to change at line 126 skipping to change at line 84
{ {
// preliminaries // preliminaries
#include "armadillo_bits/forward_proto.hpp" #include "armadillo_bits/forward_proto.hpp"
#include "armadillo_bits/static_assert.hpp" #include "armadillo_bits/static_assert.hpp"
#include "armadillo_bits/typedef.hpp" #include "armadillo_bits/typedef.hpp"
#include "armadillo_bits/format_wrap.hpp" #include "armadillo_bits/format_wrap.hpp"
#include "armadillo_bits/cmath_wrap.hpp" #include "armadillo_bits/cmath_wrap.hpp"
#include "armadillo_bits/constants.hpp" #include "armadillo_bits/constants.hpp"
#include "armadillo_bits/version.hpp"
#include "armadillo_bits/traits.hpp" #include "armadillo_bits/traits.hpp"
#include "armadillo_bits/promote_type.hpp"
#include "armadillo_bits/upgrade_val.hpp"
#include "armadillo_bits/restrictors.hpp"
#include "armadillo_bits/access.hpp" #include "armadillo_bits/access.hpp"
// //
// class prototypes // class prototypes
#include "armadillo_bits/syslib_proto.hpp" #include "armadillo_bits/syslib_proto.hpp"
#include "armadillo_bits/podarray_proto.hpp" #include "armadillo_bits/podarray_proto.hpp"
#include "armadillo_bits/blas_proto.hpp" #include "armadillo_bits/blas_proto.hpp"
#include "armadillo_bits/lapack_proto.hpp" #include "armadillo_bits/lapack_proto.hpp"
skipping to change at line 161 skipping to change at line 123
#include "armadillo_bits/subview_cube_proto.hpp" #include "armadillo_bits/subview_cube_proto.hpp"
#include "armadillo_bits/diagview_proto.hpp" #include "armadillo_bits/diagview_proto.hpp"
#include "armadillo_bits/diskio_proto.hpp" #include "armadillo_bits/diskio_proto.hpp"
#include "armadillo_bits/wall_clock_proto.hpp" #include "armadillo_bits/wall_clock_proto.hpp"
#include "armadillo_bits/running_stat_proto.hpp" #include "armadillo_bits/running_stat_proto.hpp"
#include "armadillo_bits/running_stat_vec_proto.hpp" #include "armadillo_bits/running_stat_vec_proto.hpp"
#include "armadillo_bits/Op_proto.hpp" #include "armadillo_bits/Op_proto.hpp"
#include "armadillo_bits/OpCube_proto.hpp" #include "armadillo_bits/OpCube_proto.hpp"
#include "armadillo_bits/eOp_proto.hpp"
#include "armadillo_bits/eOpCube_proto.hpp"
#include "armadillo_bits/Glue_proto.hpp" #include "armadillo_bits/Glue_proto.hpp"
#include "armadillo_bits/eGlue_proto.hpp"
#include "armadillo_bits/GlueCube_proto.hpp" #include "armadillo_bits/GlueCube_proto.hpp"
#include "armadillo_bits/eGlueCube_proto.hpp"
#include "armadillo_bits/eop_core_proto.hpp"
#include "armadillo_bits/eop_cube_core_proto.hpp"
#include "armadillo_bits/eglue_core_proto.hpp"
#include "armadillo_bits/eglue_cube_core_proto.hpp"
#include "armadillo_bits/op_diagmat_proto.hpp" #include "armadillo_bits/op_diagmat_proto.hpp"
#include "armadillo_bits/op_diagvec_proto.hpp"
#include "armadillo_bits/op_dot_proto.hpp" #include "armadillo_bits/op_dot_proto.hpp"
#include "armadillo_bits/op_inv_proto.hpp" #include "armadillo_bits/op_inv_proto.hpp"
#include "armadillo_bits/op_htrans_proto.hpp" #include "armadillo_bits/op_htrans_proto.hpp"
#include "armadillo_bits/op_misc_proto.hpp"
#include "armadillo_bits/op_max_proto.hpp" #include "armadillo_bits/op_max_proto.hpp"
#include "armadillo_bits/op_min_proto.hpp" #include "armadillo_bits/op_min_proto.hpp"
#include "armadillo_bits/op_mean_proto.hpp" #include "armadillo_bits/op_mean_proto.hpp"
#include "armadillo_bits/op_median_proto.hpp" #include "armadillo_bits/op_median_proto.hpp"
#include "armadillo_bits/op_neg_proto.hpp"
#include "armadillo_bits/op_ones_proto.hpp"
#include "armadillo_bits/op_rand_proto.hpp"
#include "armadillo_bits/op_randn_proto.hpp"
#include "armadillo_bits/op_scalar_misc_proto.hpp"
#include "armadillo_bits/op_sort_proto.hpp" #include "armadillo_bits/op_sort_proto.hpp"
#include "armadillo_bits/op_sum_proto.hpp" #include "armadillo_bits/op_sum_proto.hpp"
#include "armadillo_bits/op_stddev_proto.hpp" #include "armadillo_bits/op_stddev_proto.hpp"
#include "armadillo_bits/op_trig_proto.hpp"
#include "armadillo_bits/op_trans_proto.hpp" #include "armadillo_bits/op_trans_proto.hpp"
#include "armadillo_bits/op_var_proto.hpp" #include "armadillo_bits/op_var_proto.hpp"
#include "armadillo_bits/op_zeros_proto.hpp"
#include "armadillo_bits/op_repmat_proto.hpp" #include "armadillo_bits/op_repmat_proto.hpp"
#include "armadillo_bits/op_reshape_proto.hpp" #include "armadillo_bits/op_reshape_proto.hpp"
#include "armadillo_bits/op_cov_proto.hpp" #include "armadillo_bits/op_cov_proto.hpp"
#include "armadillo_bits/op_cor_proto.hpp" #include "armadillo_bits/op_cor_proto.hpp"
#include "armadillo_bits/op_shuffle_proto.hpp" #include "armadillo_bits/op_shuffle_proto.hpp"
#include "armadillo_bits/op_prod_proto.hpp" #include "armadillo_bits/op_prod_proto.hpp"
#include "armadillo_bits/op_eps_proto.hpp"
#include "armadillo_bits/op_pinv_proto.hpp" #include "armadillo_bits/op_pinv_proto.hpp"
#include "armadillo_bits/op_dotext_proto.hpp"
#include "armadillo_bits/op_flip_proto.hpp"
#include "armadillo_bits/op_princomp_proto.hpp"
#include "armadillo_bits/glue_plus_proto.hpp"
#include "armadillo_bits/glue_minus_proto.hpp"
#include "armadillo_bits/glue_times_proto.hpp" #include "armadillo_bits/glue_times_proto.hpp"
#include "armadillo_bits/glue_schur_proto.hpp"
#include "armadillo_bits/glue_div_proto.hpp"
#include "armadillo_bits/glue_cov_proto.hpp" #include "armadillo_bits/glue_cov_proto.hpp"
#include "armadillo_bits/glue_cor_proto.hpp" #include "armadillo_bits/glue_cor_proto.hpp"
#include "armadillo_bits/glue_kron_proto.hpp" #include "armadillo_bits/glue_kron_proto.hpp"
#include "armadillo_bits/glue_cube_plus_proto.hpp"
#include "armadillo_bits/glue_cube_minus_proto.hpp"
#include "armadillo_bits/glue_cube_schur_proto.hpp"
#include "armadillo_bits/glue_cube_div_proto.hpp"
// //
// debugging functions // debugging functions
#include "armadillo_bits/debug.hpp" #include "armadillo_bits/debug.hpp"
// //
// classes that underlay metaprogramming // classes that underlay metaprogramming
#include "armadillo_bits/Proxy.hpp"
#include "armadillo_bits/ProxyCube.hpp"
#include "armadillo_bits/diagmat_proxy.hpp"
#include "armadillo_bits/unwrap.hpp" #include "armadillo_bits/unwrap.hpp"
#include "armadillo_bits/unwrap_cube.hpp" #include "armadillo_bits/unwrap_cube.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/Glue_meat.hpp" #include "armadillo_bits/Glue_meat.hpp"
#include "armadillo_bits/GlueCube_meat.hpp" #include "armadillo_bits/GlueCube_meat.hpp"
#include "armadillo_bits/glue_metaprog.hpp" #include "armadillo_bits/eop_aux.hpp"
#include "armadillo_bits/glue_cube_metaprog.hpp"
#include "armadillo_bits/eOp_meat.hpp"
#include "armadillo_bits/eOpCube_meat.hpp"
#include "armadillo_bits/eGlue_meat.hpp"
#include "armadillo_bits/eGlueCube_meat.hpp"
#include "armadillo_bits/eglue_misc.hpp"
#include "armadillo_bits/eglue_cube_misc.hpp"
// //
// ostream // ostream
#include "armadillo_bits/arma_ostream_proto.hpp" #include "armadillo_bits/arma_ostream_proto.hpp"
#include "armadillo_bits/arma_ostream_meat.hpp" #include "armadillo_bits/arma_ostream_meat.hpp"
// //
// operators // operators
#include "armadillo_bits/operator_plus.hpp" #include "armadillo_bits/operator_plus.hpp"
#include "armadillo_bits/operator_minus.hpp" #include "armadillo_bits/operator_minus.hpp"
#include "armadillo_bits/operator_times.hpp" #include "armadillo_bits/operator_times.hpp"
#include "armadillo_bits/operator_times_dot.hpp"
#include "armadillo_bits/operator_schur.hpp" #include "armadillo_bits/operator_schur.hpp"
#include "armadillo_bits/operator_div.hpp" #include "armadillo_bits/operator_div.hpp"
#include "armadillo_bits/operator_relational.hpp" #include "armadillo_bits/operator_relational.hpp"
#include "armadillo_bits/operator_cube_plus.hpp" #include "armadillo_bits/operator_cube_plus.hpp"
#include "armadillo_bits/operator_cube_minus.hpp" #include "armadillo_bits/operator_cube_minus.hpp"
#include "armadillo_bits/operator_cube_times.hpp" #include "armadillo_bits/operator_cube_times.hpp"
#include "armadillo_bits/operator_cube_schur.hpp" #include "armadillo_bits/operator_cube_schur.hpp"
#include "armadillo_bits/operator_cube_div.hpp" #include "armadillo_bits/operator_cube_div.hpp"
#include "armadillo_bits/operator_cube_relational.hpp" #include "armadillo_bits/operator_cube_relational.hpp"
skipping to change at line 266 skipping to change at line 241
// the order of the fn_*.hpp include files matters, // the order of the fn_*.hpp include files matters,
// as some files require functionality given in preceding files // as some files require functionality given in preceding files
#include "armadillo_bits/fn_conv_to.hpp" #include "armadillo_bits/fn_conv_to.hpp"
#include "armadillo_bits/fn_min.hpp" #include "armadillo_bits/fn_min.hpp"
#include "armadillo_bits/fn_max.hpp" #include "armadillo_bits/fn_max.hpp"
#include "armadillo_bits/fn_accu.hpp" #include "armadillo_bits/fn_accu.hpp"
#include "armadillo_bits/fn_sum.hpp" #include "armadillo_bits/fn_sum.hpp"
#include "armadillo_bits/fn_diagmat.hpp" #include "armadillo_bits/fn_diagmat.hpp"
#include "armadillo_bits/fn_diagvec.hpp"
#include "armadillo_bits/fn_inv.hpp" #include "armadillo_bits/fn_inv.hpp"
#include "armadillo_bits/fn_trace.hpp" #include "armadillo_bits/fn_trace.hpp"
#include "armadillo_bits/fn_trans.hpp" #include "armadillo_bits/fn_trans.hpp"
#include "armadillo_bits/fn_det.hpp" #include "armadillo_bits/fn_det.hpp"
#include "armadillo_bits/fn_log_det.hpp"
#include "armadillo_bits/fn_eig.hpp" #include "armadillo_bits/fn_eig.hpp"
#include "armadillo_bits/fn_lu.hpp" #include "armadillo_bits/fn_lu.hpp"
#include "armadillo_bits/fn_zeros.hpp" #include "armadillo_bits/fn_zeros.hpp"
#include "armadillo_bits/fn_ones.hpp" #include "armadillo_bits/fn_ones.hpp"
#include "armadillo_bits/fn_misc.hpp" #include "armadillo_bits/fn_misc.hpp"
#include "armadillo_bits/fn_norm.hpp" #include "armadillo_bits/fn_norm.hpp"
#include "armadillo_bits/fn_dot.hpp" #include "armadillo_bits/fn_dot.hpp"
#include "armadillo_bits/fn_rand.hpp" #include "armadillo_bits/fn_rand.hpp"
#include "armadillo_bits/fn_randn.hpp" #include "armadillo_bits/fn_randn.hpp"
#include "armadillo_bits/fn_trig.hpp" #include "armadillo_bits/fn_trig.hpp"
skipping to change at line 301 skipping to change at line 278
#include "armadillo_bits/fn_repmat.hpp" #include "armadillo_bits/fn_repmat.hpp"
#include "armadillo_bits/fn_reshape.hpp" #include "armadillo_bits/fn_reshape.hpp"
#include "armadillo_bits/fn_cov.hpp" #include "armadillo_bits/fn_cov.hpp"
#include "armadillo_bits/fn_cor.hpp" #include "armadillo_bits/fn_cor.hpp"
#include "armadillo_bits/fn_shuffle.hpp" #include "armadillo_bits/fn_shuffle.hpp"
#include "armadillo_bits/fn_prod.hpp" #include "armadillo_bits/fn_prod.hpp"
#include "armadillo_bits/fn_eps.hpp" #include "armadillo_bits/fn_eps.hpp"
#include "armadillo_bits/fn_pinv.hpp" #include "armadillo_bits/fn_pinv.hpp"
#include "armadillo_bits/fn_rank.hpp" #include "armadillo_bits/fn_rank.hpp"
#include "armadillo_bits/fn_kron.hpp" #include "armadillo_bits/fn_kron.hpp"
#include "armadillo_bits/fn_flip.hpp"
#include "armadillo_bits/fn_as_scalar.hpp" #include "armadillo_bits/fn_as_scalar.hpp"
#include "armadillo_bits/fn_princomp.hpp"
// //
// class meat // class meat
#include "armadillo_bits/gemm.hpp" #include "armadillo_bits/gemm.hpp"
#include "armadillo_bits/gemv.hpp" #include "armadillo_bits/gemv.hpp"
#include "armadillo_bits/gemm_mixed.hpp" #include "armadillo_bits/gemm_mixed.hpp"
#include "armadillo_bits/eop_core_meat.hpp"
#include "armadillo_bits/eop_cube_core_meat.hpp"
#include "armadillo_bits/eglue_core_meat.hpp"
#include "armadillo_bits/eglue_cube_core_meat.hpp"
#include "armadillo_bits/podarray_meat.hpp" #include "armadillo_bits/podarray_meat.hpp"
#include "armadillo_bits/auxlib_meat.hpp" #include "armadillo_bits/auxlib_meat.hpp"
#include "armadillo_bits/Mat_meat.hpp" #include "armadillo_bits/Mat_meat.hpp"
#include "armadillo_bits/Col_meat.hpp" #include "armadillo_bits/Col_meat.hpp"
#include "armadillo_bits/Row_meat.hpp" #include "armadillo_bits/Row_meat.hpp"
#include "armadillo_bits/Cube_meat.hpp" #include "armadillo_bits/Cube_meat.hpp"
#include "armadillo_bits/field_meat.hpp" #include "armadillo_bits/field_meat.hpp"
#include "armadillo_bits/subview_meat.hpp" #include "armadillo_bits/subview_meat.hpp"
#include "armadillo_bits/subview_field_meat.hpp" #include "armadillo_bits/subview_field_meat.hpp"
#include "armadillo_bits/subview_cube_meat.hpp" #include "armadillo_bits/subview_cube_meat.hpp"
#include "armadillo_bits/diagview_meat.hpp" #include "armadillo_bits/diagview_meat.hpp"
#include "armadillo_bits/diskio_meat.hpp" #include "armadillo_bits/diskio_meat.hpp"
#include "armadillo_bits/wall_clock_meat.hpp" #include "armadillo_bits/wall_clock_meat.hpp"
#include "armadillo_bits/running_stat_meat.hpp" #include "armadillo_bits/running_stat_meat.hpp"
#include "armadillo_bits/running_stat_vec_meat.hpp" #include "armadillo_bits/running_stat_vec_meat.hpp"
#include "armadillo_bits/op_diagmat_meat.hpp" #include "armadillo_bits/op_diagmat_meat.hpp"
#include "armadillo_bits/op_diagvec_meat.hpp"
#include "armadillo_bits/op_dot_meat.hpp" #include "armadillo_bits/op_dot_meat.hpp"
#include "armadillo_bits/op_inv_meat.hpp" #include "armadillo_bits/op_inv_meat.hpp"
#include "armadillo_bits/op_htrans_meat.hpp" #include "armadillo_bits/op_htrans_meat.hpp"
#include "armadillo_bits/op_misc_meat.hpp"
#include "armadillo_bits/op_max_meat.hpp" #include "armadillo_bits/op_max_meat.hpp"
#include "armadillo_bits/op_min_meat.hpp" #include "armadillo_bits/op_min_meat.hpp"
#include "armadillo_bits/op_mean_meat.hpp" #include "armadillo_bits/op_mean_meat.hpp"
#include "armadillo_bits/op_median_meat.hpp" #include "armadillo_bits/op_median_meat.hpp"
#include "armadillo_bits/op_neg_meat.hpp"
#include "armadillo_bits/op_ones_meat.hpp"
#include "armadillo_bits/op_rand_meat.hpp"
#include "armadillo_bits/op_randn_meat.hpp"
#include "armadillo_bits/op_scalar_misc_meat.hpp"
#include "armadillo_bits/op_sort_meat.hpp" #include "armadillo_bits/op_sort_meat.hpp"
#include "armadillo_bits/op_sum_meat.hpp" #include "armadillo_bits/op_sum_meat.hpp"
#include "armadillo_bits/op_stddev_meat.hpp" #include "armadillo_bits/op_stddev_meat.hpp"
#include "armadillo_bits/op_trans_meat.hpp" #include "armadillo_bits/op_trans_meat.hpp"
#include "armadillo_bits/op_trig_meat.hpp"
#include "armadillo_bits/op_var_meat.hpp" #include "armadillo_bits/op_var_meat.hpp"
#include "armadillo_bits/op_zeros_meat.hpp"
#include "armadillo_bits/op_repmat_meat.hpp" #include "armadillo_bits/op_repmat_meat.hpp"
#include "armadillo_bits/op_reshape_meat.hpp" #include "armadillo_bits/op_reshape_meat.hpp"
#include "armadillo_bits/op_cov_meat.hpp" #include "armadillo_bits/op_cov_meat.hpp"
#include "armadillo_bits/op_cor_meat.hpp" #include "armadillo_bits/op_cor_meat.hpp"
#include "armadillo_bits/op_shuffle_meat.hpp" #include "armadillo_bits/op_shuffle_meat.hpp"
#include "armadillo_bits/op_prod_meat.hpp" #include "armadillo_bits/op_prod_meat.hpp"
#include "armadillo_bits/op_eps_meat.hpp"
#include "armadillo_bits/op_pinv_meat.hpp" #include "armadillo_bits/op_pinv_meat.hpp"
#include "armadillo_bits/op_dotext_meat.hpp"
#include "armadillo_bits/op_flip_meat.hpp"
#include "armadillo_bits/op_princomp_meat.hpp"
#include "armadillo_bits/glue_plus_meat.hpp"
#include "armadillo_bits/glue_minus_meat.hpp"
#include "armadillo_bits/glue_times_meat.hpp" #include "armadillo_bits/glue_times_meat.hpp"
#include "armadillo_bits/glue_schur_meat.hpp"
#include "armadillo_bits/glue_div_meat.hpp"
#include "armadillo_bits/glue_cov_meat.hpp" #include "armadillo_bits/glue_cov_meat.hpp"
#include "armadillo_bits/glue_cor_meat.hpp" #include "armadillo_bits/glue_cor_meat.hpp"
#include "armadillo_bits/glue_kron_meat.hpp" #include "armadillo_bits/glue_kron_meat.hpp"
#include "armadillo_bits/glue_cube_plus_meat.hpp"
#include "armadillo_bits/glue_cube_minus_meat.hpp"
#include "armadillo_bits/glue_cube_schur_meat.hpp"
#include "armadillo_bits/glue_cube_div_meat.hpp"
} }
#endif #endif
 End of changes. 38 change blocks. 
87 lines changed or deleted 56 lines changed or added


 atlas_proto.hpp   atlas_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 auxlib_meat.hpp   auxlib_meat.hpp 
// Copyright (C) 2009 NICTA and the authors listed below // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Edmund Highcock (edmund dot highcock at merton dot ox dot ac dot uk) // - Edmund Highcock (edmund dot highcock at merton dot ox dot ac dot uk)
// //
// 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 auxlib //! \addtogroup auxlib
//! @{ //! @{
//! immediate matrix inverse //! immediate matrix inverse
template<typename eT> template<typename eT>
inline inline
void bool
auxlib::inv_noalias(Mat<eT>& out, const Mat<eT>& X) auxlib::inv_noalias(Mat<eT>& out, const Mat<eT>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
switch(X.n_rows) switch(X.n_rows)
{ {
case 1: case 1:
{ {
out.set_size(1,1); out.set_size(1,1);
out[0] = eT(1) / X[0]; out[0] = eT(1) / X[0];
skipping to change at line 134 skipping to change at line 135
out = X; out = X;
podarray<int> ipiv(out.n_rows); podarray<int> ipiv(out.n_rows);
int info = atlas::clapack_getrf(atlas::CblasColMajor, out.n_rows, o ut.n_cols, out.memptr(), out.n_rows, ipiv.memptr()); int info = atlas::clapack_getrf(atlas::CblasColMajor, out.n_rows, o ut.n_cols, out.memptr(), out.n_rows, ipiv.memptr());
if(info == 0) if(info == 0)
{ {
info = atlas::clapack_getri(atlas::CblasColMajor, out.n_rows, out .memptr(), out.n_rows, ipiv.memptr()); info = atlas::clapack_getri(atlas::CblasColMajor, out.n_rows, out .memptr(), out.n_rows, ipiv.memptr());
} }
arma_check( (info > 0), "auxlib::inv_noalias(): matrix appears to b e singular" ); return (info == 0);
} }
#elif defined(ARMA_USE_LAPACK) #elif defined(ARMA_USE_LAPACK)
{ {
out = X; out = X;
int n_rows = out.n_rows; int n_rows = out.n_rows;
int n_cols = out.n_cols; int n_cols = out.n_cols;
int info = 0; int info = 0;
podarray<int> ipiv(out.n_rows); podarray<int> ipiv(out.n_rows);
skipping to change at line 166 skipping to change at line 167
if(info == 0) if(info == 0)
{ {
// query for optimum size of work_len // query for optimum size of work_len
int work_len_tmp = -1; int work_len_tmp = -1;
lapack::getri_(&n_rows, out.memptr(), &n_rows, ipiv.memptr(), wor k.memptr(), &work_len_tmp, &info); lapack::getri_(&n_rows, out.memptr(), &n_rows, ipiv.memptr(), wor k.memptr(), &work_len_tmp, &info);
if(info == 0) if(info == 0)
{ {
int proposed_work_len = static_cast<int>(auxlib::tmp_real(work[ 0])); int proposed_work_len = static_cast<int>(access::tmp_real(work[ 0]));
// if necessary, allocate more memory // if necessary, allocate more memory
if(work_len < proposed_work_len) if(work_len < proposed_work_len)
{ {
work_len = proposed_work_len; work_len = proposed_work_len;
work.set_size(work_len); work.set_size(work_len);
} }
} }
lapack::getri_(&n_rows, out.memptr(), &n_rows, ipiv.memptr(), wor k.memptr(), &work_len, &info); lapack::getri_(&n_rows, out.memptr(), &n_rows, ipiv.memptr(), wor k.memptr(), &work_len, &info);
} }
arma_check( (info > 0), "auxlib::inv_noalias(): matrix appears to b e singular" ); return (info == 0);
} }
#else #else
{ {
arma_stop("auxlib::inv_noalias(): need ATLAS or LAPACK library"); arma_stop("inv(): need ATLAS or LAPACK");
} }
#endif #endif
}; };
} }
return true;
} }
//! immediate inplace matrix inverse //! immediate inplace matrix inverse
template<typename eT> template<typename eT>
inline inline
void bool
auxlib::inv_inplace(Mat<eT>& X) auxlib::inv_inplace(Mat<eT>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
// for more info, see: // for more info, see:
// http://www.dr-lex.34sp.com/random/matrix_inv.html // http://www.dr-lex.34sp.com/random/matrix_inv.html
// http://www.cvl.iis.u-tokyo.ac.jp/~miyazaki/tech/teche23.html // http://www.cvl.iis.u-tokyo.ac.jp/~miyazaki/tech/teche23.html
// http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/f ourD/index.htm // http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/f ourD/index.htm
// http://www.geometrictools.com//LibFoundation/Mathematics/Wm4Matrix4.in l // http://www.geometrictools.com//LibFoundation/Mathematics/Wm4Matrix4.in l
skipping to change at line 304 skipping to change at line 307
Mat<eT>& out = X; Mat<eT>& out = X;
podarray<int> ipiv(out.n_rows); podarray<int> ipiv(out.n_rows);
int info = atlas::clapack_getrf(atlas::CblasColMajor, out.n_rows, o ut.n_cols, out.memptr(), out.n_rows, ipiv.memptr()); int info = atlas::clapack_getrf(atlas::CblasColMajor, out.n_rows, o ut.n_cols, out.memptr(), out.n_rows, ipiv.memptr());
if(info == 0) if(info == 0)
{ {
info = atlas::clapack_getri(atlas::CblasColMajor, out.n_rows, out .memptr(), out.n_rows, ipiv.memptr()); info = atlas::clapack_getri(atlas::CblasColMajor, out.n_rows, out .memptr(), out.n_rows, ipiv.memptr());
} }
arma_check( (info > 0), "auxlib::inv_inplace(): matrix appears to b e singular" ); return (info == 0);
} }
#elif defined(ARMA_USE_LAPACK) #elif defined(ARMA_USE_LAPACK)
{ {
Mat<eT>& out = X; Mat<eT>& out = X;
int n_rows = out.n_rows; int n_rows = out.n_rows;
int n_cols = out.n_cols; int n_cols = out.n_cols;
int info = 0; int info = 0;
podarray<int> ipiv(out.n_rows); podarray<int> ipiv(out.n_rows);
skipping to change at line 336 skipping to change at line 339
if(info == 0) if(info == 0)
{ {
// query for optimum size of work_len // query for optimum size of work_len
int work_len_tmp = -1; int work_len_tmp = -1;
lapack::getri_(&n_rows, out.memptr(), &n_rows, ipiv.memptr(), wor k.memptr(), &work_len_tmp, &info); lapack::getri_(&n_rows, out.memptr(), &n_rows, ipiv.memptr(), wor k.memptr(), &work_len_tmp, &info);
if(info == 0) if(info == 0)
{ {
int proposed_work_len = static_cast<int>(auxlib::tmp_real(work[ 0])); int proposed_work_len = static_cast<int>(access::tmp_real(work[ 0]));
// if necessary, allocate more memory // if necessary, allocate more memory
if(work_len < proposed_work_len) if(work_len < proposed_work_len)
{ {
work_len = proposed_work_len; work_len = proposed_work_len;
work.set_size(work_len); work.set_size(work_len);
} }
} }
lapack::getri_(&n_rows, out.memptr(), &n_rows, ipiv.memptr(), wor k.memptr(), &work_len, &info); lapack::getri_(&n_rows, out.memptr(), &n_rows, ipiv.memptr(), wor k.memptr(), &work_len, &info);
} }
arma_check( (info > 0), "auxlib::inv_noalias(): matrix appears to b e singular" ); return (info == 0);
} }
#else #else
{ {
arma_stop("auxlib::inv_inplace(): need ATLAS or LAPACK"); arma_stop("inv(): need ATLAS or LAPACK");
} }
#endif #endif
} }
} }
return true;
} }
//! immediate determinant of a matrix using ATLAS or LAPACK //! immediate determinant of a matrix using ATLAS or LAPACK
template<typename eT> template<typename eT>
inline inline
eT eT
auxlib::det(const Mat<eT>& X) auxlib::det(const Mat<eT>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
switch(X.n_rows) switch(X.n_rows)
{ {
case 0: case 0:
return 0.0; return eT(0);
case 1: case 1:
return X[0]; return X[0];
case 2: case 2:
return (X.at(0,0)*X.at(1,1) - X.at(0,1)*X.at(1,0)); return (X.at(0,0)*X.at(1,1) - X.at(0,1)*X.at(1,0));
case 3: case 3:
{ {
const eT* a_col0 = X.colptr(0); const eT* a_col0 = X.colptr(0);
skipping to change at line 473 skipping to change at line 477
} }
} }
return val * eT(sign); return val * eT(sign);
} }
#elif defined(ARMA_USE_LAPACK) #elif defined(ARMA_USE_LAPACK)
{ {
Mat<eT> tmp = X; Mat<eT> tmp = X;
podarray<int> ipiv(tmp.n_rows); podarray<int> ipiv(tmp.n_rows);
int info = 0; int info = 0;
int n_rows = int(tmp.n_rows); int n_rows = int(tmp.n_rows);
int n_cols = int(tmp.n_cols); int n_cols = int(tmp.n_cols);
lapack::getrf_(&n_rows, &n_cols, tmp.memptr(), &n_rows, ipiv.memptr (), &info); lapack::getrf_(&n_rows, &n_cols, tmp.memptr(), &n_rows, ipiv.memptr (), &info);
// on output tmp appears to be L+U_alt, where U_alt is U with the m ain diagonal set to zero // on output tmp appears to be L+U_alt, where U_alt is U with the m ain diagonal set to zero
eT val = tmp.at(0,0); eT val = tmp.at(0,0);
for(u32 i=1; i < tmp.n_rows; ++i) for(u32 i=1; i < tmp.n_rows; ++i)
{ {
val *= tmp.at(i,i); val *= tmp.at(i,i);
skipping to change at line 499 skipping to change at line 503
if( int(i) != (ipiv.mem[i] - 1) ) // NOTE: adjustment of -1 is r equired as Fortran counts from 1 if( int(i) != (ipiv.mem[i] - 1) ) // NOTE: adjustment of -1 is r equired as Fortran counts from 1
{ {
sign *= -1; sign *= -1;
} }
} }
return val * eT(sign); return val * eT(sign);
} }
#else #else
{ {
arma_stop("auxlib::det(): need ATLAS or LAPACK library"); arma_stop("det(): need ATLAS or LAPACK");
return eT(0); return eT(0);
} }
#endif #endif
} }
} }
} }
//! immediate log determinant of a matrix using ATLAS or LAPACK
template<typename eT>
inline
void
auxlib::log_det(eT& out_val, typename get_pod_type<eT>::result& out_sign, c
onst Mat<eT>& X)
{
arma_extra_debug_sigprint();
typedef typename get_pod_type<eT>::result T;
#if defined(ARMA_USE_ATLAS)
{
Mat<eT> tmp = X;
podarray<int> ipiv(tmp.n_rows);
atlas::clapack_getrf(atlas::CblasColMajor, tmp.n_rows, tmp.n_cols, tmp.
memptr(), tmp.n_rows, ipiv.memptr());
// on output tmp appears to be L+U_alt, where U_alt is U with the main
diagonal set to zero
s32 sign = (is_complex<eT>::value == false) ? ( (access::tmp_real( tmp.
at(0,0) ) < T(0)) ? -1 : +1 ) : +1;
eT val = (is_complex<eT>::value == false) ? std::log( (access::tmp_re
al( tmp.at(0,0) ) < T(0)) ? tmp.at(0,0)*T(-1) : tmp.at(0,0) ) : std::log( t
mp.at(0,0) );
for(u32 i=1; i < tmp.n_rows; ++i)
{
const eT x = tmp.at(i,i);
sign *= (is_complex<eT>::value == false) ? ( (access::tmp_real(x) < T
(0)) ? -1 : +1 ) : +1;
val += (is_complex<eT>::value == false) ? std::log( (access::tmp_rea
l(x) < T(0)) ? x*T(-1) : x ) : std::log(x);
}
for(u32 i=0; i < tmp.n_rows; ++i)
{
if( int(i) != ipiv.mem[i] ) // NOTE: no adjustment required, as the
clapack version of getrf() assumes counting from 0
{
sign *= -1;
}
}
out_val = val;
out_sign = T(sign);
}
#elif defined(ARMA_USE_LAPACK)
{
Mat<eT> tmp = X;
podarray<int> ipiv(tmp.n_rows);
int info = 0;
int n_rows = int(tmp.n_rows);
int n_cols = int(tmp.n_cols);
lapack::getrf_(&n_rows, &n_cols, tmp.memptr(), &n_rows, ipiv.memptr(),
&info);
// on output tmp appears to be L+U_alt, where U_alt is U with the main
diagonal set to zero
s32 sign = (is_complex<eT>::value == false) ? ( (access::tmp_real( tmp.
at(0,0) ) < T(0)) ? -1 : +1 ) : +1;
eT val = (is_complex<eT>::value == false) ? std::log( (access::tmp_re
al( tmp.at(0,0) ) < T(0)) ? tmp.at(0,0)*T(-1) : tmp.at(0,0) ) : std::log( t
mp.at(0,0) );
for(u32 i=1; i < tmp.n_rows; ++i)
{
const eT x = tmp.at(i,i);
sign *= (is_complex<eT>::value == false) ? ( (access::tmp_real(x) < T
(0)) ? -1 : +1 ) : +1;
val += (is_complex<eT>::value == false) ? std::log( (access::tmp_rea
l(x) < T(0)) ? x*T(-1) : x ) : std::log(x);
}
for(u32 i=0; i < tmp.n_rows; ++i)
{
if( int(i) != (ipiv.mem[i] - 1) ) // NOTE: adjustment of -1 is requi
red as Fortran counts from 1
{
sign *= -1;
}
}
out_val = val;
out_sign = T(sign);
}
#else
{
arma_stop("log_det(): need ATLAS or LAPACK");
out_val = eT(0);
out_sign = T(0);
}
#endif
}
//! immediate LU decomposition of a matrix using ATLAS or LAPACK //! immediate LU decomposition of a matrix using ATLAS or LAPACK
template<typename eT> template<typename eT>
inline inline
void void
auxlib::lu(Mat<eT>& L, Mat<eT>& U, podarray<int>& ipiv, const Mat<eT>& X) auxlib::lu(Mat<eT>& L, Mat<eT>& U, podarray<int>& ipiv, const Mat<eT>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
U = X; U = X;
skipping to change at line 568 skipping to change at line 658
for(u32 row=col+1; row<L.n_rows; ++row) for(u32 row=col+1; row<L.n_rows; ++row)
{ {
L.at(row,col) = U.at(row,col); L.at(row,col) = U.at(row,col);
U.at(row,col) = eT(0); U.at(row,col) = eT(0);
} }
} }
} }
#else #else
{ {
arma_stop("auxlib::lu(): need ATLAS or LAPACK library"); arma_stop("lu(): need ATLAS or LAPACK");
} }
#endif #endif
} }
template<typename eT> template<typename eT>
inline inline
void void
auxlib::lu(Mat<eT>& L, Mat<eT>& U, Mat<eT>& P, const Mat<eT>& X) auxlib::lu(Mat<eT>& L, Mat<eT>& U, Mat<eT>& P, const Mat<eT>& X)
{ {
skipping to change at line 635 skipping to change at line 725
void void
auxlib::eig_sym(Col<eT>& eigval, const Mat<eT>& A_orig) auxlib::eig_sym(Col<eT>& eigval, const Mat<eT>& A_orig)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
#if defined(ARMA_USE_LAPACK) #if defined(ARMA_USE_LAPACK)
{ {
const unwrap_check<Mat<eT> > tmp(A_orig, eigval); const unwrap_check<Mat<eT> > tmp(A_orig, eigval);
const Mat<eT>& A = tmp.M; const Mat<eT>& A = tmp.M;
arma_debug_check( (A.n_rows != A.n_cols), "auxlib::eig_sym(): given mat rix is not square"); arma_debug_check( (A.n_rows != A.n_cols), "eig_sym(): given matrix is n ot square");
// rudimentary "better-than-nothing" test for symmetry // rudimentary "better-than-nothing" test for symmetry
//arma_debug_check( (A.at(A.n_rows-1, 0) != A.at(0, A.n_cols-1)), "auxl ib::eig(): given matrix is not symmetric" ); //arma_debug_check( (A.at(A.n_rows-1, 0) != A.at(0, A.n_cols-1)), "auxl ib::eig(): given matrix is not symmetric" );
char jobz = 'N'; char jobz = 'N';
char uplo = 'U'; char uplo = 'U';
int n_rows = A.n_rows; int n_rows = A.n_rows;
int lwork = (std::max)(1,3*n_rows-1); int lwork = (std::max)(1,3*n_rows-1);
skipping to change at line 657 skipping to change at line 747
podarray<eT> work(lwork); podarray<eT> work(lwork);
Mat<eT> A_copy = A; Mat<eT> A_copy = A;
int info; int info;
arma_extra_debug_print("lapack::syev_()"); arma_extra_debug_print("lapack::syev_()");
lapack::syev_(&jobz, &uplo, &n_rows, A_copy.memptr(), &n_rows, eigval.m emptr(), work.memptr(), &lwork, &info); lapack::syev_(&jobz, &uplo, &n_rows, A_copy.memptr(), &n_rows, eigval.m emptr(), work.memptr(), &lwork, &info);
} }
#else #else
{ {
arma_stop("auxlib::eig_sym(): need LAPACK library"); arma_stop("eig_sym(): need LAPACK");
} }
#endif #endif
} }
//! immediate eigenvalues of a hermitian complex matrix using LAPACK //! immediate eigenvalues of a hermitian complex matrix using LAPACK
template<typename T> template<typename T>
inline inline
void void
auxlib::eig_sym(Col<T>& eigval, const Mat< std::complex<T> >& A) auxlib::eig_sym(Col<T>& eigval, const Mat< std::complex<T> >& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename std::complex<T> eT; typedef typename std::complex<T> eT;
#if defined(ARMA_USE_LAPACK) #if defined(ARMA_USE_LAPACK)
{ {
arma_debug_check( (A.n_rows != A.n_cols), "auxlib::eig_sym(): given mat rix is not hermitian"); arma_debug_check( (A.n_rows != A.n_cols), "eig_sym(): given matrix is n ot hermitian");
char jobz = 'N'; char jobz = 'N';
char uplo = 'U'; char uplo = 'U';
int n_rows = A.n_rows; int n_rows = A.n_rows;
int lda = A.n_rows; int lda = A.n_rows;
int lwork = (std::max)(1, 2*n_rows - 1); // TODO: automatically find best size of lwork int lwork = (std::max)(1, 2*n_rows - 1); // TODO: automatically find best size of lwork
eigval.set_size(n_rows); eigval.set_size(n_rows);
skipping to change at line 696 skipping to change at line 786
podarray<T> rwork( (std::max)(1, 3*n_rows - 2) ); podarray<T> rwork( (std::max)(1, 3*n_rows - 2) );
Mat<eT> A_copy = A; Mat<eT> A_copy = A;
int info; int info;
arma_extra_debug_print("lapack::heev_()"); arma_extra_debug_print("lapack::heev_()");
lapack::heev_(&jobz, &uplo, &n_rows, A_copy.memptr(), &lda, eigval.memp tr(), work.memptr(), &lwork, rwork.memptr(), &info); lapack::heev_(&jobz, &uplo, &n_rows, A_copy.memptr(), &lda, eigval.memp tr(), work.memptr(), &lwork, rwork.memptr(), &info);
} }
#else #else
{ {
arma_stop("auxlib::eig_sym(): need LAPACK library"); arma_stop("eig_sym(): need LAPACK");
} }
#endif #endif
} }
//! immediate eigenvalues and eigenvectors of a symmetric real matrix using LAPACK //! immediate eigenvalues and eigenvectors of a symmetric real matrix using LAPACK
template<typename eT> template<typename eT>
inline inline
void void
auxlib::eig_sym(Col<eT>& eigval, Mat<eT>& eigvec, const Mat<eT>& A_orig) auxlib::eig_sym(Col<eT>& eigval, Mat<eT>& eigvec, const Mat<eT>& A_orig)
{ {
skipping to change at line 719 skipping to change at line 809
// TODO: check for aliasing // TODO: check for aliasing
#if defined(ARMA_USE_LAPACK) #if defined(ARMA_USE_LAPACK)
{ {
const unwrap_check< Mat<eT> > tmp1(A_orig, eigval); const unwrap_check< Mat<eT> > tmp1(A_orig, eigval);
const Mat<eT>& A_tmp = tmp1.M; const Mat<eT>& A_tmp = tmp1.M;
const unwrap_check< Mat<eT> > tmp2(A_tmp, eigvec); const unwrap_check< Mat<eT> > tmp2(A_tmp, eigvec);
const Mat<eT>& A = tmp2.M; const Mat<eT>& A = tmp2.M;
arma_debug_check( (A.n_rows != A.n_cols), "auxlib::eig_sym(): given mat rix is not square" ); arma_debug_check( (A.n_rows != A.n_cols), "eig_sym(): given matrix is n ot square" );
// rudimentary "better-than-nothing" test for symmetry // rudimentary "better-than-nothing" test for symmetry
//arma_debug_check( (A.at(A.n_rows-1, 0) != A.at(0, A.n_cols-1)), "auxl ib::eig(): given matrix is not symmetric" ); //arma_debug_check( (A.at(A.n_rows-1, 0) != A.at(0, A.n_cols-1)), "auxl ib::eig(): given matrix is not symmetric" );
char jobz = 'V'; char jobz = 'V';
char uplo = 'U'; char uplo = 'U';
int n_rows = A.n_rows; int n_rows = A.n_rows;
int lwork = (std::max)(1, 3*n_rows-1); int lwork = (std::max)(1, 3*n_rows-1);
skipping to change at line 741 skipping to change at line 831
podarray<eT> work(lwork); podarray<eT> work(lwork);
eigvec = A; eigvec = A;
int info; int info;
arma_extra_debug_print("lapack::syev_()"); arma_extra_debug_print("lapack::syev_()");
lapack::syev_(&jobz, &uplo, &n_rows, eigvec.memptr(), &n_rows, eigval.m emptr(), work.memptr(), &lwork, &info); lapack::syev_(&jobz, &uplo, &n_rows, eigvec.memptr(), &n_rows, eigval.m emptr(), work.memptr(), &lwork, &info);
} }
#else #else
{ {
arma_stop("auxlib::eig_sym(): need LAPACK library"); arma_stop("eig_sym(): need LAPACK");
} }
#endif #endif
} }
//! immediate eigenvalues and eigenvectors of a hermitian complex matrix us ing LAPACK //! immediate eigenvalues and eigenvectors of a hermitian complex matrix us ing LAPACK
template<typename T> template<typename T>
inline inline
void void
auxlib::eig_sym(Col<T>& eigval, Mat< std::complex<T> >& eigvec, const Mat< std::complex<T> >& A_orig) auxlib::eig_sym(Col<T>& eigval, Mat< std::complex<T> >& eigvec, const Mat< std::complex<T> >& A_orig)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename std::complex<T> eT; typedef typename std::complex<T> eT;
#if defined(ARMA_USE_LAPACK) #if defined(ARMA_USE_LAPACK)
{ {
const unwrap_check< Mat<eT> > tmp(A_orig, eigvec); const unwrap_check< Mat<eT> > tmp(A_orig, eigvec);
const Mat<eT>& A = tmp.M; const Mat<eT>& A = tmp.M;
arma_debug_check( (A.n_rows != A.n_cols), "auxlib::eig_sym(): given mat rix is not hermitian" ); arma_debug_check( (A.n_rows != A.n_cols), "eig_sym(): given matrix is n ot hermitian" );
char jobz = 'V'; char jobz = 'V';
char uplo = 'U'; char uplo = 'U';
int n_rows = A.n_rows; int n_rows = A.n_rows;
int lda = A.n_rows; int lda = A.n_rows;
int lwork = (std::max)(1, 2*n_rows - 1); // TODO: automatically find best size of lwork int lwork = (std::max)(1, 2*n_rows - 1); // TODO: automatically find best size of lwork
eigval.set_size(n_rows); eigval.set_size(n_rows);
skipping to change at line 784 skipping to change at line 874
podarray<T> rwork( (std::max)(1, 3*n_rows - 2) ); podarray<T> rwork( (std::max)(1, 3*n_rows - 2) );
eigvec = A; eigvec = A;
int info; int info;
arma_extra_debug_print("lapack::heev_()"); arma_extra_debug_print("lapack::heev_()");
lapack::heev_(&jobz, &uplo, &n_rows, eigvec.memptr(), &lda, eigval.memp tr(), work.memptr(), &lwork, rwork.memptr(), &info); lapack::heev_(&jobz, &uplo, &n_rows, eigvec.memptr(), &lda, eigval.memp tr(), work.memptr(), &lwork, rwork.memptr(), &info);
} }
#else #else
{ {
arma_stop("auxlib::eig_sym(): need LAPACK library"); arma_stop("eig_sym(): need LAPACK");
} }
#endif #endif
} }
//! Eigenvalues and eigenvectors of a general square real matrix using LAPA CK. //! Eigenvalues and eigenvectors of a general square real matrix using LAPA CK.
//! The argument 'side' specifies which eigenvectors should be calculated //! The argument 'side' specifies which eigenvectors should be calculated
//! (see code for mode details). //! (see code for mode details).
template<typename T> template<typename T>
inline inline
skipping to change at line 811 skipping to change at line 901
const Mat<T>& A, const Mat<T>& A,
const char side const char side
) )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
// TODO: check for aliasing // TODO: check for aliasing
#if defined(ARMA_USE_LAPACK) #if defined(ARMA_USE_LAPACK)
{ {
arma_debug_check( (A.n_rows != A.n_cols), "auxlib::eig_gen(): given mat rix is not square" ); arma_debug_check( (A.n_rows != A.n_cols), "eig_gen(): given matrix is n ot square" );
char jobvl; char jobvl;
char jobvr; char jobvr;
switch(side) switch(side)
{ {
case 'l': // left case 'l': // left
jobvl = 'V'; jobvl = 'V';
jobvr = 'N'; jobvr = 'N';
break; break;
skipping to change at line 839 skipping to change at line 929
jobvl = 'V'; jobvl = 'V';
jobvr = 'V'; jobvr = 'V';
break; break;
case 'n': // neither case 'n': // neither
jobvl = 'N'; jobvl = 'N';
jobvr = 'N'; jobvr = 'N';
break; break;
default: default:
arma_stop("auxlib::eig_gen(): parameter 'side' is invalid"); arma_stop("eig_gen(): parameter 'side' is invalid");
} }
int n_rows = A.n_rows; int n_rows = A.n_rows;
int lda = A.n_rows; int lda = A.n_rows;
int lwork = (std::max)(1, 4*n_rows); // TODO: automatically find best size of lwork int lwork = (std::max)(1, 4*n_rows); // TODO: automatically find best size of lwork
eigval.set_size(n_rows); eigval.set_size(n_rows);
l_eigvec.set_size(n_rows, n_rows); l_eigvec.set_size(n_rows, n_rows);
r_eigvec.set_size(n_rows, n_rows); r_eigvec.set_size(n_rows, n_rows);
skipping to change at line 871 skipping to change at line 961
eigval.set_size(n_rows); eigval.set_size(n_rows);
for(u32 i=0; i<u32(n_rows); ++i) for(u32 i=0; i<u32(n_rows); ++i)
{ {
eigval[i] = std::complex<T>(wr[i], wi[i]); eigval[i] = std::complex<T>(wr[i], wi[i]);
} }
} }
#else #else
{ {
arma_stop("auxlib::eig_gen(): need LAPACK library"); arma_stop("eig_gen(): need LAPACK");
} }
#endif #endif
} }
//! Eigenvalues and eigenvectors of a general square complex matrix using L APACK //! Eigenvalues and eigenvectors of a general square complex matrix using L APACK
//! The argument 'side' specifies which eigenvectors should be calculated //! The argument 'side' specifies which eigenvectors should be calculated
//! (see code for mode details). //! (see code for mode details).
template<typename T> template<typename T>
inline inline
skipping to change at line 900 skipping to change at line 990
) )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
// TODO: check for aliasing // TODO: check for aliasing
typedef typename std::complex<T> eT; typedef typename std::complex<T> eT;
#if defined(ARMA_USE_LAPACK) #if defined(ARMA_USE_LAPACK)
{ {
arma_debug_check( (A.n_rows != A.n_cols), "auxlib::eig_gen(): given mat rix is not square" ); arma_debug_check( (A.n_rows != A.n_cols), "eig_gen(): given matrix is n ot square" );
char jobvl; char jobvl;
char jobvr; char jobvr;
switch(side) switch(side)
{ {
case 'l': // left case 'l': // left
jobvl = 'V'; jobvl = 'V';
jobvr = 'N'; jobvr = 'N';
break; break;
skipping to change at line 928 skipping to change at line 1018
jobvl = 'V'; jobvl = 'V';
jobvr = 'V'; jobvr = 'V';
break; break;
case 'n': // neither case 'n': // neither
jobvl = 'N'; jobvl = 'N';
jobvr = 'N'; jobvr = 'N';
break; break;
default: default:
arma_stop("auxlib::eig_gen(): parameter 'side' is invalid"); arma_stop("eig_gen(): parameter 'side' is invalid");
} }
int n_rows = A.n_rows; int n_rows = A.n_rows;
int lda = A.n_rows; int lda = A.n_rows;
int lwork = (std::max)(1, 4*n_rows); // TODO: automatically find best size of lwork int lwork = (std::max)(1, 4*n_rows); // TODO: automatically find best size of lwork
eigval.set_size(n_rows); eigval.set_size(n_rows);
l_eigvec.set_size(n_rows, n_rows); l_eigvec.set_size(n_rows, n_rows);
r_eigvec.set_size(n_rows, n_rows); r_eigvec.set_size(n_rows, n_rows);
skipping to change at line 950 skipping to change at line 1040
podarray<T> rwork( (std::max)(1, 3*n_rows) ); // was 2,3 podarray<T> rwork( (std::max)(1, 3*n_rows) ); // was 2,3
Mat<eT> A_copy = A; Mat<eT> A_copy = A;
int info; int info;
arma_extra_debug_print("lapack::cx_geev_()"); arma_extra_debug_print("lapack::cx_geev_()");
lapack::cx_geev_(&jobvl, &jobvr, &n_rows, A_copy.memptr(), &lda, eigval .memptr(), l_eigvec.memptr(), &n_rows, r_eigvec.memptr(), &n_rows, work.mem ptr(), &lwork, rwork.memptr(), &info); lapack::cx_geev_(&jobvl, &jobvr, &n_rows, A_copy.memptr(), &lda, eigval .memptr(), l_eigvec.memptr(), &n_rows, r_eigvec.memptr(), &n_rows, work.mem ptr(), &lwork, rwork.memptr(), &info);
} }
#else #else
{ {
arma_stop("auxlib::eig_gen(): need LAPACK library"); arma_stop("eig_gen(): need LAPACK");
} }
#endif #endif
} }
template<typename eT> template<typename eT>
inline inline
bool bool
auxlib::chol(Mat<eT>& out, const Mat<eT>& X) auxlib::chol(Mat<eT>& out, const Mat<eT>& X)
{ {
skipping to change at line 986 skipping to change at line 1076
for(u32 row=col+1; row<X.n_rows; ++row) for(u32 row=col+1; row<X.n_rows; ++row)
{ {
colptr[row] = eT(0); colptr[row] = eT(0);
} }
} }
return (info == 0); return (info == 0);
} }
#else #else
{ {
arma_stop("auxlib::chol(): need LAPACK library"); arma_stop("chol(): need LAPACK");
return false; return false;
} }
#endif #endif
} }
template<typename eT> template<typename eT>
inline inline
bool bool
auxlib::qr(Mat<eT>& Q, Mat<eT>& R, const Mat<eT>& X) auxlib::qr(Mat<eT>& Q, Mat<eT>& R, const Mat<eT>& X)
{ {
skipping to change at line 1019 skipping to change at line 1109
podarray<eT> work(work_len); podarray<eT> work(work_len);
R = X; R = X;
// query for the optimum value of work_len // query for the optimum value of work_len
work_len_tmp = -1; work_len_tmp = -1;
lapack::geqrf_(&m, &n, R.memptr(), &m, tau.memptr(), work.memptr(), &wo rk_len_tmp, &info); lapack::geqrf_(&m, &n, R.memptr(), &m, tau.memptr(), work.memptr(), &wo rk_len_tmp, &info);
if(info == 0) if(info == 0)
{ {
work_len = static_cast<int>(auxlib::tmp_real(work[0])); work_len = static_cast<int>(access::tmp_real(work[0]));
work.set_size(work_len); work.set_size(work_len);
} }
lapack::geqrf_(&m, &n, R.memptr(), &m, tau.memptr(), work.memptr(), &wo rk_len, &info); lapack::geqrf_(&m, &n, R.memptr(), &m, tau.memptr(), work.memptr(), &wo rk_len, &info);
Q.set_size(X.n_rows, X.n_rows); Q.set_size(X.n_rows, X.n_rows);
eT* Q_mem = Q.memptr(); eT* Q_mem = Q.memptr();
const eT* R_mem = R.mem; const eT* R_mem = R.mem;
skipping to change at line 1054 skipping to change at line 1144
} }
if( (is_float<eT>::value == true) || (is_double<eT>::value == true) ) if( (is_float<eT>::value == true) || (is_double<eT>::value == true) )
{ {
// query for the optimum value of work_len // query for the optimum value of work_len
work_len_tmp = -1; work_len_tmp = -1;
lapack::orgqr_(&m, &m, &k, Q.memptr(), &m, tau.memptr(), work.memptr( ), &work_len_tmp, &info); lapack::orgqr_(&m, &m, &k, Q.memptr(), &m, tau.memptr(), work.memptr( ), &work_len_tmp, &info);
if(info == 0) if(info == 0)
{ {
work_len = static_cast<int>(auxlib::tmp_real(work[0])); work_len = static_cast<int>(access::tmp_real(work[0]));
work.set_size(work_len); work.set_size(work_len);
} }
lapack::orgqr_(&m, &m, &k, Q.memptr(), &m, tau.memptr(), work.memptr( ), &work_len, &info); lapack::orgqr_(&m, &m, &k, Q.memptr(), &m, tau.memptr(), work.memptr( ), &work_len, &info);
} }
else else
if( (is_supported_complex_float<eT>::value == true) || (is_supported_co mplex_double<eT>::value == true) ) if( (is_supported_complex_float<eT>::value == true) || (is_supported_co mplex_double<eT>::value == true) )
{ {
// query for the optimum value of work_len // query for the optimum value of work_len
work_len_tmp = -1; work_len_tmp = -1;
lapack::ungqr_(&m, &m, &k, Q.memptr(), &m, tau.memptr(), work.memptr( ), &work_len_tmp, &info); lapack::ungqr_(&m, &m, &k, Q.memptr(), &m, tau.memptr(), work.memptr( ), &work_len_tmp, &info);
if(info == 0) if(info == 0)
{ {
work_len = static_cast<int>(auxlib::tmp_real(work[0])); work_len = static_cast<int>(access::tmp_real(work[0]));
work.set_size(work_len); work.set_size(work_len);
} }
lapack::ungqr_(&m, &m, &k, Q.memptr(), &m, tau.memptr(), work.memptr( ), &work_len, &info); lapack::ungqr_(&m, &m, &k, Q.memptr(), &m, tau.memptr(), work.memptr( ), &work_len, &info);
} }
return (info == 0); return (info == 0);
} }
#else #else
{ {
arma_stop("auxlib::qr(): need LAPACK library"); arma_stop("qr(): need LAPACK");
return false; return false;
} }
#endif #endif
} }
template<typename eT> template<typename eT>
inline inline
bool bool
auxlib::svd(Col<eT>& S, const Mat<eT>& X) auxlib::svd(Col<eT>& S, const Mat<eT>& X)
{ {
skipping to change at line 1156 skipping to change at line 1246
return (info == 0); return (info == 0);
} }
else else
{ {
return false; return false;
} }
} }
#else #else
{ {
arma_stop("auxlib::svd(): need LAPACK library"); arma_stop("svd(): need LAPACK");
return false; return false;
} }
#endif #endif
} }
template<typename T> template<typename T>
inline inline
bool bool
auxlib::svd(Col<T>& S, const Mat< std::complex<T> >& X) auxlib::svd(Col<T>& S, const Mat< std::complex<T> >& X)
{ {
skipping to change at line 1241 skipping to change at line 1331
return (info == 0); return (info == 0);
} }
else else
{ {
return false; return false;
} }
} }
#else #else
{ {
arma_stop("auxlib::svd(): need LAPACK library"); arma_stop("svd(): need LAPACK");
return false; return false;
} }
#endif #endif
} }
template<typename eT> template<typename eT>
inline inline
bool bool
auxlib::svd(Mat<eT>& U, Col<eT>& S, Mat<eT>& V, const Mat<eT>& X) auxlib::svd(Mat<eT>& U, Col<eT>& S, Mat<eT>& V, const Mat<eT>& X)
{ {
skipping to change at line 1318 skipping to change at line 1408
return (info == 0); return (info == 0);
} }
else else
{ {
return false; return false;
} }
} }
#else #else
{ {
arma_stop("auxlib::svd(): need LAPACK library"); arma_stop("svd(): need LAPACK");
return false; return false;
} }
#endif #endif
} }
template<typename T> template<typename T>
inline inline
bool bool
auxlib::svd(Mat< std::complex<T> >& U, Col<T> &S, Mat< std::complex<T> >& V , const Mat< std::complex<T> >& X) auxlib::svd(Mat< std::complex<T> >& U, Col<T> &S, Mat< std::complex<T> >& V , const Mat< std::complex<T> >& X)
{ {
skipping to change at line 1405 skipping to change at line 1495
return (info == 0); return (info == 0);
} }
else else
{ {
return false; return false;
} }
} }
#else #else
{ {
arma_stop("auxlib::svd(): need LAPACK library"); arma_stop("svd(): need LAPACK");
return false; return false;
} }
#endif #endif
} }
//! Solve a system of linear equations //! Solve a system of linear equations
//! Assumes that A.n_rows = A.n_cols //! Assumes that A.n_rows = A.n_cols
//! and B.n_rows = A.n_rows //! and B.n_rows = A.n_rows
template<typename eT> template<typename eT>
skipping to change at line 1441 skipping to change at line 1531
out = B; out = B;
Mat<eT> A_copy = A; Mat<eT> A_copy = A;
lapack::gesv_<eT>(&n, &nrhs, A_copy.memptr(), &lda, ipiv.memptr(), out. memptr(), &ldb, &info); lapack::gesv_<eT>(&n, &nrhs, A_copy.memptr(), &lda, ipiv.memptr(), out. memptr(), &ldb, &info);
return (info == 0); return (info == 0);
} }
#else #else
{ {
arma_stop("auxlib::solve(): need LAPACK library"); arma_stop("solve(): need LAPACK");
return false; return false;
} }
#endif #endif
} }
//! Solve an over-determined system. //! Solve an over-determined system.
//! Assumes that A.n_rows > A.n_cols //! Assumes that A.n_rows > A.n_cols
//! and B.n_rows = A.n_rows //! and B.n_rows = A.n_rows
template<typename eT> template<typename eT>
inline inline
skipping to change at line 1502 skipping to change at line 1592
for(u32 col=0; col<B.n_cols; ++col) for(u32 col=0; col<B.n_cols; ++col)
{ {
syslib::copy_elem( out.colptr(col), tmp.colptr(col), A.n_cols ); syslib::copy_elem( out.colptr(col), tmp.colptr(col), A.n_cols );
} }
return (info == 0); return (info == 0);
} }
#else #else
{ {
arma_stop("auxlib::solve_od(): need LAPACK library"); arma_stop("auxlib::solve_od(): need LAPACK");
return false; return false;
} }
#endif #endif
} }
//! Solve an under-determined system. //! Solve an under-determined system.
//! Assumes that A.n_rows < A.n_cols //! Assumes that A.n_rows < A.n_cols
//! and B.n_rows = A.n_rows //! and B.n_rows = A.n_rows
template<typename eT> template<typename eT>
inline inline
skipping to change at line 1577 skipping to change at line 1667
for(u32 col=0; col<B.n_cols; ++col) for(u32 col=0; col<B.n_cols; ++col)
{ {
syslib::copy_elem( out.colptr(col), tmp.colptr(col), A.n_cols ); syslib::copy_elem( out.colptr(col), tmp.colptr(col), A.n_cols );
} }
return (info == 0); return (info == 0);
} }
#else #else
{ {
arma_stop("auxlib::solve_ud(): need LAPACK library"); arma_stop("auxlib::solve_ud(): need LAPACK");
return false; return false;
} }
#endif #endif
} }
//! @} //! @}
 End of changes. 44 change blocks. 
41 lines changed or deleted 148 lines changed or added


 auxlib_proto.hpp   auxlib_proto.hpp 
// Copyright (C) 2009 NICTA and the authors listed below // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Edmund Highcock (edmund dot highcock at merton dot ox dot ac dot uk) // - Edmund Highcock (edmund dot highcock at merton dot ox dot ac dot uk)
// //
// 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
skipping to change at line 24 skipping to change at line 25
// (see http://www.opensource.org/licenses for more info) // (see http://www.opensource.org/licenses for more info)
//! \addtogroup auxlib //! \addtogroup auxlib
//! @{ //! @{
//! wrapper for accessing external functions defined in ATLAS, LAPACK or BL AS libraries //! wrapper for accessing external functions defined in ATLAS, LAPACK or BL AS libraries
class auxlib class auxlib
{ {
public: public:
template<typename eT>
inline static const eT& tmp_real(const eT& X) { return X; }
template<typename T>
inline static const T& tmp_real(const std::complex<T>& X) { return X.rea
l(); }
// //
// inv // inv
template<typename eT> template<typename eT>
inline static void inv_noalias(Mat<eT>& out, const Mat<eT>& X); inline static bool inv_noalias(Mat<eT>& out, const Mat<eT>& X);
template<typename eT> template<typename eT>
inline static void inv_inplace(Mat<eT>& X); inline static bool inv_inplace(Mat<eT>& X);
// //
// det // det
template<typename eT> template<typename eT>
inline static eT det(const Mat<eT>& X); inline static eT det(const Mat<eT>& X);
template<typename eT>
inline static void log_det(eT& out_val, typename get_pod_type<eT>::result
& out_sign, const Mat<eT>& X);
// //
// lu // lu
template<typename eT> template<typename eT>
inline static void lu(Mat<eT>& L, Mat<eT>& U, podarray<int>& ipiv, const Mat<eT>& X_orig); inline static void lu(Mat<eT>& L, Mat<eT>& U, podarray<int>& ipiv, const Mat<eT>& X_orig);
template<typename eT> template<typename eT>
inline static void lu(Mat<eT>& L, Mat<eT>& U, Mat<eT>& P, const Mat<eT>& X); inline static void lu(Mat<eT>& L, Mat<eT>& U, Mat<eT>& P, const Mat<eT>& X);
template<typename eT> template<typename eT>
 End of changes. 5 change blocks. 
10 lines changed or deleted 8 lines changed or added


 blas_proto.hpp   blas_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 cmath_wrap.hpp   cmath_wrap.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 config.hpp   config.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 37 skipping to change at line 38
#define ARMA_USE_BOOST_DATE #define ARMA_USE_BOOST_DATE
/* #undef ARMA_EXTRA_DEBUG */ /* #undef ARMA_EXTRA_DEBUG */
/* #undef ARMA_NO_DEBUG */ /* #undef ARMA_NO_DEBUG */
#if defined(ARMA_USE_ATLAS) #if defined(ARMA_USE_ATLAS)
#if !defined(ARMA_ATLAS_INCLUDE_DIR) #if !defined(ARMA_ATLAS_INCLUDE_DIR)
#define ARMA_ATLAS_INCLUDE_DIR /usr/include #define ARMA_ATLAS_INCLUDE_DIR /usr/include
#endif #endif
#endif #endif
#if defined(__CUDACC__)
#undef ARMA_HAVE_STD_ISFINITE
#undef ARMA_HAVE_STD_ISINF
#undef ARMA_HAVE_STD_ISNAN
#endif
#if defined(__INTEL_COMPILER)
#if (__INTEL_COMPILER <= 1110)
#undef ARMA_HAVE_STD_ISFINITE
#endif
#endif
 End of changes. 2 change blocks. 
1 lines changed or deleted 2 lines changed or added


 constants.hpp   constants.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 154 skipping to change at line 155
//! Wien wavelength displacement law constant //! Wien wavelength displacement law constant
static const eT b() { return eT(2.8977685e-3); } static const eT b() { return eT(2.8977685e-3); }
}; };
typedef Math<float> fmath; typedef Math<float> fmath;
typedef Math<double> math; typedef Math<double> math;
typedef Phy<float> fphy; typedef Phy<float> fphy;
typedef Phy<double> phy; typedef Phy<double> phy;
struct arma_version
{
static const unsigned int major = 0;
static const unsigned int minor = 8;
static const unsigned int patch = 2;
};
struct arma_config
{
#if defined(ARMA_USE_ATLAS)
static const bool atlas = true;
#else
static const bool atlas = false;
#endif
#if defined(ARMA_USE_LAPACK)
static const bool lapack = true;
#else
static const bool lapack = false;
#endif
#if defined(ARMA_USE_BLAS)
static const bool blas = true;
#else
static const bool blas = false;
#endif
#if defined(ARMA_USE_BOOST)
static const bool boost = true;
#else
static const bool boost = false;
#endif
#if defined(ARMA_USE_BOOST_DATE)
static const bool boost_date = true;
#else
static const bool boost_date = false;
#endif
#if !defined(ARMA_NO_DEBUG) && !defined(NDEBUG)
static const bool debug = true;
#else
static const bool debug = false;
#endif
#if defined(ARMA_EXTRA_DEBUG)
static const bool extra_debug = true;
#else
static const bool extra_debug = false;
#endif
#if defined(ARMA_GOOD_COMPILER)
static const bool good_comp = true;
#else
static const bool good_comp = false;
#endif
};
//! @} //! @}
 End of changes. 2 change blocks. 
59 lines changed or deleted 2 lines changed or added


 debug.hpp   debug.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 debug //! \addtogroup debug
//! @{ //! @{
// //
// arma_stop
//! print a message to std::cout and/or throw a run-time error exception
template<typename T1>
inline
void
arma_stop(const T1& x)
{
std::cerr.flush();
std::cout.flush();
std::cout << '\n';
std::cout << "run-time error: " << x << '\n';
std::cout << '\n';
std::cout.flush();
throw std::runtime_error("");
}
//
// arma_print // arma_print
inline inline
void void
arma_print() arma_print()
{ {
std::cout << std::endl; std::cout << std::endl;
} }
template<typename T1> template<typename T1>
skipping to change at line 182 skipping to change at line 203
arma_warn(const bool state, const arma_boost::basic_format<T1,T2>& x) arma_warn(const bool state, const arma_boost::basic_format<T1,T2>& x)
{ {
if(state==true) if(state==true)
arma_print(x); arma_print(x);
} }
#endif #endif
// //
// arma_check // arma_check
//! if state is true, throw a run-time error exception //! if state is true, abort program
template<typename T1> template<typename T1>
inline inline
void void
arma_hot arma_hot
arma_check(const bool state, const T1& x) arma_check(const bool state, const T1& x)
{ {
if(state==true) if(state==true)
{ {
throw std::runtime_error(x); arma_stop(x);
} }
} }
template<typename T1, typename T2> template<typename T1, typename T2>
inline inline
void void
arma_hot 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)
{ {
throw std::runtime_error( std::string(x) + std::string(y) ); arma_stop( std::string(x) + std::string(y) );
} }
} }
#ifdef ARMA_USE_BOOST #ifdef ARMA_USE_BOOST
template<typename T1> template<typename T1>
inline inline
void void
arma_hot arma_hot
arma_check(const bool state, const arma_boost::basic_format<T1>& x) arma_check(const bool state, const arma_boost::basic_format<T1>& x)
{ {
if(state==true) if(state==true)
{ {
throw std::runtime_error(str(x)); arma_stop(str(x));
} }
} }
#else #else
template<typename T1, typename T2> template<typename T1, typename T2>
inline inline
void void
arma_hot arma_hot
arma_check(const bool state, const arma_boost::basic_format<T1,T2>& x) arma_check(const bool state, const arma_boost::basic_format<T1,T2>& x)
{ {
if(state==true) if(state==true)
{ {
throw std::runtime_error(str(x)); arma_stop(str(x));
} }
} }
#endif #endif
// //
// functions for checking whether two matrices have the same dimensions // functions for checking whether two matrices have the same dimensions
inline inline
std::string std::string
arma_incompat_size_string(const u32 A_n_rows, const u32 A_n_cols, const u32 B_n_rows, const u32 B_n_cols, const char* x) arma_incompat_size_string(const u32 A_n_rows, const u32 A_n_cols, const u32 B_n_rows, const u32 B_n_cols, const char* x)
skipping to change at line 254 skipping to change at line 275
return tmp.str(); return tmp.str();
} }
inline inline
void void
arma_hot arma_hot
arma_assert_same_size(const u32 A_n_rows, const u32 A_n_cols, const u32 B_n _rows, const u32 B_n_cols, const char* x) arma_assert_same_size(const u32 A_n_rows, const u32 A_n_cols, const u32 B_n _rows, const u32 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) )
{ {
throw std::runtime_error arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
( cols, x) );
arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x)
);
} }
} }
//! if given matrices have different sizes, throw a run-time error exceptio n //! stop if given matrices have different sizes
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
inline inline
void void
arma_hot 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)
{ {
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) )
{ {
throw std::runtime_error arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_
( cols, x) );
arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) }
); }
//! stop if given proxies have different sizes
template<typename eT1, typename eT2>
inline
void
arma_hot
arma_assert_same_size(const Proxy<eT1>& A, const Proxy<eT2>& B, const char*
x)
{
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) );
}
}
template<typename eT1, typename eT2>
inline
void
arma_hot
arma_assert_same_size(const subview<eT1>& A, const subview<eT2>& B, const c
har* x)
{
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) );
} }
} }
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
inline inline
void void
arma_hot 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)
{ {
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) )
{ {
throw std::runtime_error arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_
( cols, x) );
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>
inline inline
void void
arma_hot 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)
{ {
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) )
{ {
throw std::runtime_error arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_
( cols, x) );
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>
inline inline
void void
arma_hot arma_hot
arma_assert_same_size(const subview<eT1>& A, const subview<eT2>& B, const c har* x) arma_assert_same_size(const Mat<eT1>& A, const Proxy<eT2>& B, 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) )
{ {
throw std::runtime_error arma_stop ( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n
( _cols, x) );
arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) }
); }
template<typename eT1, typename eT2>
inline
void
arma_hot
arma_assert_same_size(const Proxy<eT1>& A, const Mat<eT2>& B, const char* x
)
{
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) );
}
}
template<typename eT1, typename eT2>
inline
void
arma_hot
arma_assert_same_size(const Proxy<eT1>& A, const subview<eT2>& B, const cha
r* x)
{
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) );
}
}
template<typename eT1, typename eT2>
inline
void
arma_hot
arma_assert_same_size(const subview<eT1>& A, const Proxy<eT2>& B, const cha
r* x)
{
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) );
} }
} }
// //
// functions for checking whether two cubes have the same dimensions // functions for checking whether two cubes have the same dimensions
inline inline
std::string std::string
arma_incompat_size_string(const u32 A_n_rows, const u32 A_n_cols, const u32 A_n_slices, const u32 B_n_rows, const u32 B_n_cols, const u32 B_n_slices, const char* x) arma_incompat_size_string(const u32 A_n_rows, const u32 A_n_cols, const u32 A_n_slices, const u32 B_n_rows, const u32 B_n_cols, const u32 B_n_slices, const char* x)
{ {
skipping to change at line 343 skipping to change at line 410
return tmp.str(); return tmp.str();
} }
inline inline
void void
arma_hot arma_hot
arma_assert_same_size(const u32 A_n_rows, const u32 A_n_cols, const u32 A_n _slices, const u32 B_n_rows, const u32 B_n_cols, const u32 B_n_slices, cons t char* x) arma_assert_same_size(const u32 A_n_rows, const u32 A_n_cols, const u32 A_n _slices, const u32 B_n_rows, const u32 B_n_cols, const u32 B_n_slices, cons t 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) )
{ {
throw std::runtime_error 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_incompat_size_string(A_n_rows, A_n_cols, A_n_slices, B_n_rows, B
_n_cols, B_n_slices, x)
);
} }
} }
//! if given cubes have different sizes, throw a run-time error exception //! stop if given cubes have different sizes
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
inline inline
void void
arma_hot 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) )
{ {
throw std::runtime_error 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_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>
inline inline
void void
arma_hot 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) )
{ {
throw std::runtime_error 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_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>
inline inline
void void
arma_hot 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) )
{ {
throw std::runtime_error 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_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>
inline inline
void void
arma_hot 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))
{ {
throw std::runtime_error 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_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
template<typename eT1, typename eT2>
inline
void
arma_hot
arma_assert_same_size(const ProxyCube<eT1>& A, const ProxyCube<eT2>& B, con
st char* x)
{
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) );
} }
} }
// //
// 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>
inline inline
void void
arma_hot 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) )
{ {
throw std::runtime_error arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.
( n_rows, B.n_cols, 1, x) );
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>
inline inline
void void
arma_hot 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) )
{ {
throw std::runtime_error arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B
( .n_cols, B.n_slices, x) );
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>
inline inline
void void
arma_hot 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) )
{ {
throw std::runtime_error arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.
( n_rows, B.n_cols, 1, x) );
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>
inline inline
void void
arma_hot 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) )
{ {
throw std::runtime_error arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B
( .n_cols, B.n_slices, x) );
arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B.n_cols,
B.n_slices, x)
);
} }
} }
// //
// 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
inline inline
void void
arma_hot arma_hot
arma_assert_mul_size(const u32 A_n_rows, const u32 A_n_cols, const u32 B_n_ rows, const u32 B_n_cols, const char* x) arma_assert_mul_size(const u32 A_n_rows, const u32 A_n_cols, const u32 B_n_ rows, const u32 B_n_cols, const char* x)
{ {
if(A_n_cols != B_n_rows) if(A_n_cols != B_n_rows)
{ {
throw std::runtime_error arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_
( cols, x) );
arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x)
);
} }
} }
//! if given matrices are incompatible for multiplication, throw a run-time error exception //! stop if given matrices are incompatible for multiplication
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
inline inline
void void
arma_hot 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)
{ {
if(A.n_cols != B.n_rows) if(A.n_cols != B.n_rows)
{ {
throw std::runtime_error arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_
( cols, x) );
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
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
inline inline
void void
arma_hot 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 Mat<eT2>& B, const bool do_tr ans_A, const bool do_trans_B, const char* x)
{ {
if(A.n_cols != B.n_rows) const u32 final_A_n_cols = (do_trans_A == false) ? A.n_cols : A.n_rows;
const u32 final_B_n_rows = (do_trans_B == false) ? B.n_rows : B.n_cols;
if(final_A_n_cols != final_B_n_rows)
{ {
throw std::runtime_error const u32 final_A_n_rows = (do_trans_A == false) ? A.n_rows : A.n_cols;
( const u32 final_B_n_cols = (do_trans_B == false) ? B.n_cols : B.n_rows;
arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, 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>
inline inline
void void
arma_hot arma_hot
arma_assert_mul_size(const subview<eT1>& A, const Mat<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)
{ {
throw std::runtime_error arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_
( cols, x) );
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>
inline inline
void void
arma_hot 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 Mat<eT2>& B, const char* x)
{ {
if(A.n_cols != B.n_rows) if(A.n_cols != B.n_rows)
{ {
throw std::runtime_error arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_
( cols, x) );
arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x)
);
} }
} }
// template<typename eT1, typename eT2>
// arma_stop
//! throw a run-time error exception
template<typename T1>
inline inline
void void
arma_stop(const T1& x) arma_hot
arma_assert_mul_size(const subview<eT1>& A, const subview<eT2>& B, const ch
ar* x)
{ {
arma_check(true, x); 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) );
}
} }
// //
// macros // macros
#define ARMA_STRING1(x) #x #define ARMA_STRING1(x) #x
#define ARMA_STRING2(x) ARMA_STRING1(x) #define ARMA_STRING2(x) ARMA_STRING1(x)
#define ARMA_FILELINE __FILE__ ": " ARMA_STRING2(__LINE__) #define ARMA_FILELINE __FILE__ ": " ARMA_STRING2(__LINE__)
#if defined (__GNUG__) #if defined (__GNUG__)
 End of changes. 38 change blocks. 
106 lines changed or deleted 176 lines changed or added


 diagview_meat.hpp   diagview_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 32 skipping to change at line 33
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
template<typename eT> template<typename eT>
arma_inline arma_inline
diagview<eT>::diagview(const Mat<eT>& in_m, const u32 in_row_offset, const u32 in_col_offset, const u32 in_len) diagview<eT>::diagview(const Mat<eT>& in_m, const u32 in_row_offset, const u32 in_col_offset, const u32 in_len)
: m(in_m) : m(in_m)
, m_ptr(0) , m_ptr(0)
, row_offset(in_row_offset) , row_offset(in_row_offset)
, col_offset(in_col_offset) , col_offset(in_col_offset)
, n_rows(in_len)
, n_cols( (in_len > 0) ? 1 : 0 )
, n_elem(in_len) , n_elem(in_len)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
template<typename eT> template<typename eT>
arma_inline arma_inline
diagview<eT>::diagview(Mat<eT>& in_m, const u32 in_row_offset, const u32 in _col_offset, const u32 in_len) diagview<eT>::diagview(Mat<eT>& in_m, const u32 in_row_offset, const u32 in _col_offset, const u32 in_len)
: m(in_m) : m(in_m)
, m_ptr(&in_m) , m_ptr(&in_m)
, row_offset(in_row_offset) , row_offset(in_row_offset)
, col_offset(in_col_offset) , col_offset(in_col_offset)
, n_rows(in_len)
, n_cols( (in_len > 0) ? 1 : 0 )
, n_elem(in_len) , n_elem(in_len)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
//! set a diagonal of our matrix using data from a foreign object //! set a diagonal of our matrix using data from a foreign object
template<typename eT> template<typename eT>
template<typename T1> template<typename T1>
inline inline
void void
skipping to change at line 112 skipping to change at line 117
inline inline
void void
diagview<eT>::extract(Mat<eT>& actual_out, const diagview<eT>& in) diagview<eT>::extract(Mat<eT>& actual_out, const diagview<eT>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const Mat<eT>& in_m = in.m; const Mat<eT>& in_m = in.m;
const bool alias = (&actual_out == &in_m); const bool alias = (&actual_out == &in_m);
Mat<eT>* tmp = (alias) ? new Mat<eT> : 0; Mat<eT>* tmp = (alias) ? new Mat<eT> : 0;
Mat<eT>& out = (alias) ? (*tmp) : actual_out; Mat<eT>& out = (alias) ? (*tmp) : actual_out;
const u32 in_n_elem = in.n_elem; const u32 in_n_elem = in.n_elem;
const u32 in_row_offset = in.row_offset; const u32 in_row_offset = in.row_offset;
const u32 in_col_offset = in.col_offset; const u32 in_col_offset = in.col_offset;
out.set_size(in_n_elem,1); out.set_size(in_n_elem,1);
eT* out_mem = out.memptr(); eT* out_mem = out.memptr();
for(u32 i=0; i<in_n_elem; ++i) for(u32 i=0; i<in_n_elem; ++i)
{ {
skipping to change at line 134 skipping to change at line 139
} }
if(alias) if(alias)
{ {
actual_out = out; actual_out = out;
delete tmp; delete tmp;
} }
} }
//! X += Y.diagview(...)
template<typename eT>
inline
void
diagview<eT>::plus_inplace(Mat<eT>& out, const diagview<eT>& in)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, 1, "matrix
addition");
const Mat<eT>& in_m = in.m;
const u32 in_n_elem = in.n_elem;
const u32 in_row_offset = in.row_offset;
const u32 in_col_offset = in.col_offset;
eT* out_mem = out.memptr();
for(u32 i=0; i<in_n_elem; ++i)
{
out_mem[i] += in_m.at(i+in_row_offset, i+in_col_offset);
}
}
//! X -= Y.diagview(...)
template<typename eT>
inline
void
diagview<eT>::minus_inplace(Mat<eT>& out, const diagview<eT>& in)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, 1, "matrix
subtraction");
const Mat<eT>& in_m = in.m;
const u32 in_n_elem = in.n_elem;
const u32 in_row_offset = in.row_offset;
const u32 in_col_offset = in.col_offset;
eT* out_mem = out.memptr();
for(u32 i=0; i<in_n_elem; ++i)
{
out_mem[i] -= in_m.at(i+in_row_offset, i+in_col_offset);
}
}
//! X %= Y.submat(...)
template<typename eT>
inline
void
diagview<eT>::schur_inplace(Mat<eT>& out, const diagview<eT>& in)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, 1, "elemen
t-wise matrix multiplication");
const Mat<eT>& in_m = in.m;
const u32 in_n_elem = in.n_elem;
const u32 in_row_offset = in.row_offset;
const u32 in_col_offset = in.col_offset;
eT* out_mem = out.memptr();
for(u32 i=0; i<in_n_elem; ++i)
{
out_mem[i] *= in_m.at(i+in_row_offset, i+in_col_offset);
}
}
//! X /= Y.diagview(...)
template<typename eT>
inline
void
diagview<eT>::div_inplace(Mat<eT>& out, const diagview<eT>& in)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, 1, "elemen
t-wise matrix division");
const Mat<eT>& in_m = in.m;
const u32 in_n_elem = in.n_elem;
const u32 in_row_offset = in.row_offset;
const u32 in_col_offset = in.col_offset;
eT* out_mem = out.memptr();
for(u32 i=0; i<in_n_elem; ++i)
{
out_mem[i] /= in_m.at(i+in_row_offset, i+in_col_offset);
}
}
template<typename eT> template<typename eT>
arma_inline arma_inline
eT& eT&
diagview<eT>::operator[](const u32 i) diagview<eT>::operator[](const u32 i)
{ {
return (*m_ptr).at(i+row_offset, i+col_offset); return (*m_ptr).at(i+row_offset, i+col_offset);
} }
template<typename eT> template<typename eT>
arma_inline arma_inline
eT eT
diagview<eT>::operator[](const u32 i) const diagview<eT>::operator[](const u32 i) const
{ {
return m.at(i+row_offset, i+col_offset); return m.at(i+row_offset, i+col_offset);
} }
template<typename eT> template<typename eT>
arma_inline arma_inline
eT& eT&
diagview<eT>::at(const u32 row, const u32 col)
{
return (*m_ptr).at(row+row_offset, row+col_offset);
}
template<typename eT>
arma_inline
eT
diagview<eT>::at(const u32 row, const u32 col) const
{
return m.at(row+row_offset, row+col_offset);
}
template<typename eT>
arma_inline
eT&
diagview<eT>::operator()(const u32 i) diagview<eT>::operator()(const u32 i)
{ {
arma_check( (m_ptr == 0), "diagview::operator(): matrix is read only"); arma_check( (m_ptr == 0), "diagview::operator(): matrix is read only");
arma_debug_check( (i >= n_elem), "diagview::operator(): index out of boun ds" ); arma_debug_check( (i >= n_elem), "diagview::operator(): out of bounds" );
return (*m_ptr).at(i+row_offset, i+col_offset); return (*m_ptr).at(i+row_offset, i+col_offset);
} }
template<typename eT> template<typename eT>
arma_inline arma_inline
eT eT
diagview<eT>::operator()(const u32 i) const diagview<eT>::operator()(const u32 i) const
{ {
arma_debug_check( (i >= n_elem), "diagview::operator(): index out of boun ds" ); arma_debug_check( (i >= n_elem), "diagview::operator(): out of bounds" );
return m.at(i+row_offset, i+col_offset); return m.at(i+row_offset, i+col_offset);
} }
template<typename eT> template<typename eT>
arma_inline
eT&
diagview<eT>::operator()(const u32 row, const u32 col)
{
arma_check( (m_ptr == 0), "diagview::operator(): matrix is read only");
arma_debug_check( ((row >= n_elem) || (col > 0)), "diagview::operator():
out of bounds" );
return (*m_ptr).at(row+row_offset, row+col_offset);
}
template<typename eT>
arma_inline
eT
diagview<eT>::operator()(const u32 row, const u32 col) const
{
arma_debug_check( ((row >= n_elem) || (col > 0)), "diagview::operator():
out of bounds" );
return m.at(row+row_offset, row+col_offset);
}
template<typename eT>
inline inline
void void
diagview<eT>::fill(const eT val) diagview<eT>::fill(const eT val)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_check( (m_ptr == 0), "diagview::operator(): matrix is read only"); arma_check( (m_ptr == 0), "diagview::fill(): matrix is read only");
Mat<eT>& x = (*m_ptr); Mat<eT>& x = (*m_ptr);
for(u32 i=0; i<n_elem; ++i) for(u32 i=0; i<n_elem; ++i)
{ {
x.at(i+row_offset, i+col_offset) = val; x.at(i+row_offset, i+col_offset) = val;
} }
} }
template<typename eT> template<typename eT>
inline inline
void void
diagview<eT>::zeros() diagview<eT>::zeros()
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_check( (m_ptr == 0), "diagview::operator(): matrix is read only"); arma_check( (m_ptr == 0), "diagview::zeros(): matrix is read only");
Mat<eT>& x = (*m_ptr); Mat<eT>& x = (*m_ptr);
for(u32 i=0; i<n_elem; ++i) for(u32 i=0; i<n_elem; ++i)
{ {
x.at(i+row_offset, i+col_offset) = eT(0); x.at(i+row_offset, i+col_offset) = eT(0);
} }
} }
template<typename eT>
inline
void
diagview<eT>::ones()
{
arma_extra_debug_sigprint();
arma_check( (m_ptr == 0), "diagview::ones(): matrix is read only");
Mat<eT>& x = (*m_ptr);
for(u32 i=0; i<n_elem; ++i)
{
x.at(i+row_offset, i+col_offset) = eT(1);
}
}
//! @} //! @}
 End of changes. 12 change blocks. 
6 lines changed or deleted 166 lines changed or added


 diagview_proto.hpp   diagview_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 27 skipping to change at line 28
//! Class for storing data required to extract and set the diagonals of a m atrix //! Class for storing data required to extract and set the diagonals of a m atrix
template<typename eT> template<typename eT>
class diagview : public Base<eT, diagview<eT> > class diagview : public Base<eT, diagview<eT> >
{ {
public: const Mat<eT>& m; public: const Mat<eT>& m;
protected: Mat<eT>* m_ptr; protected: Mat<eT>* m_ptr;
public: public:
typedef eT elem_type; typedef eT elem_type;
typedef typename get_pod_type<elem_type>::pod_type pod_type; typedef typename get_pod_type<eT>::result pod_type;
const u32 row_offset; const u32 row_offset;
const u32 col_offset; const u32 col_offset;
const u32 n_rows; // equal to n_elem
const u32 n_cols; // equal to one if n_elem > 0, otherwise equal to zero
const u32 n_elem; const u32 n_elem;
protected: protected:
arma_inline diagview(const Mat<eT>& in_m, const u32 in_row_offset, const u32 in_col_offset, const u32 len); arma_inline diagview(const Mat<eT>& in_m, const u32 in_row_offset, const u32 in_col_offset, const u32 len);
arma_inline diagview( Mat<eT>& in_m, const u32 in_row_offset, const u32 in_col_offset, const u32 len); arma_inline diagview( Mat<eT>& in_m, const u32 in_row_offset, const u32 in_col_offset, const u32 len);
public: public:
inline ~diagview(); inline ~diagview();
skipping to change at line 54 skipping to change at line 58
inline void operator=(const Base<eT,T1>& x); inline void operator=(const Base<eT,T1>& x);
inline void operator=(const diagview& x); inline void operator=(const diagview& x);
arma_inline eT& operator[](const u32 i); arma_inline eT& operator[](const u32 i);
arma_inline eT operator[](const u32 i) const; arma_inline eT operator[](const u32 i) const;
arma_inline eT& operator()(const u32 i); arma_inline eT& operator()(const u32 i);
arma_inline eT operator()(const u32 i) const; arma_inline eT operator()(const u32 i) const;
// arma_inline double& at(const u32 in_n_row, in_n_col); arma_inline eT& at(const u32 in_n_row, const u32 in_n_col);
// arma_inline double at(const u32 in_n_row, in_n_col) const; arma_inline eT at(const u32 in_n_row, const u32 in_n_col) const;
//
// arma_inline double& operator()(const u32 in_n_row, in_n_col); arma_inline eT& operator()(const u32 in_n_row, const u32 in_n_col);
// arma_inline double operator()(const u32 in_n_row, in_n_col) const; arma_inline eT operator()(const u32 in_n_row, const u32 in_n_col) const;
inline void fill(const eT val); inline void fill(const eT val);
inline void zeros(); inline void zeros();
inline void ones();
inline static void extract(Mat<eT>& out, const diagview& in); inline static void extract(Mat<eT>& out, const diagview& in);
inline static void plus_inplace(Mat<eT>& out, const diagview& in);
inline static void minus_inplace(Mat<eT>& out, const diagview& in);
inline static void schur_inplace(Mat<eT>& out, const diagview& in);
inline static void div_inplace(Mat<eT>& out, const diagview& in);
private: private:
friend class Mat<eT>; friend class Mat<eT>;
diagview(); diagview();
//diagview(const diagview&); // making this private causes an error unde r gcc 4.1/4.2, but not 4.3 //diagview(const diagview&); // making this private causes an error unde r gcc 4.1/4.2, but not 4.3
}; };
//! @} //! @}
 End of changes. 6 change blocks. 
8 lines changed or deleted 18 lines changed or added


 diskio_meat.hpp   diskio_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Ian Cullinan (ian dot cullinan at nicta dot com dot au)
// //
// 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 439 skipping to change at line 441
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::fstream f(tmp_name.c_str(), std::fstream::out);
if(f.is_open() == false) if(f.is_open() == false)
{ {
arma_print("unable to write ", tmp_name); arma_print("unable to write ", tmp_name);
} }
else else
{ {
u32 cell_width; diskio::save_raw_ascii(x, tmp_name, f);
const bool writing_problem = (f.good() == false);
// TODO: need sane values for complex numbers f.flush();
f.close();
if( (is_float<eT>::value == true) || (is_double<eT>::value == true) ) arma_warn(writing_problem, "trouble writing ", tmp_name);
{
f.setf(ios::scientific);
f.precision(8);
cell_width = 16;
}
for(u32 row=0; row < x.n_rows; ++row) if(writing_problem == false)
{ {
for(u32 col=0; col < x.n_cols; ++col) diskio::safe_rename(tmp_name, final_name);
{ }
f.put(' '); }
}
if( (is_float<eT>::value == true) || (is_double<eT>::value == true) //! 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.
f.width(cell_width); template<typename eT>
} inline
void
diskio::save_raw_ascii(const Mat<eT>& x, const std::string& name, std::ostr
eam& f)
{
arma_extra_debug_sigprint();
f << x.at(row,col); u32 cell_width;
}
f.put('\n'); // TODO: need sane values for complex numbers
}
const bool writing_problem = (f.good() == false); if( (is_float<eT>::value == true) || (is_double<eT>::value == true) )
{
f.setf(ios::scientific);
f.precision(8);
cell_width = 16;
}
arma_warn(writing_problem, "trouble writing ", tmp_name ); for(u32 row=0; row < x.n_rows; ++row)
{
for(u32 col=0; col < x.n_cols; ++col)
{
f.put(' ');
f.flush(); if( (is_float<eT>::value == true) || (is_double<eT>::value == true) )
f.close(); {
f.width(cell_width);
}
if(writing_problem == false) f << x.at(row,col);
{
diskio::safe_rename(tmp_name, final_name);
} }
}
f.put('\n');
}
} }
//! Save a matrix in text format (human readable), //! Save a matrix in text format (human readable),
//! with a header that indicates the matrix type as well as its dimensions //! with a header that indicates the matrix type as well as its dimensions
template<typename eT> template<typename eT>
inline inline
void void
diskio::save_arma_ascii(const Mat<eT>& x, const std::string& final_name) diskio::save_arma_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);
std::ofstream f(tmp_name.c_str()); std::ofstream f(tmp_name.c_str());
diskio::save_arma_ascii(x, tmp_name, f); if(f.is_open() == false)
{
arma_debug_print("unable to write ", tmp_name);
}
else
{
diskio::save_arma_ascii(x, tmp_name, f);
const bool writing_problem = (f.good() == false); const bool writing_problem = (f.good() == false);
f.flush(); f.flush();
f.close(); f.close();
arma_warn( writing_problem, "trouble writing ", tmp_name ); arma_warn( writing_problem, "trouble writing ", tmp_name );
if(writing_problem == false) if(writing_problem == false)
{ {
diskio::safe_rename(tmp_name, final_name); diskio::safe_rename(tmp_name, final_name);
}
} }
} }
//! Save a matrix in text format (human readable), //! Save a matrix in text format (human readable),
//! with a header that indicates the matrix type as well as its dimensions //! with a header that indicates the matrix type as well as its dimensions
template<typename eT> template<typename eT>
inline inline
void void
diskio::save_arma_ascii(const Mat<eT>& x, const std::string& name, std::ofs tream& f) diskio::save_arma_ascii(const Mat<eT>& x, const std::string& name, std::ost ream& f)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
if(f.is_open() == false) const ios::fmtflags orig_flags = f.flags();
{
arma_debug_print("unable to write ", name);
}
else
{
const ios::fmtflags orig_flags = f.flags();
f << diskio::gen_txt_header(x) << '\n'; f << diskio::gen_txt_header(x) << '\n';
f << x.n_rows << ' ' << x.n_cols << '\n'; f << x.n_rows << ' ' << x.n_cols << '\n';
u32 cell_width; u32 cell_width;
// TODO: need sane values for complex numbers // TODO: need sane values for complex numbers
if( (is_float<eT>::value == true) || (is_double<eT>::value == true) ) if( (is_float<eT>::value == true) || (is_double<eT>::value == true) )
{ {
f.setf(ios::scientific); f.setf(ios::scientific);
f.precision(8); f.precision(8);
cell_width = 16; cell_width = 16;
} }
for(u32 row=0; row < x.n_rows; ++row) for(u32 row=0; row < x.n_rows; ++row)
{
for(u32 col=0; col < x.n_cols; ++col)
{ {
for(u32 col=0; col < x.n_cols; ++col) f.put(' ');
{
f.put(' ');
if( (is_float<eT>::value == true) || (is_double<eT>::value == true)
)
{
f.width(cell_width);
}
f << x.at(row,col); if( (is_float<eT>::value == true) || (is_double<eT>::value == true) )
{
f.width(cell_width);
} }
f.put('\n'); f << x.at(row,col);
} }
f.flags(orig_flags); f.put('\n');
} }
f.flags(orig_flags);
} }
//! Save a matrix in binary format, //! Save a matrix in binary format,
//! with a header that stores the matrix type as well as its dimensions //! with a header that stores the matrix type as well as its dimensions
template<typename eT> template<typename eT>
inline inline
void void
diskio::save_arma_binary(const Mat<eT>& x, const std::string& final_name) diskio::save_arma_binary(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);
std::ofstream f(tmp_name.c_str(), std::fstream::binary); std::ofstream f(tmp_name.c_str(), std::fstream::binary);
diskio::save_arma_binary(x, tmp_name, f); if(f.is_open() == false)
{
arma_print("unable to write ", tmp_name);
}
else
{
diskio::save_arma_binary(x, tmp_name, f);
const bool writing_problem = (f.good() == false); const bool writing_problem = (f.good() == false);
f.flush(); f.flush();
f.close(); f.close();
arma_warn( writing_problem, "trouble writing ", tmp_name ); arma_warn( writing_problem, "trouble writing ", tmp_name );
if(writing_problem == false) if(writing_problem == false)
{ {
diskio::safe_rename(tmp_name, final_name); diskio::safe_rename(tmp_name, final_name);
}
} }
} }
//! Save a matrix in binary format, //! Save a matrix in binary format,
//! with a header that stores the matrix type as well as its dimensions //! with a header that stores the matrix type as well as its dimensions
template<typename eT> template<typename eT>
inline inline
void void
diskio::save_arma_binary(const Mat<eT>& x, const std::string& name, std::of stream& f) diskio::save_arma_binary(const Mat<eT>& x, const std::string& name, std::os tream& f)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
if(f.is_open() == false) f << diskio::gen_bin_header(x) << '\n';
{ f << x.n_rows << ' ' << x.n_cols << '\n';
arma_print("unable to write ", name);
}
else
{
f << diskio::gen_bin_header(x) << '\n';
f << x.n_rows << ' ' << x.n_cols << '\n';
f.write(reinterpret_cast<const char*>(x.mem), x.n_elem*sizeof(eT));
}
f.write(reinterpret_cast<const char*>(x.mem), x.n_elem*sizeof(eT));
} }
//
// TODO:
// add functionality to save the image in a normalised format,
// i.e. scaled so that every value falls in the [0,255] range.
//! Save a matrix as a PGM greyscale image //! Save a matrix as a PGM greyscale image
template<typename eT> template<typename eT>
inline inline
void void
diskio::save_pgm_binary(const Mat<eT>& x, const std::string& final_name) diskio::save_pgm_binary(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);
std::fstream f(tmp_name.c_str(), std::fstream::out | std::fstream::binary ); std::fstream f(tmp_name.c_str(), std::fstream::out | std::fstream::binary );
if(f.is_open() == false) if(f.is_open() == false)
{ {
arma_print("unable to write ", tmp_name); arma_print("unable to write ", tmp_name);
} }
else else
{ {
f << "P5" << '\n'; diskio::save_pgm_binary(x, tmp_name, f);
f << x.n_cols << ' ' << x.n_rows << '\n';
f << 255 << '\n';
const u32 n_elem = x.n_rows * x.n_cols;
podarray<u8> tmp(n_elem);
u32 i = 0;
for(u32 row=0; row < x.n_rows; ++row)
{
for(u32 col=0; col < x.n_cols; ++col)
{
tmp[i] = u8( x(row,col) ); // TODO: add round() ?
++i;
}
}
f.write(reinterpret_cast<const char*>(tmp.mem), n_elem);
const bool writing_problem = (f.good() == false); const bool writing_problem = (f.good() == false);
arma_warn(writing_problem, "trouble writing ", tmp_name ); arma_warn(writing_problem, "trouble writing ", tmp_name );
f.flush(); f.flush();
f.close(); f.close();
if(writing_problem == false) if(writing_problem == false)
{ {
diskio::safe_rename(tmp_name, final_name); diskio::safe_rename(tmp_name, final_name);
} }
} }
}
//
// TODO:
// add functionality to save the image in a normalised format,
// i.e. scaled so that every value falls in the [0,255] range.
//! Save a matrix as a PGM greyscale image
template<typename eT>
inline
void
diskio::save_pgm_binary(const Mat<eT>& x, const std::string& name, std::ost
ream& f)
{
arma_extra_debug_sigprint();
f << "P5" << '\n';
f << x.n_cols << ' ' << x.n_rows << '\n';
f << 255 << '\n';
const u32 n_elem = x.n_rows * x.n_cols;
podarray<u8> tmp(n_elem);
u32 i = 0;
for(u32 row=0; row < x.n_rows; ++row)
{
for(u32 col=0; col < x.n_cols; ++col)
{
tmp[i] = u8( x(row,col) ); // TODO: add round() ?
++i;
}
}
f.write(reinterpret_cast<const char*>(tmp.mem), n_elem);
}
//! Save a matrix as a PGM greyscale image
template<typename T>
inline
void
diskio::save_pgm_binary(const Mat< std::complex<T> >& x, const std::string&
final_name)
{
arma_extra_debug_sigprint();
const uchar_mat tmp = conv_to<uchar_mat>::from(x);
diskio::save_pgm_binary(tmp, final_name);
} }
//! Save a matrix as a PGM greyscale image //! Save a matrix as a PGM greyscale image
template<typename T> template<typename T>
inline inline
void void
diskio::save_pgm_binary(const Mat< std::complex<T> >& x, const std::string& name) diskio::save_pgm_binary(const Mat< std::complex<T> >& x, const std::string& name, std::ostream& f)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const uchar_mat tmp = conv_to<uchar_mat>::from(x); const uchar_mat tmp = conv_to<uchar_mat>::from(x);
diskio::save_pgm_binary(tmp,name); diskio::save_pgm_binary(tmp, name, f);
} }
//! Load a matrix as raw text (no header, human readable). //! Load a matrix as raw text (no header, human readable).
//! Can read matrices saved as text in Matlab and Octave. //! Can read matrices saved as text in Matlab and Octave.
//! NOTE: this is much slower than reading a file with a header. //! NOTE: this is much slower than reading a file with a header.
template<typename eT> template<typename eT>
inline inline
void void
diskio::load_raw_ascii(Mat<eT>& x, const std::string& name) diskio::load_raw_ascii(Mat<eT>& x, const std::string& name)
{ {
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);
bool load_okay = true;
if(f.is_open() == false) if(f.is_open() == false)
{ {
load_okay = false; x.reset();
arma_extra_debug_print("unable to read ", name); arma_extra_debug_print("unable to read ", name);
} }
else else
{ {
//std::fstream::pos_type start = f.tellg(); diskio::load_raw_ascii(x, name, f);
f.close();
}
}
// //! Load a matrix as raw text (no header, human readable).
// work out the size //! 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>
inline
void
diskio::load_raw_ascii(Mat<eT>& x, const std::string& name, std::istream& f
)
{
arma_extra_debug_sigprint();
u32 f_n_rows = 0; bool load_okay = true;
u32 f_n_cols = 0;
bool f_n_cols_found = false; //std::fstream::pos_type start = f.tellg();
std::string line_string; //
std::string token; // work out the size
while( (f.good() == true) && (load_okay == true) ) u32 f_n_rows = 0;
{ u32 f_n_cols = 0;
std::getline(f, line_string);
if(line_string.size() == 0)
break;
std::stringstream line_stream(line_string); bool f_n_cols_found = false;
u32 line_n_cols = 0; std::string line_string;
while (line_stream >> token) std::string token;
line_n_cols++;
if(f_n_cols_found == false) while( (f.good() == true) && (load_okay == true) )
{ {
f_n_cols = line_n_cols; std::getline(f, line_string);
f_n_cols_found = true; if(line_string.size() == 0)
} break;
else
std::stringstream line_stream(line_string);
u32 line_n_cols = 0;
while (line_stream >> token)
line_n_cols++;
if(f_n_cols_found == false)
{
f_n_cols = line_n_cols;
f_n_cols_found = true;
}
else
{
if(line_n_cols != f_n_cols)
{ {
if(line_n_cols != f_n_cols) arma_print("inconsistent number of columns in ", name );
{ load_okay = false;
arma_print("inconsistent number of columns in ", name );
load_okay = false;
}
} }
++f_n_rows;
} }
if(load_okay == true) ++f_n_rows;
{ }
f.clear();
f.seekg(0, ios::beg); if(load_okay == true)
//f.seekg(start); {
f.clear();
f.seekg(0, ios::beg);
//f.seekg(start);
x.set_size(f_n_rows, f_n_cols); x.set_size(f_n_rows, f_n_cols);
eT val; eT val;
for(u32 row=0; row < x.n_rows; ++row) for(u32 row=0; row < x.n_rows; ++row)
{
for(u32 col=0; col < x.n_cols; ++col)
{ {
for(u32 col=0; col < x.n_cols; ++col) // f >> token;
{ // x.at(row,col) = eT( strtod(token.c_str(), 0) );
// f >> token;
// x.at(row,col) = eT( strtod(token.c_str(), 0) );
f >> val; f >> val;
x.at(row,col) = val; x.at(row,col) = val;
}
} }
} }
}
if(f.good() == false) if(f.good() == false)
{ {
arma_print("trouble reading ", name ); arma_print("trouble reading ", name );
load_okay = false; load_okay = false;
}
f.close();
} }
if(load_okay == false) if(load_okay == false)
{ {
x.reset(); x.reset();
} }
} }
//! Load a matrix in text format (human readable), //! Load a matrix in text format (human readable),
//! with a header that indicates the matrix type as well as its dimensions //! with a header that indicates the matrix type as well as its dimensions
template<typename eT> template<typename eT>
inline inline
void void
diskio::load_arma_ascii(Mat<eT>& x, const std::string& name) diskio::load_arma_ascii(Mat<eT>& x, const std::string& name)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
std::ifstream f(name.c_str()); std::ifstream f(name.c_str());
diskio::load_arma_ascii(x, name, f); if(f.is_open() == false)
f.close(); {
x.reset();
arma_extra_debug_print("unable to read ", name);
}
else
{
diskio::load_arma_ascii(x, name, f);
f.close();
}
} }
//! Load a matrix in text format (human readable), //! Load a matrix in text format (human readable),
//! with a header that indicates the matrix type as well as its dimensions //! with a header that indicates the matrix type as well as its dimensions
template<typename eT> template<typename eT>
inline inline
void void
diskio::load_arma_ascii(Mat<eT>& x, const std::string& name, std::ifstream& f) diskio::load_arma_ascii(Mat<eT>& x, const std::string& name, std::istream& f)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
bool load_okay = true; bool load_okay = true;
if(f.is_open() == false) std::string f_header;
{ u32 f_n_rows;
load_okay = false; u32 f_n_cols;
arma_extra_debug_print("unable to read ", name);
}
else
{
std::string f_header;
u32 f_n_rows;
u32 f_n_cols;
f >> f_header;
f >> f_n_rows;
f >> f_n_cols;
if(f_header == diskio::gen_txt_header(x)) f >> f_header;
{ f >> f_n_rows;
x.set_size(f_n_rows, f_n_cols); f >> f_n_cols;
for(u32 row=0; row < x.n_rows; ++row) if(f_header == diskio::gen_txt_header(x))
{ {
for(u32 col=0; col < x.n_cols; ++col) x.set_size(f_n_rows, f_n_cols);
{
f >> x.at(row,col);
}
}
if(f.good() == false) for(u32 row=0; row < x.n_rows; ++row)
{
for(u32 col=0; col < x.n_cols; ++col)
{ {
arma_print("trouble reading ", name); f >> x.at(row,col);
load_okay = false;
} }
} }
else
if(f.good() == false)
{ {
arma_print("incorrect header in ", name ); arma_print("trouble reading ", name);
load_okay = false; load_okay = false;
} }
} }
else
if(load_okay == false) {
arma_print("incorrect header in ", name );
load_okay = false;
}
if(load_okay == false)
{ {
x.reset(); x.reset();
} }
} }
//! Load a matrix in binary format, //! Load a matrix in binary format,
//! with a header that indicates the matrix type as well as its dimensions //! with a header that indicates the matrix type as well as its dimensions
template<typename eT> template<typename eT>
inline inline
void void
diskio::load_arma_binary(Mat<eT>& x, const std::string& name) diskio::load_arma_binary(Mat<eT>& x, const std::string& name)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
std::ifstream f; std::ifstream f;
f.open(name.c_str(), std::fstream::binary); f.open(name.c_str(), std::fstream::binary);
diskio::load_arma_binary(x, name, f);
f.close(); if(f.is_open() == false)
{
x.reset();
arma_extra_debug_print("unable to read ", name);
}
else
{
diskio::load_arma_binary(x, name, f);
f.close();
}
} }
template<typename eT> template<typename eT>
inline inline
void void
diskio::load_arma_binary(Mat<eT>& x, const std::string& name, std::ifstream & f) diskio::load_arma_binary(Mat<eT>& x, const std::string& name, std::istream& f)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
bool load_okay = true; bool load_okay = true;
if(f.is_open() == false) std::string f_header;
{ u32 f_n_rows;
load_okay = false; u32 f_n_cols;
arma_extra_debug_print("unable to read ", name);
}
else
{
std::string f_header;
u32 f_n_rows;
u32 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_bin_header(x)) if(f_header == diskio::gen_bin_header(x))
{ {
//f.seekg(1, ios::cur); // NOTE: this may not be portable, as on a W //f.seekg(1, ios::cur); // NOTE: this may not be portable, as on a Win
indows machine a newline could be two characters dows machine a newline could be two characters
f.get(); f.get();
x.set_size(f_n_rows,f_n_cols); x.set_size(f_n_rows,f_n_cols);
f.read( reinterpret_cast<char *>(x.memptr()), x.n_elem*sizeof(eT)); f.read( reinterpret_cast<char *>(x.memptr()), x.n_elem*sizeof(eT));
if(f.good() == false) if(f.good() == false)
{
arma_print("trouble reading ", name);
load_okay = false;
}
}
else
{ {
arma_print("incorrect header in ", name); arma_print("trouble reading ", name);
load_okay = false; load_okay = false;
} }
}
else
{
arma_print("incorrect header in ", name);
load_okay = false;
} }
if(load_okay == false) if(load_okay == false)
{ {
x.reset(); x.reset();
} }
} }
inline inline
void void
diskio::pnm_skip_comments(std::istream& f) diskio::pnm_skip_comments(std::istream& f)
{ {
while( isspace(f.peek()) ) while( isspace(f.peek()) )
{ {
while( isspace(f.peek()) ) while( isspace(f.peek()) )
{
f.get(); f.get();
}
if(f.peek() == '#') if(f.peek() == '#')
{ {
while( (f.peek() != '\r') && (f.peek()!='\n') ) while( (f.peek() != '\r') && (f.peek()!='\n') )
{
f.get(); f.get();
}
} }
} }
} }
//! Load a PGM greyscale image as a matrix //! Load a PGM greyscale image as a matrix
template<typename eT> template<typename eT>
inline inline
void void
diskio::load_pgm_binary(Mat<eT>& x, const std::string& name) diskio::load_pgm_binary(Mat<eT>& x, const std::string& name)
{ {
skipping to change at line 1068 skipping to change at line 1115
//! Load a PGM greyscale image as a matrix //! Load a PGM greyscale image as a matrix
template<typename T> template<typename T>
inline inline
void void
diskio::load_pgm_binary(Mat< std::complex<T> >& x, const std::string& name) diskio::load_pgm_binary(Mat< std::complex<T> >& x, const std::string& name)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
uchar_mat tmp; uchar_mat tmp;
tmp.load(name); diskio::load_pgm_binary(tmp, name);
x = conv_to< Mat< std::complex<T> > >::from(tmp);
}
//! Load a PGM greyscale image as a matrix
template<typename T>
inline
void
diskio::load_pgm_binary(Mat< std::complex<T> >& x, const std::string& name,
std::istream& is)
{
arma_extra_debug_sigprint();
uchar_mat tmp;
diskio::load_pgm_binary(tmp, name, is);
x = conv_to< Mat< std::complex<T> > >::from(tmp); x = conv_to< Mat< std::complex<T> > >::from(tmp);
} }
//! Try to load a matrix by automatically determining its type //! Try to load a matrix by automatically determining its type
template<typename eT> template<typename eT>
inline inline
void void
diskio::load_auto_detect(Mat<eT>& x, const std::string& name) diskio::load_auto_detect(Mat<eT>& x, const std::string& name)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
static const std::string ARMA_MAT_TXT = "ARMA_MAT_TXT";
static const std::string ARMA_MAT_BIN = "ARMA_MAT_BIN";
static const std::string P5 = "P5";
std::fstream f; std::fstream f;
f.open(name.c_str(), std::fstream::in | std::fstream::binary); f.open(name.c_str(), std::fstream::in | std::fstream::binary);
if(f.is_open() == false) if(f.is_open() == false)
{ {
x.reset();
arma_extra_debug_print("unable to read ", name); arma_extra_debug_print("unable to read ", name);
x.reset();
} }
else else
{ {
podarray<char> raw_header(ARMA_MAT_TXT.length() + 1); diskio::load_auto_detect(x, name, f); // Do the actual load
f.close();
}
}
//! Try to load a matrix by automatically determining its type
template<typename eT>
inline
void
diskio::load_auto_detect(Mat<eT>& x, const std::string& name, std::istream&
f)
{
arma_extra_debug_sigprint();
static const std::string ARMA_MAT_TXT = "ARMA_MAT_TXT";
static const std::string ARMA_MAT_BIN = "ARMA_MAT_BIN";
static const std::string P5 = "P5";
f.read(raw_header.memptr(), ARMA_MAT_TXT.length()); podarray<char> raw_header(ARMA_MAT_TXT.length() + 1);
raw_header[ARMA_MAT_TXT.length()] = '\0';
const std::string header = raw_header.mem; std::streampos pos = f.tellg();
if(ARMA_MAT_TXT == header.substr(0,ARMA_MAT_TXT.length())) f.read(raw_header.memptr(), ARMA_MAT_TXT.length());
{ raw_header[ARMA_MAT_TXT.length()] = '\0';
load_arma_ascii(x, name);
}
else
if(ARMA_MAT_BIN == header.substr(0,ARMA_MAT_BIN.length()))
{
load_arma_binary(x, name);
}
else
if(P5 == header.substr(0,P5.length()))
{
load_pgm_binary(x, name);
}
else
{
load_raw_ascii(x, name);
}
f.close(); f.seekg(pos);
}
const std::string header = raw_header.mem;
if(ARMA_MAT_TXT == header.substr(0,ARMA_MAT_TXT.length()))
{
load_arma_ascii(x, name, f);
}
else
if(ARMA_MAT_BIN == header.substr(0,ARMA_MAT_BIN.length()))
{
load_arma_binary(x, name, f);
}
else
if(P5 == header.substr(0,P5.length()))
{
load_pgm_binary(x, name, f);
}
else
{
load_raw_ascii(x, name, f);
}
} }
// 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
void void
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)
{ {
skipping to change at line 1145 skipping to change at line 1218
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::fstream f(tmp_name.c_str(), std::fstream::out);
if(f.is_open() == false) if(f.is_open() == false)
{ {
arma_print("unable to write ", tmp_name); arma_print("unable to write ", tmp_name);
} }
else else
{ {
u32 cell_width; save_raw_ascii(x, tmp_name, f);
// TODO: need sane values for complex numbers
if( (is_float<eT>::value == true) || (is_double<eT>::value == true) )
{
f.setf(ios::scientific);
f.precision(8);
cell_width = 16;
}
for(u32 slice=0; slice < x.n_slices; ++slice)
{
for(u32 row=0; row < x.n_rows; ++row)
{
for(u32 col=0; col < x.n_cols; ++col)
{
f.put(' ');
if( (is_float<eT>::value == true) || (is_double<eT>::value == tru
e) )
{
f.width(cell_width);
}
f << x.at(row,col,slice);
}
f.put('\n');
}
}
const bool writing_problem = (f.good() == false); const bool writing_problem = (f.good() == false);
arma_warn(writing_problem, "trouble writing ", tmp_name ); arma_warn(writing_problem, "trouble writing ", tmp_name );
f.flush(); f.flush();
f.close(); f.close();
if(writing_problem == false) if(writing_problem == false)
{ {
diskio::safe_rename(tmp_name, final_name); diskio::safe_rename(tmp_name, final_name);
} }
} }
} }
//! Save a cube in text format (human readable), //! Save a cube as raw text (no header, human readable).
//! with a header that indicates the cube type as well as its dimensions
template<typename eT> template<typename eT>
inline inline
void void
diskio::save_arma_ascii(const Cube<eT>& x, const std::string& final_name) diskio::save_raw_ascii(const Cube<eT>& x, const std::string& name, std::ost ream& f)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const std::string tmp_name = diskio::gen_tmp_name(final_name); u32 cell_width;
std::ofstream f(tmp_name.c_str()); // TODO: need sane values for complex numbers
diskio::save_arma_ascii(x, tmp_name, f); if( (is_float<eT>::value == true) || (is_double<eT>::value == true) )
{
f.setf(ios::scientific);
f.precision(8);
cell_width = 16;
}
const bool writing_problem = (f.good() == false); for(u32 slice=0; slice < x.n_slices; ++slice)
{
for(u32 row=0; row < x.n_rows; ++row)
{
for(u32 col=0; col < x.n_cols; ++col)
{
f.put(' ');
f.flush(); if( (is_float<eT>::value == true) || (is_double<eT>::value == true)
f.close(); )
{
f.width(cell_width);
}
arma_warn( writing_problem, "trouble writing ", tmp_name ); f << x.at(row,col,slice);
}
if(writing_problem == false) f.put('\n');
{ }
diskio::safe_rename(tmp_name, final_name);
} }
} }
//! Save a cube in text format (human readable), //! Save a cube in text format (human readable),
//! with a header that indicates the cube type as well as its dimensions //! with a header that indicates the cube type as well as its dimensions
template<typename eT> template<typename eT>
inline inline
void void
diskio::save_arma_ascii(const Cube<eT>& x, const std::string& name, std::of stream& f) diskio::save_arma_ascii(const Cube<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);
std::ofstream f(tmp_name.c_str());
if(f.is_open() == false) if(f.is_open() == false)
{ {
arma_debug_print("unable to write ", name); arma_debug_print("unable to write ", tmp_name);
} }
else else
{ {
const ios::fmtflags orig_flags = f.flags(); diskio::save_arma_ascii(x, tmp_name, f);
f << diskio::gen_txt_header(x) << '\n'; const bool writing_problem = (f.good() == false);
f << x.n_rows << ' ' << x.n_cols << ' ' << x.n_slices << '\n';
u32 cell_width; f.flush();
f.close();
// TODO: need sane values for complex numbers arma_warn( writing_problem, "trouble writing ", tmp_name );
if( (is_float<eT>::value == true) || (is_double<eT>::value == true) ) if(writing_problem == false)
{ {
f.setf(ios::scientific); diskio::safe_rename(tmp_name, final_name);
f.precision(8);
cell_width = 16;
} }
}
}
for(u32 slice=0; slice < x.n_slices; ++slice) //! Save a cube in text format (human readable),
//! with a header that indicates the cube type as well as its dimensions
template<typename eT>
inline
void
diskio::save_arma_ascii(const Cube<eT>& x, const std::string& name, std::os
tream& 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 << ' ' << x.n_slices << '\n';
u32 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(8);
cell_width = 16;
}
for(u32 slice=0; slice < x.n_slices; ++slice)
{
for(u32 row=0; row < x.n_rows; ++row)
{ {
for(u32 row=0; row < x.n_rows; ++row) for(u32 col=0; col < x.n_cols; ++col)
{ {
for(u32 col=0; col < x.n_cols; ++col) f.put(' ');
{
f.put(' ');
if( (is_float<eT>::value == true) || (is_double<eT>::value == tru
e) )
{
f.width(cell_width);
}
f << x.at(row,col,slice); if( (is_float<eT>::value == true) || (is_double<eT>::value == true)
)
{
f.width(cell_width);
} }
f.put('\n'); f << x.at(row,col,slice);
} }
}
f.flags(orig_flags); f.put('\n');
}
} }
f.flags(orig_flags);
} }
//! Save a cube in binary format, //! Save a cube in binary format,
//! with a header that stores the cube type as well as its dimensions //! with a header that stores the cube type as well as its dimensions
template<typename eT> template<typename eT>
inline inline
void void
diskio::save_arma_binary(const Cube<eT>& x, const std::string& final_name) diskio::save_arma_binary(const Cube<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::fstream::binary); std::ofstream f(tmp_name.c_str(), std::fstream::binary);
diskio::save_arma_binary(x, tmp_name, f); if(f.is_open() == false)
{
arma_print("unable to write ", tmp_name);
}
else
{
diskio::save_arma_binary(x, tmp_name, f);
const bool writing_problem = (f.good() == false); const bool writing_problem = (f.good() == false);
f.flush(); f.flush();
f.close(); f.close();
arma_warn( writing_problem, "trouble writing ", tmp_name ); arma_warn( writing_problem, "trouble writing ", tmp_name );
if(writing_problem == false) if(writing_problem == false)
{ {
diskio::safe_rename(tmp_name, final_name); diskio::safe_rename(tmp_name, final_name);
}
} }
} }
//! Save a cube in binary format, //! Save a cube in binary format,
//! with a header that stores the cube type as well as its dimensions //! with a header that stores the cube type as well as its dimensions
template<typename eT> template<typename eT>
inline inline
void void
diskio::save_arma_binary(const Cube<eT>& x, const std::string& name, std::o fstream& f) diskio::save_arma_binary(const Cube<eT>& x, const std::string& name, std::o stream& f)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
f << diskio::gen_bin_header(x) << '\n';
f << x.n_rows << ' ' << x.n_cols << ' ' << x.n_slices << '\n';
if(f.is_open() == false) f.write(reinterpret_cast<const char*>(x.mem), x.n_elem*sizeof(eT));
{
arma_print("unable to write ", name);
}
else
{
f << diskio::gen_bin_header(x) << '\n';
f << x.n_rows << ' ' << x.n_cols << ' ' << x.n_slices << '\n';
f.write(reinterpret_cast<const char*>(x.mem), x.n_elem*sizeof(eT));
}
} }
//! Load a cube as raw text (no header, human readable). //! Load a cube as raw text (no header, human readable).
//! NOTE: this is much slower than reading a file with a header. //! NOTE: this is much slower than reading a file with a header.
template<typename eT> template<typename eT>
inline inline
void void
diskio::load_raw_ascii(Cube<eT>& x, const std::string& name) diskio::load_raw_ascii(Cube<eT>& x, const std::string& name)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
Mat<eT> tmp; Mat<eT> tmp;
tmp.load(name); diskio::load_raw_ascii(tmp, name);
x.set_size(tmp.n_rows, tmp.n_cols, 1); x.set_size(tmp.n_rows, tmp.n_cols, 1);
if(x.n_slices > 0) if(x.n_slices > 0)
{ {
x.slice(0) = tmp; x.slice(0) = tmp;
} }
} }
//! Load a cube in text format (human readable), //! Load a cube as raw text (no header, human readable).
//! with a header that indicates the cube type as well as its dimensions //! NOTE: this is much slower than reading a file with a header.
template<typename eT> template<typename eT>
inline inline
void void
diskio::load_arma_ascii(Cube<eT>& x, const std::string& name) diskio::load_raw_ascii(Cube<eT>& x, const std::string& name, std::istream& f)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
std::ifstream f(name.c_str()); Mat<eT> tmp;
diskio::load_arma_ascii(x, name, f); diskio::load_raw_ascii(tmp, name, f);
f.close();
x.set_size(tmp.n_rows, tmp.n_cols, 1);
if(x.n_slices > 0)
{
x.slice(0) = tmp;
}
} }
//! Load a cube in text format (human readable), //! Load a cube in text format (human readable),
//! with a header that indicates the cube type as well as its dimensions //! with a header that indicates the cube type as well as its dimensions
template<typename eT> template<typename eT>
inline inline
void void
diskio::load_arma_ascii(Cube<eT>& x, const std::string& name, std::ifstream & f) diskio::load_arma_ascii(Cube<eT>& x, const std::string& name)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
bool load_okay = true; std::ifstream f(name.c_str());
if(f.is_open() == false) if(f.is_open() == false)
{ {
load_okay = false;
arma_extra_debug_print("unable to read ", name); arma_extra_debug_print("unable to read ", name);
} }
else else
{ {
std::string f_header; diskio::load_arma_ascii(x, name, f);
u32 f_n_rows; f.close();
u32 f_n_cols; }
u32 f_n_slices; }
f >> f_header; //! Load a cube in text format (human readable),
f >> f_n_rows; //! with a header that indicates the cube type as well as its dimensions
f >> f_n_cols; template<typename eT>
f >> f_n_slices; inline
void
diskio::load_arma_ascii(Cube<eT>& x, const std::string& name, std::istream&
f)
{
arma_extra_debug_sigprint();
if(f_header == diskio::gen_txt_header(x)) bool load_okay = true;
{
x.set_size(f_n_rows, f_n_cols, f_n_slices); std::string f_header;
u32 f_n_rows;
u32 f_n_cols;
u32 f_n_slices;
f >> f_header;
f >> f_n_rows;
f >> f_n_cols;
f >> f_n_slices;
if(f_header == diskio::gen_txt_header(x))
{
x.set_size(f_n_rows, f_n_cols, f_n_slices);
for(u32 slice=0; slice < x.n_slices; ++slice) for(u32 slice=0; slice < x.n_slices; ++slice)
{
for(u32 row=0; row < x.n_rows; ++row)
{ {
for(u32 row=0; row < x.n_rows; ++row) for(u32 col=0; col < x.n_cols; ++col)
{ {
for(u32 col=0; col < x.n_cols; ++col) f >> x.at(row,col,slice);
{
f >> x.at(row,col,slice);
}
} }
} }
if(f.good() == false)
{
arma_print("trouble reading ", name);
load_okay = false;
}
} }
else
if(f.good() == false)
{ {
arma_print("incorrect header in ", name ); arma_print("trouble reading ", name);
load_okay = false; load_okay = false;
} }
}
else
{
arma_print("incorrect header in ", name );
load_okay = false;
} }
if(load_okay == false) if(load_okay == false)
{ {
x.reset(); x.reset();
} }
} }
//! Load a cube in binary format, //! Load a cube in binary format,
//! with a header that indicates the cube type as well as its dimensions //! with a header that indicates the cube type as well as its dimensions
template<typename eT> template<typename eT>
inline inline
void void
diskio::load_arma_binary(Cube<eT>& x, const std::string& name) diskio::load_arma_binary(Cube<eT>& x, const std::string& name)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
std::ifstream f; std::ifstream f;
f.open(name.c_str(), std::fstream::binary); f.open(name.c_str(), std::fstream::binary);
diskio::load_arma_binary(x, name, f);
f.close(); if(f.is_open() == false)
{
arma_extra_debug_print("unable to read ", name);
}
else
{
diskio::load_arma_binary(x, name, f);
f.close();
}
} }
template<typename eT> template<typename eT>
inline inline
void void
diskio::load_arma_binary(Cube<eT>& x, const std::string& name, std::ifstrea m& f) diskio::load_arma_binary(Cube<eT>& x, const std::string& name, std::istream & f)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
bool load_okay = true; bool load_okay = true;
if(f.is_open() == false) std::string f_header;
{ u32 f_n_rows;
load_okay = false; u32 f_n_cols;
arma_extra_debug_print("unable to read ", name); u32 f_n_slices;
}
else
{
std::string f_header;
u32 f_n_rows;
u32 f_n_cols;
u32 f_n_slices;
f >> f_header; f >> f_header;
f >> f_n_rows; f >> f_n_rows;
f >> f_n_cols; f >> f_n_cols;
f >> f_n_slices; f >> f_n_slices;
if(f_header == diskio::gen_bin_header(x)) if(f_header == diskio::gen_bin_header(x))
{ {
//f.seekg(1, ios::cur); // NOTE: this may not be portable, as on a W //f.seekg(1, ios::cur); // NOTE: this may not be portable, as on a Win
indows machine a newline could be two characters dows machine a newline could be two characters
f.get(); f.get();
x.set_size(f_n_rows, f_n_cols, f_n_slices); x.set_size(f_n_rows, f_n_cols, f_n_slices);
f.read( reinterpret_cast<char *>(x.memptr()), x.n_elem*sizeof(eT)); f.read( reinterpret_cast<char *>(x.memptr()), x.n_elem*sizeof(eT));
if(f.good() == false) if(f.good() == false)
{
arma_print("trouble reading ", name);
load_okay = false;
}
}
else
{ {
arma_print("incorrect header in ", name); arma_print("trouble reading ", name);
load_okay = false; load_okay = false;
} }
}
else
{
arma_print("incorrect header in ", name);
load_okay = false;
} }
if(load_okay == false) if(load_okay == false)
{ {
x.reset(); x.reset();
} }
} }
//! Try to load a cube by automatically determining its type //! Try to load a cube by automatically determining its type
template<typename eT> template<typename eT>
inline inline
void void
diskio::load_auto_detect(Cube<eT>& x, const std::string& name) diskio::load_auto_detect(Cube<eT>& x, const std::string& name)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
static const std::string ARMA_CUB_TXT = "ARMA_CUB_TXT";
static const std::string ARMA_CUB_BIN = "ARMA_CUB_BIN";
static const std::string P6 = "P6";
std::fstream f; std::fstream f;
f.open(name.c_str(), std::fstream::in | std::fstream::binary); f.open(name.c_str(), std::fstream::in | std::fstream::binary);
if(f.is_open() == false) if(f.is_open() == false)
{ {
x.reset();
arma_extra_debug_print("unable to read ", name); arma_extra_debug_print("unable to read ", name);
x.reset();
} }
else else
{ {
podarray<char> raw_header(ARMA_CUB_TXT.length() + 1); diskio::load_auto_detect(x, name, f); // Do the actual load
f.close();
}
}
f.read(raw_header.memptr(), ARMA_CUB_TXT.length()); //! Try to load a cube by automatically determining its type
raw_header[ARMA_CUB_TXT.length()] = '\0'; template<typename eT>
inline
void
diskio::load_auto_detect(Cube<eT>& x, const std::string& name, std::istream
& f)
{
arma_extra_debug_sigprint();
const std::string header = raw_header.mem; static const std::string ARMA_CUB_TXT = "ARMA_CUB_TXT";
static const std::string ARMA_CUB_BIN = "ARMA_CUB_BIN";
static const std::string P6 = "P6";
if(ARMA_CUB_TXT == header.substr(0, ARMA_CUB_TXT.length())) podarray<char> raw_header(ARMA_CUB_TXT.length() + 1);
{
load_arma_ascii(x, name);
}
else
if(ARMA_CUB_BIN == header.substr(0, ARMA_CUB_BIN.length()))
{
load_arma_binary(x, name);
}
else
if(P6 == header.substr(0,P6.length()))
{
load_ppm_binary(x, name);
}
else
{
load_raw_ascii(x, name);
}
f.close(); std::streampos pos = f.tellg();
}
f.read(raw_header.memptr(), ARMA_CUB_TXT.length());
raw_header[ARMA_CUB_TXT.length()] = '\0';
f.seekg(pos);
const std::string header = raw_header.mem;
if(ARMA_CUB_TXT == header.substr(0, ARMA_CUB_TXT.length()))
{
load_arma_ascii(x, name, f);
}
else
if(ARMA_CUB_BIN == header.substr(0, ARMA_CUB_BIN.length()))
{
load_arma_binary(x, name, f);
}
else
if(P6 == header.substr(0,P6.length()))
{
load_ppm_binary(x, name, f);
}
else
{
load_raw_ascii(x, name, f);
}
} }
// fields // fields
template<typename T1> template<typename T1>
inline inline
void void
diskio::save_arma_binary(const field<T1>& x, const std::string& final_name) diskio::save_arma_binary(const field<T1>& x, const std::string& final_name)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_type_check< (is_Mat<T1>::value == false) && (is_Cube<T1>::value == f
alse) >::apply();
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::fstream::binary ); std::ofstream f( tmp_name.c_str(), std::fstream::binary );
if(f.is_open() == false) if(f.is_open() == false)
{ {
arma_print("couldn't write ", tmp_name); arma_print("couldn't write ", tmp_name);
} }
else else
{ {
f << "ARMA_FLD_BIN" << '\n'; diskio::save_arma_binary(x, tmp_name, f);
f << x.n_rows << '\n';
f << x.n_cols << '\n';
for(u32 i=0; i<x.n_elem; ++i)
{
diskio::save_arma_binary(x[i], tmp_name, f);
}
const bool writing_problem = (f.good() == false); const bool writing_problem = (f.good() == false);
arma_warn(writing_problem, "trouble writing ", tmp_name ); arma_warn(writing_problem, "trouble writing ", tmp_name );
f.flush(); f.flush();
f.close(); f.close();
if(writing_problem == false) if(writing_problem == false)
{ {
diskio::safe_rename(tmp_name, final_name); diskio::safe_rename(tmp_name, final_name);
} }
} }
}
template<typename T1>
inline
void
diskio::save_arma_binary(const field<T1>& x, const std::string& name, std::
ostream& f)
{
arma_extra_debug_sigprint();
arma_type_check< (is_Mat<T1>::value == false) && (is_Cube<T1>::value == f
alse) >::apply();
f << "ARMA_FLD_BIN" << '\n';
f << x.n_rows << '\n';
f << x.n_cols << '\n';
for(u32 i=0; i<x.n_elem; ++i)
{
diskio::save_arma_binary(x[i], name, f);
}
} }
template<typename T1> template<typename T1>
inline inline
void void
diskio::load_arma_binary(field<T1>& x, const std::string& name) diskio::load_arma_binary(field<T1>& x, const std::string& name)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
std::ifstream f( name.c_str(), std::fstream::binary );
if(f.is_open() == false)
{
arma_extra_debug_print("unable to read ", name);
}
else
{
diskio::load_arma_binary(x, name, f);
f.close();
}
}
template<typename T1>
inline
void
diskio::load_arma_binary(field<T1>& x, const std::string& name, std::istrea
m& f)
{
arma_extra_debug_sigprint();
arma_type_check< (is_Mat<T1>::value == false) && (is_Cube<T1>::value == f alse) >::apply(); arma_type_check< (is_Mat<T1>::value == false) && (is_Cube<T1>::value == f alse) >::apply();
bool load_okay = true; bool load_okay = true;
std::ifstream f( name.c_str(), std::fstream::binary ); std::string f_type;
f >> f_type;
if(f.fail()) if(f_type != "ARMA_FLD_BIN")
{ {
arma_print("unsupported field type in ", name);
load_okay = false; load_okay = false;
arma_extra_debug_print("unable to read ", name);
} }
else else
{ {
std::string f_type; u32 f_n_rows;
f >> f_type; u32 f_n_cols;
if(f_type != "ARMA_FLD_BIN") f >> f_n_rows;
{ f >> f_n_cols;
arma_print("unsupported field type in ", name);
load_okay = false;
}
else
{
u32 f_n_rows;
u32 f_n_cols;
f >> f_n_rows; x.set_size(f_n_rows, f_n_cols);
f >> f_n_cols;
x.set_size(f_n_rows, f_n_cols); f.get();
f.get(); for(u32 i=0; i<x.n_elem; ++i)
{
diskio::load_arma_binary(x[i], name, f);
for(u32 i=0; i<x.n_elem; ++i) if(f.good() == false)
{ {
diskio::load_arma_binary(x[i], name, f); arma_print("trouble reading ", name);
load_okay = false;
if(f.good() == false) break;
{
arma_print("trouble reading ", name);
load_okay = false;
break;
}
} }
} }
} }
f.close();
if(load_okay == false) if(load_okay == false)
{ {
x.reset(); x.reset();
} }
} }
inline inline
void void
diskio::save_std_string(const field<std::string>& x, const std::string& fin al_name) diskio::save_std_string(const field<std::string>& x, const std::string& fin al_name)
{ {
skipping to change at line 1666 skipping to change at line 1794
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::fstream::binary ); std::ofstream f( tmp_name.c_str(), std::fstream::binary );
if(f.is_open() == false) if(f.is_open() == false)
{ {
arma_print("couldn't write ", tmp_name); arma_print("couldn't write ", tmp_name);
} }
else else
{ {
for(u32 row=0; row<x.n_rows; ++row) diskio::save_std_string(x, tmp_name, f);
for(u32 col=0; col<x.n_cols; ++col)
{
f << x.at(row,col);
if(col < x.n_cols-1)
{
f << ' ';
}
else
{
f << '\n';
}
}
const bool writing_problem = (f.good() == false); const bool writing_problem = (f.good() == false);
arma_warn(writing_problem, "trouble writing ", tmp_name );
f.flush(); f.flush();
f.close(); f.close();
if(writing_problem == false) if(writing_problem == false)
{ {
diskio::safe_rename(tmp_name, final_name); diskio::safe_rename(tmp_name, final_name);
} }
}
}
inline
void
diskio::save_std_string(const field<std::string>& x, const std::string& nam
e, std::ostream& f)
{
arma_extra_debug_sigprint();
for(u32 row=0; row<x.n_rows; ++row)
for(u32 col=0; col<x.n_cols; ++col)
{
f << x.at(row,col);
if(col < x.n_cols-1)
{
f << ' ';
}
else
{
f << '\n';
}
} }
const bool writing_problem = (f.good() == false);
arma_warn(writing_problem, "trouble writing ", name );
} }
inline inline
void void
diskio::load_std_string(field<std::string>& x, const std::string& name) diskio::load_std_string(field<std::string>& x, const std::string& name)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
bool load_okay = true;
std::ifstream f( name.c_str() ); std::ifstream f( name.c_str() );
if(f.fail()) if(f.is_open() == false)
{ {
load_okay = false; arma_print("unable to read ", name);
arma_extra_debug_print("unable to read ", name);
} }
else else
{ {
// diskio::load_std_string(x, name, f);
// work out the size
u32 f_n_rows = 0; f.close();
u32 f_n_cols = 0; }
}
bool f_n_cols_found = false; inline
void
diskio::load_std_string(field<std::string>& x, const std::string& name, std
::istream& f)
{
arma_extra_debug_sigprint();
std::string line_string; bool load_okay = true;
std::string token;
while( (f.good() == true) && (load_okay == true) ) //
{ // work out the size
std::getline(f, line_string);
if(line_string.size() == 0)
break;
std::stringstream line_stream(line_string); u32 f_n_rows = 0;
u32 f_n_cols = 0;
u32 line_n_cols = 0; bool f_n_cols_found = false;
while (line_stream >> token)
line_n_cols++;
if(f_n_cols_found == false) std::string line_string;
{ std::string token;
f_n_cols = line_n_cols;
f_n_cols_found = true;
}
else
{
if(line_n_cols != f_n_cols)
{
load_okay = false;
arma_print("inconsistent number of columns in ", name );
}
}
++f_n_rows; while( (f.good() == true) && (load_okay == true) )
} {
std::getline(f, line_string);
if(line_string.size() == 0)
break;
if(load_okay == true) std::stringstream line_stream(line_string);
{
f.clear();
f.seekg(0, ios::beg);
//f.seekg(start);
x.set_size(f_n_rows, f_n_cols); u32 line_n_cols = 0;
while (line_stream >> token)
line_n_cols++;
for(u32 row=0; row < x.n_rows; ++row) if(f_n_cols_found == false)
{
f_n_cols = line_n_cols;
f_n_cols_found = true;
}
else
{
if(line_n_cols != f_n_cols)
{ {
for(u32 col=0; col < x.n_cols; ++col) load_okay = false;
{ arma_print("inconsistent number of columns in ", name );
f >> x.at(row,col);
}
} }
} }
if(f.good() == false) ++f_n_rows;
}
if(load_okay == true)
{
f.clear();
f.seekg(0, ios::beg);
//f.seekg(start);
x.set_size(f_n_rows, f_n_cols);
for(u32 row=0; row < x.n_rows; ++row)
{ {
load_okay = false; for(u32 col=0; col < x.n_cols; ++col)
arma_print("trouble reading ", name ); {
f >> x.at(row,col);
}
} }
}
f.close(); if(f.good() == false)
{
load_okay = false;
arma_print("trouble reading ", name );
} }
if(load_okay == false) if(load_okay == false)
{ {
x.reset(); x.reset();
} }
} }
//! Try to load a field by automatically determining its type //! Try to load a field by automatically determining its type
template<typename T1> template<typename T1>
inline inline
void void
diskio::load_auto_detect(field<T1>& x, const std::string& name) diskio::load_auto_detect(field<T1>& x, const std::string& name)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_type_check<is_Mat<T1>::value == false>::apply();
static const std::string ARMA_FLD_BIN = "ARMA_FLD_BIN";
static const std::string P6 = "P6";
std::fstream f; std::fstream f;
f.open(name.c_str(), std::fstream::in | std::fstream::binary); f.open(name.c_str(), std::fstream::in | std::fstream::binary);
if(f.is_open() == false) if(f.is_open() == false)
{ {
x.reset();
arma_extra_debug_print("unable to read ", name); arma_extra_debug_print("unable to read ", name);
x.reset();
} }
else else
{ {
podarray<char> raw_header(ARMA_FLD_BIN.length() + 1); diskio::load_auto_detect(x, name, f); // Do the actual load
f.close();
}
}
f.read(raw_header.memptr(), ARMA_FLD_BIN.length()); //! Try to load a field by automatically determining its type
raw_header[ARMA_FLD_BIN.length()] = '\0'; template<typename T1>
inline
void
diskio::load_auto_detect(field<T1>& x, const std::string& name, std::istrea
m& f)
{
arma_extra_debug_sigprint();
const std::string header = raw_header.mem; arma_type_check<is_Mat<T1>::value == false>::apply();
if(ARMA_FLD_BIN == header.substr(0,ARMA_FLD_BIN.length())) static const std::string ARMA_FLD_BIN = "ARMA_FLD_BIN";
{ static const std::string P6 = "P6";
load_arma_binary(x, name);
}
else
if(P6 == header.substr(0,P6.length()))
{
load_ppm_binary(x, name);
}
else
{
arma_print("unsupported header in ", name);
x.reset();
}
f.close(); podarray<char> raw_header(ARMA_FLD_BIN.length() + 1);
}
std::streampos pos = f.tellg();
f.read(raw_header.memptr(), ARMA_FLD_BIN.length());
f.seekg(pos);
raw_header[ARMA_FLD_BIN.length()] = '\0';
const std::string header = raw_header.mem;
if(ARMA_FLD_BIN == header.substr(0,ARMA_FLD_BIN.length()))
{
load_arma_binary(x, name, f);
}
else
if(P6 == header.substr(0,P6.length()))
{
load_ppm_binary(x, name, f);
}
else
{
arma_print("unsupported header in ", name);
x.reset();
}
} }
// //
// handling of PPM images // handling of PPM images
template<typename eT> template<typename eT>
inline inline
void void
diskio::load_ppm_binary(Cube<eT>& x, const std::string& name) diskio::load_ppm_binary(Cube<eT>& x, const std::string& name)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
std::fstream f; std::fstream f;
f.open(name.c_str(), std::fstream::in | std::fstream::binary); f.open(name.c_str(), std::fstream::in | std::fstream::binary);
bool load_okay = true;
if(f.is_open() == false) if(f.is_open() == false)
{ {
load_okay = false;
arma_extra_debug_print("unable to read ", name); arma_extra_debug_print("unable to read ", name);
} }
else else
{ {
std::string f_header; diskio::load_ppm_binary(x, name, f);
f >> f_header; f.close();
}
}
if(f_header == "P6") template<typename eT>
{ inline
u32 f_n_rows = 0; void
u32 f_n_cols = 0; diskio::load_ppm_binary(Cube<eT>& x, const std::string& name, std::istream&
int f_maxval = 0; f)
{
arma_extra_debug_sigprint();
diskio::pnm_skip_comments(f); bool load_okay = true;
f >> f_n_cols; std::string f_header;
diskio::pnm_skip_comments(f); f >> f_header;
f >> f_n_rows; if(f_header == "P6")
diskio::pnm_skip_comments(f); {
u32 f_n_rows = 0;
u32 f_n_cols = 0;
int f_maxval = 0;
f >> f_maxval; diskio::pnm_skip_comments(f);
f.get();
if( (f_maxval > 0) || (f_maxval <= 65535) ) f >> f_n_cols;
{ diskio::pnm_skip_comments(f);
x.set_size(f_n_rows, f_n_cols, 3);
if(f_maxval <= 255) f >> f_n_rows;
{ diskio::pnm_skip_comments(f);
const u32 n_elem = 3*f_n_cols*f_n_rows;
podarray<u8> tmp(n_elem);
f.read( reinterpret_cast<char*>(tmp.memptr()), n_elem); f >> f_maxval;
f.get();
u32 i = 0; if( (f_maxval > 0) || (f_maxval <= 65535) )
{
x.set_size(f_n_rows, f_n_cols, 3);
//cout << "f_n_cols = " << f_n_cols << endl; if(f_maxval <= 255)
//cout << "f_n_rows = " << f_n_rows << endl; {
const u32 n_elem = 3*f_n_cols*f_n_rows;
podarray<u8> tmp(n_elem);
for(u32 row=0; row < f_n_rows; ++row) f.read( reinterpret_cast<char*>(tmp.memptr()), n_elem);
{
for(u32 col=0; col < f_n_cols; ++col) u32 i = 0;
{
x.at(row,col,0) = eT(tmp[i+0]);
x.at(row,col,1) = eT(tmp[i+1]);
x.at(row,col,2) = eT(tmp[i+2]);
i+=3;
}
//cout << "f_n_cols = " << f_n_cols << endl;
//cout << "f_n_rows = " << f_n_rows << endl;
for(u32 row=0; row < f_n_rows; ++row)
{
for(u32 col=0; col < f_n_cols; ++col)
{
x.at(row,col,0) = eT(tmp[i+0]);
x.at(row,col,1) = eT(tmp[i+1]);
x.at(row,col,2) = eT(tmp[i+2]);
i+=3;
} }
} }
else }
{ else
const u32 n_elem = 3*f_n_cols*f_n_rows; {
podarray<u16> tmp(n_elem); const u32 n_elem = 3*f_n_cols*f_n_rows;
podarray<u16> tmp(n_elem);
f.read( reinterpret_cast<char *>(tmp.memptr()), 2*n_elem); f.read( reinterpret_cast<char *>(tmp.memptr()), 2*n_elem);
u32 i = 0; u32 i = 0;
for(u32 row=0; row < f_n_rows; ++row) for(u32 row=0; row < f_n_rows; ++row)
{
for(u32 col=0; col < f_n_cols; ++col)
{ {
for(u32 col=0; col < f_n_cols; ++col) x.at(row,col,0) = eT(tmp[i+0]);
{ x.at(row,col,1) = eT(tmp[i+1]);
x.at(row,col,0) = eT(tmp[i+0]); x.at(row,col,2) = eT(tmp[i+2]);
x.at(row,col,1) = eT(tmp[i+1]); i+=3;
x.at(row,col,2) = eT(tmp[i+2]);
i+=3;
}
} }
} }
} }
if(f.good() == false)
{
arma_print("trouble reading ", name);
load_okay = false;
}
} }
else
if(f.good() == false)
{ {
arma_print("unsupported header in ", name); arma_print("trouble reading ", name);
load_okay = false; load_okay = false;
} }
f.close(); }
else
{
arma_print("unsupported header in ", name);
load_okay = false;
} }
if(load_okay == false) if(load_okay == false)
{ {
x.reset(); x.reset();
} }
} }
template<typename eT> template<typename eT>
inline inline
void void
diskio::save_ppm_binary(const Cube<eT>& x, const std::string& final_name) diskio::save_ppm_binary(const Cube<eT>& x, const std::string& final_name)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_check( (x.n_slices != 3), "diskio::save_ppm_binary(): given cu
be must have exactly 3 slices" );
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::fstream::binary ); std::ofstream f( tmp_name.c_str(), std::fstream::binary );
if(f.is_open() == false) if(f.is_open() == false)
{ {
arma_print("couldn't write ", tmp_name); arma_print("couldn't write ", tmp_name);
} }
else else
{ {
const u32 n_elem = 3 * x.n_rows * x.n_cols; diskio::save_ppm_binary(x, tmp_name, f);
podarray<u8> tmp(n_elem);
u32 i = 0;
for(u32 row=0; row < x.n_rows; ++row)
{
for(u32 col=0; col < x.n_cols; ++col)
{
tmp[i+0] = u8( x.at(row,col,0) );
tmp[i+1] = u8( x.at(row,col,1) );
tmp[i+2] = u8( x.at(row,col,2) );
i+=3;
}
}
f << "P6" << '\n';
f << x.n_cols << '\n';
f << x.n_rows << '\n';
f << 255 << '\n';
f.write(reinterpret_cast<const char*>(tmp.mem), n_elem);
const bool writing_problem = (f.good() == false); const bool writing_problem = (f.good() == false);
arma_warn(writing_problem, "trouble writing ", tmp_name );
f.flush(); f.flush();
f.close(); f.close();
if(writing_problem == false) if(writing_problem == false)
{ {
diskio::safe_rename(tmp_name, final_name); diskio::safe_rename(tmp_name, final_name);
} }
}
}
template<typename eT>
inline
void
diskio::save_ppm_binary(const Cube<eT>& x, const std::string& name, std::os
tream& f)
{
arma_extra_debug_sigprint();
arma_debug_check( (x.n_slices != 3), "diskio::save_ppm_binary(): given cu
be must have exactly 3 slices" );
const u32 n_elem = 3 * x.n_rows * x.n_cols;
podarray<u8> tmp(n_elem);
u32 i = 0;
for(u32 row=0; row < x.n_rows; ++row)
{
for(u32 col=0; col < x.n_cols; ++col)
{
tmp[i+0] = u8( x.at(row,col,0) );
tmp[i+1] = u8( x.at(row,col,1) );
tmp[i+2] = u8( x.at(row,col,2) );
i+=3;
}
} }
f << "P6" << '\n';
f << x.n_cols << '\n';
f << x.n_rows << '\n';
f << 255 << '\n';
f.write(reinterpret_cast<const char*>(tmp.mem), n_elem);
const bool writing_problem = (f.good() == false);
arma_warn(writing_problem, "trouble writing ", name );
} }
template<typename T1> template<typename T1>
inline inline
void void
diskio::load_ppm_binary(field<T1>& x, const std::string& name) diskio::load_ppm_binary(field<T1>& x, const std::string& name)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_type_check<is_Mat<T1>::value == false>::apply();
typedef typename T1::elem_type eT;
std::fstream f; std::fstream f;
f.open(name.c_str(), std::fstream::in | std::fstream::binary); f.open(name.c_str(), std::fstream::in | std::fstream::binary);
bool load_okay = true;
if(f.is_open() == false) if(f.is_open() == false)
{ {
load_okay = false;
arma_extra_debug_print("unable to read ", name); arma_extra_debug_print("unable to read ", name);
} }
else else
{ {
std::string f_header; diskio::load_ppm_binary(x, name, f);
f >> f_header; f.close();
}
}
if(f_header == "P6") template<typename T1>
{ inline
u32 f_n_rows = 0; void
u32 f_n_cols = 0; diskio::load_ppm_binary(field<T1>& x, const std::string& name, std::istream
int f_maxval = 0; & f)
{
arma_extra_debug_sigprint();
diskio::pnm_skip_comments(f); arma_type_check<is_Mat<T1>::value == false>::apply();
typedef typename T1::elem_type eT;
f >> f_n_cols; bool load_okay = true;
diskio::pnm_skip_comments(f);
f >> f_n_rows; std::string f_header;
diskio::pnm_skip_comments(f); f >> f_header;
f >> f_maxval; if(f_header == "P6")
f.get(); {
u32 f_n_rows = 0;
u32 f_n_cols = 0;
int f_maxval = 0;
if( (f_maxval > 0) || (f_maxval <= 65535) ) diskio::pnm_skip_comments(f);
{
x.set_size(3);
Mat<eT>& R = x(0);
Mat<eT>& G = x(1);
Mat<eT>& B = x(2);
R.set_size(f_n_rows,f_n_cols);
G.set_size(f_n_rows,f_n_cols);
B.set_size(f_n_rows,f_n_cols);
if(f_maxval <= 255) f >> f_n_cols;
{ diskio::pnm_skip_comments(f);
const u32 n_elem = 3*f_n_cols*f_n_rows;
podarray<u8> tmp(n_elem);
f.read( reinterpret_cast<char*>(tmp.memptr()), n_elem); f >> f_n_rows;
diskio::pnm_skip_comments(f);
u32 i = 0; f >> f_maxval;
f.get();
//cout << "f_n_cols = " << f_n_cols << endl; if( (f_maxval > 0) || (f_maxval <= 65535) )
//cout << "f_n_rows = " << f_n_rows << endl; {
x.set_size(3);
Mat<eT>& R = x(0);
Mat<eT>& G = x(1);
Mat<eT>& B = x(2);
R.set_size(f_n_rows,f_n_cols);
G.set_size(f_n_rows,f_n_cols);
B.set_size(f_n_rows,f_n_cols);
for(u32 row=0; row < f_n_rows; ++row) if(f_maxval <= 255)
{ {
for(u32 col=0; col < f_n_cols; ++col) const u32 n_elem = 3*f_n_cols*f_n_rows;
{ podarray<u8> tmp(n_elem);
R.at(row,col) = eT(tmp[i+0]);
G.at(row,col) = eT(tmp[i+1]); f.read( reinterpret_cast<char*>(tmp.memptr()), n_elem);
B.at(row,col) = eT(tmp[i+2]);
i+=3;
}
u32 i = 0;
//cout << "f_n_cols = " << f_n_cols << endl;
//cout << "f_n_rows = " << f_n_rows << endl;
for(u32 row=0; row < f_n_rows; ++row)
{
for(u32 col=0; col < f_n_cols; ++col)
{
R.at(row,col) = eT(tmp[i+0]);
G.at(row,col) = eT(tmp[i+1]);
B.at(row,col) = eT(tmp[i+2]);
i+=3;
} }
} }
else }
{ else
const u32 n_elem = 3*f_n_cols*f_n_rows; {
podarray<u16> tmp(n_elem); const u32 n_elem = 3*f_n_cols*f_n_rows;
podarray<u16> tmp(n_elem);
f.read( reinterpret_cast<char *>(tmp.memptr()), 2*n_elem); f.read( reinterpret_cast<char *>(tmp.memptr()), 2*n_elem);
u32 i = 0; u32 i = 0;
for(u32 row=0; row < f_n_rows; ++row) for(u32 row=0; row < f_n_rows; ++row)
{
for(u32 col=0; col < f_n_cols; ++col)
{ {
for(u32 col=0; col < f_n_cols; ++col) R.at(row,col) = eT(tmp[i+0]);
{ G.at(row,col) = eT(tmp[i+1]);
R.at(row,col) = eT(tmp[i+0]); B.at(row,col) = eT(tmp[i+2]);
G.at(row,col) = eT(tmp[i+1]); i+=3;
B.at(row,col) = eT(tmp[i+2]);
i+=3;
}
} }
} }
} }
if(f.good() == false)
{
arma_print("trouble reading ", name);
load_okay = false;
}
} }
else
if(f.good() == false)
{ {
arma_print("unsupported header in ", name); arma_print("trouble reading ", name);
load_okay = false; load_okay = false;
} }
f.close(); }
else
{
arma_print("unsupported header in ", name);
load_okay = false;
} }
if(load_okay == false) if(load_okay == false)
{ {
x.reset(); x.reset();
} }
} }
template<typename T1> template<typename T1>
inline inline
void void
diskio::save_ppm_binary(const field<T1>& x, const std::string& final_name) diskio::save_ppm_binary(const field<T1>& 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);
std::ofstream f( tmp_name.c_str(), std::fstream::binary );
if(f.is_open() == false)
{
arma_print("couldn't write ", tmp_name);
}
else
{
diskio::save_ppm_binary(x, tmp_name, f);
const bool writing_problem = (f.good() == false);
f.flush();
f.close();
if(writing_problem == false)
{
diskio::safe_rename(tmp_name, final_name);
}
}
}
template<typename T1>
inline
void
diskio::save_ppm_binary(const field<T1>& x, const std::string& name, std::o
stream& f)
{
arma_extra_debug_sigprint();
arma_type_check<is_Mat<T1>::value == false>::apply(); arma_type_check<is_Mat<T1>::value == false>::apply();
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
arma_debug_check( (x.n_elem != 3), "diskio::save_ppm_binary(): given fiel d must have exactly 3 matrices of equal size" ); arma_debug_check( (x.n_elem != 3), "diskio::save_ppm_binary(): given fiel d must have exactly 3 matrices of equal size" );
bool same_size = true; bool same_size = true;
for(u32 i=1; i<3; ++i) for(u32 i=1; i<3; ++i)
{ {
if( (x(0).n_rows != x(i).n_rows) || (x(0).n_cols != x(i).n_cols) ) if( (x(0).n_rows != x(i).n_rows) || (x(0).n_cols != x(i).n_cols) )
{ {
same_size = false; same_size = false;
break; break;
} }
} }
arma_debug_check( (same_size != true), "diskio::save_ppm_binary(): given field must have exactly 3 matrices of equal size" ); arma_debug_check( (same_size != true), "diskio::save_ppm_binary(): given field must have exactly 3 matrices of equal size" );
const Mat<eT>& R = x(0); const Mat<eT>& R = x(0);
const Mat<eT>& G = x(1); const Mat<eT>& G = x(1);
const Mat<eT>& B = x(2); const Mat<eT>& B = x(2);
const std::string tmp_name = diskio::gen_tmp_name(final_name); f << "P6" << '\n';
std::ofstream f( tmp_name.c_str(), std::fstream::binary ); f << R.n_cols << '\n';
f << R.n_rows << '\n';
if(f.is_open() == false) f << 255 << '\n';
{
arma_print("couldn't write ", tmp_name);
}
else
{
f << "P6" << '\n';
f << R.n_cols << '\n';
f << R.n_rows << '\n';
f << 255 << '\n';
const u32 n_elem = 3 * R.n_rows * R.n_cols; const u32 n_elem = 3 * R.n_rows * R.n_cols;
podarray<u8> tmp(n_elem); podarray<u8> tmp(n_elem);
u32 i = 0; u32 i = 0;
for(u32 row=0; row < R.n_rows; ++row) for(u32 row=0; row < R.n_rows; ++row)
{
for(u32 col=0; col < R.n_cols; ++col)
{ {
for(u32 col=0; col < R.n_cols; ++col) tmp[i+0] = u8( access::tmp_real( R.at(row,col) ) );
{ tmp[i+1] = u8( access::tmp_real( G.at(row,col) ) );
tmp[i+0] = u8( R.at(row,col) ); tmp[i+2] = u8( access::tmp_real( B.at(row,col) ) );
tmp[i+1] = u8( G.at(row,col) );
tmp[i+2] = u8( B.at(row,col) );
i+=3; i+=3;
}
} }
}
f.write(reinterpret_cast<const char*>(tmp.mem), n_elem); f.write(reinterpret_cast<const char*>(tmp.mem), n_elem);
const bool writing_problem = (f.good() == false);
arma_warn(writing_problem, "trouble writing ", tmp_name );
f.flush();
f.close();
if(writing_problem == false)
{
diskio::safe_rename(tmp_name, final_name);
}
} const bool writing_problem = (f.good() == false);
arma_warn(writing_problem, "trouble writing ", name );
} }
//! @} //! @}
 End of changes. 297 change blocks. 
793 lines changed or deleted 1000 lines changed or added


 diskio_proto.hpp   diskio_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Ian Cullinan (ian dot cullinan at nicta dot com dot au)
// //
// 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 58 skipping to change at line 60
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 void safe_rename(const std::string& old_name, const std::st ring& new_name); inline static void safe_rename(const std::string& old_name, const std::st ring& new_name);
// //
// matrix saving // matrix saving
template<typename eT> inline static void save_raw_ascii (const Mat<eT>& template<typename eT> inline static void save_raw_ascii (const Mat<eT>&
x, const std::string& name); x, const std::string& final_name);
template<typename eT> inline static void save_arma_ascii (const Mat<eT>& template<typename eT> inline static void save_raw_ascii (const Mat<eT>&
x, const std::string& name); x, const std::string& name, std::ostream& f);
template<typename eT> inline static void save_arma_ascii (const Mat<eT>& template<typename eT> inline static void save_arma_ascii (const Mat<eT>&
x, const std::string& name, std::ofstream& f); x, const std::string& final_name);
template<typename eT> inline static void save_arma_binary(const Mat<eT>& template<typename eT> inline static void save_arma_ascii (const Mat<eT>&
x, const std::string& name); x, const std::string& name, std::ostream& f);
template<typename eT> inline static void save_arma_binary(const Mat<eT>& template<typename eT> inline static void save_arma_binary(const Mat<eT>&
x, const std::string& name, std::ofstream& f); x, const std::string& final_name);
template<typename eT> inline static void save_pgm_binary (const Mat<eT>& template<typename eT> inline static void save_arma_binary(const Mat<eT>&
x, const std::string& name); x, const std::string& name, std::ostream& f);
template<typename T> inline static void save_pgm_binary (const Mat< std: template<typename eT> inline static void save_pgm_binary (const Mat<eT>&
:complex<T> >& x, const std::string& name); x, const std::string& final_nname);
template<typename eT> inline static void save_pgm_binary (const Mat<eT>&
x, const std::string& name, std::ostream& f);
template<typename T> inline static void save_pgm_binary (const Mat< std:
:complex<T> >& x, const std::string& final_name);
template<typename T> inline static void save_pgm_binary (const Mat< std:
:complex<T> >& x, const std::string& name, std::ostream& f);
// //
// matrix loading // matrix loading
template<typename eT> inline static void load_raw_ascii (Mat<eT>& x, con st std::string& name); template<typename eT> inline static void load_raw_ascii (Mat<eT>& x, con st std::string& name);
template<typename eT> inline static void load_raw_ascii (Mat<eT>& x, con st std::string& name, std::istream& f);
template<typename eT> inline static void load_arma_ascii (Mat<eT>& x, con st std::string& name); template<typename eT> inline static void load_arma_ascii (Mat<eT>& x, con st std::string& name);
template<typename eT> inline static void load_arma_ascii (Mat<eT>& x, con st std::string& name, std::ifstream& f); template<typename eT> inline static void load_arma_ascii (Mat<eT>& x, con st std::string& name, std::istream& f);
template<typename eT> inline static void load_arma_binary(Mat<eT>& x, con st std::string& name); template<typename eT> inline static void load_arma_binary(Mat<eT>& x, con st std::string& name);
template<typename eT> inline static void load_arma_binary(Mat<eT>& x, con st std::string& name, std::ifstream& f); template<typename eT> inline static void load_arma_binary(Mat<eT>& x, con st std::string& name, std::istream& f);
template<typename eT> inline static void load_pgm_binary (Mat<eT>& x, con st std::string& name); template<typename eT> inline static void load_pgm_binary (Mat<eT>& x, con st std::string& name);
template<typename T> inline static void load_pgm_binary (Mat< std::compl ex<T> >& x, const std::string& name);
template<typename eT> inline static void load_pgm_binary (Mat<eT>& x, con st std::string& name, std::istream& is); template<typename eT> inline static void load_pgm_binary (Mat<eT>& x, con st std::string& name, std::istream& is);
template<typename T> inline static void load_pgm_binary (Mat< std::compl
ex<T> >& x, const std::string& name);
template<typename T> inline static void load_pgm_binary (Mat< std::compl
ex<T> >& x, const std::string& name, std::istream& is);
template<typename eT> inline static void load_auto_detect(Mat<eT>& x, con st std::string& name); template<typename eT> inline static void load_auto_detect(Mat<eT>& x, con st std::string& name);
template<typename eT> inline static void load_auto_detect(Mat<eT>& x, con st std::string& name, std::istream& f);
inline static void pnm_skip_comments(std::istream& f); inline static void pnm_skip_comments(std::istream& f);
// //
// cube saving // cube saving
template<typename eT> inline static void save_raw_ascii (const Cube<eT>& x, const std::string& name); template<typename eT> inline static void save_raw_ascii (const Cube<eT>& x, const std::string& name);
template<typename eT> inline static void save_raw_ascii (const Cube<eT>& x, const std::string& name, std::ostream& f);
template<typename eT> inline static void save_arma_ascii (const Cube<eT>& x, const std::string& name); template<typename eT> inline static void save_arma_ascii (const Cube<eT>& x, const std::string& name);
template<typename eT> inline static void save_arma_ascii (const Cube<eT>& x, const std::string& name, std::ofstream& f); template<typename eT> inline static void save_arma_ascii (const Cube<eT>& x, const std::string& name, std::ostream& f);
template<typename eT> inline static void save_arma_binary(const Cube<eT>& x, const std::string& name); template<typename eT> inline static void save_arma_binary(const Cube<eT>& x, const std::string& name);
template<typename eT> inline static void save_arma_binary(const Cube<eT>& x, const std::string& name, std::ofstream& f); template<typename eT> inline static void save_arma_binary(const Cube<eT>& x, const std::string& name, std::ostream& f);
// //
// cube loading // cube loading
template<typename eT> inline static void load_raw_ascii (Cube<eT>& x, co nst std::string& name); template<typename eT> inline static void load_raw_ascii (Cube<eT>& x, co nst std::string& name);
template<typename eT> inline static void load_raw_ascii (Cube<eT>& x, co nst std::string& name, std::istream& f);
template<typename eT> inline static void load_arma_ascii (Cube<eT>& x, co nst std::string& name); template<typename eT> inline static void load_arma_ascii (Cube<eT>& x, co nst std::string& name);
template<typename eT> inline static void load_arma_ascii (Cube<eT>& x, co nst std::string& name, std::ifstream& f); template<typename eT> inline static void load_arma_ascii (Cube<eT>& x, co nst std::string& name, std::istream& f);
template<typename eT> inline static void load_arma_binary(Cube<eT>& x, co nst std::string& name); template<typename eT> inline static void load_arma_binary(Cube<eT>& x, co nst std::string& name);
template<typename eT> inline static void load_arma_binary(Cube<eT>& x, co nst std::string& name, std::ifstream& f); template<typename eT> inline static void load_arma_binary(Cube<eT>& x, co nst std::string& name, std::istream& f);
template<typename eT> inline static void load_auto_detect(Cube<eT>& x, co nst std::string& name); template<typename eT> inline static void load_auto_detect(Cube<eT>& x, co nst std::string& name);
template<typename eT> inline static void load_auto_detect(Cube<eT>& x, co nst std::string& name, std::istream& f);
// //
// field saving and loading // field saving and loading
template<typename T1> inline static void save_arma_binary(const field<T1> & x, const std::string& name); template<typename T1> inline static void save_arma_binary(const field<T1> & x, const std::string& name);
template<typename T1> inline static void save_arma_binary(const field<T1> & x, const std::string& name, std::ostream& f);
template<typename T1> inline static void load_arma_binary( field<T1> & x, const std::string& name); template<typename T1> inline static void load_arma_binary( field<T1> & x, const std::string& name);
template<typename T1> inline static void load_arma_binary( field<T1> & x, const std::string& name, std::istream& f);
inline static void save_std_string(const field<std::string>& x, const std ::string& name); inline static void save_std_string(const field<std::string>& x, const std ::string& name);
inline static void save_std_string(const field<std::string>& x, const std ::string& name, std::ostream& f);
inline static void load_std_string( field<std::string>& x, const std ::string& name); inline static void load_std_string( field<std::string>& x, const std ::string& name);
inline static void load_std_string( field<std::string>& x, const std ::string& name, std::istream& f);
template<typename T1> inline static void load_auto_detect(field<T1>& x, c onst std::string& name); template<typename T1> inline static void load_auto_detect(field<T1>& x, c onst std::string& name);
template<typename T1> inline static void load_auto_detect(field<T1>& x, c onst std::string& name, std::istream& f);
// //
// PPM images // PPM images
template<typename T1> inline static void save_ppm_binary(const Cube<T1>& x, const std::string& final_name); template<typename T1> inline static void save_ppm_binary(const Cube<T1>& x, const std::string& final_name);
template<typename T1> inline static void save_ppm_binary(const Cube<T1>& x, const std::string& name, std::ostream& f);
template<typename T1> inline static void load_ppm_binary( Cube<T1>& x, const std::string& final_name); template<typename T1> inline static void load_ppm_binary( Cube<T1>& x, const std::string& final_name);
template<typename T1> inline static void load_ppm_binary( Cube<T1>& x, const std::string& name, std::istream& f);
template<typename T1> inline static void save_ppm_binary(const field<T1>& x, const std::string& final_name); template<typename T1> inline static void save_ppm_binary(const field<T1>& x, const std::string& final_name);
template<typename T1> inline static void save_ppm_binary(const field<T1>& x, const std::string& final_name, std::ostream& f);
template<typename T1> inline static void load_ppm_binary( field<T1>& x, const std::string& final_name); template<typename T1> inline static void load_ppm_binary( field<T1>& x, const std::string& final_name);
template<typename T1> inline static void load_ppm_binary( field<T1>& x, const std::string& final_name, std::istream& f);
}; };
//! @} //! @}
 End of changes. 25 change blocks. 
22 lines changed or deleted 47 lines changed or added


 field_meat.hpp   field_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Ian Cullinan (ian dot cullinan at nicta dot com dot au)
// //
// 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 158 skipping to change at line 160
void void
field<oT>::set_size(const u32 n_rows_in, const u32 n_cols_in) field<oT>::set_size(const u32 n_rows_in, const u32 n_cols_in)
{ {
arma_extra_debug_sigprint(arma_boost::format("n_rows_in = %d, n_cols_in = %d") % n_rows_in % n_cols_in); arma_extra_debug_sigprint(arma_boost::format("n_rows_in = %d, n_cols_in = %d") % n_rows_in % n_cols_in);
init(n_rows_in, n_cols_in); init(n_rows_in, n_cols_in);
} }
//! change the field to have the specified dimensions (data is not preserve d) //! change the field to have the specified dimensions (data is not preserve d)
template<typename oT> template<typename oT>
template<typename oT2>
inline inline
void void
field<oT>::copy_size(const field<oT>& x) field<oT>::copy_size(const field<oT2>& x)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
if(this != &x) init(x.n_rows, x.n_cols);
{
init(x.n_rows, x.n_cols);
}
} }
//! linear element accessor (treats the field as a vector); no bounds check //! linear element accessor (treats the field as a vector); no bounds check
template<typename oT> template<typename oT>
arma_inline arma_inline
oT& oT&
field<oT>::operator[] (const u32 i) field<oT>::operator[] (const u32 i)
{ {
return (*mem[i]); return (*mem[i]);
} }
skipping to change at line 501 skipping to change at line 501
field<oT>::save(const std::string name, const file_type type) const field<oT>::save(const std::string name, const file_type type) const
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
field_aux::save(*this, name, type); field_aux::save(*this, name, type);
} }
template<typename oT> template<typename oT>
inline inline
void void
field<oT>::save(std::ostream& os, const file_type type) const
{
arma_extra_debug_sigprint();
field_aux::save(*this, os, type);
}
template<typename oT>
inline
void
field<oT>::load(const std::string name, const file_type type) field<oT>::load(const std::string name, const file_type type)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
field_aux::load(*this, name, type); field_aux::load(*this, name, type);
} }
template<typename oT>
inline
void
field<oT>::load(std::istream& is, const file_type type)
{
arma_extra_debug_sigprint();
field_aux::load(*this, is, type);
}
//! construct a field from a given field //! construct a field from a given field
template<typename oT> template<typename oT>
inline inline
void void
field<oT>::init(const field<oT>& x) field<oT>::init(const field<oT>& x)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
if(this != &x) if(this != &x)
{ {
skipping to change at line 714 skipping to change at line 734
field_aux::save(const field<oT>& x, const std::string& name, const file_typ e type) field_aux::save(const field<oT>& x, const std::string& name, const file_typ e type)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_print("field_aux::save(): sorry, saving this type of field is curren tly not supported"); arma_print("field_aux::save(): sorry, saving this type of field is curren tly not supported");
} }
template<typename oT> template<typename oT>
inline inline
void void
field_aux::save(const field<oT>& x, std::ostream& os, const file_type type)
{
arma_extra_debug_sigprint();
arma_print("field_aux::save(): sorry, saving this type of field is curren
tly not supported");
}
template<typename oT>
inline
void
field_aux::load(field<oT>& x, const std::string& name, const file_type type ) field_aux::load(field<oT>& x, const std::string& name, const file_type type )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_print("field_aux::load(): sorry, loading this type of field is curre ntly not supported"); arma_print("field_aux::load(): sorry, loading this type of field is curre ntly not supported");
x.reset(); x.reset();
} }
template<typename oT>
inline
void
field_aux::load(field<oT>& x, std::istream& is, const file_type type)
{
arma_extra_debug_sigprint();
arma_print("field_aux::load(): sorry, loading this type of field is curre
ntly not supported");
x.reset();
}
template<typename eT> template<typename eT>
inline inline
void void
field_aux::save(const field< Mat<eT> >& x, const std::string& name, const f ile_type type) field_aux::save(const field< Mat<eT> >& x, const std::string& name, const f ile_type type)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
switch(type) switch(type)
{ {
case arma_binary: case arma_binary:
skipping to change at line 747 skipping to change at line 788
break; break;
default: default:
arma_stop("field_aux::save(): unsupported type"); arma_stop("field_aux::save(): unsupported type");
} }
} }
template<typename eT> template<typename eT>
inline inline
void void
field_aux::save(const field< Mat<eT> >& x, std::ostream& os, const file_typ
e type)
{
arma_extra_debug_sigprint();
switch(type)
{
case arma_binary:
diskio::save_arma_binary(x, "[ostream]", os);
break;
case ppm_binary:
diskio::save_ppm_binary(x, "[ostream]", os);
break;
default:
arma_stop("field_aux::save(): unsupported type");
}
}
template<typename eT>
inline
void
field_aux::load(field< Mat<eT> >& x, const std::string& name, const file_ty pe type) field_aux::load(field< Mat<eT> >& x, const std::string& name, const file_ty pe type)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
switch(type) switch(type)
{ {
case auto_detect: case auto_detect:
diskio::load_auto_detect(x, name); diskio::load_auto_detect(x, name);
break; break;
skipping to change at line 773 skipping to change at line 836
break; break;
default: default:
arma_stop("field_aux::load(): unsupported type"); arma_stop("field_aux::load(): unsupported type");
} }
} }
template<typename eT> template<typename eT>
inline inline
void void
field_aux::load(field< Mat<eT> >& x, std::istream& is, const file_type type
)
{
arma_extra_debug_sigprint();
switch(type)
{
case auto_detect:
diskio::load_auto_detect(x, "[istream]", is);
break;
case arma_binary:
diskio::load_arma_binary(x, "[istream]", is);
break;
case ppm_binary:
diskio::load_ppm_binary(x, "[istream]", is);
break;
default:
arma_stop("field_aux::load(): unsupported type");
}
}
template<typename eT>
inline
void
field_aux::save(const field< Col<eT> >& x, const std::string& name, const f ile_type type) field_aux::save(const field< Col<eT> >& x, const std::string& name, const f ile_type type)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
switch(type) switch(type)
{ {
case arma_binary: case arma_binary:
diskio::save_arma_binary(x, name); diskio::save_arma_binary(x, name);
break; break;
skipping to change at line 795 skipping to change at line 884
break; break;
default: default:
arma_stop("field_aux::save(): unsupported type"); arma_stop("field_aux::save(): unsupported type");
} }
} }
template<typename eT> template<typename eT>
inline inline
void void
field_aux::save(const field< Col<eT> >& x, std::ostream& os, const file_typ
e type)
{
arma_extra_debug_sigprint();
switch(type)
{
case arma_binary:
diskio::save_arma_binary(x, "[ostream]", os);
break;
case ppm_binary:
diskio::save_ppm_binary(x, "[ostream]", os);
break;
default:
arma_stop("field_aux::save(): unsupported type");
}
}
template<typename eT>
inline
void
field_aux::load(field< Col<eT> >& x, const std::string& name, const file_ty pe type) field_aux::load(field< Col<eT> >& x, const std::string& name, const file_ty pe type)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
switch(type) switch(type)
{ {
case auto_detect: case auto_detect:
diskio::load_auto_detect(x, name); diskio::load_auto_detect(x, name);
break; break;
skipping to change at line 821 skipping to change at line 932
break; break;
default: default:
arma_stop("field_aux::load(): unsupported type"); arma_stop("field_aux::load(): unsupported type");
} }
} }
template<typename eT> template<typename eT>
inline inline
void void
field_aux::load(field< Col<eT> >& x, std::istream& is, const file_type type
)
{
arma_extra_debug_sigprint();
switch(type)
{
case auto_detect:
diskio::load_auto_detect(x, "[istream]", is);
break;
case arma_binary:
diskio::load_arma_binary(x, "[istream]", is);
break;
case ppm_binary:
diskio::load_ppm_binary(x, "[istream]", is);
break;
default:
arma_stop("field_aux::load(): unsupported type");
}
}
template<typename eT>
inline
void
field_aux::save(const field< Row<eT> >& x, const std::string& name, const f ile_type type) field_aux::save(const field< Row<eT> >& x, const std::string& name, const f ile_type type)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
switch(type) switch(type)
{ {
case arma_binary: case arma_binary:
diskio::save_arma_binary(x, name); diskio::save_arma_binary(x, name);
break; break;
skipping to change at line 843 skipping to change at line 980
break; break;
default: default:
arma_stop("field_aux::save(): unsupported type"); arma_stop("field_aux::save(): unsupported type");
} }
} }
template<typename eT> template<typename eT>
inline inline
void void
field_aux::save(const field< Row<eT> >& x, std::ostream& os, const file_typ
e type)
{
arma_extra_debug_sigprint();
switch(type)
{
case arma_binary:
diskio::save_arma_binary(x, "[ostream]", os);
break;
case ppm_binary:
diskio::save_ppm_binary(x, "[ostream]", os);
break;
default:
arma_stop("field_aux::save(): unsupported type");
}
}
template<typename eT>
inline
void
field_aux::load(field< Row<eT> >& x, const std::string& name, const file_ty pe type) field_aux::load(field< Row<eT> >& x, const std::string& name, const file_ty pe type)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
switch(type) switch(type)
{ {
case auto_detect: case auto_detect:
diskio::load_auto_detect(x, name); diskio::load_auto_detect(x, name);
break; break;
skipping to change at line 869 skipping to change at line 1028
break; break;
default: default:
arma_stop("field_aux::load(): unsupported type"); arma_stop("field_aux::load(): unsupported type");
} }
} }
template<typename eT> template<typename eT>
inline inline
void void
field_aux::load(field< Row<eT> >& x, std::istream& is, const file_type type
)
{
arma_extra_debug_sigprint();
switch(type)
{
case auto_detect:
diskio::load_auto_detect(x, "[istream]", is);
break;
case arma_binary:
diskio::load_arma_binary(x, "[istream]", is);
break;
case ppm_binary:
diskio::load_ppm_binary(x, "[istream]", is);
break;
default:
arma_stop("field_aux::load(): unsupported type");
}
}
template<typename eT>
inline
void
field_aux::save(const field< Cube<eT> >& x, const std::string& name, const file_type type) field_aux::save(const field< Cube<eT> >& x, const std::string& name, const file_type type)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
switch(type) switch(type)
{ {
case arma_binary: case arma_binary:
diskio::save_arma_binary(x, name); diskio::save_arma_binary(x, name);
break; break;
skipping to change at line 891 skipping to change at line 1076
break; break;
default: default:
arma_stop("field_aux::save(): unsupported type"); arma_stop("field_aux::save(): unsupported type");
} }
} }
template<typename eT> template<typename eT>
inline inline
void void
field_aux::save(const field< Cube<eT> >& x, std::ostream& os, const file_ty
pe type)
{
arma_extra_debug_sigprint();
switch(type)
{
case arma_binary:
diskio::save_arma_binary(x, "[ostream]", os);
break;
case ppm_binary:
diskio::save_ppm_binary(x, "[ostream]", os);
break;
default:
arma_stop("field_aux::save(): unsupported type");
}
}
template<typename eT>
inline
void
field_aux::load(field< Cube<eT> >& x, const std::string& name, const file_t ype type) field_aux::load(field< Cube<eT> >& x, const std::string& name, const file_t ype type)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
switch(type) switch(type)
{ {
case auto_detect: case auto_detect:
diskio::load_auto_detect(x, name); diskio::load_auto_detect(x, name);
break; break;
skipping to change at line 914 skipping to change at line 1121
case ppm_binary: case ppm_binary:
diskio::load_ppm_binary(x, name); diskio::load_ppm_binary(x, name);
break; break;
default: default:
arma_stop("field_aux::load(): unsupported type"); arma_stop("field_aux::load(): unsupported type");
} }
} }
template<typename eT>
inline
void
field_aux::load(field< Cube<eT> >& x, std::istream& is, const file_type typ
e)
{
arma_extra_debug_sigprint();
switch(type)
{
case auto_detect:
diskio::load_auto_detect(x, "[istream]", is);
break;
case arma_binary:
diskio::load_arma_binary(x, "[istream]", is);
break;
case ppm_binary:
diskio::load_ppm_binary(x, "[istream]", is);
break;
default:
arma_stop("field_aux::load(): unsupported type");
}
}
inline inline
void void
field_aux::save(const field< std::string >& x, const std::string& name, con st file_type type) field_aux::save(const field< std::string >& x, const std::string& name, con st file_type type)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
diskio::save_std_string(x, name); diskio::save_std_string(x, name);
} }
inline inline
void void
field_aux::save(const field< std::string >& x, std::ostream& os, const file
_type type)
{
arma_extra_debug_sigprint();
diskio::save_std_string(x, "[ostream]", os);
}
inline
void
field_aux::load(field< std::string >& x, const std::string& name, const fil e_type type) field_aux::load(field< std::string >& x, const std::string& name, const fil e_type type)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
diskio::load_std_string(x, name); diskio::load_std_string(x, name);
} }
inline
void
field_aux::load(field< std::string >& x, std::istream& is, const file_type
type)
{
arma_extra_debug_sigprint();
diskio::load_std_string(x, "[istream]", is);
}
//! @} //! @}
 End of changes. 19 change blocks. 
6 lines changed or deleted 269 lines changed or added


 field_proto.hpp   field_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Ian Cullinan (ian dot cullinan at nicta dot com dot au)
// //
// 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 55 skipping to change at line 57
inline const field& operator=(const field& x); inline const field& operator=(const field& x);
inline field(const subview_field<oT>& x); inline field(const subview_field<oT>& x);
inline const field& operator=(const subview_field<oT>& x); inline const field& operator=(const subview_field<oT>& x);
inline explicit field(const u32 n_elem_in); inline explicit field(const u32 n_elem_in);
inline field(const u32 n_rows_in, const u32 n_cols_in); inline field(const u32 n_rows_in, const u32 n_cols_in);
inline void set_size(const u32 n_obj_in); inline void set_size(const u32 n_obj_in);
inline void set_size(const u32 n_rows_in, const u32 n_cols_in); inline void set_size(const u32 n_rows_in, const u32 n_cols_in);
inline void copy_size(const field& x);
template<typename oT2>
inline void copy_size(const field<oT2>& x);
arma_inline oT& operator[](const u32 i); arma_inline oT& operator[](const u32 i);
arma_inline const oT& operator[](const u32 i) const; arma_inline const oT& operator[](const u32 i) const;
arma_inline oT& operator()(const u32 i); arma_inline oT& operator()(const u32 i);
arma_inline const oT& operator()(const u32 i) const; arma_inline const oT& operator()(const u32 i) const;
arma_inline oT& at(const u32 row, const u32 col); arma_inline oT& at(const u32 row, const u32 col);
arma_inline const oT& at(const u32 row, const u32 col) const; arma_inline const oT& at(const u32 row, const u32 col) const;
skipping to change at line 92 skipping to change at line 96
inline const subview_field<oT> subfield(const u32 in_row1, const u32 in_c ol1, const u32 in_row2, const u32 in_col2) const; inline const subview_field<oT> subfield(const u32 in_row1, const u32 in_c ol1, const u32 in_row2, const u32 in_col2) const;
inline void print(const std::string extra_text = "") const; inline void print(const std::string extra_text = "") const;
inline void print(std::ostream& user_stream, const std::string extra_text = "") const; inline void print(std::ostream& user_stream, const std::string extra_text = "") const;
inline void fill(const oT& x); inline void fill(const oT& x);
inline void reset(); inline void reset();
inline void reset_objects(); inline void reset_objects();
inline void save(const std::string name, const file_type type = arma_bina inline void save(const std::string name, const file_type type = arma_bi
ry) const; nary) const;
inline void load(const std::string name, const file_type type = auto_dete inline void save( std::ostream& os, const file_type type = arma_bi
ct); nary) const;
inline void load(const std::string name, const file_type type = auto_de
tect);
inline void load( std::istream& is, const file_type type = auto_de
tect);
private: private:
inline void init(const field<oT>& x); inline void init(const field<oT>& x);
inline void init(const u32 n_rows_in, const u32 n_cols_in); inline void init(const u32 n_rows_in, const u32 n_cols_in);
inline void delete_objects(); inline void delete_objects();
inline void create_objects(); inline void create_objects();
friend class field_aux; friend class field_aux;
skipping to change at line 119 skipping to change at line 126
public: public:
template<typename oT> inline static void reset_objects(field< oT >& x); template<typename oT> inline static void reset_objects(field< oT >& x);
template<typename eT> inline static void reset_objects(field< Mat<eT> >& x); template<typename eT> inline static void reset_objects(field< Mat<eT> >& x);
template<typename eT> inline static void reset_objects(field< Col<eT> >& x); template<typename eT> inline static void reset_objects(field< Col<eT> >& x);
template<typename eT> inline static void reset_objects(field< Row<eT> >& x); template<typename eT> inline static void reset_objects(field< Row<eT> >& x);
template<typename eT> inline static void reset_objects(field< Cube<eT> >& x); template<typename eT> inline static void reset_objects(field< Cube<eT> >& x);
inline static void reset_objects(field< std::string >& x); inline static void reset_objects(field< std::string >& x);
template<typename oT> inline static void save(const field< oT >& x, const std::string& name, const file_type type); template<typename oT> inline static void save(const field< oT >& x, const std::string& name, const file_type type);
template<typename oT> inline static void save(const field< oT >& x, std::ostream& os, const file_type type);
template<typename oT> inline static void load( field< oT >& x, const std::string& name, const file_type type); template<typename oT> inline static void load( field< oT >& x, const std::string& name, const file_type type);
template<typename oT> inline static void load( field< oT >& x, std::istream& is, const file_type type);
template<typename eT> inline static void save(const field< Mat<eT> >& x, const std::string& name, const file_type type); template<typename eT> inline static void save(const field< Mat<eT> >& x, const std::string& name, const file_type type);
template<typename eT> inline static void save(const field< Mat<eT> >& x, std::ostream& os, const file_type type);
template<typename eT> inline static void load( field< Mat<eT> >& x, const std::string& name, const file_type type); template<typename eT> inline static void load( field< Mat<eT> >& x, const std::string& name, const file_type type);
template<typename eT> inline static void load( field< Mat<eT> >& x, std::istream& is, const file_type type);
template<typename eT> inline static void save(const field< Col<eT> >& x, const std::string& name, const file_type type); template<typename eT> inline static void save(const field< Col<eT> >& x, const std::string& name, const file_type type);
template<typename eT> inline static void save(const field< Col<eT> >& x, std::ostream& os, const file_type type);
template<typename eT> inline static void load( field< Col<eT> >& x, const std::string& name, const file_type type); template<typename eT> inline static void load( field< Col<eT> >& x, const std::string& name, const file_type type);
template<typename eT> inline static void load( field< Col<eT> >& x, std::istream& is, const file_type type);
template<typename eT> inline static void save(const field< Row<eT> >& x, const std::string& name, const file_type type); template<typename eT> inline static void save(const field< Row<eT> >& x, const std::string& name, const file_type type);
template<typename eT> inline static void save(const field< Row<eT> >& x, std::ostream& os, const file_type type);
template<typename eT> inline static void load( field< Row<eT> >& x, const std::string& name, const file_type type); template<typename eT> inline static void load( field< Row<eT> >& x, const std::string& name, const file_type type);
template<typename eT> inline static void load( field< Row<eT> >& x, std::istream& is, const file_type type);
template<typename eT> inline static void save(const field< Cube<eT> >& x, const std::string& name, const file_type type); template<typename eT> inline static void save(const field< Cube<eT> >& x, const std::string& name, const file_type type);
template<typename eT> inline static void save(const field< Cube<eT> >& x, std::ostream& os, const file_type type);
template<typename eT> inline static void load( field< Cube<eT> >& x, const std::string& name, const file_type type); template<typename eT> inline static void load( field< Cube<eT> >& x, const std::string& name, const file_type type);
template<typename eT> inline static void load( field< Cube<eT> >& x, std::istream& is, const file_type type);
inline static void save(const field< std::string >& x, const std::string& name, const file_type type); inline static void save(const field< std::string >& x, const std::string& name, const file_type type);
inline static void save(const field< std::string >& x, std::ostream& os, const file_type type);
inline static void load( field< std::string >& x, const std::string& name, const file_type type); inline static void load( field< std::string >& x, const std::string& name, const file_type type);
inline static void load( field< std::string >& x, std::istream& is, const file_type type);
}; };
//! @} //! @}
 End of changes. 16 change blocks. 
6 lines changed or deleted 27 lines changed or added


 fn_accu.hpp   fn_accu.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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_accu //! \addtogroup fn_accu
//! @{ //! @{
//! accumulate the elements of a matrix
template<typename T1> template<typename T1>
arma_hot
inline inline
typename T1::elem_type typename T1::elem_type
accu(const Base<typename T1::elem_type,T1>& X) accu_unwrap(const Base<typename T1::elem_type,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
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;
const u32 A_n_elem = A.n_elem; const u32 N = A.n_elem;
const eT* A_mem = A.mem;
eT val = eT(0); eT val = eT(0);
for(u32 i=0; i<A_n_elem; ++i) for(u32 i=0; i<N; ++i)
{ {
val += A_mem[i]; val += A[i];
} }
return val; return val;
} }
//! accumulate the elements of a cube
template<typename T1> template<typename T1>
arma_hot
inline inline
typename T1::elem_type typename T1::elem_type
accu(const BaseCube<typename T1::elem_type,T1>& X) accu_proxy(const Base<typename T1::elem_type,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
const unwrap_cube<T1> tmp(X.get_ref()); const Proxy<T1> A(X.get_ref());
const Cube<eT>& A = tmp.M;
const u32 A_n_elem = A.n_elem; const u32 N = A.n_elem;
const eT* A_mem = A.mem;
eT val = eT(0); eT val = eT(0);
for(u32 i=0; i<A_n_elem; ++i) for(u32 i=0; i<N; ++i)
{ {
val += A_mem[i]; val += A[i];
} }
return val; return val;
} }
#if defined(ARMA_GOOD_COMPILER) //! accumulate the elements of a matrix
//! sum of squares
template<typename T1>
inline
typename T1::elem_type
accu(const Op<T1, op_square>& in)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const unwrap<T1> tmp(in.m);
const Mat<eT>& A = tmp.M;
const u32 A_n_elem = A.n_elem;
const eT* A_mem = A.mem;
eT acc = eT(0);
for(u32 i=0; i<A_n_elem; ++i)
{
const eT val = A_mem[i];
acc += val*val;
}
return acc;
}
//! sum of squares
template<typename T1>
inline
typename T1::elem_type
accu(const OpCube<T1, op_square>& in)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const unwrap_cube<T1> tmp(in.m);
const Cube<eT>& A = tmp.M;
const u32 A_n_elem = A.n_elem;
const eT* A_mem = A.mem;
eT acc = eT(0);
for(u32 i=0; i<A_n_elem; ++i)
{
const eT val = A_mem[i];
acc += val*val;
}
return acc;
}
//! sum of square roots
template<typename T1> template<typename T1>
inline arma_inline
typename T1::elem_type typename T1::elem_type
accu(const Op<T1, op_sqrt>& in) accu(const Base<typename T1::elem_type,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; return (is_Mat<T1>::value == true) ? accu_unwrap(X) : accu_proxy(X);
const unwrap<T1> tmp(in.m);
const Mat<eT>& A = tmp.M;
const u32 A_n_elem = A.n_elem;
const eT* A_mem = A.mem;
eT acc = eT(0);
for(u32 i=0; i<A_n_elem; ++i)
{
acc += std::sqrt(A_mem[i]);
}
return acc;
} }
//! sum of square roots //! accumulate the elements of a cube
template<typename T1> template<typename T1>
arma_hot
inline inline
typename T1::elem_type typename T1::elem_type
accu(const OpCube<T1, op_sqrt>& in) accu(const BaseCube<typename T1::elem_type,T1>& X)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const unwrap_cube<T1> tmp(in.m);
const Cube<eT>& A = tmp.M;
const u32 A_n_elem = A.n_elem;
const eT* A_mem = A.mem;
eT acc = eT(0);
for(u32 i=0; i<A_n_elem; ++i)
{
acc += std::sqrt(A_mem[i]);
}
return acc;
}
//! sum of squares of differences
template<typename T1, typename T2>
inline
typename T1::elem_type
accu(const Op< Glue<T1,T2, glue_minus>, op_square>& in)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const unwrap<T1> tmp1(in.m.A);
const unwrap<T2> tmp2(in.m.B);
const Mat<eT>& A = tmp1.M;
const Mat<eT>& B = tmp2.M;
arma_debug_assert_same_size(A,B, "accu()");
const u32 n_elem = A.n_elem;
eT acc = eT(0);
for(u32 i=0; i<n_elem; ++i)
{
const eT val = A.mem[i] - B.mem[i];
acc += val*val;
}
return acc;
}
//! sum of squares of differences
template<typename T1, typename T2>
inline
typename T1::elem_type
accu(const OpCube< GlueCube<T1,T2, glue_cube_minus>, op_square>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
const unwrap_cube<T1> tmp1(in.m.A); const ProxyCube<T1> A(X.get_ref());
const unwrap_cube<T2> tmp2(in.m.B);
const Cube<eT>& A = tmp1.M;
const Cube<eT>& B = tmp2.M;
arma_debug_assert_same_size(A,B, "accu()");
const u32 n_elem = A.n_elem;
eT acc = eT(0);
for(u32 i=0; i<n_elem; ++i)
{
const eT val = A.mem[i] - B.mem[i];
acc += val*val;
}
return acc;
}
//! accumulate the result of A % B, where % is the Schur product (element-w
ise multiplication)
template<typename eT>
inline
eT
accu_schur(const Mat<eT>& A, const Mat<eT>& B)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(A,B, "accu()");
const eT* const A_mem = A.mem;
const eT* const B_mem = B.mem;
const u32 n_elem = A.n_elem;
eT val = eT(0);
for(u32 i=0; i<n_elem; ++i)
{
val += A_mem[i] * B_mem[i];
}
return val;
}
//! accumulate the result of A % B, where % is the Schur product (element-w
ise multiplication)
template<typename eT>
inline
eT
accu_schur(const Cube<eT>& A, const Cube<eT>& B)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(A,B, "accu()");
const eT* const A_mem = A.mem;
const eT* const B_mem = B.mem;
const u32 n_elem = A.n_elem; const u32 n_elem = A.n_elem;
eT val = eT(0);
for(u32 i=0; i<n_elem; ++i)
{
val += A_mem[i] * B_mem[i];
}
return val;
}
//! accumulate the result of A % B, where % is the Schur product (element-w
ise multiplication)
template<typename eT>
inline
eT
accu(const Glue<Mat<eT>,Mat<eT>,glue_schur>& X)
{
return accu_schur(X.A, X.B);
}
//! accumulate the result of A % B, where % is the Schur product (element-w
ise multiplication)
template<typename eT>
inline
eT
accu(const GlueCube< Cube<eT>, Cube<eT>, glue_cube_schur >& X)
{
return accu_schur(X.A, X.B);
}
//! accumulate the result of A % B % C, where % is the Schur product (eleme
nt-wise multiplication)
template<typename eT>
inline
eT
accu(const Glue<Glue<Mat<eT>,Mat<eT>,glue_schur>,Mat<eT>,glue_schur>& X)
{
arma_extra_debug_sigprint();
const Mat<eT>& A = X.A.A;
const Mat<eT>& B = X.A.B;
const Mat<eT>& C = X.B;
arma_debug_assert_same_size(A,B, "accu()");
arma_debug_assert_same_size(A,C, "accu()");
const eT* const A_mem = A.mem;
const eT* const B_mem = B.mem;
const eT* const C_mem = C.mem;
const u32 n_elem = A.n_elem;
eT val = eT(0); eT val = eT(0);
for(u32 i=0; i<n_elem; ++i) for(u32 i=0; i<n_elem; ++i)
{ {
val += A_mem[i] * B_mem[i] * C_mem[i]; val += A[i];
} }
return val; return val;
} }
//! accumulate the result of A % B % C, where % is the Schur product (eleme
nt-wise multiplication)
template<typename eT>
inline
eT
accu(const GlueCube< GlueCube< Cube<eT>, Cube<eT>, glue_cube_schur >, Cube<
eT>, glue_cube_schur >& X)
{
arma_extra_debug_sigprint();
const Cube<eT>& A = X.A.A;
const Cube<eT>& B = X.A.B;
const Cube<eT>& C = X.B;
arma_debug_assert_same_size(A,B, "accu()");
arma_debug_assert_same_size(B,C, "accu()");
const eT* const A_mem = A.mem;
const eT* const B_mem = B.mem;
const eT* const C_mem = C.mem;
const u32 n_elem = A.n_elem;
eT val = eT(0);
for(u32 i=0; i<n_elem; ++i)
{
val += A_mem[i] * B_mem[i] * C_mem[i];
}
return val;
}
//! \brief
//! accumulate the result of T1 % T2
//! where % is the Schur product (element-wise multiplication),
//! while T1 and T2 can be 'mat', 'rowvec', 'colvec', 'Op', 'Glue'
template<typename T1, typename T2>
inline
typename T1::elem_type
accu(const Glue<T1,T2,glue_schur>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<typename T1::elem_type, typename T2::elem_type>::check();
typedef typename T1::elem_type eT;
const u32 N_mat = 1 + depth_lhs< glue_schur, Glue<T1,T2,glue_schur> >::nu
m;
arma_extra_debug_print( arma_boost::format("N_mat = %d") % N_mat );
if(N_mat == 2)
{
const unwrap<T1> tmp1(X.A);
const unwrap<T2> tmp2(X.B);
return accu_schur(tmp1.M, tmp2.M);
}
else
{
const Mat<eT>* ptrs[N_mat];
bool del[N_mat];
mat_ptrs<glue_schur, Glue<T1,T2,glue_schur> >::get_ptrs(ptrs, del, X);
for(u32 i=0; i<N_mat; ++i) arma_extra_debug_print( arma_boost::format(
"ptrs[%d] = %x") % i % ptrs[i] );
for(u32 i=0; i<N_mat; ++i) arma_extra_debug_print( arma_boost::format(
" del[%d] = %d") % i % del[i] );
const Mat<eT>& tmp_mat = *(ptrs[0]);
for(u32 i=1; i<N_mat; ++i)
{
arma_debug_assert_same_size(tmp_mat, *(ptrs[i]), "accu()");
}
// const u32 n_rows = ptrs[0]->n_rows;
// const u32 n_cols = ptrs[0]->n_cols;
eT val = eT(0);
const u32 n_elem = ptrs[0]->n_elem;
for(u32 j=0; j<n_elem; ++j)
{
eT tmp = ptrs[0]->mem[j];
for(u32 i=1; i<N_mat; ++i)
{
tmp *= ptrs[i]->mem[j];
}
val += tmp;
}
for(u32 i=0; i<N_mat; ++i)
{
if(del[i] == true)
{
arma_extra_debug_print( arma_boost::format("delete mat_ptr[%d]") %
i );
delete ptrs[i];
}
}
return val;
}
}
//! sum of values along the main diagonal
template<typename T1>
inline
typename T1::elem_type
accu(const Op<T1, op_diagmat>& X)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const unwrap<T1> tmp(X.m);
const Mat<eT>& A = tmp.M;
arma_debug_check( !A.is_square(), "accu(): sum of diagonal values of a no
n-square matrix requested" );
eT acc = eT(0);
for(u32 i=0; i<A.n_rows; ++i)
{
acc += A.at(i,i);
}
return acc;
}
template<typename eT>
inline
eT
accu(const Op<Mat<eT>, op_diagmat_vec>& X)
{
arma_extra_debug_sigprint();
const Mat<eT>& A = X.m;
arma_debug_check( !A.is_vec(), "accu(): internal error: expected a vector
" );
return accu(A);
}
//! accumulate the elements of a diagview //! accumulate the elements of a diagview
template<typename eT> template<typename eT>
inline inline
eT eT
accu(const diagview<eT>& X) accu(const diagview<eT>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const u32 n_elem = X.n_elem; const u32 n_elem = X.n_elem;
eT val = eT(0); eT val = eT(0);
skipping to change at line 563 skipping to change at line 192
eT val = eT(0); eT val = eT(0);
for(u32 row=0; row<n_rows; ++row) for(u32 row=0; row<n_rows; ++row)
{ {
val += S_colptr[row]; val += S_colptr[row];
} }
return val; return val;
} }
//! accumulate the result of submatrix % matrix, where % is the Schur produ
ct (element-wise multiplication)
template<typename eT>
inline
eT
accu(const Glue<subview<eT>,Mat<eT>,glue_schur>& X)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(X.A, X.B, "accu()");
const Mat<eT>& A = X.A.m;
const Mat<eT>& B = X.B;
const u32 A_sub_n_rows = X.A.n_rows;
const u32 A_sub_n_cols = X.A.n_cols;
const u32 A_aux_row1 = X.A.aux_row1;
const u32 A_aux_col1 = X.A.aux_col1;
eT val = eT(0);
for(u32 col = 0; col<A_sub_n_cols; ++col)
{
const u32 col_mod = A_aux_col1 + col;
for(u32 row = 0; row<A_sub_n_rows; ++row)
{
const u32 row_mod = A_aux_row1 + row;
val += A.at(row_mod, col_mod) * B.at(row,col);
}
}
return val;
}
//! accumulate the result of matrix % submatrix, where % is the Schur produ
ct (element-wise multiplication)
template<typename eT>
inline
eT
accu(const Glue<Mat<eT>,subview<eT>,glue_schur>& X)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(X.A, X.B, "accu()");
const Mat<eT>& A = X.A;
const Mat<eT>& B = X.B.m;
// const u32 B_sub_n_rows = X.B.n_rows;
// const u32 B_sub_n_cols = X.B.n_cols;
const u32 B_aux_row1 = X.B.aux_row1;
const u32 B_aux_col1 = X.B.aux_col1;
eT val = eT(0);
for(u32 col = 0; col<A.n_cols; ++col)
{
const u32 col_mod = B_aux_col1 + col;
for(u32 row = 0; row<A.n_rows; ++row)
{
const u32 row_mod = B_aux_row1 + row;
val += A.at(row, col) * B.at(row_mod, col_mod);
}
}
return val;
}
//! accumulate the result of submatrix % submatrix, where % is the Schur pr
oduct (element-wise multiplication)
template<typename eT>
inline
eT
accu(const Glue<subview<eT>,subview<eT>,glue_schur>& X)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(X.A, X.B, "accu()");
const Mat<eT>& A = X.A.m;
const Mat<eT>& B = X.B.m;
const u32 A_sub_n_rows = X.A.n_rows;
const u32 A_sub_n_cols = X.A.n_cols;
// const u32 B_sub_n_rows = X.B.n_rows;
// const u32 B_sub_n_cols = X.B.n_cols;
const u32 A_aux_row1 = X.A.aux_row1;
const u32 A_aux_col1 = X.A.aux_col1;
const u32 B_aux_row1 = X.B.aux_row1;
const u32 B_aux_col1 = X.B.aux_col1;
eT val = eT(0);
for(u32 col = 0; col<A_sub_n_cols; ++col)
{
const u32 A_col_mod = A_aux_col1 + col;
const u32 B_col_mod = B_aux_col1 + col;
for(u32 row = 0; row<A_sub_n_rows; ++row)
{
const u32 A_row_mod = A_aux_row1 + row;
const u32 B_row_mod = B_aux_row1 + row;
val += A.at(A_row_mod, A_col_mod) * B.at(B_row_mod, B_col_mod);
}
}
return val;
}
#endif
//! @} //! @}
 End of changes. 28 change blocks. 
531 lines changed or deleted 23 lines changed or added


 fn_as_scalar.hpp   fn_as_scalar.hpp 
skipping to change at line 19 skipping to change at line 19
// 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_as_scalar //! \addtogroup fn_as_scalar
//! @{ //! @{
template<u32 N>
struct as_scalar_redirect
{
template<typename T1>
inline static typename T1::elem_type apply(const T1& X);
};
template<>
struct as_scalar_redirect<2>
{
template<typename T1, typename T2>
inline static typename T1::elem_type apply(const Glue<T1,T2,glue_times>&
X);
};
template<>
struct as_scalar_redirect<3>
{
template<typename T1, typename T2, typename T3>
inline static typename T1::elem_type apply(const Glue< Glue<T1, T2, glue_
times>, T3, glue_times>& X);
};
template<u32 N>
template<typename T1>
inline
typename T1::elem_type
as_scalar_redirect<N>::apply(const T1& X)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const unwrap<T1> tmp(X);
const Mat<eT>& A = tmp.M;
arma_debug_check( (A.n_elem != 1), "as_scalar(): expression doesn't evalu
ate to exactly one element" );
return A.mem[0];
}
template<typename T1, typename T2>
inline
typename T1::elem_type
as_scalar_redirect<2>::apply(const Glue<T1, T2, glue_times>& X)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
// T1 must result in a matrix with one row
// T2 must result in a matrix with one column
const partial_unwrap<T1> tmp1(X.A);
const partial_unwrap<T2> tmp2(X.B);
const Mat<eT>& A = tmp1.M;
const Mat<eT>& B = tmp2.M;
const u32 A_n_rows = (tmp1.do_trans == false) ? A.n_rows : A.n_cols;
const u32 A_n_cols = (tmp1.do_trans == false) ? A.n_cols : A.n_rows;
const u32 B_n_rows = (tmp2.do_trans == false) ? B.n_rows : B.n_cols;
const u32 B_n_cols = (tmp2.do_trans == false) ? B.n_cols : B.n_rows;
const eT val = tmp1.val * tmp2.val;
arma_debug_check( (A_n_rows != 1) || (B_n_cols != 1) || (A_n_cols != B_n_
rows), "as_scalar(): incompatible dimensions" );
return val * op_dot::direct_dot(A.n_elem, A.mem, B.mem);
}
template<typename T1, typename T2, typename T3>
inline
typename T1::elem_type
as_scalar_redirect<3>::apply(const Glue< Glue<T1, T2, glue_times>, T3, glue
_times >& X)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
// T1 * T2 must result in a matrix with one row
// T3 must result in a matrix with one column
typedef typename strip_inv <T2 >::stored_type T2_stripped_1;
typedef typename strip_diagmat<T2_stripped_1>::stored_type T2_stripped_2;
const strip_inv <T2> strip1(X.A.B);
const strip_diagmat<T2_stripped_1> strip2(strip1.M);
const bool tmp2_do_inv = strip1.do_inv;
const bool tmp2_do_diagmat = strip2.do_diagmat;
const partial_unwrap<T1> tmp1(X.A.A);
const partial_unwrap<T2_stripped_2> tmp2(strip2.M);
const partial_unwrap<T3> tmp3(X.B);
const Mat<eT>& A = tmp1.M;
const Mat<eT>& B = tmp2.M;
const Mat<eT>& C = tmp3.M;
if(tmp2_do_diagmat == false)
{
const u32 A_n_rows = (tmp1.do_trans == false) ? A.n_rows : A.n_cols;
const u32 A_n_cols = (tmp1.do_trans == false) ? A.n_cols : A.n_rows;
const u32 B_n_rows = (tmp2.do_trans == false) ? B.n_rows : B.n_cols;
const u32 B_n_cols = (tmp2.do_trans == false) ? B.n_cols : B.n_rows;
const u32 C_n_rows = (tmp3.do_trans == false) ? C.n_rows : C.n_cols;
const u32 C_n_cols = (tmp3.do_trans == false) ? C.n_cols : C.n_rows;
const eT val = tmp1.val * tmp2.val * tmp3.val;
arma_debug_check
(
(A_n_rows != 1) ||
(C_n_cols != 1) ||
(A_n_cols != B_n_rows) ||
(B_n_cols != C_n_rows)
,
"as_scalar(): incompatible dimensions"
);
if(tmp2_do_inv == true)
{
arma_debug_check( (B.is_square() == false), "as_scalar(): incompatibl
e dimensions" );
Mat<eT> B_inv;
if(tmp2.do_trans == false)
{
op_inv::apply(B_inv, B);
}
else
{
const Mat<eT> B_trans = trans(B);
op_inv::apply(B_inv, B_trans);
}
return val * op_dotext::direct_rowvec_mat_colvec(A.mem, B_inv, C.mem)
;
}
else
{
if(tmp2.do_trans == false)
{
return val * op_dotext::direct_rowvec_mat_colvec(A.mem, B, C.mem);
}
else
{
return val * op_dotext::direct_rowvec_transmat_colvec(A.mem, B, C.m
em);
}
}
}
else
{
const u32 A_n_rows = (tmp1.do_trans == false) ? A.n_rows : A.n_cols;
const u32 A_n_cols = (tmp1.do_trans == false) ? A.n_cols : A.n_rows;
const bool B_is_vec = B.is_vec();
const u32 B_n_rows = (B_is_vec == true) ? B.n_elem : ( (tmp2.do_trans =
= false) ? B.n_rows : B.n_cols );
const u32 B_n_cols = (B_is_vec == true) ? B.n_elem : ( (tmp2.do_trans =
= false) ? B.n_cols : B.n_rows );
const u32 C_n_rows = (tmp3.do_trans == false) ? C.n_rows : C.n_cols;
const u32 C_n_cols = (tmp3.do_trans == false) ? C.n_cols : C.n_rows;
const eT val = tmp1.val * tmp2.val * tmp3.val;
arma_debug_check
(
(A_n_rows != 1) ||
(C_n_cols != 1) ||
(A_n_cols != B_n_rows) ||
(B_n_cols != C_n_rows)
,
"as_scalar(): incompatible dimensions"
);
if(B_is_vec == true)
{
if(tmp2_do_inv == true)
{
return val * op_dotext::direct_rowvec_invdiagvec_colvec(A.mem, B, C
.mem);
}
else
{
return val * op_dot::direct_dot(A.n_elem, A.mem, B.mem, C.mem);
}
}
else
{
if(tmp2_do_inv == true)
{
return val * op_dotext::direct_rowvec_invdiagmat_colvec(A.mem, B, C
.mem);
}
else
{
return val * op_dotext::direct_rowvec_diagmat_colvec(A.mem, B, C.me
m);
}
}
}
}
template<typename T1>
inline
typename T1::elem_type
as_scalar_diag(const Base<typename T1::elem_type,T1>& X)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const unwrap<T1> tmp(X.get_ref());
const Mat<eT>& A = tmp.M;
arma_debug_check( (A.n_elem != 1), "as_scalar(): expression doesn't evalu
ate to exactly one element" );
return A.mem[0];
}
template<typename T1, typename T2, typename T3>
inline
typename T1::elem_type
as_scalar_diag(const Glue< Glue<T1, T2, glue_times_diag>, T3, glue_times >&
X)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
// T1 * T2 must result in a matrix with one row
// T3 must result in a matrix with one column
typedef typename strip_diagmat<T2>::stored_type T2_stripped;
const strip_diagmat<T2> strip(X.A.B);
const partial_unwrap<T1> tmp1(X.A.A);
const partial_unwrap<T2_stripped> tmp2(strip.M);
const partial_unwrap<T3> tmp3(X.B);
const Mat<eT>& A = tmp1.M;
const Mat<eT>& B = tmp2.M;
const Mat<eT>& C = tmp3.M;
const u32 A_n_rows = (tmp1.do_trans == false) ? A.n_rows : A.n_cols;
const u32 A_n_cols = (tmp1.do_trans == false) ? A.n_cols : A.n_rows;
const bool B_is_vec = B.is_vec();
const u32 B_n_rows = (B_is_vec == true) ? B.n_elem : ( (tmp2.do_trans ==
false) ? B.n_rows : B.n_cols );
const u32 B_n_cols = (B_is_vec == true) ? B.n_elem : ( (tmp2.do_trans ==
false) ? B.n_cols : B.n_rows );
const u32 C_n_rows = (tmp3.do_trans == false) ? C.n_rows : C.n_cols;
const u32 C_n_cols = (tmp3.do_trans == false) ? C.n_cols : C.n_rows;
const eT val = tmp1.val * tmp2.val * tmp3.val;
arma_debug_check
(
(A_n_rows != 1) ||
(C_n_cols != 1) ||
(A_n_cols != B_n_rows) ||
(B_n_cols != C_n_rows)
,
"as_scalar(): incompatible dimensions"
);
if(B_is_vec == true)
{
return val * op_dot::direct_dot(A.n_elem, A.mem, B.mem, C.mem);
}
else
{
return val * op_dotext::direct_rowvec_diagmat_colvec(A.mem, B, C.mem);
}
}
template<typename T1, typename T2>
arma_inline
typename T1::elem_type
as_scalar(const Glue<T1, T2, glue_times>& X)
{
arma_extra_debug_sigprint();
if(is_glue_times_diag<T1>::value == false)
{
const s32 N_mat = 1 + depth_lhs< glue_times, Glue<T1,T2,glue_times> >::
num;
arma_extra_debug_print(arma_boost::format("N_mat = %d") % N_mat);
return as_scalar_redirect<N_mat>::apply(X);
}
else
{
return as_scalar_diag(X);
}
}
template<typename T1> template<typename T1>
inline inline
typename T1::elem_type typename T1::elem_type
as_scalar(const Base<typename T1::elem_type,T1>& X) as_scalar(const Base<typename T1::elem_type,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
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;
arma_debug_check( (A.n_elem != 1), "as_scalar(): expression doesn't evalu ate to exactly one element" ); arma_debug_check( (A.n_elem != 1), "as_scalar(): expression doesn't evalu ate to exactly one element" );
return A.mem[0]; return A.mem[0];
} }
template<typename T1> template<typename T1>
arma_inline
typename T1::elem_type
as_scalar(const eOp<T1, eop_neg>& X)
{
arma_extra_debug_sigprint();
return -(as_scalar(X.P.Q));
}
template<typename T1>
inline inline
typename T1::elem_type typename T1::elem_type
as_scalar(const BaseCube<typename T1::elem_type,T1>& X) as_scalar(const BaseCube<typename T1::elem_type,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
const unwrap_cube<T1> tmp(X.get_ref()); const unwrap_cube<T1> tmp(X.get_ref());
const Cube<eT>& A = tmp.M; const Cube<eT>& A = tmp.M;
arma_debug_check( (A.n_elem != 1), "as_scalar(): expression doesn't evalu ate to exactly one element" ); arma_debug_check( (A.n_elem != 1), "as_scalar(): expression doesn't evalu ate to exactly one element" );
return A.mem[0]; return A.mem[0];
} }
template<typename T> struct arma_scalar_only { };
template<> struct arma_scalar_only<char> { typedef char result; };
template<> struct arma_scalar_only<short> { typedef short result; };
template<> struct arma_scalar_only<int> { typedef int result; };
template<> struct arma_scalar_only<long> { typedef long result; };
template<> struct arma_scalar_only<float> { typedef float result; };
template<> struct arma_scalar_only<double> { typedef double result; };
template<> struct arma_scalar_only<unsigned char> { typedef unsigned char
result; };
template<> struct arma_scalar_only<unsigned short> { typedef unsigned short
result; };
template<> struct arma_scalar_only<unsigned int> { typedef unsigned int
result; };
template<> struct arma_scalar_only<unsigned long> { typedef unsigned long
result; };
template<typename T> struct arma_scalar_only< std::complex<T> > { typedef s
td::complex<T> result; };
template<typename T> template<typename T>
arma_inline arma_inline
const typename arma_scalar_only<T>::result & const typename arma_scalar_only<T>::result &
as_scalar(const T& x) as_scalar(const T& x)
{ {
return x; return x;
} }
//! @} //! @}
 End of changes. 3 change blocks. 
21 lines changed or deleted 325 lines changed or added


 fn_chol.hpp   fn_chol.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 fn_conv_to.hpp   fn_conv_to.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 23 skipping to change at line 24
// (see http://www.opensource.org/licenses for more info) // (see http://www.opensource.org/licenses for more info)
//! \addtogroup fn_conv_to //! \addtogroup fn_conv_to
//! @{ //! @{
// //
// //
// conversions between various mat types // conversions between various mat types
template<typename out_eT, typename in_eT> template<typename out_eT, typename in_eT>
inline arma_inline
void void
copy_complex_elem(out_eT& out, const in_eT& in) copy_complex_elem(out_eT& out, const in_eT& in)
{ {
//arma_extra_debug_sigprint(); //arma_extra_debug_sigprint();
out = out_eT(in); out = out_eT(in);
} }
template<typename out_eT, typename in_T> template<typename out_eT, typename in_T>
inline arma_inline
void void
copy_complex_elem(out_eT& out, const std::complex<in_T>& in) copy_complex_elem(out_eT& out, const std::complex<in_T>& in)
{ {
//arma_extra_debug_sigprint(); //arma_extra_debug_sigprint();
out = out_eT( in.real() ); out = out_eT( in.real() );
} }
template<typename out_T, typename in_T> template<typename out_T, typename in_T>
inline arma_inline
void void
copy_complex_elem(std::complex<out_T>& out, const std::complex<in_T>& in) copy_complex_elem(std::complex<out_T>& out, const std::complex<in_T>& in)
{ {
//arma_extra_debug_sigprint(); //arma_extra_debug_sigprint();
typedef std::complex<out_T> out_eT; typedef std::complex<out_T> out_eT;
out = out_eT(in); out = out_eT(in);
} }
// //
 End of changes. 4 change blocks. 
4 lines changed or deleted 5 lines changed or added


 fn_cor.hpp   fn_cor.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
 End of changes. 1 change blocks. 
2 lines changed or deleted 2 lines changed or added


 fn_cov.hpp   fn_cov.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
 End of changes. 1 change blocks. 
2 lines changed or deleted 2 lines changed or added


 fn_det.hpp   fn_det.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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_det //! \addtogroup fn_det
//! @{ //! @{
template<typename T1> inline typename T1::elem_type det(const Base<typename
T1::elem_type,T1>& X);
template<typename T1> inline typename T1::elem_type det(const Op<T1, op_dia
gmat>& X);
template<typename eT> inline eT det(const Op<Mat<eT>, op_diagmat_vec>& X);
template<typename T1, typename T2> inline typename T1::elem_type det(const
Glue<T1, T2, glue_times>& X);
template<typename T1> inline typename T1::elem_type det(const Op<T1,op_inv>
& in);
template<typename T1> inline typename T1::elem_type det(const Op<T1,op_tran
s>& in);
//! determinant of mat //! determinant of mat
template<typename T1> template<typename T1>
inline inline
typename T1::elem_type typename T1::elem_type
det(const Base<typename T1::elem_type,T1>& X) det(const Base<typename T1::elem_type,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
const unwrap<T1> A_tmp(X.get_ref()); const unwrap<T1> tmp(X.get_ref());
const Mat<eT>& A = A_tmp.M; const Mat<eT>& A = tmp.M;
arma_debug_check( !A.is_square(), "det(): matrix must be square" ); arma_debug_check( !A.is_square(), "det(): matrix must be square" );
return auxlib::det(A); return auxlib::det(A);
} }
//! determinant of diagmat(mat) //! determinant of diagmat
template<typename T1> template<typename T1>
inline inline
typename T1::elem_type typename T1::elem_type
det(const Op<T1, op_diagmat>& X) det(const Op<T1, op_diagmat>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap<T1> A_tmp(X.m);
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
const Mat<eT>& A = A_tmp.M;
arma_debug_check( (A.n_elem == 0), "det(): empty matrix");
arma_debug_check( !A.is_square(), "det(): incompatible dimensions for dia
gmat operation" );
eT val = A.at(0,0);
for(u32 i=1; i<A.n_rows; ++i)
{
val *= A.at(i,i);
}
return val;
}
//! determinant of diagmat(colvec or rowvec)
template<typename eT>
inline
eT
det(const Op<Mat<eT>, op_diagmat_vec>& X)
{
arma_extra_debug_sigprint();
const Mat<eT>& A = X.m; const diagmat_proxy<T1> A(X.m);
arma_debug_check( (A.n_elem == 0), "det(): empty matrix"); arma_debug_check( (A.n_elem == 0), "det(): given object has no elements"
arma_debug_check( !A.is_vec(), "det_diagvec(): internal error: can't inte );
rpret as a vector" );
eT val = A.mem[0]; eT val = A[0];
for(u32 i=1; i<A.n_elem; ++i) for(u32 i=1; i<A.n_elem; ++i)
{ {
val *= A.mem[i]; val *= A[i];
} }
return val; return val;
} }
//! determinant of A*B, avoiding the times operation if A and B are square
matrices with the same dimensions
template<typename T1, typename T2>
inline
typename T1::elem_type
det(const Glue<T1,T2,glue_times>& X)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const unwrap<T1> tmp1(X.A);
const unwrap<T2> tmp2(X.B);
const Mat<eT>& A = tmp1.M;
const Mat<eT>& B = tmp2.M;
if( (A.n_rows == A.n_cols) && (A.n_rows == B.n_rows) && (A.n_cols == B.n_
cols) )
{
return det(A) * det(B);
}
else
{
return det(Mat<eT>(X));
}
}
//! determinant of inv(A), without doing the inverse operation //! determinant of inv(A), without doing the inverse operation
template<typename T1> template<typename T1>
inline inline
typename T1::elem_type typename T1::elem_type
det(const Op<T1,op_inv>& in) det(const Op<T1,op_inv>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
isnt_fltpt<eT>::check(); isnt_fltpt<eT>::check();
eT tmp = det(in.m); eT tmp = det(in.m);
arma_debug_warn( (tmp == eT(0)), "det(): warning: determinant is zero" ); arma_warn( (tmp == eT(0)), "det(): warning: denominator is zero" );
return eT(1) / tmp; return eT(1) / tmp;
} }
//! determinant of trans(A) //! determinant of trans(A)
template<typename T1> template<typename T1>
inline inline
typename T1::elem_type typename T1::elem_type
det(const Op<T1,op_trans>& in) det(const Op<T1,op_trans>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
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;
return det(X); return det(X);
} }
//! @} //! @}
 End of changes. 13 change blocks. 
81 lines changed or deleted 12 lines changed or added


 fn_diagmat.hpp   fn_diagmat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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_diagmat //! \addtogroup fn_diagmat
//! @{ //! @{
//! interpret a mat as a diagonal matrix (i.e. off-diagonal entries are zer //! interpret a matrix or a vector as a diagonal matrix (i.e. off-diagonal
o) entries are zero)
// TODO: allow placement of vector onto a sub- or super- diagonal
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_diagmat> const Op<T1, op_diagmat>
diagmat(const Base<typename T1::elem_type,T1>& X) diagmat(const Base<typename T1::elem_type,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_diagmat>(X.get_ref()); return Op<T1, op_diagmat>(X.get_ref());
} }
//! interpret a colvec as a diagonal matrix
template<typename eT>
inline
const Op<Mat<eT>, op_diagmat_vec>
diagmat(const Col<eT>& X)
{
arma_extra_debug_sigprint();
return Op<Mat<eT>, op_diagmat_vec>(X);
}
//! interpret a rowvec as a diagonal matrix
template<typename eT>
inline
const Op<Mat<eT>, op_diagmat_vec>
diagmat(const Row<eT>& X)
{
arma_extra_debug_sigprint();
return Op<Mat<eT>, op_diagmat_vec>(X);
}
//! create a diagonal matrix out of subview_col
template<typename eT>
inline
Mat<eT>
diagmat(const subview_col<eT>& X)
{
arma_extra_debug_sigprint();
Mat<eT> out;
out.zeros(X.n_elem, X.n_elem);
for(u32 i=0; i<X.n_elem; ++i)
{
out.at(i,i) = X[i];
}
return out;
}
//! create a diagonal matrix out of subview_row
template<typename eT>
inline
Mat<eT>
diagmat(const subview_row<eT>& X)
{
arma_extra_debug_sigprint();
Mat<eT> out;
out.zeros(X.n_elem, X.n_elem);
for(u32 i=0; i<X.n_elem; ++i)
{
out.at(i,i) = X[i];
}
return out;
}
//! create a diagonal matrix out of diagview
template<typename eT>
inline
Mat<eT>
diagmat(const diagview<eT>& X)
{
arma_extra_debug_sigprint();
Mat<eT> out;
out.zeros(X.n_elem, X.n_elem);
for(u32 i=0; i<X.n_elem; ++i)
{
out.at(i,i) = X[i];
}
return out;
}
//! two consecutive diagmat operations are equivalent to one diagmat operat
ion
template<typename T1>
inline
const Op<T1, op_diagmat>&
diagmat(const Op<T1, op_diagmat>& X)
{
arma_extra_debug_sigprint();
arma_extra_debug_print("diagmat(): two consecutive diagmat() operations d
etected");
return X;
}
//! @} //! @}
 End of changes. 4 change blocks. 
97 lines changed or deleted 6 lines changed or added


 fn_dot.hpp   fn_dot.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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_dot //! \addtogroup fn_dot
//! @{ //! @{
template<typename T1, typename T2> template<typename T1, typename T2>
inline arma_inline
typename T1::elem_type typename T1::elem_type
dot(const Base<typename T1::elem_type,T1>& A, const Base<typename T1::elem_ type,T2>& B) dot(const Base<typename T1::elem_type,T1>& A, const Base<typename T1::elem_ type,T2>& B)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return op_dot::apply(A,B); return op_dot::apply(A,B);
} }
template<typename T1, typename T2> template<typename T1, typename T2>
inline arma_inline
typename T1::elem_type typename T1::elem_type
norm_dot(const Base<typename T1::elem_type,T1>& A, const Base<typename T1:: elem_type,T2>& B) norm_dot(const Base<typename T1::elem_type,T1>& A, const Base<typename T1:: elem_type,T2>& B)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return op_norm_dot::apply(A,B); return op_norm_dot::apply(A,B);
} }
//! @} //! @}
 End of changes. 3 change blocks. 
3 lines changed or deleted 4 lines changed or added


 fn_eig.hpp   fn_eig.hpp 
// Copyright (C) 2009 NICTA and the authors listed below // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Edmund Highcock (edmund dot highcock at merton dot ox dot ac dot uk) // - Edmund Highcock (edmund dot highcock at merton dot ox dot ac dot uk)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 fn_eps.hpp   fn_eps.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
skipping to change at line 24 skipping to change at line 24
// 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_eps //! \addtogroup fn_eps
//! @{ //! @{
//! \brief //! \brief
//! eps version for non-complex matrices and vectors //! eps version for non-complex matrices and vectors
template<typename T1> template<typename T1>
inline inline
const Op<T1, op_eps> const eOp<T1, eop_eps>
eps(const Base<typename T1::elem_type, T1>& X) eps(const Base<typename T1::elem_type, T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
isnt_fltpt<eT>::check(); return eOp<T1, eop_eps>(X.get_ref());
return Op<T1, op_eps>(X.get_ref());
} }
//! \brief //! \brief
//! eps version for complex matrices and vectors //! eps version for complex matrices and vectors
template<typename T1> template<typename T1>
inline inline
Mat< typename T1::pod_type > Mat< typename T1::pod_type >
eps(const Base< std::complex<typename T1::pod_type>, T1>& X) eps(const Base< std::complex<typename T1::pod_type>, T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::pod_type T; typedef typename T1::pod_type T;
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
isnt_fltpt<T>::check();
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;
Mat<T> out; Mat<T> out(A.n_rows, A.n_cols);
op_eps::direct_eps(out, A);
return out; T* out_mem = out.memptr();
} const eT* A_mem = A.memptr();
const u32 n_elem = A.n_elem;
for(u32 i=0; i<n_elem; ++i)
{
out_mem[i] = eop_aux::direct_eps( A_mem[i] );
}
//! \brief return out;
//! eps version for scalars of type float
arma_inline
float
eps(const float x)
{
return op_eps::direct_eps(x);
} }
//! \brief template<typename eT>
//! eps version for scalars of type double
arma_inline arma_inline
double typename arma_integral_only<eT>::result
eps(const double x) eps(const eT& x)
{ {
return op_eps::direct_eps(x); return eT(0);
} }
//! \brief template<typename eT>
//! eps version for std::complex<float>
arma_inline arma_inline
float typename arma_float_only<eT>::result
eps(const std::complex<float>& x) eps(const eT& x)
{ {
return op_eps::direct_eps(x); return eop_aux::direct_eps(x);
} }
//! \brief template<typename T>
//! eps version for std::complex<double>
arma_inline arma_inline
double typename arma_float_only<T>::result
eps(const std::complex<double>& x) eps(const std::complex<T>& x)
{ {
return op_eps::direct_eps(x); return eop_aux::direct_eps(x);
} }
//! @} //! @}
 End of changes. 16 change blocks. 
34 lines changed or deleted 26 lines changed or added


 fn_htrans.hpp   fn_htrans.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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_htrans //! \addtogroup fn_htrans
//! @{ //! @{
template<typename T> template<typename T1>
inline arma_inline
const Op<Mat< std::complex<T> >, op_htrans> const Op<T1, op_htrans>
htrans(const Mat< std::complex<T> >& X) htrans(const Base<std::complex<typename T1::pod_type>,T1>& X)
{
arma_extra_debug_sigprint();
return Op<Mat< std::complex<T> >, op_htrans>(X);
}
template<typename T>
inline
const Op<Row< std::complex<T> >, op_htrans>
htrans(const Row< std::complex<T> >& X)
{
arma_extra_debug_sigprint();
return Op<Row< std::complex<T> >, op_htrans>(X);
}
template<typename T>
inline
const Op<Col< std::complex<T> >, op_htrans>
htrans(const Col< std::complex<T> >& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<Col< std::complex<T> >, op_htrans>(X); return Op<T1, op_htrans>(X.get_ref());
} }
template<typename T, typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_htrans> const Op<T1, op_trans>
htrans(const Base<std::complex<T>,T1>& X) htrans(const Base<typename T1::pod_type,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_extra_debug_print("htrans(): non-complex object given -- using regul ar transpose");
return Op<T1, op_htrans>(X.get_ref()); return Op<T1, op_trans>(X.get_ref());
} }
//! two consecutive hermitian transpose operations cancel each other //! two consecutive hermitian transpose operations cancel each other
template<typename T1> template<typename T1>
inline arma_inline
const T1& const T1&
htrans(const Op<T1, op_htrans>& X) htrans(const Op<T1, op_htrans>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_extra_debug_print("htrans(): removing op_htrans"); arma_extra_debug_print("htrans(): removing op_htrans");
return X.m; return X.m;
} }
//! @} //! @}
 End of changes. 7 change blocks. 
32 lines changed or deleted 14 lines changed or added


 fn_inv.hpp   fn_inv.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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_inv //! \addtogroup fn_inv
//! @{ //! @{
//! delayed matrix inverse //! delayed matrix inverse
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_inv> const Op<T1, op_inv>
inv(const Base<typename T1::elem_type,T1>& X) inv(const Base<typename T1::elem_type,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_inv>(X.get_ref()); return Op<T1, op_inv>(X.get_ref());
} }
//! remove the inverse operation if applied twice consecutively //! remove the inverse operation if applied twice consecutively
template<typename T1> template<typename T1>
inline arma_inline
const T1& const T1&
inv(const Op<T1, op_inv>& X) inv(const Op<T1, op_inv>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return X.m; return X.m;
} }
//! @} //! @}
 End of changes. 3 change blocks. 
3 lines changed or deleted 4 lines changed or added


 fn_kron.hpp   fn_kron.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
skipping to change at line 24 skipping to change at line 24
// 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_kron //! \addtogroup fn_kron
//! @{ //! @{
//! \brief //! \brief
//! kronecker product of two matrices, //! kronecker product of two matrices,
//! with the matrices having the same element type //! with the matrices having the same element type
template<typename T1, typename T2> template<typename T1, typename T2>
inline arma_inline
const Glue<T1,T2,glue_kron> const Glue<T1,T2,glue_kron>
kron(const Base<typename T1::elem_type,T1>& A, const Base<typename T1::elem _type,T2>& B) kron(const Base<typename T1::elem_type,T1>& A, const Base<typename T1::elem _type,T2>& B)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Glue<T1, T2, glue_kron>(A.get_ref(), B.get_ref()); return Glue<T1, T2, glue_kron>(A.get_ref(), B.get_ref());
} }
//! \brief //! \brief
//! kronecker product of two matrices, //! kronecker product of two matrices,
 End of changes. 2 change blocks. 
3 lines changed or deleted 3 lines changed or added


 fn_lu.hpp   fn_lu.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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_lu //! \addtogroup fn_lu
//! @{ //! @{
//! immediate lower upper decomposition //! immediate lower upper decomposition
template<typename T1> template<typename T1>
inline inline
void void
lu(Mat<typename T1::elem_type>& L, Mat<typename T1::elem_type>& U, const Ba lu
se<typename T1::elem_type,T1>& X) (
Mat<typename T1::elem_type>& L,
Mat<typename T1::elem_type>& U,
const Base<typename T1::elem_type,T1>& X
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
arma_debug_check( (&L == &U), "lu(): L and U are the same object"); arma_debug_check( (&L == &U), "lu(): L and U are the same object");
const unwrap_check<T1> tmp1(X.get_ref(), L); const unwrap_check<T1> tmp1(X.get_ref(), L);
const Mat<eT>& A = tmp1.M; const Mat<eT>& A = tmp1.M;
const unwrap_check< Mat<eT> > tmp2(A, U); const unwrap_check< Mat<eT> > tmp2(A, U);
const Mat<eT>& B = tmp2.M; const Mat<eT>& B = tmp2.M;
auxlib::lu(L, U, B); auxlib::lu(L, U, B);
} }
//! immediate lower upper decomposition, also providing the permutation mat rix //! immediate lower upper decomposition, also providing the permutation mat rix
template<typename T1> template<typename T1>
inline inline
void void
lu(Mat<typename T1::elem_type>& L, Mat<typename T1::elem_type>& U, Mat<type lu
name T1::elem_type>& P, const Base<typename T1::elem_type,T1>& X) (
Mat<typename T1::elem_type>& L,
Mat<typename T1::elem_type>& U,
Mat<typename T1::elem_type>& P,
const Base<typename T1::elem_type,T1>& X
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
arma_debug_check( ( (&L == &U) || (&L == &P) || (&U == &P) ), "lu(): two or more output objects are the same object"); arma_debug_check( ( (&L == &U) || (&L == &P) || (&U == &P) ), "lu(): two or more output objects are the same object");
const unwrap_check<T1> tmp1(X.get_ref(), L); const unwrap_check<T1> tmp1(X.get_ref(), L);
const Mat<eT>& A = tmp1.M; const Mat<eT>& A = tmp1.M;
 End of changes. 3 change blocks. 
5 lines changed or deleted 15 lines changed or added


 fn_max.hpp   fn_max.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 27 skipping to change at line 28
//! \brief //! \brief
//! Delayed 'maximum values' operation. //! Delayed 'maximum values' operation.
//! The dimension, along which the maxima are found, is set via 'dim'. //! The dimension, along which the maxima are found, is set via 'dim'.
//! For dim = 0, the maximum value of each column is found. //! For dim = 0, the maximum value of each column is found.
//! For dim = 1, the maximum value of each row is found. //! For dim = 1, the maximum value of each row is found.
//! The default is dim = 0. //! The default is dim = 0.
//! NOTE: This function works differently than in Matlab/Octave. //! NOTE: This function works differently than in Matlab/Octave.
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_max> const Op<T1, op_max>
max(const Base<typename T1::elem_type,T1>& X, const u32 dim = 0) max(const Base<typename T1::elem_type,T1>& X, const u32 dim = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_max>(X.get_ref(), dim, 0); return Op<T1, op_max>(X.get_ref(), dim, 0);
} }
//! Immediate 'find the maximum value in a row vector' operation //! Immediate 'find the maximum value in a row vector' operation
template<typename eT> template<typename eT>
skipping to change at line 84 skipping to change at line 85
const unwrap<T1> tmp1(in.m); const unwrap<T1> tmp1(in.m);
const Mat<eT>& X = tmp1.M; const Mat<eT>& X = tmp1.M;
arma_debug_check( (X.n_elem == 0), "max(): given matrix has no elements" ); arma_debug_check( (X.n_elem == 0), "max(): given matrix has no elements" );
return op_max::direct_max(X.mem, X.n_elem); return op_max::direct_max(X.mem, X.n_elem);
} }
template<typename T1> template<typename T1>
inline arma_inline
const Op< Op<T1, op_max>, op_max> const Op< Op<T1, op_max>, op_max>
max(const Op<T1, op_max>& in, const u32 dim) max(const Op<T1, op_max>& in, const u32 dim)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op< Op<T1, op_max>, op_max>(in, dim, 0); return Op< Op<T1, op_max>, op_max>(in, dim, 0);
} }
template<typename eT> template<typename eT>
inline inline
 End of changes. 3 change blocks. 
3 lines changed or deleted 4 lines changed or added


 fn_mean.hpp   fn_mean.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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_mean //! \addtogroup fn_mean
//! @{ //! @{
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_mean> const Op<T1, op_mean>
mean(const Base<typename T1::elem_type,T1>& X, const u32 dim = 0) mean(const Base<typename T1::elem_type,T1>& X, const u32 dim = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_mean>(X.get_ref(), dim, 0); return Op<T1, op_mean>(X.get_ref(), dim, 0);
} }
//! Immediate 'find the mean value of a row vector' operation //! Immediate 'find the mean value of a row vector' operation
template<typename eT> template<typename eT>
skipping to change at line 76 skipping to change at line 77
const unwrap<T1> tmp1(in.m); const unwrap<T1> tmp1(in.m);
const Mat<eT>& X = tmp1.M; const Mat<eT>& X = tmp1.M;
arma_debug_check( (X.n_elem == 0), "mean(): given matrix has no elements" ); arma_debug_check( (X.n_elem == 0), "mean(): given matrix has no elements" );
return op_mean::direct_mean(X.mem, X.n_elem); return op_mean::direct_mean(X.mem, X.n_elem);
} }
template<typename T1> template<typename T1>
inline arma_inline
const Op< Op<T1, op_mean>, op_mean> const Op< Op<T1, op_mean>, op_mean>
mean(const Op<T1, op_mean>& in, const u32 dim) mean(const Op<T1, op_mean>& in, const u32 dim)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op< Op<T1, op_mean>, op_mean>(in, dim, 0); return Op< Op<T1, op_mean>, op_mean>(in, dim, 0);
} }
template<typename eT> template<typename eT>
inline inline
 End of changes. 3 change blocks. 
3 lines changed or deleted 4 lines changed or added


 fn_median.hpp   fn_median.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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_median //! \addtogroup fn_median
//! @{ //! @{
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_median> const Op<T1, op_median>
median(const Base<typename T1::elem_type,T1>& X, const u32 dim = 0) median(const Base<typename T1::elem_type,T1>& X, const u32 dim = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_median>(X.get_ref(), dim, 0); return Op<T1, op_median>(X.get_ref(), dim, 0);
} }
//! Immediate 'find the median value of a row vector' operation //! Immediate 'find the median value of a row vector' operation
template<typename eT> template<typename eT>
 End of changes. 2 change blocks. 
2 lines changed or deleted 3 lines changed or added


 fn_min.hpp   fn_min.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 27 skipping to change at line 28
//! \brief //! \brief
//! Delayed 'minimum values' operation. //! Delayed 'minimum values' operation.
//! The dimension, along which the minima are found, is set via 'dim'. //! The dimension, along which the minima are found, is set via 'dim'.
//! For dim = 0, the maximum value of each column is found (i.e. searches b y traversing across rows). //! For dim = 0, the maximum value of each column is found (i.e. searches b y traversing across rows).
//! For dim = 1, the maximum value of each row is found (i.e. searches by t raversing across columns). //! For dim = 1, the maximum value of each row is found (i.e. searches by t raversing across columns).
//! The default is dim = 0. //! The default is dim = 0.
//! NOTE: This function works differently than in Matlab/Octave. //! NOTE: This function works differently than in Matlab/Octave.
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_min> const Op<T1, op_min>
min(const Base<typename T1::elem_type,T1>& X, const u32 dim = 0) min(const Base<typename T1::elem_type,T1>& X, const u32 dim = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_min>(X.get_ref(), dim, 0); return Op<T1, op_min>(X.get_ref(), dim, 0);
} }
//! Immediate 'find the minimum value in a row vector' operation //! Immediate 'find the minimum value in a row vector' operation
template<typename eT> template<typename eT>
 End of changes. 2 change blocks. 
2 lines changed or deleted 3 lines changed or added


 fn_misc.hpp   fn_misc.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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_misc //! \addtogroup fn_misc
//! @{ //! @{
//! \brief //! \brief
//! Generate a vector with 'num' elements. //! Generate a vector with 'num' elements.
//! The values of the elements linearly increase from 'start' upto (and inc luding) 'end'. //! The values of the elements linearly increase from 'start' upto (and inc luding) 'end'.
template<typename eT> template<typename vec_type>
inline inline
Mat<eT> vec_type
linspace(const eT start, const eT end, const u32 num, const u32 dim = 0) linspace
(
const typename vec_type::pod_type start,
const typename vec_type::pod_type end,
const u32 num,
const u32 dim = 0
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_type_check< (is_Mat<vec_type>::value == false) >::apply();
arma_debug_check( (num < 2), "linspace(): num must be >= 2"); arma_debug_check( (num < 2), "linspace(): num must be >= 2");
Mat<eT> x; arma_warn( (dim != 0), "linspace(): the 'dim' argument is deprecated -- p lease use template based specification instead" );
if(dim == 0) typedef typename vec_type::elem_type eT;
{ typedef typename vec_type::pod_type T;
x.set_size(num,1); // column vector
}
else
{
x.set_size(1,num); // row vector
}
const eT delta = (end-start)/(num-1); // // this will be the default in the future:
// const u32 n_rows = (is_Row<vec_type>::value == true) ? 1 : num;
// const u32 n_cols = (is_Row<vec_type>::value == true) ? num : 1;
x[0] = start; // for temporary compatibility with old user code:
const u32 n_rows = (is_Row<vec_type>::value == true) ? 1 : ( (dim == 0)
? num : 1 );
const u32 n_cols = (is_Row<vec_type>::value == true) ? num : ( (dim == 0)
? 1 : num );
const eT delta = (end-start)/T(num-1);
Mat<eT> x(n_rows, n_cols);
eT* x_mem = x.memptr();
x_mem[0] = start;
for(u32 i=1; i<num; ++i) for(u32 i=1; i<num; ++i)
{ {
x[i] = x[i-1] + delta; x_mem[i] = x_mem[i-1] + delta;
} }
return x; return x;
} }
inline inline
mat mat
linspace(const double start, const double end, const u32 num, const u32 dim = 0) linspace(const double start, const double end, const u32 num, const u32 dim = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return linspace<double>(start, end, num, dim); return linspace<mat>(start, end, num, dim);
} }
// //
// real // real
template<typename T, typename T1> template<typename T1>
arma_inline
const T1&
real(const Base<typename T1::pod_type, T1>& X)
{
arma_extra_debug_sigprint();
return X.get_ref();
}
template<typename T1>
arma_inline
const T1&
real(const BaseCube<typename T1::pod_type, T1>& X)
{
arma_extra_debug_sigprint();
return X.get_ref();
}
template<typename T1>
inline inline
Mat<T> Mat<typename T1::pod_type>
real(const Base<std::complex<T>, T1>& X) real(const Base<std::complex<typename T1::pod_type>, T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef std::complex<T> eT; typedef typename T1::pod_type T;
const unwrap<T1> A_tmp(X.get_ref()); const Proxy<T1> A(X.get_ref());
const Mat<eT>& A = A_tmp.M;
Mat<T> out(A.n_rows, A.n_cols); Mat<T> out(A.n_rows, A.n_cols);
const eT* A_mem = A.mem;
T* out_mem = out.memptr(); T* out_mem = out.memptr();
for(u32 i=0; i<out.n_elem; ++i) for(u32 i=0; i<out.n_elem; ++i)
{ {
out_mem[i] = std::real(A_mem[i]); out_mem[i] = std::real(A[i]);
} }
return out; return out;
} }
template<typename T, typename T1> template<typename T1>
inline inline
Cube<T> Cube<typename T1::pod_type>
real(const BaseCube<std::complex<T>, T1>& X) real(const BaseCube<std::complex<typename T1::pod_type>, T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef std::complex<T> eT; typedef typename T1::pod_type T;
const unwrap_cube<T1> A_tmp(X.get_ref()); const ProxyCube<T1> A(X.get_ref());
const Cube<eT>& A = A_tmp.M;
Cube<T> out(A.n_rows, A.n_cols, A.n_slices); Cube<T> out(A.n_rows, A.n_cols, A.n_slices);
const eT* A_mem = A.mem;
T* out_mem = out.memptr(); T* out_mem = out.memptr();
for(u32 i=0; i<out.n_elem; ++i) for(u32 i=0; i<out.n_elem; ++i)
{ {
out_mem[i] = std::real(A_mem[i]); out_mem[i] = std::real(A[i]);
} }
return out; return out;
} }
// //
// imag // imag
template<typename T, typename T1> template<typename T1>
inline inline
Mat<T> const eOp<Mat<typename T1::pod_type>, eop_zeros>
imag(const Base<std::complex<T>,T1>& X) imag(const Base<typename T1::pod_type,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef std::complex<T> eT; const Proxy<T1> A(X.get_ref());
const unwrap<T1> A_tmp(X.get_ref()); return eOp<Mat<typename T1::pod_type>, eop_zeros>(A.n_rows, A.n_cols);
const Mat<eT>& A = A_tmp.M; }
template<typename T1>
inline
const eOpCube<Cube<typename T1::pod_type>, eop_cube_zeros>
imag(const BaseCube<typename T1::pod_type,T1>& X)
{
arma_extra_debug_sigprint();
const ProxyCube<T1> A(X.get_ref());
return eOpCube<Cube<typename T1::pod_type>, eop_cube_zeros>(A.n_rows, A.n
_cols, A.n_slices);
}
template<typename T1>
inline
Mat<typename T1::pod_type>
imag(const Base<std::complex<typename T1::pod_type>,T1>& X)
{
arma_extra_debug_sigprint();
typedef typename T1::pod_type T;
const Proxy<T1> A(X.get_ref());
Mat<T> out(A.n_rows, A.n_cols); Mat<T> out(A.n_rows, A.n_cols);
const eT* A_mem = A.mem;
T* out_mem = out.memptr(); T* out_mem = out.memptr();
for(u32 i=0; i<out.n_elem; ++i) for(u32 i=0; i<out.n_elem; ++i)
{ {
out_mem[i] = std::imag(A_mem[i]); out_mem[i] = std::imag(A[i]);
} }
return out; return out;
} }
template<typename T, typename T1> template<typename T1>
inline inline
Cube<T> Cube<typename T1::pod_type>
imag(const BaseCube<std::complex<T>,T1>& X) imag(const BaseCube<std::complex<typename T1::pod_type>,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef std::complex<T> eT; typedef typename T1::pod_type T;
const unwrap_cube<T1> A_tmp(X.get_ref()); const ProxyCube<T1> A(X.get_ref());
const Cube<eT>& A = A_tmp.M;
Cube<T> out(A.n_rows, A.n_cols, A.n_slices); Cube<T> out(A.n_rows, A.n_cols, A.n_slices);
const eT* A_mem = A.mem;
T* out_mem = out.memptr(); T* out_mem = out.memptr();
for(u32 i=0; i<out.n_elem; ++i) for(u32 i=0; i<out.n_elem; ++i)
{ {
out_mem[i] = std::imag(A_mem[i]); out_mem[i] = std::imag(A[i]);
} }
return out; return out;
} }
// //
// log_add // log_add
template<typename eT> template<typename eT>
inline inline
skipping to change at line 197 skipping to change at line 247
else else
{ {
#if defined(ARMA_HAVE_LOG1P) #if defined(ARMA_HAVE_LOG1P)
return (log_a + log1p(std::exp(negdelta))); return (log_a + log1p(std::exp(negdelta)));
#else #else
return (log_a + std::log(1.0 + std::exp(negdelta))); return (log_a + std::log(1.0 + std::exp(negdelta)));
#endif #endif
} }
} }
template<typename eT>
inline
eT
trunc_log(const eT x)
{
if(std::numeric_limits<eT>::is_iec559)
{
if(x == std::numeric_limits<eT>::infinity())
{
return Math<eT>::log_max();
}
if(x <= 0)
{
return Math<eT>::log_min();
}
else
{
return std::log(x);
}
}
else
{
return std::log(x);
}
}
template<typename eT>
inline
eT
trunc_exp(const eT x)
{
if(std::numeric_limits<eT>::is_iec559 && (x >= Math<eT>::log_max() ))
{
return std::numeric_limits<eT>::max();
}
else
{
return std::exp(x);
}
}
// //
// log // log
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_log> const eOp<T1, eop_log>
log(const Base<typename T1::elem_type,T1>& A) log(const Base<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_log>(A.get_ref()); return eOp<T1, eop_log>(A.get_ref());
} }
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_log> const eOpCube<T1, eop_cube_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 OpCube<T1, op_log>(A.get_ref()); return eOpCube<T1, eop_cube_log>(A.get_ref());
} }
// //
// trunc_log // trunc_log
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_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 Op<T1, op_trunc_log>(A.get_ref()); return eOp<T1, eop_trunc_log>(A.get_ref());
} }
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_trunc_log> const eOpCube<T1, eop_cube_trunc_log>
trunc_log(const BaseCube<typename T1::elem_type,T1>& A) trunc_log(const BaseCube<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_trunc_log>(A.get_ref()); return eOpCube<T1, eop_cube_trunc_log>(A.get_ref());
} }
// //
// log10 // log10
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_log10> const eOp<T1, eop_log10>
log10(const Base<typename T1::elem_type,T1>& A) log10(const Base<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_log10>(A.get_ref()); return eOp<T1, eop_log10>(A.get_ref());
} }
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_log10> const eOpCube<T1, eop_cube_log10>
log10(const BaseCube<typename T1::elem_type,T1>& A) log10(const BaseCube<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_log10>(A.get_ref()); return eOpCube<T1, eop_cube_log10>(A.get_ref());
} }
// //
// exp // exp
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_exp> const eOp<T1, eop_exp>
exp(const Base<typename T1::elem_type,T1>& A) exp(const Base<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_exp>(A.get_ref()); return eOp<T1, eop_exp>(A.get_ref());
} }
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_exp> const eOpCube<T1, eop_cube_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 OpCube<T1, op_exp>(A.get_ref()); return eOpCube<T1, eop_cube_exp>(A.get_ref());
} }
// //
// trunc_exp // trunc_exp
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_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 Op<T1, op_trunc_exp>(A.get_ref()); return eOp<T1, eop_trunc_exp>(A.get_ref());
} }
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_trunc_exp> const eOpCube<T1, eop_cube_trunc_exp>
trunc_exp(const BaseCube<typename T1::elem_type,T1>& A) trunc_exp(const BaseCube<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_trunc_exp>(A.get_ref()); return eOpCube<T1, eop_cube_trunc_exp>(A.get_ref());
} }
// //
// abs // abs
template<typename T1> template<typename T1>
arma_inline
const eOp<T1, eop_abs>
abs(const Base<typename T1::elem_type,T1>& X)
{
arma_extra_debug_sigprint();
return eOp<T1, eop_abs>(X.get_ref());
}
template<typename T1>
arma_inline
const eOpCube<T1, eop_cube_abs>
abs(const BaseCube<typename T1::elem_type,T1>& X)
{
arma_extra_debug_sigprint();
return eOpCube<T1, eop_cube_abs>(X.get_ref());
}
template<typename T1>
inline inline
Mat<typename T1::pod_type> Mat<typename T1::pod_type>
abs(const Base<typename T1::elem_type,T1>& X) abs(const Base< std::complex<typename T1::pod_type>,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap<T1> A_tmp(X.get_ref()); const Proxy<T1> A(X.get_ref());
// if T1 is a complex matrix, // if T1 is a complex matrix,
// pod_type is the underlying type used by std::complex; // pod_type is the underlying type used by std::complex;
// otherwise pod_type is the same as elem_type // otherwise pod_type is the same as elem_type
typedef typename T1::elem_type in_eT; typedef typename T1::elem_type in_eT;
typedef typename T1::pod_type out_eT; typedef typename T1::pod_type out_eT;
const Mat<in_eT>& A = A_tmp.M;
Mat<out_eT> out(A.n_rows, A.n_cols); Mat<out_eT> out(A.n_rows, A.n_cols);
const in_eT* A_mem = A.mem; out_eT* out_mem = out.memptr();
out_eT* out_mem = out.memptr();
for(u32 i=0; i<out.n_elem; ++i) for(u32 i=0; i<out.n_elem; ++i)
{ {
out_mem[i] = std::abs(A_mem[i]); out_mem[i] = std::abs(A[i]);
} }
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
Cube<typename T1::pod_type> Mat<typename T1::pod_type>
abs(const BaseCube<typename T1::elem_type,T1>& X) abs(const BaseCube< std::complex<typename T1::pod_type>,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap_cube<T1> A_tmp(X.get_ref()); const ProxyCube<T1> A(X.get_ref());
// if T1 is a complex matrix, // if T1 is a complex matrix,
// pod_type is the underlying type used by std::complex; // pod_type is the underlying type used by std::complex;
// otherwise pod_type is the same as elem_type // otherwise pod_type is the same as elem_type
typedef typename T1::elem_type in_eT; typedef typename T1::elem_type in_eT;
typedef typename T1::pod_type out_eT; typedef typename T1::pod_type out_eT;
const Cube<in_eT>& A = A_tmp.M;
Cube<out_eT> out(A.n_rows, A.n_cols, A.n_slices); Cube<out_eT> out(A.n_rows, A.n_cols, A.n_slices);
const in_eT* A_mem = A.mem; out_eT* out_mem = out.memptr();
out_eT* out_mem = out.memptr();
for(u32 i=0; i<out.n_elem; ++i) for(u32 i=0; i<out.n_elem; ++i)
{ {
out_mem[i] = std::abs(A_mem[i]); out_mem[i] = std::abs(A[i]);
} }
return out; return out;
} }
// //
// fabs // fabs
template<typename T1> template<typename T1>
inline arma_inline
const eOp<T1, eop_abs>
fabs(const Base<typename T1::pod_type,T1>& X)
{
arma_extra_debug_sigprint();
return eOp<T1, eop_abs>(X.get_ref());
}
template<typename T1>
arma_inline
const eOpCube<T1, eop_cube_abs>
fabs(const BaseCube<typename T1::pod_type,T1>& X)
{
arma_extra_debug_sigprint();
return eOpCube<T1, eop_cube_abs>(X.get_ref());
}
template<typename T1>
arma_inline
Mat<typename T1::pod_type> Mat<typename T1::pod_type>
fabs(const Base<typename T1::elem_type,T1>& A) fabs(const Base< std::complex<typename T1::pod_type>,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return abs(A); return abs(X);
} }
template<typename T1> template<typename T1>
inline arma_inline
Cube<typename T1::pod_type> Mat<typename T1::pod_type>
fabs(const BaseCube<typename T1::elem_type,T1>& A) fabs(const BaseCube< std::complex<typename T1::pod_type>,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return abs(A); return abs(X);
} }
// //
// square // square
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_square> const eOp<T1, eop_square>
square(const Base<typename T1::elem_type,T1>& A) square(const Base<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_square>(A.get_ref()); return eOp<T1, eop_square>(A.get_ref());
} }
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_square> const eOpCube<T1, eop_cube_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 OpCube<T1, op_square>(A.get_ref()); return eOpCube<T1, eop_cube_square>(A.get_ref());
} }
// //
// sqrt // sqrt
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_sqrt> const eOp<T1, eop_sqrt>
sqrt(const Base<typename T1::elem_type,T1>& A) sqrt(const Base<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_sqrt>(A.get_ref()); return eOp<T1, eop_sqrt>(A.get_ref());
} }
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_sqrt> const eOpCube<T1, eop_cube_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 OpCube<T1, op_sqrt>(A.get_ref()); return eOpCube<T1, eop_cube_sqrt>(A.get_ref());
} }
// pow //
// conj
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_pow> const T1&
pow(const Base<typename T1::elem_type,T1>& A, const typename T1::elem_type conj(const Base<typename T1::pod_type,T1>& A)
exponent)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_pow>(A.get_ref(), exponent); return A.get_ref();
} }
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_pow> const T1&
pow(const BaseCube<typename T1::elem_type,T1>& A, const typename T1::elem_t conj(const BaseCube<typename T1::pod_type,T1>& A)
ype exponent)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_pow>(A.get_ref(), exponent); return A.get_ref();
} }
// pow, specialised handling (non-complex exponent for complex matrices)
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_pow> const eOp<T1, eop_conj>
pow(const Base<typename T1::elem_type,T1>& A, const typename T1::elem_type: conj(const Base<std::complex<typename T1::pod_type>,T1>& A)
:value_type exponent)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_pow>(A.get_ref(), eT(exponent)); return eOp<T1, eop_conj>(A.get_ref());
} }
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_pow> const eOpCube<T1, eop_cube_conj>
pow(const BaseCube<typename T1::elem_type,T1>& A, const typename T1::elem_t conj(const BaseCube<std::complex<typename T1::pod_type>,T1>& A)
ype::value_type exponent)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_pow>(A.get_ref(), eT(exponent)); return eOpCube<T1, eop_cube_conj>(A.get_ref());
} }
#if defined(ARMA_GOOD_COMPILER)
// pow_s32 (integer exponent)
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_pow_s32> const T1&
pow(const Base<typename T1::elem_type,T1>& A, const s32 exponent) conj(const eOp<T1, eop_conj>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
if(exponent >= 0) return A.m;
{
return Op<T1, op_pow_s32>(A.get_ref(), exponent, 0);
}
else
{
return Op<T1, op_pow_s32>(A.get_ref(), -exponent, 1);
}
} }
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_pow_s32> const T1&
pow(const BaseCube<typename T1::elem_type,T1>& A, const s32 exponent) conj(const eOpCube<T1, eop_cube_conj>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
if(exponent >= 0) return A.m;
{
return OpCube<T1, op_pow_s32>(A.get_ref(), exponent, 0);
}
else
{
return OpCube<T1, op_pow_s32>(A.get_ref(), -exponent, 1);
}
} }
#endif // TODO: this needs a more elaborate template restriction mechanism to work
properly,
// i.e. an overloaded version of thus function should do nothing if t
he input type is non-complex
//
// //! the conjugate of the transpose of a complex matrix is the same as th
e hermitian transpose
// template<typename T1>
// arma_inline
// const Op<T1, op_htrans>
// conj(const Op<T1, op_trans>& A)
// {
// arma_extra_debug_sigprint();
//
// return Op<T1, op_htrans>(A.m);
// }
// conj // pow
template<typename T, typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_conj> const eOp<T1, eop_pow>
conj(const Base<std::complex<T>,T1>& A) pow(const Base<typename T1::elem_type,T1>& A, const typename T1::elem_type
exponent)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_conj>(A.get_ref()); return eOp<T1, eop_pow>(A.get_ref(), exponent);
} }
template<typename T, typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_conj> const eOpCube<T1, eop_cube_pow>
conj(const BaseCube<std::complex<T>,T1>& A) pow(const BaseCube<typename T1::elem_type,T1>& A, const typename T1::elem_t
ype exponent)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_conj>(A.get_ref()); return eOpCube<T1, eop_cube_pow>(A.get_ref(), exponent);
} }
// pow, specialised handling (non-complex exponent for complex matrices)
template<typename T1> template<typename T1>
inline arma_inline
const T1& const eOp<T1, eop_pow>
conj(const Op<T1, op_conj>& A) pow(const Base<typename T1::elem_type,T1>& A, const typename T1::elem_type:
:value_type exponent)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return A.m; typedef typename T1::elem_type eT;
return eOp<T1, eop_pow>(A.get_ref(), eT(exponent));
} }
template<typename T1> template<typename T1>
inline arma_inline
const T1& const eOpCube<T1, eop_cube_pow>
conj(const OpCube<T1, op_conj>& A) pow(const BaseCube<typename T1::elem_type,T1>& A, const typename T1::elem_t
ype::value_type exponent)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return A.m; typedef typename T1::elem_type eT;
return eOpCube<T1, eop_cube_pow>(A.get_ref(), eT(exponent));
} }
//! the conjugate of the transpose of a complex matrix is the same as the h #if defined(ARMA_GOOD_COMPILER)
ermitian transpose
// pow_s32 (integer exponent)
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_htrans> const eOp<T1, eop_pow_int>
conj(const Op<T1, op_trans>& A) pow(const Base<typename T1::elem_type,T1>& A, const int exponent)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_type_check< is_complex<typename T1::elem_type>::value == false >::ap if(exponent >= 0)
ply(); {
return eOp<T1, eop_pow_int>(A.get_ref(), exponent, 0);
}
else
{
return eOp<T1, eop_pow_int>(A.get_ref(), -exponent, 1);
}
}
return Op<T1, op_htrans>(A.m); template<typename T1>
arma_inline
const eOpCube<T1, eop_cube_pow_int>
pow(const BaseCube<typename T1::elem_type,T1>& A, const int exponent)
{
arma_extra_debug_sigprint();
if(exponent >= 0)
{
return eOpCube<T1, eop_cube_pow_int>(A.get_ref(), exponent, 0);
}
else
{
return eOpCube<T1, eop_cube_pow_int>(A.get_ref(), -exponent, 1);
}
} }
#endif
//! @} //! @}
 End of changes. 110 change blocks. 
231 lines changed or deleted 304 lines changed or added


 fn_norm.hpp   fn_norm.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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_norm //! \addtogroup fn_norm
//! @{ //! @{
template<typename T1> template<typename T1>
arma_hot
inline inline
typename T1::elem_type typename T1::elem_type
norm(const Base<typename T1::elem_type,T1>& X, const u32 k) norm_unwrap(const Base<typename T1::elem_type,T1>& X, const u32 k)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
const unwrap<T1> A_tmp(X.get_ref()); const unwrap<T1> tmp(X.get_ref());
const Mat<eT>& A = A_tmp.M; const Mat<eT>& A = tmp.M;
arma_debug_check( (A.n_elem == 0), "norm(): given
object has no elements" );
arma_debug_check( !( (A.n_rows == 1) || (A.n_cols == 1) ), "norm(): given
object must be a vector" );
arma_debug_check( (k == 0), "norm(): k mus
t be greater than zero" );
arma_debug_check( (A.n_elem == 0), "norm(): given const eT* A_mem = A.memptr();
object has no elements" ); const u32 N = A.n_elem;
arma_debug_check( !( (A.n_rows == 1) || (A.n_cols == 1) ), "norm(): first
argument must be a vector" );
arma_debug_check( (k == 0), "norm(): secon
d argument must be greater than zero" );
if(k==1) if(k==1)
{ {
eT acc = eT(0); eT acc = eT(0);
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<N; ++i)
{ {
acc += std::abs(A.mem[i]); acc += std::abs(A_mem[i]);
} }
return acc; return acc;
} }
else else
if(k==2) if(k==2)
{ {
if(is_complex<eT>::value == false) if(is_complex<eT>::value == false)
{ {
eT acc = eT(0); eT acc = eT(0);
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<N; ++i)
{ {
const eT tmp = A.mem[i]; const eT tmp = A_mem[i];
acc += tmp*tmp; acc += tmp*tmp;
} }
return std::sqrt(acc); return std::sqrt(acc);
} }
else else
{ {
eT acc = eT(0); eT acc = eT(0);
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<N; ++i)
{ {
acc += std::abs(A.mem[i]); acc += std::abs(A_mem[i]);
} }
return std::sqrt(acc); return std::sqrt(acc);
} }
} }
else else
{ {
eT acc = eT(0); eT acc = eT(0);
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<N; ++i)
{ {
acc += std::pow(std::abs(A.mem[i]), int(k)); acc += std::pow(std::abs(A_mem[i]), int(k));
} }
return std::pow(acc, eT(1)/eT(k)); return std::pow(acc, eT(1)/eT(k));
} }
} }
// template<typename T1>
// giving vector arguments works, as operator-() takes two mat arguments. arma_hot
// i.e. it has no specific form for dealing with colvec and rowvec,
// and colvec and rowvec are derived from mat (hence they are a type of mat
)
template<typename T1, typename T2>
inline inline
typename T1::elem_type typename T1::elem_type
norm(const Glue<T1,T2,glue_minus>& X, const u32 k) norm_proxy(const Base<typename T1::elem_type,T1>& X, const u32 k)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<typename T1::elem_type,typename T2::elem_type>::check();
const unwrap<T1> tmp1(X.A);
const unwrap<T2> tmp2(X.B);
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
const Mat<eT>& A = tmp1.M; const Proxy<T1> A(X.get_ref());
const Mat<eT>& B = tmp2.M;
arma_debug_check( ( (A.n_elem == 0) || (B.n_elem == 0) ), "norm(): one o arma_debug_check( (A.n_elem == 0), "norm(): given
r more of given objects has no elements" ); object has no elements" );
arma_debug_check( !( (A.n_rows == 1) || (A.n_cols == 1) ), "norm(): non-v arma_debug_check( !( (A.n_rows == 1) || (A.n_cols == 1) ), "norm(): given
ector argument detected" ); object must be a vector" );
arma_debug_check( !( (B.n_rows == 1) || (B.n_cols == 1) ), "norm(): non-v arma_debug_check( (k == 0), "norm(): k mus
ector argument detected" ); t be greater than zero" );
arma_debug_check( (A.n_elem != B.n_elem), "norm(): vecto
rs have different lengths" ); const u32 N = A.n_elem;
arma_debug_check( (k == 0), "norm(): secon
d argument must be greater than zero" );
if(k==1) if(k==1)
{ {
eT acc = eT(0); eT acc = eT(0);
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<N; ++i)
{ {
acc += std::abs(A.mem[i] - B.mem[i]); acc += std::abs(A[i]);
} }
return acc; return acc;
} }
else else
if(k==2) if(k==2)
{ {
eT acc = eT(0); if(is_complex<eT>::value == false)
for(u32 i=0; i<A.n_elem; ++i)
{ {
const eT tmp = A.mem[i] - B.mem[i]; eT acc = eT(0);
for(u32 i=0; i<N; ++i)
{
const eT tmp = A[i];
acc += tmp*tmp;
}
acc += tmp*tmp; return std::sqrt(acc);
} }
else
{
eT acc = eT(0);
return std::sqrt(acc); for(u32 i=0; i<N; ++i)
{
acc += std::abs(A[i]);
}
return std::sqrt(acc);
}
} }
else else
{ {
eT acc = eT(0); eT acc = eT(0);
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<N; ++i)
{ {
acc += std::pow( std::abs(A.mem[i] - B.mem[i]), int(k) ); acc += std::pow(std::abs(A[i]), int(k));
} }
return std::pow(acc, eT(1)/eT(k)); return std::pow(acc, eT(1)/eT(k));
} }
} }
template<typename T1, typename T2> template<typename T1>
inline arma_inline
typename T1::elem_type typename T1::elem_type
norm(const Glue<T1,T2,glue_plus>& X, const u32 k) norm(const Base<typename T1::elem_type,T1>& X, const u32 k)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<typename T1::elem_type,typename T2::elem_type>::check(); if(is_Mat<T1>::value == true)
const unwrap<T1> tmp1(X.A);
const unwrap<T2> tmp2(X.B);
typedef typename T1::elem_type eT;
const Mat<eT>& A = tmp1.M;
const Mat<eT>& B = tmp2.M;
arma_debug_check( ( (A.n_elem == 0) || (B.n_elem == 0) ), "norm(): one o
r more of given objects has no elements" );
arma_debug_check( !( (A.n_rows == 1) || (A.n_cols == 1) ), "norm(): non-v
ector argument detected" );
arma_debug_check( !( (B.n_rows == 1) || (B.n_cols == 1) ), "norm(): non-v
ector argument detected" );
arma_debug_check( (A.n_elem != B.n_elem), "norm(): vecto
rs have different lengths" );
arma_debug_check( (k == 0), "norm(): secon
d argument must be greater than zero" );
if(k==1)
{
eT acc = eT(0);
for(u32 i=0; i<A.n_elem; ++i)
{
acc += std::abs(A.mem[i] + B.mem[i]);
}
return acc;
}
else
if(k==2)
{ {
eT acc = eT(0); return norm_unwrap(X, k);
for(u32 i=0; i<A.n_elem; ++i)
{
const eT tmp = A.mem[i] + B.mem[i];
acc += tmp*tmp;
}
return std::sqrt(acc);
} }
else else
{ {
eT acc = eT(0); return norm_proxy(X, k);
for(u32 i=0; i<A.n_elem; ++i)
{
acc += std::pow( std::abs(A.mem[i] + B.mem[i]), int(k) );
}
return std::pow(acc, eT(1)/eT(k));
} }
} }
//! @} //! @}
 End of changes. 34 change blocks. 
110 lines changed or deleted 65 lines changed or added


 fn_ones.hpp   fn_ones.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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_ones //! \addtogroup fn_ones
//! @{ //! @{
//! Delayed generation of a dense matrix with all elements set to one //! Delayed generation of a dense matrix with all elements set to one
arma_inline
inline const eOp<mat, eop_ones_full>
const Op<mat,op_ones_full>
ones(const u32 n_rows, const u32 n_cols) ones(const u32 n_rows, const u32 n_cols)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<mat,op_ones_full>(n_rows, n_cols, 'j'); return eOp<mat, eop_ones_full>(n_rows, n_cols);
}
arma_inline
const eOpCube<cube, eop_cube_ones_full>
ones(const u32 n_rows, const u32 n_cols, const u32 n_slices)
{
arma_extra_debug_sigprint();
return eOpCube<cube, eop_cube_ones_full>(n_rows, n_cols, n_slices);
} }
template<typename mat_type> template<typename mat_type>
inline arma_inline
const Op<mat_type,op_ones_full> const eOp<mat_type, eop_ones_full>
ones(const u32 n_rows, const u32 n_cols) ones(const u32 n_rows, const u32 n_cols)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_type_check<is_Mat<mat_type>::value == false>::apply(); arma_type_check<is_Mat<mat_type>::value == false>::apply();
return Op<mat_type,op_ones_full>(n_rows, n_cols, 'j'); return eOp<mat_type, eop_ones_full>(n_rows, n_cols);
}
template<typename cube_type>
arma_inline
const eOpCube<cube_type, eop_cube_ones_full>
ones(const u32 n_rows, const u32 n_cols, const u32 n_slices)
{
arma_extra_debug_sigprint();
arma_type_check<is_Cube<cube_type>::value == false>::apply();
return eOpCube<cube_type, eop_cube_ones_full>(n_rows, n_cols, n_slices);
} }
//! Generate a vector with all elements set to one //! Generate a vector with all elements set to one
inline arma_inline
const Op<colvec, op_ones_full> const eOp<colvec, eop_ones_full>
ones(const u32 n_elem) ones(const u32 n_elem)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<colvec, op_ones_full>(n_elem, 1, 'j'); return eOp<colvec, eop_ones_full>(n_elem, 1);
} }
template<typename vec_type> template<typename vec_type>
inline arma_inline
const Op<vec_type, op_ones_full> const eOp<vec_type, eop_ones_full>
ones(const u32 n_elem) ones(const u32 n_elem)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_type_check< (is_Col<vec_type>::value == false) && (is_Row<vec_type>: :value == false) >::apply(); arma_type_check< (is_Col<vec_type>::value == false) && (is_Row<vec_type>: :value == false) >::apply();
if(is_Row<vec_type>::value == true) if(is_Row<vec_type>::value == true)
{ {
return Op<vec_type, op_ones_full>(1, n_elem, 'j'); return eOp<vec_type, eop_ones_full>(1, n_elem);
} }
else else
{ {
return Op<vec_type, op_ones_full>(n_elem, 1, 'j'); return eOp<vec_type, eop_ones_full>(n_elem, 1);
} }
} }
//! Delayed generation of a diagonal matrix with the diagonal elements set to one //! Delayed generation of a diagonal matrix with the diagonal elements set to one
inline arma_inline
const Op<mat,op_ones_diag> const eOp<mat, eop_ones_diag>
eye(const u32 n_rows, const u32 n_cols) eye(const u32 n_rows, const u32 n_cols)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_check( (n_rows != n_cols), "eye(): non-square matrix specified return eOp<mat, eop_ones_diag>(n_rows, n_cols);
" );
return Op<mat,op_ones_diag>(n_rows, n_cols, 'j');
} }
template<typename mat_type> template<typename mat_type>
inline arma_inline
const Op<mat_type,op_ones_diag> const eOp<mat_type, eop_ones_diag>
eye(const u32 n_rows, const u32 n_cols) eye(const u32 n_rows, const u32 n_cols)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_type_check<is_Mat_only<mat_type>::value == false>::apply(); arma_type_check<is_Mat_only<mat_type>::value == false>::apply();
return Op<mat_type,op_ones_diag>(n_rows, n_cols, 'j'); return eOp<mat_type, eop_ones_diag>(n_rows, n_cols);
}
//
//
// handling of cubes
//! Delayed generation of a dense cube with all elements set to one
inline
const OpCube<cube,op_ones_full>
ones(const u32 n_rows, const u32 n_cols, const u32 n_slices)
{
arma_extra_debug_sigprint();
return OpCube<cube,op_ones_full>(n_rows, n_cols, n_slices);
}
template<typename cube_type>
inline
const OpCube<cube_type,op_ones_full>
ones(const u32 n_rows, const u32 n_cols, const u32 n_slices)
{
arma_extra_debug_sigprint();
arma_type_check<is_Cube<cube_type>::value == false>::apply();
return OpCube<cube_type,op_ones_full>(n_rows, n_cols, n_slices);
} }
//! @} //! @}
 End of changes. 14 change blocks. 
51 lines changed or deleted 42 lines changed or added


 fn_pinv.hpp   fn_pinv.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
 End of changes. 1 change blocks. 
2 lines changed or deleted 2 lines changed or added


 fn_prod.hpp   fn_prod.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 27 skipping to change at line 28
//! \brief //! \brief
//! Delayed product of elements of a matrix along a specified dimension (ei ther rows or columns). //! Delayed product of elements of a matrix along a specified dimension (ei ther rows or columns).
//! The result is stored in a dense matrix that has either one column or on e row. //! The result is stored in a dense matrix that has either one column or on e row.
//! For dim = 0, find the sum of each column (i.e. traverse across rows) //! For dim = 0, find the sum of each column (i.e. traverse across rows)
//! For dim = 1, find the sum of each row (i.e. traverse across columns) //! For dim = 1, find the sum of each row (i.e. traverse across columns)
//! The default is dim = 0. //! The default is dim = 0.
//! NOTE: this function works differently than in Matlab/Octave. //! NOTE: this function works differently than in Matlab/Octave.
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_prod> const Op<T1, op_prod>
prod(const Base<typename T1::elem_type,T1>& X, const u32 dim = 0) prod(const Base<typename T1::elem_type,T1>& X, const u32 dim = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_prod>(X.get_ref(), dim, 0); return Op<T1, op_prod>(X.get_ref(), dim, 0);
} }
//! \brief //! \brief
//! Immediate 'product of all values' operation for a row vector //! Immediate 'product of all values' operation for a row vector
 End of changes. 2 change blocks. 
2 lines changed or deleted 3 lines changed or added


 fn_qr.hpp   fn_qr.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 fn_rand.hpp   fn_rand.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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_rand //! \addtogroup fn_rand
//! @{ //! @{
//! \brief
//! Generate a dense matrix with all elements set to random values in the [ 0,1] interval (uniform distribution) //! Generate a dense matrix with all elements set to random values in the [ 0,1] interval (uniform distribution)
arma_inline
inline const eOp<mat, eop_rand>
const Op<mat, op_rand>
rand(const u32 n_rows, const u32 n_cols) rand(const u32 n_rows, const u32 n_cols)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<mat, op_rand>(n_rows, n_cols, 'j'); return eOp<mat, eop_rand>(n_rows, n_cols);
}
arma_inline
const eOpCube<cube, eop_cube_rand>
rand(const u32 n_rows, const u32 n_cols, const u32 n_slices)
{
arma_extra_debug_sigprint();
return eOpCube<cube, eop_cube_rand>(n_rows, n_cols, n_slices);
} }
template<typename mat_type> template<typename mat_type>
inline arma_inline
const Op<mat_type,op_rand> const eOp<mat_type, eop_rand>
rand(const u32 n_rows, const u32 n_cols) rand(const u32 n_rows, const u32 n_cols)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_type_check<is_Mat<mat_type>::value == false>::apply(); arma_type_check<is_Mat<mat_type>::value == false>::apply();
return Op<mat_type,op_rand>(n_rows, n_cols, 'j'); return eOp<mat_type, eop_rand>(n_rows, n_cols);
}
template<typename cube_type>
arma_inline
const eOpCube<cube_type, eop_cube_rand>
rand(const u32 n_rows, const u32 n_cols, const u32 n_slices)
{
arma_extra_debug_sigprint();
arma_type_check<is_Cube<cube_type>::value == false>::apply();
return eOpCube<cube_type, eop_cube_rand>(n_rows, n_cols, n_slices);
} }
//! Generate a vector with all elements set to random values in the [0,1] i nterval (uniform distribution) //! Generate a vector with all elements set to random values in the [0,1] i nterval (uniform distribution)
inline arma_inline
const Op<colvec, op_rand> const eOp<colvec, eop_rand>
rand(const u32 n_elem) rand(const u32 n_elem)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<colvec, op_rand>(n_elem, 1, 'j'); return eOp<colvec, eop_rand>(n_elem, 1);
} }
template<typename vec_type> template<typename vec_type>
inline arma_inline
const Op<vec_type,op_rand> const eOp<vec_type, eop_rand>
rand(const u32 n_elem) rand(const u32 n_elem)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_type_check< (is_Col<vec_type>::value == false) && (is_Row<vec_type>: :value == false) >::apply(); arma_type_check< (is_Col<vec_type>::value == false) && (is_Row<vec_type>: :value == false) >::apply();
if(is_Row<vec_type>::value == true) if(is_Row<vec_type>::value == true)
{ {
return Op<vec_type,op_rand>(1, n_elem, 'j'); return eOp<vec_type, eop_rand>(1, n_elem);
} }
else else
{ {
return Op<vec_type,op_rand>(n_elem, 1, 'j'); return eOp<vec_type, eop_rand>(n_elem, 1);
} }
} }
//
//
// handling of cubes
//! Generate a dense cube with all elements set to random values in the [0,
1] interval (uniform distribution)
inline
const OpCube<cube, op_rand>
rand(const u32 n_rows, const u32 n_cols, const u32 n_slices)
{
arma_extra_debug_sigprint();
return OpCube<cube, op_rand>(n_rows, n_cols, n_slices);
}
template<typename cube_type>
inline
const OpCube<cube_type,op_rand>
rand(const u32 n_rows, const u32 n_cols, const u32 n_slices)
{
arma_extra_debug_sigprint();
arma_type_check<is_Cube<cube_type>::value == false>::apply();
return OpCube<cube_type,op_rand>(n_rows, n_cols, n_slices);
}
//! @} //! @}
 End of changes. 12 change blocks. 
43 lines changed or deleted 36 lines changed or added


 fn_randn.hpp   fn_randn.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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_randn //! \addtogroup fn_randn
//! @{ //! @{
//! Generate a dense matrix with all elements set to random values with a g aussian distribution (zero mean, unit variance) //! Generate a dense matrix with all elements set to random values with a g aussian distribution (zero mean, unit variance)
inline arma_inline
const Op<mat, op_randn> const eOp<mat, eop_randn>
randn(const u32 n_rows, const u32 n_cols) randn(const u32 n_rows, const u32 n_cols)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<mat, op_randn>(n_rows, n_cols, 'j'); return eOp<mat, eop_randn>(n_rows, n_cols);
}
arma_inline
const eOpCube<cube, eop_cube_randn>
randn(const u32 n_rows, const u32 n_cols, const u32 n_slices)
{
arma_extra_debug_sigprint();
return eOpCube<cube, eop_cube_randn>(n_rows, n_cols, n_slices);
} }
template<typename mat_type> template<typename mat_type>
inline arma_inline
const Op<mat_type,op_randn> const eOp<mat_type, eop_randn>
randn(const u32 n_rows, const u32 n_cols) randn(const u32 n_rows, const u32 n_cols)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_type_check<is_Mat<mat_type>::value == false>::apply(); arma_type_check<is_Mat<mat_type>::value == false>::apply();
return Op<mat_type,op_randn>(n_rows, n_cols, 'j'); return eOp<mat_type, eop_randn>(n_rows, n_cols);
}
template<typename cube_type>
arma_inline
const eOpCube<cube_type, eop_cube_randn>
randn(const u32 n_rows, const u32 n_cols, const u32 n_slices)
{
arma_extra_debug_sigprint();
arma_type_check<is_Cube<cube_type>::value == false>::apply();
return eOpCube<cube_type, eop_cube_randn>(n_rows, n_cols, n_slices);
} }
//! Generate a vector with all elements set to random values with a gaussia n distribution (zero mean, unit variance) //! Generate a vector with all elements set to random values with a gaussia n distribution (zero mean, unit variance)
inline arma_inline
const Op<colvec, op_randn> const eOp<colvec, eop_randn>
randn(const u32 n_elem) randn(const u32 n_elem)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<colvec, op_randn>(n_elem, 1, 'j'); return eOp<colvec, eop_randn>(n_elem, 1);
} }
template<typename vec_type> template<typename vec_type>
inline arma_inline
const Op<vec_type,op_randn> const eOp<vec_type, eop_randn>
randn(const u32 n_elem) randn(const u32 n_elem)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_type_check< (is_Col<vec_type>::value == false) && (is_Row<vec_type>: :value == false) >::apply(); arma_type_check< (is_Col<vec_type>::value == false) && (is_Row<vec_type>: :value == false) >::apply();
if(is_Row<vec_type>::value == true) if(is_Row<vec_type>::value == true)
{ {
return Op<vec_type,op_randn>(1, n_elem, 'j'); return eOp<vec_type, eop_randn>(1, n_elem);
} }
else else
{ {
return Op<vec_type,op_randn>(n_elem, 1, 'j'); return eOp<vec_type, eop_randn>(n_elem, 1);
} }
} }
//
//
// handling of cubes
//! Generate a dense cube with all elements set to random values with a gau
ssian distribution (zero mean, unit variance)
inline
const OpCube<cube, op_randn>
randn(const u32 n_rows, const u32 n_cols, const u32 n_slices)
{
arma_extra_debug_sigprint();
return OpCube<cube, op_randn>(n_rows, n_cols, n_slices);
}
template<typename cube_type>
inline
const OpCube<cube_type,op_randn>
randn(const u32 n_rows, const u32 n_cols, const u32 n_slices)
{
arma_extra_debug_sigprint();
arma_type_check<is_Cube<cube_type>::value == false>::apply();
return OpCube<cube_type,op_randn>(n_rows, n_cols, n_slices);
}
//! @} //! @}
 End of changes. 11 change blocks. 
41 lines changed or deleted 36 lines changed or added


 fn_rank.hpp   fn_rank.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
skipping to change at line 40 skipping to change at line 40
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;
Col<T> s; Col<T> s;
const bool status = auxlib::svd(s, A); const bool status = auxlib::svd(s, A);
if(status == true) if(status == true)
{ {
if(tol == T(0)) if(tol == T(0))
{ {
tol = (std::max)(A.n_rows, A.n_cols) * op_eps::direct_eps(max(s)); tol = (std::max)(A.n_rows, A.n_cols) * eop_aux::direct_eps(max(s));
} }
// count non zero valued elements in s // count non zero valued elements in s
const T* s_mem = s.memptr(); const T* s_mem = s.memptr();
const u32 n_elem = s.n_elem; const u32 n_elem = s.n_elem;
u32 count = 0; u32 count = 0;
for(u32 i=0; i<n_elem; ++i) for(u32 i=0; i<n_elem; ++i)
{ {
 End of changes. 2 change blocks. 
3 lines changed or deleted 3 lines changed or added


 fn_repmat.hpp   fn_repmat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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_repmat //! \addtogroup fn_repmat
//! @{ //! @{
//! \brief //! \brief
//! delayed 'repeat matrix' construction of a matrix //! delayed 'repeat matrix' construction of a matrix
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_repmat> const Op<T1, op_repmat>
repmat(const Base<typename T1::elem_type,T1>& A, const u32 r, const u32 c) repmat(const Base<typename T1::elem_type,T1>& A, const u32 r, const u32 c)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_repmat>(A.get_ref(), r, c); return Op<T1, op_repmat>(A.get_ref(), r, c);
} }
//! @} //! @}
 End of changes. 2 change blocks. 
3 lines changed or deleted 3 lines changed or added


 fn_reshape.hpp   fn_reshape.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 fn_shuffle.hpp   fn_shuffle.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
 End of changes. 1 change blocks. 
2 lines changed or deleted 2 lines changed or added


 fn_solve.hpp   fn_solve.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 fn_sort.hpp   fn_sort.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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>
inline arma_inline
const Op<T1, op_sort> const Op<T1, op_sort>
sort(const Base<typename T1::elem_type,T1>& X, const u32 sort_type = 0, con st u32 dim = 0) sort(const Base<typename T1::elem_type,T1>& X, const u32 sort_type = 0, con st u32 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.get_ref(), sort_type, dim);
} }
template<typename eT> template<typename eT>
inline arma_inline
const Op<Col<eT>, op_sort> const Op<Col<eT>, op_sort>
sort(const Col<eT>& X, const u32 sort_type = 0) sort(const Col<eT>& X, const u32 sort_type = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const u32 dim = 0; const u32 dim = 0;
return Op<Col<eT>, op_sort>(X, sort_type, dim); return Op<Col<eT>, op_sort>(X, sort_type, dim);
} }
template<typename eT> template<typename eT>
inline arma_inline
const Op<Row<eT>, op_sort> const Op<Row<eT>, op_sort>
sort(const Row<eT>& X, const u32 sort_type = 0) sort(const Row<eT>& X, const u32 sort_type = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const u32 dim = 1; const u32 dim = 1;
return Op<Row<eT>, op_sort>(X, sort_type, dim); return Op<Row<eT>, op_sort>(X, sort_type, dim);
} }
 End of changes. 4 change blocks. 
4 lines changed or deleted 5 lines changed or added


 fn_sort_index.hpp   fn_sort_index.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 fn_stddev.hpp   fn_stddev.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 25 skipping to change at line 26
//! \addtogroup fn_stddev //! \addtogroup fn_stddev
//! @{ //! @{
template<typename T1> template<typename T1>
inline inline
Mat<typename T1::pod_type> Mat<typename T1::pod_type>
stddev(const Base<typename T1::elem_type,T1>& X, const u32 norm_type = 0, c onst u32 dim = 0) stddev(const Base<typename T1::elem_type,T1>& X, const u32 norm_type = 0, c onst u32 dim = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap<T1> A_tmp(X.get_ref());
// if T1 is a complex matrix,
// pod_type is the underlying type used by std::complex;
// otherwise pod_type is the same as elem_type
typedef typename T1::elem_type in_eT; typedef typename T1::elem_type in_eT;
typedef typename T1::pod_type out_eT; typedef typename T1::pod_type out_eT;
const Mat<in_eT>& A = A_tmp.M; const unwrap<T1> tmp(X.get_ref());
const Mat<in_eT>& A = tmp.M;
Mat<out_eT> out; Mat<out_eT> out;
op_stddev::apply(out, A, norm_type, dim); op_stddev::apply(out, A, norm_type, dim);
return out; return out;
} }
//! Immediate 'find the standard deviation of a row vector' operation //! Immediate 'find the standard deviation of a row vector' operation
template<typename eT> template<typename eT>
inline inline
eT typename get_pod_type<eT>::result
stddev(const Row<eT>& A, const u32 norm_type = 0) stddev(const Row<eT>& A, const u32 norm_type = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element s" ); arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element s" );
return std::sqrt( op_var::direct_var(A.mem, A.n_elem, norm_type) ); return std::sqrt( op_var::direct_var(A.mem, A.n_elem, norm_type) );
} }
//! Immediate 'find the standard deviation of a row vector' operation (vers
ion for complex numbers)
template<typename T>
inline
T
stddev(const Row< std::complex<T> >& A, const u32 norm_type = 0)
{
arma_extra_debug_sigprint();
arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element
s" );
return std::sqrt( op_var::direct_var(A.mem, A.n_elem, norm_type) );
}
//! Immediate 'find the standard deviation of a column vector' operation //! Immediate 'find the standard deviation of a column vector' operation
template<typename eT> template<typename eT>
inline inline
eT typename get_pod_type<eT>::result
stddev(const Col<eT>& A, const u32 norm_type = 0) stddev(const Col<eT>& A, const u32 norm_type = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element s" ); arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element s" );
return std::sqrt( op_var::direct_var(A.mem, A.n_elem, norm_type) ); return std::sqrt( op_var::direct_var(A.mem, A.n_elem, norm_type) );
} }
//! Immediate 'find the standard deviation of a column vector' operation (v
ersion for complex numbers)
template<typename T>
inline
T
stddev(const Col< std::complex<T> >& A, const u32 norm_type = 0)
{
arma_extra_debug_sigprint();
arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element
s" );
return std::sqrt( op_var::direct_var(A.mem, A.n_elem, norm_type) );
}
//! find the standard deviation of a subview_row //! find the standard deviation of a subview_row
template<typename eT> template<typename eT>
inline inline
eT typename get_pod_type<eT>::result
stddev(const subview_row<eT>& A, const u32 norm_type = 0) stddev(const subview_row<eT>& A, const u32 norm_type = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element s" ); arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element s" );
return std::sqrt( op_var::direct_var(A, norm_type) ); return std::sqrt( op_var::direct_var(A, norm_type) );
} }
//! find the standard deviation of a subview_row (version for complex numbe
rs)
template<typename T>
inline
T
stddev(const subview_row< std::complex<T> >& A, const u32 norm_type = 0)
{
arma_extra_debug_sigprint();
arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element
s" );
return std::sqrt( op_var::direct_var(A, norm_type) );
}
//! find the standard deviation of a subview_col //! find the standard deviation of a subview_col
template<typename eT> template<typename eT>
inline inline
eT typename get_pod_type<eT>::result
stddev(const subview_col<eT>& A, const u32 norm_type = 0) stddev(const subview_col<eT>& A, const u32 norm_type = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element s" ); arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element s" );
return std::sqrt( op_var::direct_var(A, norm_type) ); return std::sqrt( op_var::direct_var(A, norm_type) );
} }
//! find the standard deviation of a subview_col (version for complex numbe
rs)
template<typename T>
inline
T
stddev(const subview_col< std::complex<T> >& A, const u32 norm_type = 0)
{
arma_extra_debug_sigprint();
arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element
s" );
return std::sqrt( op_var::direct_var(A, norm_type) );
}
//! find the standard deviation of a diagview //! find the standard deviation of a diagview
template<typename eT> template<typename eT>
inline inline
eT typename get_pod_type<eT>::result
stddev(const diagview<eT>& A, const u32 norm_type = 0) stddev(const diagview<eT>& A, const u32 norm_type = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element s" ); arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element s" );
return std::sqrt( op_var::direct_var(A, norm_type) ); return std::sqrt( op_var::direct_var(A, norm_type) );
} }
//! find the standard deviation of a diagview (version for complex numbers)
template<typename T>
inline
T
stddev(const diagview< std::complex<T> >& A, const u32 norm_type = 0)
{
arma_extra_debug_sigprint();
arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no element
s" );
return std::sqrt( op_var::direct_var(A, norm_type) );
}
//! @} //! @}
 End of changes. 13 change blocks. 
87 lines changed or deleted 9 lines changed or added


 fn_sum.hpp   fn_sum.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 27 skipping to change at line 28
//! \brief //! \brief
//! Delayed sum of elements of a matrix along a specified dimension (either rows or columns). //! Delayed sum of elements of a matrix along a specified dimension (either rows or columns).
//! The result is stored in a dense matrix that has either one column or on e row. //! The result is stored in a dense matrix that has either one column or on e row.
//! For dim = 0, find the sum of each column. //! For dim = 0, find the sum of each column.
//! For dim = 1, find the sum of each row. //! For dim = 1, find the sum of each row.
//! The default is dim = 0. //! The default is dim = 0.
//! NOTE: this function works differently than in Matlab/Octave. //! NOTE: this function works differently than in Matlab/Octave.
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_sum> const Op<T1, op_sum>
sum(const Base<typename T1::elem_type,T1>& X, const u32 dim = 0) sum(const Base<typename T1::elem_type,T1>& X, const u32 dim = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_sum>(X.get_ref(), dim, 0); return Op<T1, op_sum>(X.get_ref(), dim, 0);
} }
//! \brief //! \brief
//! Immediate 'sum all values' operation for a row vector //! Immediate 'sum all values' operation for a row vector
template<typename eT> template<typename eT>
inline arma_inline
eT eT
sum(const Row<eT>& X) sum(const Row<eT>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return accu(X); return accu(X);
} }
//! \brief //! \brief
//! Immediate 'sum all values' operation for a column vector //! Immediate 'sum all values' operation for a column vector
template<typename eT> template<typename eT>
inline arma_inline
eT eT
sum(const Col<eT>& X) sum(const Col<eT>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return accu(X); return accu(X);
} }
//! \brief //! \brief
//! Immediate 'sum all values' operation, //! Immediate 'sum all values' operation,
//! invoked, for example, by: sum(sum(A)) //! invoked, for example, by: sum(sum(A))
template<typename T1> template<typename T1>
inline arma_inline
typename T1::elem_type typename T1::elem_type
sum(const Op<T1, op_sum>& in) sum(const Op<T1, op_sum>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_extra_debug_print("sum(): two consecutive sum() calls detected"); arma_extra_debug_print("sum(): two consecutive sum() calls detected");
return accu(in.m); return accu(in.m);
} }
template<typename T1> template<typename T1>
inline arma_inline
const Op<Op<T1, op_sum>, op_sum> const Op<Op<T1, op_sum>, op_sum>
sum(const Op<T1, op_sum>& in, const u32 dim) sum(const Op<T1, op_sum>& in, const u32 dim)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<Op<T1, op_sum>, op_sum>(in, dim, 0); return Op<Op<T1, op_sum>, op_sum>(in, dim, 0);
} }
//! sum all values of a subview_row //! sum all values of a subview_row
template<typename eT> template<typename eT>
inline arma_inline
eT eT
sum(const subview_row<eT>& X) sum(const subview_row<eT>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return accu(X); return accu(X);
} }
//! sum all values of a subview_col //! sum all values of a subview_col
template<typename eT> template<typename eT>
inline arma_inline
eT eT
sum(const subview_col<eT>& X) sum(const subview_col<eT>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return accu(X); return accu(X);
} }
//! sum all values of a diagview //! sum all values of a diagview
template<typename eT> template<typename eT>
inline arma_inline
eT eT
sum(const diagview<eT>& X) sum(const diagview<eT>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return accu(X); return accu(X);
} }
//! @} //! @}
 End of changes. 9 change blocks. 
9 lines changed or deleted 10 lines changed or added


 fn_svd.hpp   fn_svd.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 51 skipping to change at line 52
} }
template<typename T1> template<typename T1>
inline inline
Col<typename T1::pod_type> Col<typename T1::pod_type>
svd(const Base<typename T1::elem_type,T1>& X) svd(const Base<typename T1::elem_type,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
Col<typename T1::pod_type> out; Col<typename T1::pod_type> out;
svd(out, X);
const bool status = svd(out, X);
if(status == false)
{
out.set_size(0);
}
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
bool bool
svd svd
( (
Mat<typename T1::elem_type>& U, Mat<typename T1::elem_type>& U,
 End of changes. 2 change blocks. 
2 lines changed or deleted 9 lines changed or added


 fn_trace.hpp   fn_trace.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 28 skipping to change at line 29
//! Immediate trace (sum of diagonal elements) of a square dense matrix //! Immediate trace (sum of diagonal elements) of a square dense matrix
template<typename T1> template<typename T1>
inline inline
typename T1::elem_type typename T1::elem_type
trace(const Base<typename T1::elem_type,T1>& X) trace(const Base<typename T1::elem_type,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
const unwrap<T1> A_tmp(X.get_ref()); const Proxy<T1> A(X.get_ref());
const Mat<eT>& A = A_tmp.M;
arma_debug_check( !A.is_square(), "trace(): matrix must be square" ); arma_debug_check( (A.n_rows != A.n_cols), "trace(): matrix must be square " );
eT val = eT(0); eT val = eT(0);
for(u32 i=0; i<A.n_rows; ++i) for(u32 i=0; i<A.n_rows; ++i)
{ {
val += A.at(i,i); val += A.at(i,i);
} }
return val; return val;
} }
#if defined(ARMA_GOOD_COMPILER) template<typename T1>
//! \brief
//! Immediate trace (sum of diagonal elements) of A + B.
//! A and B must be square and have the same dimensions.
template<typename T1, typename T2>
inline inline
typename T1::elem_type typename T1::elem_type
trace(const Glue<T1,T2,glue_plus>& X) trace(const Op<T1, op_diagmat>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
isnt_same_type<typename T1::elem_type, typename T2::elem_type>::check();
const unwrap<T1> tmp1(X.A);
const unwrap<T2> tmp2(X.B);
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
const Mat<eT>& A = tmp1.M; const diagmat_proxy<T1> A(X.m);
const Mat<eT>& B = tmp2.M;
arma_debug_assert_same_size(A, B, "matrix addition");
arma_debug_check( !A.is_square(), "trace(): matrices must be square");
return trace(A) + trace(B);
}
//! \brief
//! Immediate trace (sum of diagonal elements) of A - B.
//! A and B must be square and have the same dimensions.
template<typename T1, typename T2>
inline
typename T1::elem_type
trace(const Glue<T1,T2,glue_minus>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<typename T1::elem_type, typename T2::elem_type>::check();
const unwrap<T1> tmp1(X.A);
const unwrap<T2> tmp2(X.B);
typedef typename T1::elem_type eT;
const Mat<eT>& A = tmp1.M;
const Mat<eT>& B = tmp2.M;
arma_debug_assert_same_size(A, B, "matrix subtraction");
arma_debug_check( !A.is_square(), "trace(): matrices must be square");
return trace(A) - trace(B);
}
//! \brief
//! Immediate trace (sum of diagonal elements) of A % B (where % is the ele
ment-wise multiplication operator).
//! A and B must be square and have the same dimensions.
template<typename T1, typename T2>
inline
typename T1::elem_type
trace(const Glue<T1,T2,glue_schur>& X)
{
arma_extra_debug_sigprint();
isnt_same_type<typename T1::elem_type, typename T2::elem_type>::check();
const unwrap<T1> tmp1(X.A);
const unwrap<T2> tmp2(X.B);
typedef typename T1::elem_type eT;
const Mat<eT>& A = tmp1.M; const u32 N = A.n_elem;
const Mat<eT>& B = tmp2.M;
arma_debug_assert_same_size(A, B, "matrix schur product");
arma_debug_check( !A.is_square(), "trace(): matrices must be square" );
eT val = eT(0); eT val = eT(0);
for(u32 i=0; i<A.n_rows; ++i)
for(u32 i=0; i<N; ++i)
{ {
val += A.at(i,i) * B.at(i,i); val += A[i];
} }
return val; return val;
} }
//! \brief
//! trace (sum of diagonal elements) of k * T1,
//! where k is a scalar and T1 is converted to a dense matrix.
template<typename T1>
inline
typename T1::elem_type
trace(const Op<T1,op_scalar_times>& in)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const unwrap<T1> tmp(in.m);
const Mat<eT>& X = tmp.M;
return trace(X) * in.aux;
}
//! trace (sum of diagonal elements) of a diagonal matrix
template<typename eT>
inline
eT
trace(const Op<Mat<eT>, op_diagmat>& X)
{
arma_extra_debug_sigprint();
return trace(X.m);
}
template<typename eT>
inline
eT
trace(const Op<Mat<eT>, op_diagmat_vec>& X)
{
arma_extra_debug_sigprint();
const Mat<eT>& A = X.m;
arma_debug_check( !A.is_vec(), "trace(): internal error: can't interpret
as a vector" );
return accu(X.m);
}
#endif
//! @} //! @}
 End of changes. 11 change blocks. 
120 lines changed or deleted 11 lines changed or added


 fn_trans.hpp   fn_trans.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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_trans //! \addtogroup fn_trans
//! @{ //! @{
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_trans> const Op<T1, op_trans>
trans(const Base<typename T1::elem_type,T1>& X) trans(const Base<typename T1::elem_type,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_trans>(X.get_ref()); return Op<T1, op_trans>(X.get_ref());
} }
template<typename eT>
inline
const Op<Row<eT>, op_trans>
trans(const Row<eT>& X)
{
arma_extra_debug_sigprint();
return Op<Row<eT>, op_trans>(X);
}
template<typename eT>
inline
const Op<Col<eT>, op_trans>
trans(const Col<eT>& X)
{
arma_extra_debug_sigprint();
return Op<Col<eT>, op_trans>(X);
}
//! two consecutive transpose operations cancel each other //! two consecutive transpose operations cancel each other
template<typename T1> template<typename T1>
inline arma_inline
const T1& const T1&
trans(const Op<T1, op_trans>& X) trans(const Op<T1, op_trans>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_extra_debug_print("trans(): removing op_trans"); arma_extra_debug_print("trans(): removing op_trans");
return X.m; return X.m;
} }
//! transpose of a diagonal matrix gives you the original matrix back //! transpose of a diagonal matrix (which is square) does nothing
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_diagmat> const Op<T1, op_diagmat>
trans(const Op<T1, op_diagmat>& X) trans(const Op<T1, op_diagmat>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_extra_debug_print("trans(): not applying op_trans to diagonal matrix "); arma_extra_debug_print("trans(): not applying op_trans to diagonal matrix ");
return X; return X;
} }
//! the transpose of the conjugate of a complex matrix is equivalent to the
hermitian transpose
template<typename T1>
inline
const Op<T1, op_htrans>
trans(const Op<T1, op_conj>& X)
{
arma_extra_debug_sigprint();
arma_type_check< is_complex<typename T1::elem_type>::value == false >::ap
ply();
return Op<T1, op_htrans>(X.m);
}
//! @} //! @}
 End of changes. 7 change blocks. 
40 lines changed or deleted 6 lines changed or added


 fn_trig.hpp   fn_trig.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 28 skipping to change at line 29
// //
// trigonometric functions: // trigonometric functions:
// cos family: cos, acos, cosh, acosh // cos family: cos, acos, cosh, acosh
// sin family: sin, asin, sinh, asinh // sin family: sin, asin, sinh, asinh
// tan family: tan, atan, tanh, atanh // tan family: tan, atan, tanh, atanh
// //
// cos // cos
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_cos> const eOp<T1, eop_cos>
cos(const Base<typename T1::elem_type,T1>& A) cos(const Base<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_cos>(A.get_ref()); return eOp<T1, eop_cos>(A.get_ref());
} }
//
// acos
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_acos> const eOpCube<T1, eop_cube_cos>
acos(const Base<typename T1::elem_type,T1>& A) cos(const BaseCube<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_acos>(A.get_ref()); return eOpCube<T1, eop_cube_cos>(A.get_ref());
} }
// //
// cosh // acos
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_cosh> const eOp<T1, eop_acos>
cosh(const Base<typename T1::elem_type,T1>& A) acos(const Base<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_cosh>(A.get_ref()); return eOp<T1, eop_acos>(A.get_ref());
} }
//
// acosh
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_acosh> const eOpCube<T1, eop_cube_acos>
acosh(const Base<typename T1::elem_type,T1>& A) acos(const BaseCube<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_acosh>(A.get_ref()); return eOpCube<T1, eop_cube_acos>(A.get_ref());
} }
// //
// sin // cosh
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_sin> const eOp<T1, eop_cosh>
sin(const Base<typename T1::elem_type,T1>& A) cosh(const Base<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_sin>(A.get_ref()); return eOp<T1, eop_cosh>(A.get_ref());
} }
//
// asin
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_asin> const eOpCube<T1, eop_cube_cosh>
asin(const Base<typename T1::elem_type,T1>& A) cosh(const BaseCube<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_asin>(A.get_ref()); return eOpCube<T1, eop_cube_cosh>(A.get_ref());
} }
// //
// sinh // acosh
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_sinh> const eOp<T1, eop_acosh>
sinh(const Base<typename T1::elem_type,T1>& A) acosh(const Base<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_sinh>(A.get_ref()); return eOp<T1, eop_acosh>(A.get_ref());
} }
//
// asinh
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_asinh> const eOpCube<T1, eop_cube_acosh>
asinh(const Base<typename T1::elem_type,T1>& A) acosh(const BaseCube<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_asinh>(A.get_ref()); return eOpCube<T1, eop_cube_acosh>(A.get_ref());
} }
// //
// tan // sin
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_tan> const eOp<T1, eop_sin>
tan(const Base<typename T1::elem_type,T1>& A) sin(const Base<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_tan>(A.get_ref()); return eOp<T1, eop_sin>(A.get_ref());
} }
//
// atan
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_atan> const eOpCube<T1, eop_cube_sin>
atan(const Base<typename T1::elem_type,T1>& A) sin(const BaseCube<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_atan>(A.get_ref()); return eOpCube<T1, eop_cube_sin>(A.get_ref());
} }
// //
// tanh // asin
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_tanh> const eOp<T1, eop_asin>
tanh(const Base<typename T1::elem_type,T1>& A) asin(const Base<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_tanh>(A.get_ref()); return eOp<T1, eop_asin>(A.get_ref());
} }
//
// atanh
template<typename T1> template<typename T1>
inline arma_inline
const Op<T1, op_atanh> const eOpCube<T1, eop_cube_asin>
atanh(const Base<typename T1::elem_type,T1>& A) asin(const BaseCube<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_atanh>(A.get_ref()); return eOpCube<T1, eop_cube_asin>(A.get_ref());
} }
// //
// // sinh
// handling of cubes
//
// cos
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_cos> const eOp<T1, eop_sinh>
cos(const BaseCube<typename T1::elem_type,T1>& A) sinh(const Base<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_cos>(A.get_ref()); return eOp<T1, eop_sinh>(A.get_ref());
} }
//
// acos
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_acos> const eOpCube<T1, eop_cube_sinh>
acos(const BaseCube<typename T1::elem_type,T1>& A) sinh(const BaseCube<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_acos>(A.get_ref()); return eOpCube<T1, eop_cube_sinh>(A.get_ref());
} }
// //
// cosh // asinh
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_cosh> const eOp<T1, eop_asinh>
cosh(const BaseCube<typename T1::elem_type,T1>& A) asinh(const Base<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_cosh>(A.get_ref()); return eOp<T1, eop_asinh>(A.get_ref());
} }
//
// acosh
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_acosh> const eOpCube<T1, eop_cube_asinh>
acosh(const BaseCube<typename T1::elem_type,T1>& A) asinh(const BaseCube<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_acosh>(A.get_ref()); return eOpCube<T1, eop_cube_asinh>(A.get_ref());
} }
// //
// sin // tan
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_sin> const eOp<T1, eop_tan>
sin(const BaseCube<typename T1::elem_type,T1>& A) tan(const Base<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_sin>(A.get_ref()); return eOp<T1, eop_tan>(A.get_ref());
} }
//
// asin
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_asin> const eOpCube<T1, eop_cube_tan>
asin(const BaseCube<typename T1::elem_type,T1>& A) tan(const BaseCube<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_asin>(A.get_ref()); return eOpCube<T1, eop_cube_tan>(A.get_ref());
} }
// //
// sinh // atan
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_sinh> const eOp<T1, eop_atan>
sinh(const BaseCube<typename T1::elem_type,T1>& A) atan(const Base<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_sinh>(A.get_ref()); return eOp<T1, eop_atan>(A.get_ref());
} }
//
// asinh
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_asinh> const eOpCube<T1, eop_cube_atan>
asinh(const BaseCube<typename T1::elem_type,T1>& A) atan(const BaseCube<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_asinh>(A.get_ref()); return eOpCube<T1, eop_cube_atan>(A.get_ref());
} }
// //
// tan // tanh
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_tan> const eOp<T1, eop_tanh>
tan(const BaseCube<typename T1::elem_type,T1>& A) tanh(const Base<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_tan>(A.get_ref()); return eOp<T1, eop_tanh>(A.get_ref());
} }
//
// atan
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_atan> const eOpCube<T1, eop_cube_tanh>
atan(const BaseCube<typename T1::elem_type,T1>& A) tanh(const BaseCube<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_atan>(A.get_ref()); return eOpCube<T1, eop_cube_tanh>(A.get_ref());
} }
// //
// tanh // atanh
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_tanh> const eOp<T1, eop_atanh>
tanh(const BaseCube<typename T1::elem_type,T1>& A) atanh(const Base<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_tanh>(A.get_ref()); return eOp<T1, eop_atanh>(A.get_ref());
} }
//
// atanh
template<typename T1> template<typename T1>
inline arma_inline
const OpCube<T1, op_atanh> const eOpCube<T1, eop_cube_atanh>
atanh(const BaseCube<typename T1::elem_type,T1>& A) atanh(const BaseCube<typename T1::elem_type,T1>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_atanh>(A.get_ref()); return eOpCube<T1, eop_cube_atanh>(A.get_ref());
} }
//! @} //! @}
 End of changes. 72 change blocks. 
146 lines changed or deleted 107 lines changed or added


 fn_var.hpp   fn_var.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 25 skipping to change at line 26
//! \addtogroup fn_var //! \addtogroup fn_var
//! @{ //! @{
template<typename T1> template<typename T1>
inline inline
Mat<typename T1::pod_type> Mat<typename T1::pod_type>
var(const Base<typename T1::elem_type,T1>& X, const u32 norm_type = 0, cons t u32 dim = 0) var(const Base<typename T1::elem_type,T1>& X, const u32 norm_type = 0, cons t u32 dim = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap<T1> A_tmp(X.get_ref());
// if T1 is a complex matrix,
// pod_type is the underlying type used by std::complex;
// otherwise pod_type is the same as elem_type
typedef typename T1::elem_type in_eT; typedef typename T1::elem_type in_eT;
typedef typename T1::pod_type out_eT; typedef typename T1::pod_type out_eT;
const Mat<in_eT>& A = A_tmp.M; const unwrap<T1> tmp(X.get_ref());
const Mat<in_eT>& A = tmp.M;
Mat<out_eT> out; Mat<out_eT> out;
op_var::apply(out, A, norm_type, dim); op_var::apply(out, A, norm_type, dim);
return out; return out;
} }
//! Immediate 'find the variance of a row vector' operation //! Immediate 'find the variance of a row vector' operation
template<typename eT> template<typename eT>
inline inline
eT typename get_pod_type<eT>::result
var(const Row<eT>& A, const u32 norm_type = 0) var(const Row<eT>& A, const u32 norm_type = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" ); arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
return op_var::direct_var(A.mem, A.n_elem, norm_type); return op_var::direct_var(A.mem, A.n_elem, norm_type);
} }
//! Immediate 'find the variance of a row vector' operation (version for co
mplex numbers)
template<typename T>
inline
T
var(const Row< std::complex<T> >& A, const u32 norm_type = 0)
{
arma_extra_debug_sigprint();
arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements"
);
return op_var::direct_var(A.mem, A.n_elem, norm_type);
}
//! Immediate 'find the variance of a column vector' operation //! Immediate 'find the variance of a column vector' operation
template<typename eT> template<typename eT>
inline inline
eT typename get_pod_type<eT>::result
var(const Col<eT>& A, const u32 norm_type = 0) var(const Col<eT>& A, const u32 norm_type = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" ); arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
return op_var::direct_var(A.mem, A.n_elem, norm_type); return op_var::direct_var(A.mem, A.n_elem, norm_type);
} }
//! Immediate 'find the variance of a column vector' operation (version for
complex numbers)
template<typename T>
inline
T
var(const Col< std::complex<T> >& A, const u32 norm_type = 0)
{
arma_extra_debug_sigprint();
arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements"
);
return op_var::direct_var(A.mem, A.n_elem, norm_type);
}
template<typename eT> template<typename eT>
inline inline
eT typename get_pod_type<eT>::result
var(const subview_row<eT>& A, const u32 norm_type = 0) var(const subview_row<eT>& A, const u32 norm_type = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" ); arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
return op_var::direct_var(A, norm_type); return op_var::direct_var(A, norm_type);
} }
template<typename T>
inline
T
var(const subview_row< std::complex<T> >& A, const u32 norm_type = 0)
{
arma_extra_debug_sigprint();
arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements"
);
return op_var::direct_var(A, norm_type);
}
template<typename eT> template<typename eT>
inline inline
eT typename get_pod_type<eT>::result
var(const subview_col<eT>& A, const u32 norm_type = 0) var(const subview_col<eT>& A, const u32 norm_type = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" ); arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
return op_var::direct_var(A, norm_type); return op_var::direct_var(A, norm_type);
} }
template<typename T>
inline
T
var(const subview_col< std::complex<T> >& A, const u32 norm_type = 0)
{
arma_extra_debug_sigprint();
arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements"
);
return op_var::direct_var(A, norm_type);
}
template<typename eT> template<typename eT>
inline inline
eT typename get_pod_type<eT>::result
var(const diagview<eT>& A, const u32 norm_type = 0) var(const diagview<eT>& A, const u32 norm_type = 0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" ); arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
return op_var::direct_var(A, norm_type); return op_var::direct_var(A, norm_type);
} }
template<typename T>
inline
T
var(const diagview< std::complex<T> >& A, const u32 norm_type = 0)
{
arma_extra_debug_sigprint();
arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements"
);
return op_var::direct_var(A, norm_type);
}
//! @} //! @}
 End of changes. 13 change blocks. 
82 lines changed or deleted 9 lines changed or added


 fn_zeros.hpp   fn_zeros.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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_zeros //! \addtogroup fn_zeros
//! @{ //! @{
//! Generate a dense matrix with all elements set to zero //! Generate a dense matrix with all elements set to zero
inline arma_inline
const Op<mat, op_zeros> const eOp<mat, eop_zeros>
zeros(const u32 n_rows, const u32 n_cols) zeros(const u32 n_rows, const u32 n_cols)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<mat, op_zeros>(n_rows, n_cols, 'j'); return eOp<mat, eop_zeros>(n_rows, n_cols);
}
arma_inline
const eOpCube<cube, eop_cube_zeros>
zeros(const u32 n_rows, const u32 n_cols, const u32 n_slices)
{
arma_extra_debug_sigprint();
return eOpCube<cube, eop_cube_zeros>(n_rows, n_cols, n_slices);
} }
template<typename mat_type> template<typename mat_type>
inline arma_inline
const Op<mat_type,op_zeros> const eOp<mat_type, eop_zeros>
zeros(const u32 n_rows, const u32 n_cols) zeros(const u32 n_rows, const u32 n_cols)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_type_check<is_Mat<mat_type>::value == false>::apply(); arma_type_check<is_Mat<mat_type>::value == false>::apply();
return Op<mat_type,op_zeros>(n_rows, n_cols, 'j'); return eOp<mat_type, eop_zeros>(n_rows, n_cols);
}
template<typename cube_type>
arma_inline
const eOpCube<cube_type, eop_cube_zeros>
zeros(const u32 n_rows, const u32 n_cols, const u32 n_slices)
{
arma_extra_debug_sigprint();
arma_type_check<is_Cube<cube_type>::value == false>::apply();
return eOpCube<cube_type, eop_cube_zeros>(n_rows, n_cols, n_slices);
} }
//! Generate a vector with all elements set to zero //! Generate a vector with all elements set to zero
inline arma_inline
const Op<colvec, op_zeros> const eOp<colvec, eop_zeros>
zeros(const u32 n_elem) zeros(const u32 n_elem)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<colvec, op_zeros>(n_elem, 1, 'j'); return eOp<colvec, eop_zeros>(n_elem, 1);
} }
template<typename vec_type> template<typename vec_type>
inline arma_inline
const Op<vec_type,op_zeros> const eOp<vec_type, eop_zeros>
zeros(const u32 n_elem) zeros(const u32 n_elem)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_type_check< (is_Col<vec_type>::value == false) && (is_Row<vec_type>: :value == false) >::apply(); arma_type_check< (is_Col<vec_type>::value == false) && (is_Row<vec_type>: :value == false) >::apply();
if(is_Row<vec_type>::value == true) if(is_Row<vec_type>::value == true)
{ {
return Op<vec_type,op_zeros>(1, n_elem, 'j'); return eOp<vec_type, eop_zeros>(1, n_elem);
} }
else else
{ {
return Op<vec_type,op_zeros>(n_elem, 1, 'j'); return eOp<vec_type, eop_zeros>(n_elem, 1);
} }
} }
//
//
// handling of cubes
//! Generate a dense cube with all elements set to zero
inline
const OpCube<cube, op_zeros>
zeros(const u32 n_rows, const u32 n_cols, const u32 n_slices)
{
arma_extra_debug_sigprint();
return OpCube<cube, op_zeros>(n_rows, n_cols, n_slices);
}
template<typename cube_type>
inline
const OpCube<cube_type,op_zeros>
zeros(const u32 n_rows, const u32 n_cols, const u32 n_slices)
{
arma_extra_debug_sigprint();
arma_type_check<is_Cube<cube_type>::value == false>::apply();
return OpCube<cube_type,op_zeros>(n_rows, n_cols, n_slices);
}
//! @} //! @}
 End of changes. 11 change blocks. 
40 lines changed or deleted 36 lines changed or added


 format_wrap.hpp   format_wrap.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 forward_proto.hpp   forward_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 40 skipping to change at line 41
template<typename eT> class diagview; template<typename eT> class diagview;
class diskio; class diskio;
class op_min; class op_min;
class op_max; class op_max;
class op_trans; class op_trans;
class op_htrans; class op_htrans;
class op_conj;
class op_diagmat;
class op_inv; class op_inv;
class op_sum; class op_sum;
class op_neg; class op_diagmat;
class op_scalar_plus;
class op_scalar_minus_pre;
class op_scalar_minus_post;
class op_scalar_times;
class op_scalar_divide;
class glue_div;
class glue_minus;
class glue_plus;
class glue_times;
class glue_times_vec;
class glue_schur;
class glue_plus_diag; class eop_conj;
class glue_minus_diag;
class glue_times_diag;
class glue_schur_diag;
class glue_cube_div; class glue_times;
class glue_cube_minus; class glue_times_diag;
class glue_cube_plus;
class glue_cube_schur;
template<const bool, const bool, const bool, const bool> class gemm; template<const bool, const bool, const bool, const bool> class gemm;
template<const bool, const bool, const bool> class gemv; template<const bool, const bool, const bool> class gemv;
template<typename T1, typename op_type> class Op; template<typename T1, typename op_type> class Op;
template<typename T1, typename op_type> class OpCube; template<typename T1, typename eop_type> class eOp;
template<typename T1, typename op_type> class OpCube;
template<typename T1, typename eop_type> class eOpCube;
template<typename T1, typename T2, typename glue_type> class Glue;
template<typename T1, typename T2, typename eglue_type> class eGlue;
template<typename T1, typename T2, typename glue_type> class GlueCube;
template<typename T1, typename T2, typename eglue_type> class eGlueCube;
template<typename T1, typename T2, typename glue_type> class Glue; template<typename T1> class Proxy;
template<typename T1, typename T2, typename glue_type> class GlueCube; template<typename T1> class ProxyCube;
//! \addtogroup diskio //! \addtogroup diskio
//! @{ //! @{
//! file types supported by Armadillo //! file types supported by Armadillo
enum file_type enum file_type
{ {
auto_detect, //!< Automatically detect the file type (file must be one o f the following types) auto_detect, //!< Automatically detect the file type (file must be one o f the following types)
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
 End of changes. 7 change blocks. 
28 lines changed or deleted 19 lines changed or added


 gemm.hpp   gemm.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 28 skipping to change at line 29
//! \brief //! \brief
//! Partial emulation of ATLAS/BLAS gemm(), using caching for speedup. //! Partial emulation of ATLAS/BLAS gemm(), using caching for speedup.
//! Matrix 'C' is assumed to have been set to the correct size (i.e. taking into account transposes) //! Matrix 'C' is assumed to have been set to the correct size (i.e. taking into account transposes)
template<const bool do_trans_A=false, const bool do_trans_B=false, const bo ol use_alpha=false, const bool use_beta=false> template<const bool do_trans_A=false, const bool do_trans_B=false, const bo ol use_alpha=false, const bool use_beta=false>
class gemm_emul_cache class gemm_emul_cache
{ {
public: public:
template<typename eT> template<typename eT>
arma_hot
inline inline
static static
void void
apply apply
( (
Mat<eT>& C, Mat<eT>& C,
const Mat<eT>& A, const Mat<eT>& A,
const Mat<eT>& B, const Mat<eT>& B,
const eT alpha = eT(1), const eT alpha = eT(1),
const eT beta = eT(0) const eT beta = eT(0)
skipping to change at line 208 skipping to change at line 210
}; };
//! Partial emulation of ATLAS/BLAS gemm(), non-cached version. //! Partial emulation of ATLAS/BLAS gemm(), non-cached version.
//! Matrix 'C' is assumed to have been set to the correct size (i.e. taking into account transposes) //! Matrix 'C' is assumed to have been set to the correct size (i.e. taking into account transposes)
template<const bool do_trans_A=false, const bool do_trans_B=false, const bo ol use_alpha=false, const bool use_beta=false> template<const bool do_trans_A=false, const bool do_trans_B=false, const bo ol use_alpha=false, const bool use_beta=false>
class gemm_emul_simple class gemm_emul_simple
{ {
public: public:
template<typename eT> template<typename eT>
arma_hot
inline inline
static static
void void
apply apply
( (
Mat<eT>& C, Mat<eT>& C,
const Mat<eT>& A, const Mat<eT>& A,
const Mat<eT>& B, const Mat<eT>& B,
const eT alpha = eT(1), const eT alpha = eT(1),
const eT beta = eT(0) const eT beta = eT(0)
skipping to change at line 493 skipping to change at line 496
if( (A.n_elem <= 64u) && (B.n_elem <= 64u) ) if( (A.n_elem <= 64u) && (B.n_elem <= 64u) )
{ {
gemm_emul_simple<do_trans_A, do_trans_B, use_alpha, use_beta>::apply( C,A,B,alpha,beta); gemm_emul_simple<do_trans_A, do_trans_B, use_alpha, use_beta>::apply( C,A,B,alpha,beta);
} }
else else
{ {
gemm_emul_cache<do_trans_A, do_trans_B, use_alpha, use_beta>::apply(C ,A,B,alpha,beta); gemm_emul_cache<do_trans_A, do_trans_B, use_alpha, use_beta>::apply(C ,A,B,alpha,beta);
} }
} }
inline arma_inline
static static
void void
apply apply
( (
Mat<float>& C, Mat<float>& C,
const Mat<float>& A, const Mat<float>& A,
const Mat<float>& B, const Mat<float>& B,
const float alpha = float(1), const float alpha = float(1),
const float beta = float(0) const float beta = float(0)
) )
{ {
gemm<do_trans_A, do_trans_B, use_alpha, use_beta>::apply_blas_type(C,A, B,alpha,beta); gemm<do_trans_A, do_trans_B, use_alpha, use_beta>::apply_blas_type(C,A, B,alpha,beta);
} }
inline arma_inline
static static
void void
apply apply
( (
Mat<double>& C, Mat<double>& C,
const Mat<double>& A, const Mat<double>& A,
const Mat<double>& B, const Mat<double>& B,
const double alpha = double(1), const double alpha = double(1),
const double beta = double(0) const double beta = double(0)
) )
{ {
gemm<do_trans_A, do_trans_B, use_alpha, use_beta>::apply_blas_type(C,A, B,alpha,beta); gemm<do_trans_A, do_trans_B, use_alpha, use_beta>::apply_blas_type(C,A, B,alpha,beta);
} }
inline arma_inline
static static
void void
apply apply
( (
Mat< std::complex<float> >& C, Mat< std::complex<float> >& C,
const Mat< std::complex<float> >& A, const Mat< std::complex<float> >& A,
const Mat< std::complex<float> >& B, const Mat< std::complex<float> >& B,
const std::complex<float> alpha = std::complex<float>(1), const std::complex<float> alpha = std::complex<float>(1),
const std::complex<float> beta = std::complex<float>(0) const std::complex<float> beta = std::complex<float>(0)
) )
{ {
gemm<do_trans_A, do_trans_B, use_alpha, use_beta>::apply_blas_type(C,A, B,alpha,beta); gemm<do_trans_A, do_trans_B, use_alpha, use_beta>::apply_blas_type(C,A, B,alpha,beta);
} }
inline arma_inline
static static
void void
apply apply
( (
Mat< std::complex<double> >& C, Mat< std::complex<double> >& C,
const Mat< std::complex<double> >& A, const Mat< std::complex<double> >& A,
const Mat< std::complex<double> >& B, const Mat< std::complex<double> >& B,
const std::complex<double> alpha = std::complex<double>(1), const std::complex<double> alpha = std::complex<double>(1),
const std::complex<double> beta = std::complex<double>(0) const std::complex<double> beta = std::complex<double>(0)
) )
 End of changes. 7 change blocks. 
5 lines changed or deleted 8 lines changed or added


 gemm_mixed.hpp   gemm_mixed.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 29 skipping to change at line 30
//! Matrix multplication where the matrices have different element types. //! Matrix multplication where the matrices have different element types.
//! Uses caching for speedup. //! Uses caching for speedup.
//! Matrix 'C' is assumed to have been set to the correct size (i.e. taking into account transposes) //! Matrix 'C' is assumed to have been set to the correct size (i.e. taking into account transposes)
template<const bool do_trans_A=false, const bool do_trans_B=false, const bo ol use_alpha=false, const bool use_beta=false> template<const bool do_trans_A=false, const bool do_trans_B=false, const bo ol use_alpha=false, const bool use_beta=false>
class gemm_mixed_cache class gemm_mixed_cache
{ {
public: public:
template<typename out_eT, typename in_eT1, typename in_eT2> template<typename out_eT, typename in_eT1, typename in_eT2>
arma_hot
inline inline
static static
void void
apply apply
( (
Mat<out_eT>& C, Mat<out_eT>& C,
const Mat<in_eT1>& A, const Mat<in_eT1>& A,
const Mat<in_eT2>& B, const Mat<in_eT2>& B,
const out_eT alpha = out_eT(1), const out_eT alpha = out_eT(1),
const out_eT beta = out_eT(0) const out_eT beta = out_eT(0)
skipping to change at line 210 skipping to change at line 212
//! Matrix multplication where the matrices have different element types. //! Matrix multplication where the matrices have different element types.
//! Simple version (no caching). //! Simple version (no caching).
//! Matrix 'C' is assumed to have been set to the correct size (i.e. taking into account transposes) //! Matrix 'C' is assumed to have been set to the correct size (i.e. taking into account transposes)
template<const bool do_trans_A=false, const bool do_trans_B=false, const bo ol use_alpha=false, const bool use_beta=false> template<const bool do_trans_A=false, const bool do_trans_B=false, const bo ol use_alpha=false, const bool use_beta=false>
class gemm_mixed_simple class gemm_mixed_simple
{ {
public: public:
template<typename out_eT, typename in_eT1, typename in_eT2> template<typename out_eT, typename in_eT1, typename in_eT2>
arma_hot
inline inline
static static
void void
apply apply
( (
Mat<out_eT>& C, Mat<out_eT>& C,
const Mat<in_eT1>& A, const Mat<in_eT1>& A,
const Mat<in_eT2>& B, const Mat<in_eT2>& B,
const out_eT alpha = out_eT(1), const out_eT alpha = out_eT(1),
const out_eT beta = out_eT(0) const out_eT beta = out_eT(0)
 End of changes. 3 change blocks. 
1 lines changed or deleted 4 lines changed or added


 gemv.hpp   gemv.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 28 skipping to change at line 29
//! \brief //! \brief
//! Partial emulation of ATLAS/BLAS gemv(). //! Partial emulation of ATLAS/BLAS gemv().
//! 'y' is assumed to have been set to the correct size (i.e. taking into a ccount the transpose) //! 'y' is assumed to have been set to the correct size (i.e. taking into a ccount the transpose)
template<const bool do_trans_A=false, const bool use_alpha=false, const boo l use_beta=false> template<const bool do_trans_A=false, const bool use_alpha=false, const boo l use_beta=false>
class gemv_arma class gemv_arma
{ {
public: public:
template<typename eT> template<typename eT>
arma_hot
inline inline
static static
void void
apply( eT* y, const Mat<eT>& A, const eT* x, const eT alpha = eT(1), cons t eT beta = eT(0) ) apply( eT* y, const Mat<eT>& A, const eT* x, const eT alpha = eT(1), cons t eT beta = eT(0) )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const u32 A_n_rows = A.n_rows; const u32 A_n_rows = A.n_rows;
const u32 A_n_cols = A.n_cols; const u32 A_n_cols = A.n_cols;
skipping to change at line 124 skipping to change at line 126
template<const bool do_trans_A=false, const bool use_alpha=false, const boo l use_beta=false> template<const bool do_trans_A=false, const bool use_alpha=false, const boo l use_beta=false>
class gemv class gemv
{ {
public: public:
template<typename eT> template<typename eT>
inline inline
static static
void void
apply( eT* y, const Mat<eT>& A, const eT* x, const eT alpha = eT(1), cons t eT beta = eT(0) ) apply_blas_type( eT* y, const Mat<eT>& A, const eT* x, const eT alpha = e T(1), const eT beta = eT(0) )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
if( (A.n_elem <= 256u) || (is_supported_blas_type<eT>::value == false) ) if(A.n_elem <= 256u)
{ {
gemv_arma<do_trans_A, use_alpha, use_beta>::apply(y,A,x,alpha,beta); gemv_arma<do_trans_A, use_alpha, use_beta>::apply(y,A,x,alpha,beta);
} }
else else
{ {
#if defined(ARMA_USE_ATLAS) #if defined(ARMA_USE_ATLAS)
{ {
arma_extra_debug_print("atlas::cblas_gemv()"); arma_extra_debug_print("atlas::cblas_gemv()");
atlas::cblas_gemv<eT> atlas::cblas_gemv<eT>
skipping to change at line 192 skipping to change at line 194
} }
#else #else
{ {
gemv_arma<do_trans_A, use_alpha, use_beta>::apply(y,A,x,alpha,beta) ; gemv_arma<do_trans_A, use_alpha, use_beta>::apply(y,A,x,alpha,beta) ;
} }
#endif #endif
} }
} }
template<typename eT>
arma_inline
static
void
apply( eT* y, const Mat<eT>& A, const eT* x, const eT alpha = eT(1), cons
t eT beta = eT(0) )
{
gemv_arma<do_trans_A, use_alpha, use_beta>::apply(y,A,x,alpha,beta);
}
arma_inline
static
void
apply
(
float* y,
const Mat<float>& A,
const float* x,
const float alpha = float(1),
const float beta = float(0)
)
{
gemv<do_trans_A, use_alpha, use_beta>::apply_blas_type(y,A,x,alpha,beta
);
}
arma_inline
static
void
apply
(
double* y,
const Mat<double>& A,
const double* x,
const double alpha = double(1),
const double beta = double(0)
)
{
gemv<do_trans_A, use_alpha, use_beta>::apply_blas_type(y,A,x,alpha,beta
);
}
arma_inline
static
void
apply
(
std::complex<float>* y,
const Mat< std::complex<float > >& A,
const std::complex<float>* x,
const std::complex<float> alpha = std::complex<float>(1),
const std::complex<float> beta = std::complex<float>(0)
)
{
gemv<do_trans_A, use_alpha, use_beta>::apply_blas_type(y,A,x,alpha,beta
);
}
arma_inline
static
void
apply
(
std::complex<double>* y,
const Mat< std::complex<double> >& A,
const std::complex<double>* x,
const std::complex<double> alpha = std::complex<double>(1),
const std::complex<double> beta = std::complex<double>(0)
)
{
gemv<do_trans_A, use_alpha, use_beta>::apply_blas_type(y,A,x,alpha,beta
);
}
}; };
//! @} //! @}
 End of changes. 5 change blocks. 
3 lines changed or deleted 79 lines changed or added


 glue_cor_meat.hpp   glue_cor_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
 End of changes. 1 change blocks. 
2 lines changed or deleted 2 lines changed or added


 glue_cor_proto.hpp   glue_cor_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
 End of changes. 1 change blocks. 
2 lines changed or deleted 2 lines changed or added


 glue_cov_meat.hpp   glue_cov_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
 End of changes. 1 change blocks. 
2 lines changed or deleted 2 lines changed or added


 glue_cov_proto.hpp   glue_cov_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
 End of changes. 1 change blocks. 
2 lines changed or deleted 2 lines changed or added


 glue_kron_meat.hpp   glue_kron_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
 End of changes. 1 change blocks. 
2 lines changed or deleted 2 lines changed or added


 glue_kron_proto.hpp   glue_kron_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
 End of changes. 1 change blocks. 
2 lines changed or deleted 2 lines changed or added


 glue_times_meat.hpp   glue_times_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 glue_times //! \addtogroup glue_times
//! @{ //! @{
template<u32 N>
template<typename T1, typename T2> template<typename T1, typename T2>
inline
void void
glue_times::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_t imes>& X) glue_times_redirect<N>::apply(Mat<typename T1::elem_type>& out, const Glue< T1,T2,glue_times>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
const s32 N_mat = 1 + depth_lhs< glue_times, Glue<T1,T2,glue_times> >::nu const partial_unwrap_check<T1> tmp1(X.A, out);
m; const partial_unwrap_check<T2> tmp2(X.B, out);
arma_extra_debug_print(arma_boost::format("N_mat = %d") % N_mat);
if(N_mat == 2)
{
const unwrap<T1> tmp1(X.A);
const unwrap<T2> tmp2(X.B);
glue_times::apply(out, tmp1.M, tmp2.M);
}
else
{
// we have at least three matrices
const Mat<eT>* ptrs[N_mat];
bool del[N_mat];
// takes care of any aliasing problems
mat_ptrs_outcheck<glue_times, Glue<T1,T2,glue_times> >::get_ptrs(ptrs,
del, X, &out);
for(s32 i=0; i<N_mat; ++i) arma_extra_debug_print( arma_boost::format(
"ptrs[%d] = %x") % i % ptrs[i] );
for(s32 i=0; i<N_mat; ++i) arma_extra_debug_print( arma_boost::format(
" del[%d] = %d") % i % del[i] );
arma_extra_debug_print( arma_boost::format("required size of 'out': %d
, %d") % ptrs[0]->n_rows % ptrs[N_mat-1]->n_cols );
int order[N_mat]; for(s32 i=0; i<N_mat; ++i) order[i] = -1;
int first_id = 0;
int last_id = N_mat-1;
int starting_id = -1;
int mat_count = N_mat;
int largest_size = 0;
while(mat_count != 0)
{
for(s32 i=first_id; i != N_mat; ++i)
{
if(order[i] == -1) { first_id = i; break; }
}
for(s32 i=last_id; i != -1; --i)
{
if(order[i] == -1) { last_id = i; break; }
}
arma_extra_debug_print();
arma_extra_debug_print(arma_boost::format("mat_count = %d") % mat_cou
nt );
arma_extra_debug_print(arma_boost::format("first_id = %d") % first_i
d );
arma_extra_debug_print(arma_boost::format("last_id = %d") % last_id
);
if(first_id == last_id) { order[first_id] = 0; starting_id = first_i
d; break; }
s32 storage_cost_wo_last = mul_storage_cost( *ptrs[ first_id ], *p
trs[ last_id-1 ] );
s32 storage_cost_wo_first = mul_storage_cost( *ptrs[ first_id+1 ], *p
trs[ last_id ] );
if(storage_cost_wo_last < storage_cost_wo_first)
{
order[last_id] = mat_count-1;
if(storage_cost_wo_last > largest_size) largest_size = storage_cos
t_wo_last;
}
else
{
order[first_id] = mat_count-1;
if(storage_cost_wo_first > largest_size) largest_size = storage_co
st_wo_first;
}
arma_extra_debug_print(arma_boost::format("storage_cost_wo_last = %d
") % storage_cost_wo_last );
arma_extra_debug_print(arma_boost::format("storage_cost_wo_first = %d
") % storage_cost_wo_first );
arma_extra_debug_print("order = ");
for(s32 i=0; i != N_mat; ++i) arma_extra_debug_print(order[i]);
--mat_count;
}
arma_extra_debug_print("final order = ");
for(s32 i=0; i != N_mat; ++i) arma_extra_debug_print(order[i]);
arma_extra_debug_print(arma_boost::format("*** largest_size = %d") % la const Mat<eT>& A = tmp1.M;
rgest_size); const Mat<eT>& B = tmp2.M;
arma_extra_debug_print(arma_boost::format("starting_id = %d") % starti
ng_id);
// multiply based on order
// if there are only three matrices, we need only one temporary store:
// out = a*b*c translates to: tmp1 = a*b, out = tmp1*c
//
// if there are four matrices, we need two temporary stores
// out = a*b*c*d translates to: tmp1 = a*b, tmp2 = tmp1*c, out = tmp
2*d
//
// if there are five matrices, we need two temporary stores
// out = a*b*c*d*e translates to: tmp1 = a*b, tmp2 = tmp1*c, tmp1 =
tmp2*d, out = tmp1*e
//
// if there are six matrices, we need two temporary stores
// out = a*b*c*d*e*f translates to: tmp1 = a*b, tmp2 = tmp1*c, tmp1
= tmp2*d, tmp2 = tmp1*e, out = tmp2*f
//
const u32 N_mul = N_mat - 1;
int mul_count = N_mul;
int current_id = starting_id;
const Mat<eT>* src_mat_1_ptr = ptrs[current_id];
const Mat<eT>* src_mat_2_ptr = 0;
// TODO:
// allocate two storage areas (of size 'largest_size'), not two matrice
s
Mat<eT> tmp_mat_1; const bool do_trans_A = tmp1.do_trans;
Mat<eT> tmp_mat_2; const bool do_trans_B = tmp2.do_trans;
Mat<eT>* tmp_mat_1_ptr = &tmp_mat_1; const bool use_alpha = tmp1.do_times | tmp2.do_times;
Mat<eT>* tmp_mat_2_ptr = (N_mul <= 2) ? 0 : &tmp_mat_2; const eT alpha = use_alpha ? (tmp1.val * tmp2.val) : eT(0);
Mat<eT>* dest_mat_ptr = tmp_mat_2_ptr; glue_times::apply(out, A, B, alpha, do_trans_A, do_trans_B, use_alpha);
}
arma_extra_debug_print(arma_boost::format("tmp_mat_1_ptr = %x") % tmp_m template<typename T1, typename T2, typename T3>
at_1_ptr ); inline
arma_extra_debug_print(arma_boost::format("tmp_mat_2_ptr = %x") % tmp_m void
at_2_ptr ); glue_times_redirect<3>::apply(Mat<typename T1::elem_type>& out, const Glue<
arma_extra_debug_print(arma_boost::format("&out = %x") % &out Glue<T1,T2,glue_times>, T3, glue_times>& X)
); {
arma_extra_debug_sigprint();
while(mul_count != 0) typedef typename T1::elem_type eT;
{
arma_extra_debug_print("");
arma_extra_debug_print("");
arma_extra_debug_print(arma_boost::format("mul_count = %d") % mul_cou
nt);
arma_extra_debug_print("order = "); // there is exactly 3 objects
for(s32 i=0; i != N_mat; ++i) arma_extra_debug_print(order[i]); // hence we can safely expand X as X.A.A, X.A.B and X.B
arma_extra_debug_print("");
// only one multiplication left, hence destination matrix is the out const partial_unwrap_check<T1> tmp1(X.A.A, out);
matrix const partial_unwrap_check<T2> tmp2(X.A.B, out);
if(mul_count == 1) const partial_unwrap_check<T3> tmp3(X.B, out);
{
arma_extra_debug_print("dest_mat = &out");
dest_mat_ptr = &out;
}
else
{
if(dest_mat_ptr == tmp_mat_2_ptr)
{
arma_extra_debug_print("dest_mat_ptr = tmp_mat_2_ptr");
dest_mat_ptr = tmp_mat_1_ptr;
}
else
{
arma_extra_debug_print("dest_mat_ptr = tmp_mat_1_ptr");
dest_mat_ptr = tmp_mat_2_ptr;
}
}
arma_extra_debug_print(arma_boost::format("dest_mat_ptr = %x") % dest const Mat<eT>& A = tmp1.M;
_mat_ptr ); const Mat<eT>& B = tmp2.M;
const Mat<eT>& C = tmp3.M;
// search on either side of current_pos for a useable value. unuseab const bool do_trans_A = tmp1.do_trans;
le values are equal to -1 const bool do_trans_B = tmp2.do_trans;
s32 left_val = N_mat; const bool do_trans_C = tmp3.do_trans;
s32 left_id = -1;
s32 right_val = N_mat; const bool use_alpha = tmp1.do_times | tmp2.do_times | tmp3.do_times;
s32 right_id = -1; const eT alpha = use_alpha ? (tmp1.val * tmp2.val * tmp3.val) : eT(
0);
// go left from current_pos glue_times::apply(out, A, B, C, alpha, do_trans_A, do_trans_B, do_trans_C
for(s32 i=current_id-1; i >= 0; --i) , use_alpha);
if( order[i] > order[current_id] ) { left_val = order[i]; left_id = }
i; break; }
// go right from current_pos template<typename T1, typename T2, typename T3, typename T4>
for(s32 i=current_id+1; i < N_mat; ++i) inline
if( order[current_id] < order[i] ) { right_val = order[i]; right_id void
= i; break; } glue_times_redirect<4>::apply(Mat<typename T1::elem_type>& out, const Glue<
Glue< Glue<T1,T2,glue_times>, T3, glue_times>, T4, glue_times>& X)
{
arma_extra_debug_sigprint();
arma_extra_debug_print(""); typedef typename T1::elem_type eT;
arma_extra_debug_print(arma_boost::format("left_id = %d") % left_id
);
arma_extra_debug_print(arma_boost::format("left_val = %f") % left_val
);
arma_extra_debug_print(""); // there is exactly 4 objects
arma_extra_debug_print(arma_boost::format("right_id = %d") % right_i // hence we can safely expand X as X.A.A.A, X.A.A.B, X.A.B and X.B
d );
arma_extra_debug_print(arma_boost::format("right_val = %f") % right_v
al );
if(left_val < right_val) const partial_unwrap_check<T1> tmp1(X.A.A.A, out);
{ const partial_unwrap_check<T2> tmp2(X.A.A.B, out);
// a pre-multiply const partial_unwrap_check<T3> tmp3(X.A.B, out);
src_mat_2_ptr = ptrs[left_id]; const partial_unwrap_check<T4> tmp4(X.B, out);
arma_extra_debug_print(""); const Mat<eT>& A = tmp1.M;
arma_extra_debug_print(arma_boost::format("case pre-multiply with m const Mat<eT>& B = tmp2.M;
atrix %d") % left_id); const Mat<eT>& C = tmp3.M;
arma_extra_debug_print(arma_boost::format("required destination siz const Mat<eT>& D = tmp4.M;
e: %d, %d (%d)") % src_mat_2_ptr->n_rows % src_mat_1_ptr->n_cols % (src_m
at_2_ptr->n_rows * src_mat_1_ptr->n_cols) );
glue_times::apply_noalias(*dest_mat_ptr, *src_mat_2_ptr, *src_mat_1 const bool do_trans_A = tmp1.do_trans;
_ptr); const bool do_trans_B = tmp2.do_trans;
const bool do_trans_C = tmp3.do_trans;
const bool do_trans_D = tmp4.do_trans;
order[current_id] = -1; const bool use_alpha = tmp1.do_times | tmp2.do_times | tmp3.do_times | tm
current_id = left_id; p4.do_times;
} const eT alpha = use_alpha ? (tmp1.val * tmp2.val * tmp3.val * tmp4
else .val) : eT(0);
{
// a post-multiply
src_mat_2_ptr = ptrs[right_id];
arma_extra_debug_print(""); glue_times::apply(out, A, B, C, D, alpha, do_trans_A, do_trans_B, do_tran
arma_extra_debug_print(arma_boost::format("case post-multiply with s_C, do_trans_D, use_alpha);
matrix %d") % right_id); }
arma_extra_debug_print(arma_boost::format("required destination siz
e: %d, %d (%d)") % src_mat_1_ptr->n_rows % src_mat_2_ptr->n_cols % (src_ma
t_1_ptr->n_rows * src_mat_2_ptr->n_cols) );
glue_times::apply_noalias(*dest_mat_ptr, *src_mat_1_ptr, *src_mat_2 template<typename T1, typename T2>
_ptr); inline
void
glue_times::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_t
imes>& X)
{
arma_extra_debug_sigprint();
order[current_id] = -1; typedef typename T1::elem_type eT;
current_id = right_id;
}
// update pointer to source matrix: must point to last multiplication const s32 N_mat = 1 + depth_lhs< glue_times, Glue<T1,T2,glue_times> >::nu
result m;
src_mat_1_ptr = dest_mat_ptr;
--mul_count; arma_extra_debug_print(arma_boost::format("N_mat = %d") % N_mat);
}
for(s32 i=0; i<N_mat; ++i) glue_times_redirect<N_mat>::apply(out, X);
{
if(del[i] == true)
{
arma_extra_debug_print(arma_boost::format("delete mat_ptr[%d]") % i
);
delete ptrs[i];
}
}
}
} }
template<typename T1> template<typename T1>
inline inline
void void
glue_times::apply_inplace(Mat<typename T1::elem_type>& out, const T1& X) glue_times::apply_inplace(Mat<typename T1::elem_type>& out, const T1& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
const unwrap<T1> tmp(X); const unwrap_check<T1> tmp(X, out);
const Mat<eT>& B = tmp.M; const Mat<eT>& B = tmp.M;
arma_debug_assert_mul_size(out, B, "matrix multiply"); arma_debug_assert_mul_size(out, B, "matrix multiply");
if(out.n_cols == B.n_cols) if(out.n_cols == B.n_cols)
{ {
podarray<eT> tmp(out.n_cols); podarray<eT> tmp(out.n_cols);
eT* tmp_rowdata = tmp.memptr(); eT* tmp_rowdata = tmp.memptr();
for(u32 out_row=0; out_row < out.n_rows; ++out_row) for(u32 out_row=0; out_row < out.n_rows; ++out_row)
{ {
skipping to change at line 292 skipping to change at line 167
} }
out.at(out_row,B_col) = val; out.at(out_row,B_col) = val;
} }
} }
} }
else else
{ {
const Mat<eT> tmp(out); const Mat<eT> tmp(out);
glue_times::apply(out, tmp, B); glue_times::apply(out, tmp, B, eT(1), false, false, false);
} }
} }
//! matrix multiplication with different element types template<typename T1, typename T2>
template<typename eT1, typename eT2> arma_hot
inline inline
void void
glue_times::apply_mixed(Mat<typename promote_type<eT1,eT2>::result>& out, c onst Mat<eT1>& X, const Mat<eT2>& Y) glue_times::apply_inplace_plus(Mat<typename T1::elem_type>& out, const Glue <T1, T2, glue_times>& X, const s32 sign)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename promote_type<eT1,eT2>::result out_eT; typedef typename T1::elem_type eT;
arma_debug_assert_mul_size(X,Y, "matrix multiply");
out.set_size(X.n_rows,Y.n_cols); const partial_unwrap_check<T1> tmp1(X.A, out);
gemm_mixed<>::apply(out, X, Y); const partial_unwrap_check<T2> tmp2(X.B, out);
}
template<typename eT> const Mat<eT>& A = tmp1.M;
arma_inline const Mat<eT>& B = tmp2.M;
u32 glue_times::mul_storage_cost(const Mat<eT>& X, const Mat<eT>& Y) const eT alpha = tmp1.val * tmp2.val * ( (sign > s32(0)) ? eT(1) :
{ eT(-1) );
return X.n_rows * Y.n_cols;
}
//! multiply matrices A and B, storing the result in 'out' const bool do_trans_A = tmp1.do_trans;
//! assumes that A and B are not aliases of 'out' const bool do_trans_B = tmp2.do_trans;
template<typename eT> const bool use_alpha = tmp1.do_times | tmp2.do_times | (sign < s32(0));
inline
void
glue_times::apply_noalias(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B)
{
arma_extra_debug_sigprint();
arma_debug_assert_mul_size(A, B, "matrix multiply"); arma_debug_assert_mul_size(A, B, do_trans_A, do_trans_B, "matrix multiply ");
out.set_size(A.n_rows,B.n_cols); const u32 result_n_rows = (do_trans_A == false) ? A.n_rows : A.n_cols;
gemm<>::apply(out,A,B); const u32 result_n_cols = (do_trans_B == false) ? B.n_cols : B.n_rows;
}
template<typename eT> arma_assert_same_size(out.n_rows, out.n_cols, result_n_rows, result_n_col
inline s, "matrix addition");
void
glue_times::apply(Mat<eT>& out, const Mat<eT>& A_in, const Mat<eT>& B_in)
{
arma_extra_debug_sigprint();
if( (&out != &A_in) && (&out != &B_in) ) if( (do_trans_A == false) && (do_trans_B == false) && (use_alpha == false ) )
{ {
glue_times::apply_noalias(out,A_in,B_in); if(A.n_rows == 1)
{
gemv<true, false, true>::apply(out.memptr(), B, A.memptr(), a
lpha, eT(1));
}
if(B.n_cols == 1)
{
gemv<false, false, true>::apply(out.memptr(), A, B.memptr(), a
lpha, eT(1));
}
else
{
gemm<false, false, false, true>::apply(out, A, B, alpha, eT(1));
}
} }
else else
if( (do_trans_A == false) && (do_trans_B == false) && (use_alpha == true) )
{ {
if(A.n_rows == 1)
if( (&out == &A_in) && (&out != &B_in) )
{ {
Mat<eT> A_copy(A_in); gemv<true, true, true>::apply(out.memptr(), B, A.memptr(), al
glue_times::apply_noalias(out,A_copy,B_in); pha, eT(1));
} }
else if(B.n_cols == 1)
if( (&out != &A_in) && (&out == &B_in) )
{ {
Mat<eT> B_copy(B_in); gemv<false, true, true>::apply(out.memptr(), A, B.memptr(), al
glue_times::apply_noalias(out,A_in,B_copy); pha, eT(1));
} }
else else
if( (&out == &A_in) && (&out == &B_in) )
{ {
Mat<eT> tmp(A_in); gemm<false, false, true, true>::apply(out, A, B, alpha, eT(1));
glue_times::apply_noalias(out,tmp,tmp);
} }
} }
else
} if( (do_trans_A == true) && (do_trans_B == false) && (use_alpha == false)
)
template<typename eT>
inline
void
glue_times::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B, const M
at<eT>& C)
{
arma_extra_debug_sigprint();
arma_debug_assert_mul_size(A, B, "matrix multiply");
arma_debug_assert_mul_size(B, C, "matrix multiply");
if( mul_storage_cost(A,B) <= mul_storage_cost(B,C) )
{ {
Mat<eT> tmp; if(A.n_cols == 1)
glue_times::apply_noalias(tmp, A, B); {
gemv<true, false, true>::apply(out.memptr(), B, A.memptr(), al
if(&out != &C) pha, eT(1));
}
if(B.n_cols == 1)
{ {
glue_times::apply_noalias(out, tmp, C); gemv<true, false, true>::apply(out.memptr(), A, B.memptr(), al pha, eT(1));
} }
else else
{ {
Mat<eT> C_copy = C; gemm<true, false, false, true>::apply(out, A, B, alpha, eT(1));
glue_times::apply_noalias(out, tmp, C_copy);
} }
} }
else else
if( (do_trans_A == true) && (do_trans_B == false) && (use_alpha == true) )
{ {
Mat<eT> tmp; if(A.n_cols == 1)
glue_times::apply_noalias(tmp, B, C); {
gemv<true, true, true>::apply(out.memptr(), B, A.memptr(), alp
if(&out != &A) ha, eT(1));
}
if(B.n_cols == 1)
{ {
glue_times::apply_noalias(out, A, tmp); gemv<true, true, true>::apply(out.memptr(), A, B.memptr(), alp ha, eT(1));
} }
else else
{ {
Mat<eT> A_copy = A; gemm<true, false, true, true>::apply(out, A, B, alpha, eT(1));
glue_times::apply_noalias(out, A_copy, tmp);
} }
} }
else
} if( (do_trans_A == false) && (do_trans_B == true) && (use_alpha == false)
)
template<typename eT>
inline
eT
glue_times::direct_rowvec_mat_colvec
(
const eT* A_mem,
const Mat<eT>& B,
const eT* C_mem
)
{
arma_extra_debug_sigprint();
const u32 cost_AB = B.n_cols;
const u32 cost_BC = B.n_rows;
if(cost_AB <= cost_BC)
{ {
podarray<eT> tmp(B.n_cols); if(A.n_rows == 1)
for(u32 col=0; col<B.n_cols; ++col)
{ {
const eT* B_coldata = B.colptr(col); gemv<false, false, true>::apply(out.memptr(), B, A.memptr(), al
pha, eT(1));
eT val = eT(0); }
for(u32 i=0; i<B.n_rows; ++i) if(B.n_rows == 1)
{ {
val += A_mem[i] * B_coldata[i]; gemv<false, false, true>::apply(out.memptr(), A, B.memptr(), al
} pha, eT(1));
}
tmp[col] = val; else
{
gemm<false, true, false, true>::apply(out, A, B, alpha, eT(1));
} }
return op_dot::direct_dot(B.n_cols, tmp.mem, C_mem);
} }
else else
if( (do_trans_A == false) && (do_trans_B == true) && (use_alpha == true) )
{ {
podarray<eT> tmp(B.n_rows); if(A.n_rows == 1)
for(u32 row=0; row<B.n_rows; ++row)
{ {
eT val = eT(0); gemv<false, true, true>::apply(out.memptr(), B, A.memptr(), alp
for(u32 col=0; col<B.n_cols; ++col) ha, eT(1));
{ }
val += B.at(row,col) * C_mem[col]; if(B.n_rows == 1)
} {
gemv<false, true, true>::apply(out.memptr(), A, B.memptr(), alp
tmp[row] = val; ha, eT(1));
}
else
{
gemm<false, true, true, true>::apply(out, A, B, alpha, eT(1));
} }
return op_dot::direct_dot(B.n_rows, A_mem, tmp.mem);
} }
else
} if( (do_trans_A == true) && (do_trans_B == true) && (use_alpha == false)
)
template<typename eT>
inline
eT
glue_times::direct_rowvec_diagmat_colvec
(
const eT* A_mem,
const Mat<eT>& B,
const eT* C_mem
)
{
arma_extra_debug_sigprint();
eT val = eT(0);
for(u32 i=0; i<B.n_rows; ++i)
{ {
val += A_mem[i] * B.at(i,i) * C_mem[i]; if(A.n_cols == 1)
{
gemv<false, false, true>::apply(out.memptr(), B, A.memptr(), alp
ha, eT(1));
}
if(B.n_rows == 1)
{
gemv<true, false, true>::apply(out.memptr(), A, B.memptr(), alp
ha, eT(1));
}
else
{
gemm<true, true, false, true>::apply(out, A, B, alpha, eT(1));
}
} }
else
return val; if( (do_trans_A == true) && (do_trans_B == true) && (use_alpha == true) )
}
template<typename eT>
inline
eT
glue_times::direct_rowvec_invdiagmat_colvec
(
const eT* A_mem,
const Mat<eT>& B,
const eT* C_mem
)
{
arma_extra_debug_sigprint();
eT val = eT(0);
for(u32 i=0; i<B.n_rows; ++i)
{ {
val += (A_mem[i] * C_mem[i]) / B.at(i,i); if(A.n_cols == 1)
{
gemv<false, true, true>::apply(out.memptr(), B, A.memptr(), alph
a, eT(1));
}
if(B.n_rows == 1)
{
gemv<true, true, true>::apply(out.memptr(), A, B.memptr(), alph
a, eT(1));
}
else
{
gemm<true, true, true, true>::apply(out, A, B, alpha, eT(1));
}
} }
return val;
} }
template<typename eT> //! matrix multiplication with different element types
template<typename eT1, typename eT2>
inline inline
eT void
glue_times::direct_rowvec_invdiagvec_colvec glue_times::apply_mixed(Mat<typename promote_type<eT1,eT2>::result>& out, c
( onst Mat<eT1>& X, const Mat<eT2>& Y)
const eT* A_mem,
const Mat<eT>& B,
const eT* C_mem
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const eT* B_mem = B.mem; typedef typename promote_type<eT1,eT2>::result out_eT;
eT val = eT(0);
for(u32 i=0; i<B.n_elem; ++i) arma_debug_assert_mul_size(X,Y, "matrix multiply");
{
val += (A_mem[i] * C_mem[i]) / B_mem[i];
}
return val; out.set_size(X.n_rows,Y.n_cols);
gemm_mixed<>::apply(out, X, Y);
} }
#if defined(ARMA_GOOD_COMPILER)
template<typename eT> template<typename eT>
inline arma_inline
void u32
glue_times::apply(Mat<eT>& out, const Glue<Mat<eT>,Mat<eT>,glue_times>& X) glue_times::mul_storage_cost(const Mat<eT>& A, const Mat<eT>& B, const bool
do_trans_A, const bool do_trans_B)
{ {
glue_times::apply(out, X.A, X.B); const u32 final_A_n_rows = (do_trans_A == false) ? A.n_rows : A.n_cols;
} const u32 final_B_n_cols = (do_trans_B == false) ? B.n_cols : B.n_rows;
template<typename eT> return final_A_n_rows * final_B_n_cols;
inline
void
glue_times::apply(Mat<eT>& out, const Glue< Glue<Mat<eT>,Mat<eT>, glue_time
s>, Mat<eT>, glue_times>& X)
{
glue_times::apply(out, X.A.A, X.A.B, X.B);
} }
//! out = T1 * trans(T2) template<typename eT>
template<typename T1, typename T2> arma_hot
inline inline
void void
glue_times::apply(Mat<typename T1::elem_type>& out, const Glue<T1, Op<T2,op glue_times::apply
_trans>, glue_times>& X) (
Mat<eT>& out,
const Mat<eT>& A,
const Mat<eT>& B,
const eT alpha,
const bool do_trans_A,
const bool do_trans_B,
const bool use_alpha
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; arma_debug_assert_mul_size(A, B, do_trans_A, do_trans_B, "matrix multiply
");
// checks for aliases are done later
const unwrap<T1> tmp1(X.A); const u32 final_n_rows = (do_trans_A == false) ? A.n_rows : A.n_cols;
const unwrap<T2> tmp2(X.B.m); const u32 final_n_cols = (do_trans_B == false) ? B.n_cols : B.n_rows;
const Mat<eT>& A = tmp1.M; out.set_size(final_n_rows, final_n_cols);
const Mat<eT>& B = tmp2.M;
arma_debug_assert_mul_size(A.n_rows, A.n_cols, B.n_cols, B.n_rows, "matri x multiply"); // TODO: thoroughly test all combinations
if( (A.n_rows*B.n_rows) > 0) if( (do_trans_A == false) && (do_trans_B == false) && (use_alpha == false ) )
{ {
if(&A != &B) // A*B' if(A.n_rows == 1)
{ {
unwrap_check< Mat<eT> > A_safe_tmp(A, out); gemv<true, false, false>::apply(out.memptr(), B, A.memptr());
unwrap_check< Mat<eT> > B_safe_tmp(B, out);
const Mat<eT>& A_safe = A_safe_tmp.M;
const Mat<eT>& B_safe = B_safe_tmp.M;
out.set_size(A_safe.n_rows, B_safe.n_rows);
gemm<false,true>::apply(out, A, B);
} }
else // A*A' else
if(B.n_cols == 1)
{ {
arma_extra_debug_print("glue_times::apply(): detected A*A'"); gemv<false, false, false>::apply(out.memptr(), A, B.memptr());
}
Mat<eT> tmp; else
op_trans::apply(tmp,A); {
gemm<false, false, false, false>::apply(out, A, B);
// no aliasing problem
out.set_size(A.n_rows, A.n_rows);
for(u32 row=0; row != A.n_rows; ++row)
{
for(u32 col=0; col <= row; ++col)
{
const eT* coldata1 = tmp.colptr(row);
const eT* coldata2 = tmp.colptr(col);
eT val = eT(0);
for(u32 i=0; i < tmp.n_rows; ++i)
{
val += coldata1[i] * coldata2[i];
}
out.at(row,col) = val;
out.at(col,row) = val;
}
}
} }
}
}
//! out = trans(T1) * T2
template<typename T1, typename T2>
inline
void
glue_times::apply(Mat<typename T1::elem_type>& out, const Glue< Op<T1,op_tr
ans>, T2, glue_times>& X)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const unwrap_check<T1> tmp1(X.A.m, out);
const unwrap_check<T2> tmp2(X.B, out);
const Mat<eT>& A = tmp1.M;
const Mat<eT>& B = tmp2.M;
arma_debug_assert_mul_size(A.n_cols, A.n_rows, B.n_rows, B.n_cols, "matri
x multiply");
if( (A.n_cols*B.n_cols) > 0 )
{
out.set_size(A.n_cols, B.n_cols);
gemm<true,false>::apply(out, A, B);
}
}
//! out = trans(T1) * trans(T2)
template<typename T1, typename T2>
inline
void
glue_times::apply(Mat<typename T1::elem_type>& out, const Glue< Op<T1,op_tr
ans>, Op<T2,op_trans>, glue_times>& X)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const unwrap_check<T1> tmp1(X.A.m, out);
const unwrap_check<T2> tmp2(X.B.m, out);
const Mat<eT>& A = tmp1.M;
const Mat<eT>& B = tmp2.M;
arma_debug_assert_mul_size(A.n_cols, A.n_rows, B.n_cols, B.n_rows, "matri
x multiply");
if( (A.n_cols*B.n_rows) > 0 )
{
out.set_size(A.n_cols, B.n_rows);
gemm<true,true>::apply(out, A, B);
} }
else
} if( (do_trans_A == false) && (do_trans_B == false) && (use_alpha == true)
)
//! out = -T1 * T2
template<typename T1, typename T2>
inline
void
glue_times::apply(Mat<typename T1::elem_type>& out, const Glue< Op<T1, op_n
eg>, T2, glue_times>& X)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const unwrap_check<T1> tmp1(X.A.m, out);
const unwrap_check<T2> tmp2(X.B, out);
const Mat<eT>& A = tmp1.M;
const Mat<eT>& B = tmp2.M;
glue_times::apply(out, A, B);
const u32 n_elem = out.n_elem;
for(u32 i=0; i<n_elem; ++i)
{ {
out[i] = -out[i]; if(A.n_rows == 1)
{
gemv<true, true, false>::apply(out.memptr(), B, A.memptr(), a
lpha);
}
else
if(B.n_cols == 1)
{
gemv<false, true, false>::apply(out.memptr(), A, B.memptr(), a
lpha);
}
else
{
gemm<false, false, true, false>::apply(out, A, B, alpha);
}
} }
} else
if( (do_trans_A == true) && (do_trans_B == false) && (use_alpha == false)
template<typename T1, typename T2> )
inline
void
glue_times::apply_inplace(Mat<typename T1::elem_type>& out, const Glue<T1,
T2, glue_times>& X)
{
arma_extra_debug_sigprint();
out = out * X;
}
#endif
//
// glue_times_diag
template<typename T1, typename T2>
inline
void
glue_times_diag::apply(Mat<typename T1::elem_type>& out, const T1& A_orig,
const Op<T2,op_diagmat>& B_orig)
{
arma_extra_debug_sigprint();
isnt_same_type<typename T1::elem_type, typename T2::elem_type>::check();
const unwrap_check<T1> tmp1(A_orig, out);
const unwrap_check<T2> tmp2(B_orig.m, out);
typedef typename T1::elem_type eT;
const Mat<eT>& A = tmp1.M;
const Mat<eT>& B = tmp2.M;
arma_debug_check( (B.is_square() == false), "glue_times_diag::apply(): in
compatible matrix dimensions" );
arma_debug_assert_mul_size(A.n_rows, A.n_cols, B.n_rows, B.n_cols, "matri
x multiply");
out.set_size(A.n_rows, B.n_cols);
for(u32 col=0; col<A.n_cols; ++col)
{ {
const eT val = B.at(col,col); if(A.n_cols == 1)
const eT* A_coldata = A.colptr(col);
eT* out_coldata = out.colptr(col);
for(u32 row=0; row<B.n_rows; ++row)
{ {
out_coldata[row] = A_coldata[row] * val; gemv<true, false, false>::apply(out.memptr(), B, A.memptr());
}
else
if(B.n_cols == 1)
{
gemv<true, false, false>::apply(out.memptr(), A, B.memptr());
}
else
{
gemm<true, false, false, false>::apply(out, A, B);
} }
} }
else
} if( (do_trans_A == true) && (do_trans_B == false) && (use_alpha == true)
)
template<typename T1, typename T2>
inline
void
glue_times_diag::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_dia
gmat>& A_orig, const T2& B_orig)
{
arma_extra_debug_sigprint();
isnt_same_type<typename T1::elem_type, typename T2::elem_type>::check();
const unwrap_check<T1> tmp1(A_orig.m, out);
const unwrap_check<T2> tmp2(B_orig, out);
typedef typename T1::elem_type eT;
const Mat<eT>& A = tmp1.M;
const Mat<eT>& B = tmp2.M;
arma_debug_check( (A.is_square() == false), "glue_times_diag::apply(): in
compatible matrix dimensions" );
arma_debug_assert_mul_size(A.n_rows, A.n_cols, B.n_rows, B.n_cols, "matri
x multiply");
out.set_size(A.n_rows, B.n_cols);
for(u32 col=0; col<A.n_cols; ++col)
{ {
const eT* B_coldata = B.colptr(col); if(A.n_cols == 1)
eT* out_coldata = out.colptr(col);
for(u32 row=0; row<B.n_rows; ++row)
{ {
out_coldata[row] = A.at(row,row) * B_coldata[row]; gemv<true, true, false>::apply(out.memptr(), B, A.memptr(), al
pha);
}
if(B.n_cols == 1)
{
gemv<true, true, false>::apply(out.memptr(), A, B.memptr(), al
pha);
}
else
{
gemm<true, false, true, false>::apply(out, A, B, alpha);
} }
} }
else
} if( (do_trans_A == false) && (do_trans_B == true) && (use_alpha == false)
)
template<typename T1, typename T2>
inline
void
glue_times_diag::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_dia
gmat>& A_orig, const Op<T2,op_diagmat>& B_orig)
{
arma_extra_debug_sigprint();
isnt_same_type<typename T1::elem_type, typename T2::elem_type>::check();
unwrap_check<T1> tmp1(A_orig.m, out);
unwrap_check<T2> tmp2(B_orig.m, out);
typedef typename T1::elem_type eT;
const Mat<eT>& A = tmp1.M;
const Mat<eT>& B = tmp2.M;
arma_debug_check( !A.is_square() || !B.is_square(), "glue_times_diag::app
ly(): incompatible matrix dimensions" );
arma_debug_assert_mul_size(A.n_rows, A.n_cols, B.n_rows, B.n_cols, "matri
x multiply");
out.zeros(A.n_rows, B.n_cols);
for(u32 i=0; i<A.n_rows; ++i)
{ {
out.at(i,i) = A.at(i,i) * B.at(i,i); if(A.n_rows == 1)
{
gemv<false, false, false>::apply(out.memptr(), B, A.memptr());
}
if(B.n_rows == 1)
{
gemv<false, false, false>::apply(out.memptr(), A, B.memptr());
}
else
{
gemm<false, true, false, false>::apply(out, A, B);
}
} }
} else
if( (do_trans_A == false) && (do_trans_B == true) && (use_alpha == true)
template<typename T1, typename T2> )
inline
void
glue_times_diag::apply(Mat<typename T1::elem_type>& out, const Glue<T1, Op<
T2,op_diagmat>, glue_times_diag>& X)
{
glue_times_diag::apply(out, X.A, X.B);
}
template<typename T1, typename T2>
inline
void
glue_times_diag::apply(Mat<typename T1::elem_type>& out, const Glue<Op<T1,o
p_diagmat>, T2, glue_times_diag>& X)
{
glue_times_diag::apply(out, X.A, X.B);
}
template<typename T1, typename T2>
inline
void
glue_times_diag::apply(Mat<typename T1::elem_type>& out, const Glue<Op<T1,o
p_diagmat>, Op<T2,op_diagmat>, glue_times_diag>& X)
{
glue_times_diag::apply(out, X.A, X.B);
}
//
// glue_times_vec
//! at least one of T1 and T2 is a vector (both could be vectors)
template<typename T1, typename T2>
inline
void
glue_times_vec::apply(Mat<typename T1::elem_type>& out, const Glue<T1, T2,
glue_times_vec>& X)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
unwrap_check<T1> tmp1(X.A, out);
unwrap_check<T2> tmp2(X.B, out);
const Mat<eT>& A = tmp1.M;
const Mat<eT>& B = tmp2.M;
arma_debug_assert_mul_size(A, B, "vector multiply");
// col * row --> outer product
// mat * row --> only makes sense if mat is a col vector, hence equiv to
col * row
// col * mat --> only makes sense if mat is a row vector, hence equiv to
col * row
// row * col --> dot product
// row * mat --> ok
// mat * col --> ok
out.set_size(A.n_rows, B.n_cols);
if(A.n_cols == 1) // A is a column vector
{ {
glue_times_vec::mul_col_row(out, A.mem, B.mem); if(A.n_rows == 1)
{
gemv<false, true, false>::apply(out.memptr(), B, A.memptr(), al
pha);
}
if(B.n_rows == 1)
{
gemv<false, true, false>::apply(out.memptr(), A, B.memptr(), al
pha);
}
else
{
gemm<false, true, true, false>::apply(out, A, B, alpha);
}
} }
else else
if( (do_trans_A == true) && (do_trans_B == true) && (use_alpha == false) )
{ {
if(A.n_rows == 1) // A is a row vector if(A.n_cols == 1)
{ {
if(B.n_cols == 1) gemv<false, false, false>::apply(out.memptr(), B, A.memptr());
{
out[0] = op_dot::direct_dot(A.n_elem, A.mem, B.mem);
}
else
{
gemv<true>::apply(out.memptr(), B, A.mem);
}
} }
else // A is a matrix if(B.n_rows == 1)
{ {
gemv<>::apply(out.memptr(), A, B.mem); gemv<true, false, false>::apply(out.memptr(), A, B.memptr());
}
else
{
gemm<true, true, false, false>::apply(out, A, B);
} }
} }
else
} if( (do_trans_A == true) && (do_trans_B == true) && (use_alpha == true) )
template<typename eT>
inline
void
glue_times_vec::mul_col_row(Mat<eT>& out, const eT* A, const eT* B)
{
const u32 n_rows = out.n_rows;
const u32 n_cols = out.n_cols;
for(u32 col=0; col < n_cols; ++col)
{ {
const eT val = B[col]; if(A.n_cols == 1)
{
eT* out_coldata = out.colptr(col); gemv<false, true, false>::apply(out.memptr(), B, A.memptr(), alp
ha);
for(u32 row=0; row < n_rows; ++row) }
if(B.n_rows == 1)
{ {
out_coldata[row] = A[row] * val; gemv<true, true, false>::apply(out.memptr(), A, B.memptr(), alp
ha);
}
else
{
gemm<true, true, true, false>::apply(out, A, B, alpha);
} }
} }
} }
template<typename eT> template<typename eT>
inline inline
void void
glue_times_vec::mul_col_row_inplace_add(Mat<eT>& out, const eT* A, const eT glue_times::apply
* B) (
Mat<eT>& out,
const Mat<eT>& A,
const Mat<eT>& B,
const Mat<eT>& C,
const eT alpha,
const bool do_trans_A,
const bool do_trans_B,
const bool do_trans_C,
const bool use_alpha
)
{ {
const u32 n_rows = out.n_rows; arma_extra_debug_sigprint();
const u32 n_cols = out.n_cols;
for(u32 col=0; col < n_cols; ++col)
{
const eT val = B[col];
eT* out_coldata = out.colptr(col); Mat<eT> tmp;
for(u32 row=0; row < n_rows; ++row) if( glue_times::mul_storage_cost(A, B, do_trans_A, do_trans_B) <= glue_ti
{ mes::mul_storage_cost(B, C, do_trans_B, do_trans_C) )
out_coldata[row] += A[row] * val; {
} // out = (A*B)*C
glue_times::apply(tmp, A, B, alpha, do_trans_A, do_trans_B, use_alpha
);
glue_times::apply(out, tmp, C, eT(0), false, do_trans_C, false
);
}
else
{
// out = A*(B*C)
glue_times::apply(tmp, B, C, alpha, do_trans_B, do_trans_C, use_alpha
);
glue_times::apply(out, A, tmp, eT(0), do_trans_A, false, false
);
} }
} }
#if defined(ARMA_GOOD_COMPILER)
template<typename eT> template<typename eT>
inline inline
void void
glue_times_vec::apply(Mat<eT>& out, const Glue<Col<eT>,Row<eT>,glue_times_v glue_times::apply
ec>& X) (
Mat<eT>& out,
const Mat<eT>& A,
const Mat<eT>& B,
const Mat<eT>& C,
const Mat<eT>& D,
const eT alpha,
const bool do_trans_A,
const bool do_trans_B,
const bool do_trans_C,
const bool do_trans_D,
const bool use_alpha
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
unwrap_check< Col<eT> > tmp1(X.A, out); Mat<eT> tmp;
unwrap_check< Row<eT> > tmp2(X.B, out);
const Col<eT>& A = tmp1.M;
const Row<eT>& B = tmp2.M;
arma_debug_assert_mul_size(A, B, "vector multiply"); if( glue_times::mul_storage_cost(A, C, do_trans_A, do_trans_C) <= glue_ti
mes::mul_storage_cost(B, D, do_trans_B, do_trans_D) )
{
// out = (A*B*C)*D
glue_times::apply(tmp, A, B, C, alpha, do_trans_A, do_trans_B, do_trans
_C, use_alpha);
out.set_size(A.n_rows, B.n_cols); glue_times::apply(out, tmp, D, eT(0), false, do_trans_D, false);
}
else
{
// out = A*(B*C*D)
glue_times::apply(tmp, B, C, D, alpha, do_trans_B, do_trans_C, do_trans
_D, use_alpha);
glue_times_vec::mul_col_row(out, A.mem, B.mem); glue_times::apply(out, A, tmp, eT(0), do_trans_A, false, false);
}
} }
template<typename eT> //
// glue_times_diag
template<typename T1, typename T2>
arma_hot
inline inline
void void
glue_times_vec::apply(Mat<eT>& out, const Glue< Op<Row<eT>, op_trans>, Row< eT>, glue_times_vec>& X) glue_times_diag::apply(Mat<typename T1::elem_type>& out, const Glue<T1, T2, glue_times_diag>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
unwrap_check< Row<eT> > tmp1(X.A.m, out); typedef typename T1::elem_type eT;
unwrap_check< Row<eT> > tmp2(X.B, out);
const Row<eT>& A = tmp1.M;
const Row<eT>& B = tmp2.M;
arma_debug_assert_mul_size(A.n_cols, A.n_rows, B.n_rows, B.n_cols, "vecto const strip_diagmat<T1> S1(X.A);
r multiply"); const strip_diagmat<T2> S2(X.B);
out.set_size(A.n_cols, B.n_cols); typedef typename strip_diagmat<T1>::stored_type T1_stripped;
typedef typename strip_diagmat<T2>::stored_type T2_stripped;
glue_times_vec::mul_col_row(out, A.mem, B.mem); if( (S1.do_diagmat == true) && (S2.do_diagmat == false) )
} {
const diagmat_proxy_check<T1_stripped> A(S1.M, out);
template<typename eT> const unwrap_check<T2> tmp(X.B, out);
inline const Mat<eT>& B = tmp.M;
void
glue_times_vec::apply(Mat<eT>& out, const Glue< Col<eT>, Op<Col<eT>, op_tra
ns>, glue_times_vec>& X)
{
arma_extra_debug_sigprint();
unwrap_check< Col<eT> > tmp1(X.A, out); arma_debug_assert_mul_size(A.n_elem, A.n_elem, B.n_rows, B.n_cols, "mat
unwrap_check< Col<eT> > tmp2(X.B.m, out); rix multiply");
const Col<eT>& A = tmp1.M; out.set_size(A.n_elem, B.n_cols);
const Col<eT>& B = tmp2.M;
arma_debug_assert_mul_size(A.n_rows, A.n_cols, B.n_cols, B.n_rows, "vecto for(u32 col=0; col<B.n_cols; ++col)
r multiply"); {
eT* out_coldata = out.colptr(col);
const eT* B_coldata = B.colptr(col);
out.set_size(A.n_rows, B.n_rows); for(u32 row=0; row<B.n_rows; ++row)
{
out_coldata[row] = A[row] * B_coldata[row];
}
}
}
else
if( (S1.do_diagmat == false) && (S2.do_diagmat == true) )
{
const unwrap_check<T1> tmp(X.A, out);
const Mat<eT>& A = tmp.M;
glue_times_vec::mul_col_row(out, A.mem, B.mem); const diagmat_proxy_check<T2_stripped> B(S2.M, out);
}
template<typename T1> arma_debug_assert_mul_size(A.n_rows, A.n_cols, B.n_elem, B.n_elem, "mat
inline rix multiply");
void
glue_times_vec::apply(Mat<typename T1::elem_type>& out, const Glue<Op<T1, o
p_trans>, Col<typename T1::elem_type>,glue_times_vec>& X)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; out.set_size(A.n_rows, B.n_elem);
unwrap_check< T1 > tmp1(X.A.m, out); for(u32 col=0; col<A.n_cols; ++col)
unwrap_check< Col<eT> > tmp2(X.B, out); {
const eT val = B[col];
const Mat<eT>& A = tmp1.M; eT* out_coldata = out.colptr(col);
const Col<eT>& B = tmp2.M; const eT* A_coldata = A.colptr(col);
arma_debug_assert_mul_size(A.n_cols, A.n_rows, B.n_rows, B.n_cols, "vecto for(u32 row=0; row<A.n_rows; ++row)
r multiply"); {
out_coldata[row] = A_coldata[row] * val;
}
}
}
else
if( (S1.do_diagmat == true) && (S2.do_diagmat == true) )
{
const diagmat_proxy_check<T1_stripped> A(S1.M, out);
const diagmat_proxy_check<T2_stripped> B(S2.M, out);
out.set_size(A.n_cols, B.n_cols); arma_debug_assert_mul_size(A.n_elem, A.n_elem, B.n_elem, B.n_elem, "mat rix multiply");
// eT* out_mem = out.memptr(); out.zeros(A.n_elem, A.n_elem);
// const eT* B_mem = B.mem;
//
// const u32 A_n_cols = A.n_cols;
// const u32 B_n_rows = B.n_rows;
//
// for(u32 col=0; col < A_n_cols; ++col)
// {
// const eT* A_col = A.colptr(col);
//
// eT val = eT(0);
// for(u32 row=0; row<B_n_rows; ++row)
// {
// val += A_col[row] * B_mem[row];
// }
//
// out_mem[col] = val;
// }
gemv<true>::apply(out.memptr(), A, B.mem); for(u32 i=0; i<A.n_elem; ++i)
{
out.at(i,i) = A[i] * B[i];
}
}
} }
#endif
//! @} //! @}
 End of changes. 149 change blocks. 
874 lines changed or deleted 473 lines changed or added


 glue_times_proto.hpp   glue_times_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 glue_times //! \addtogroup glue_times
//! @{ //! @{
//! \brief
//! Template metaprogram depth_lhs
//! calculates the number of Glue<Tx,Ty, glue_type> instances on the left h
and side argument of Glue<Tx,Ty, glue_type>
//! i.e. it recursively expands each Tx, until the type of Tx is not "Glue<
..,.., glue_type>" (i.e the "glue_type" changes)
template<typename glue_type, typename T1>
struct depth_lhs
{
static const u32 num = 0;
};
template<typename glue_type, typename T1, typename T2>
struct depth_lhs< glue_type, Glue<T1,T2,glue_type> >
{
static const u32 num = 1 + depth_lhs<glue_type, T1>::num;
};
template<u32 N>
struct glue_times_redirect
{
template<typename T1, typename T2>
inline static void apply(Mat<typename T1::elem_type>& out, const Glue<T1,
T2,glue_times>& X);
};
template<>
struct glue_times_redirect<3>
{
template<typename T1, typename T2, typename T3>
inline static void apply(Mat<typename T1::elem_type>& out, const Glue< Gl
ue<T1,T2,glue_times>,T3,glue_times>& X);
};
template<>
struct glue_times_redirect<4>
{
template<typename T1, typename T2, typename T3, typename T4>
inline static void apply(Mat<typename T1::elem_type>& out, const Glue< Gl
ue< Glue<T1,T2,glue_times>, T3, glue_times>, T4, glue_times>& X);
};
//! Class which implements the immediate multiplication of two or more matr ices //! Class which implements the immediate multiplication of two or more matr ices
class glue_times class glue_times
{ {
public: public:
template<typename T1, typename T2> template<typename T1, typename T2>
inline static void apply(Mat<typename T1::elem_type>& out, const Glue<T1, T2,glue_times>& X); inline static void apply(Mat<typename T1::elem_type>& out, const Glue<T1, T2,glue_times>& X);
template<typename T1> template<typename T1>
inline static void apply_inplace(Mat<typename T1::elem_type>& out, const T1& X); inline static void apply_inplace(Mat<typename T1::elem_type>& out, const T1& X);
template<typename T1, typename T2>
arma_hot inline static void apply_inplace_plus(Mat<typename T1::elem_type
>& out, const Glue<T1, T2, glue_times>& X, const s32 sign);
template<typename eT1, typename eT2> template<typename eT1, typename eT2>
inline static void apply_mixed(Mat<typename promote_type<eT1,eT2>::result >& out, const Mat<eT1>& X, const Mat<eT2>& Y); inline static void apply_mixed(Mat<typename promote_type<eT1,eT2>::result >& out, const Mat<eT1>& X, const Mat<eT2>& Y);
template<typename eT> template<typename eT>
arma_inline static u32 mul_storage_cost(const Mat<eT>& X, const Mat<eT>& arma_inline static u32 mul_storage_cost(const Mat<eT>& A, const Mat<eT>&
Y); B, const bool do_trans_A, const bool do_trans_B);
template<typename eT>
inline static void apply_noalias(Mat<eT>& out, const Mat<eT>& A, const Ma
t<eT>& B);
template<typename eT>
inline static void apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B
);
template<typename eT> template<typename eT>
inline static void apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B , const Mat<eT>& C); arma_hot inline static void apply(Mat<eT>& out, const Mat<eT>& A, const M at<eT>& B, const eT val, const bool do_trans_A, const bool do_trans_B, cons t bool do_scalar_times);
template<typename eT> template<typename eT>
inline static eT direct_rowvec_mat_colvec(const eT* A_mem, const Mat<eT>& B, const eT* C_mem); inline static void apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B , const Mat<eT>& C, const eT val, const bool do_trans_A, const bool do_tran s_B, const bool do_trans_C, const bool do_scalar_times);
template<typename eT> template<typename eT>
inline static eT direct_rowvec_diagmat_colvec(const eT* A_mem, const Mat< inline static void apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B
eT>& B, const eT* C_mem); , const Mat<eT>& C, const Mat<eT>& D, const eT val, const bool do_trans_A,
const bool do_trans_B, const bool do_trans_C, const bool do_trans_D, const
template<typename eT> bool do_scalar_times);
inline static eT direct_rowvec_invdiagmat_colvec(const eT* A_mem, const M
at<eT>& B, const eT* C_mem);
template<typename eT>
inline static eT direct_rowvec_invdiagvec_colvec(const eT* A_mem, const M
at<eT>& B, const eT* C_mem);
#if defined(ARMA_GOOD_COMPILER)
template<typename eT>
inline static void apply(Mat<eT>& out, const Glue<Mat<eT>,Mat<eT>,glue_ti
mes>& X);
template<typename eT>
inline static void apply(Mat<eT>& out, const Glue< Glue<Mat<eT>,Mat<eT>,
glue_times>, Mat<eT>, glue_times>& X);
template<typename T1, typename T2>
inline static void apply(Mat<typename T1::elem_type>& out, const Glue<T1,
Op<T2,op_trans>,glue_times >& X);
template<typename T1, typename T2>
inline static void apply(Mat<typename T1::elem_type>& out, const Glue<Op<
T1,op_trans>,T2,glue_times>& X);
template<typename T1, typename T2>
inline static void apply(Mat<typename T1::elem_type>& out, const Glue<Op<
T1,op_trans>,Op<T2,op_trans>,glue_times>& X);
template<typename T1, typename T2>
inline static void apply(Mat<typename T1::elem_type>& out, const Glue< Op
<T1, op_neg>, T2, glue_times>& X);
template<typename T1, typename T2>
inline static void apply_inplace(Mat<typename T1::elem_type>& out, const
Glue<T1, T2, glue_times>& X);
#endif
}; };
class glue_times_diag class glue_times_diag
{ {
public: public:
template<typename T1, typename T2> template<typename T1, typename T2>
inline static void apply(Mat<typename T1::elem_type>& out, const T1& A, c arma_hot inline static void apply(Mat<typename T1::elem_type>& out, const
onst Op<T2,op_diagmat>& B); Glue<T1, T2, glue_times_diag>& X);
template<typename T1, typename T2>
inline static void apply(Mat<typename T1::elem_type>& out, const Op<T1,op
_diagmat>& A, const T2& B);
template<typename T1, typename T2>
inline static void apply(Mat<typename T1::elem_type>& out, const Op<T1,op
_diagmat>& A, const Op<T2,op_diagmat>& B);
template<typename T1, typename T2>
inline static void apply(Mat<typename T1::elem_type>& out, const Glue<T1,
Op<T2,op_diagmat>, glue_times_diag>& X);
template<typename T1, typename T2>
inline static void apply(Mat<typename T1::elem_type>& out, const Glue<Op<
T1,op_diagmat>, T2, glue_times_diag>& X);
template<typename T1, typename T2>
inline static void apply(Mat<typename T1::elem_type>& out, const Glue<Op<
T1,op_diagmat>, Op<T2,op_diagmat>, glue_times_diag>& X);
};
class glue_times_vec
{
public:
template<typename T1, typename T2>
inline static void apply(Mat<typename T1::elem_type>& out, const Glue<T1,
T2, glue_times_vec>& X);
template<typename eT>
inline static void mul_col_row(Mat<eT>& out, const eT* A_mem, const eT* B
_mem);
template<typename eT>
inline static void mul_col_row_inplace_add(Mat<eT>& out, const eT* A_mem,
const eT* B_mem);
#if defined(ARMA_GOOD_COMPILER)
template<typename eT>
inline static void apply(Mat<eT>& out, const Glue<Col<eT>, Row<eT>, glue_
times_vec>& X);
template<typename eT>
inline static void apply(Mat<eT>& out, const Glue< Op<Row<eT>, op_trans>,
Row<eT>, glue_times_vec>& X);
template<typename eT>
inline static void apply(Mat<eT>& out, const Glue< Col<eT>, Op<Col<eT>, o
p_trans>, glue_times_vec>& X);
template<typename T1>
inline static void apply(Mat<typename T1::elem_type>& out, const Glue<Op<
T1, op_trans>, Col<typename T1::elem_type>, glue_times_vec>& X);
#endif
}; };
//! @} //! @}
 End of changes. 8 change blocks. 
115 lines changed or deleted 59 lines changed or added


 itpp_wrap.hpp   itpp_wrap.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 lapack_proto.hpp   lapack_proto.hpp 
// Copyright (C) 2009 NICTA and the authors listed below // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Edmund Highcock (edmund dot highcock at merton dot ox dot ac dot uk) // - Edmund Highcock (edmund dot highcock at merton dot ox dot ac dot uk)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 op_cor_meat.hpp   op_cor_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
 End of changes. 1 change blocks. 
2 lines changed or deleted 2 lines changed or added


 op_cor_proto.hpp   op_cor_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
 End of changes. 1 change blocks. 
2 lines changed or deleted 2 lines changed or added


 op_cov_meat.hpp   op_cov_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
 End of changes. 1 change blocks. 
2 lines changed or deleted 2 lines changed or added


 op_cov_proto.hpp   op_cov_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
 End of changes. 1 change blocks. 
2 lines changed or deleted 2 lines changed or added


 op_diagmat_meat.hpp   op_diagmat_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 op_diagmat //! \addtogroup op_diagmat
//! @{ //! @{
template<typename eT>
inline
void
op_diagmat::zero_offdiag(Mat<eT>& X)
{
for(u32 col=0; col<X.n_cols; ++col)
{
eT* colmem = X.colptr(col);
// above the diagonal
for(u32 row=0; row<col; ++row)
{
colmem[row] = eT(0);
}
// below the diagonal
for(u32 row=col+1; row<X.n_rows; ++row)
{
colmem[row] = eT(0);
}
}
}
template<typename T1> template<typename T1>
inline inline
void void
op_diagmat::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_diagmat> & in) op_diagmat::apply(Mat<typename T1::elem_type>& out, const Op<T1, op_diagmat >& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap<T1> tmp(in.m);
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
const Mat<eT>& X = tmp.M;
arma_debug_check( !X.is_square(), "diagmat(): matrix must be square" ); const unwrap<T1> tmp(X.m);
const Mat<eT>& A = tmp.M;
if(&out != &X) if(A.is_vec() == true)
{ {
out.zeros(X.n_rows, X.n_rows); // generate a diagonal matrix out of a vector
for(u32 i=0; i<X.n_rows; ++i)
{
out.at(i,i) = X.at(i,i);
}
}
else
{
op_diagmat::zero_offdiag(out);
}
}
template<typename T1, typename T2>
inline
void
op_diagmat::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T1,T2, g
lue_div>, op_diagmat>& in)
{
arma_extra_debug_sigprint();
const unwrap<T1> tmp1(in.m.A);
const unwrap<T2> tmp2(in.m.B);
typedef typename T1::elem_type eT;
const Mat<eT>& A = tmp1.M; const u32 N = A.n_elem;
const Mat<eT>& B = tmp2.M; const eT* A_mem = A.memptr();
arma_debug_check( (!A.is_square() || !B.is_square()), "diagmat(): matrice
s must be square" );
arma_debug_assert_same_size(A, B, "matrix element-wise division");
// not using out.zeros() as 'out' might be an alias of A and/or B.
// the off-diagonal elements are zeroed at the end
out.set_size(A.n_rows, A.n_rows);
for(u32 i=0; i<A.n_rows; ++i)
{
out.at(i,i) = A.at(i,i) / B.at(i,i);
}
op_diagmat::zero_offdiag(out);
}
template<typename T1, typename T2>
inline
void
op_diagmat::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T1,T2, g
lue_minus>, op_diagmat>& in)
{
arma_extra_debug_sigprint();
const unwrap<T1> tmp1(in.m.A);
const unwrap<T2> tmp2(in.m.B);
typedef typename T1::elem_type eT;
const Mat<eT>& A = tmp1.M;
const Mat<eT>& B = tmp2.M;
arma_debug_check( (!A.is_square() || !B.is_square()), "diagmat(): matrice
s must be square" );
arma_debug_assert_same_size(A, B, "matrix subtraction");
// not using out.zeros() as 'out' might be an alias of A and/or B.
// the off-diagonal elements are zeroed at the end
out.set_size(A.n_rows, A.n_rows);
for(u32 i=0; i<A.n_rows; ++i)
{
out.at(i,i) = A.at(i,i) - B.at(i,i);
}
op_diagmat::zero_offdiag(out);
}
template<typename T1, typename T2>
inline
void
op_diagmat::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T1,T2, g
lue_plus>, op_diagmat>& in)
{
arma_extra_debug_sigprint();
const unwrap<T1> tmp1(in.m.A);
const unwrap<T2> tmp2(in.m.B);
typedef typename T1::elem_type eT;
const Mat<eT>& A = tmp1.M; if(&out != &A)
const Mat<eT>& B = tmp2.M;
arma_debug_check( (!A.is_square() || !B.is_square()), "diagmat(): matrice
s must be square" );
arma_debug_assert_same_size(A, B, "matrix addition");
// not using out.zeros() as 'out' might be an alias of A and/or B.
// the off-diagonal elements are zeroed at the end
out.set_size(A.n_rows, A.n_rows);
for(u32 i=0; i<A.n_rows; ++i)
{
out.at(i,i) = A.at(i,i) + B.at(i,i);
}
op_diagmat::zero_offdiag(out);
}
template<typename T1, typename T2>
inline
void
op_diagmat::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T1,T2, g
lue_schur>, op_diagmat>& in)
{
arma_extra_debug_sigprint();
const unwrap<T1> tmp1(in.m.A);
const unwrap<T2> tmp2(in.m.B);
typedef typename T1::elem_type eT;
const Mat<eT>& A = tmp1.M;
const Mat<eT>& B = tmp2.M;
arma_debug_check( (!A.is_square() || !B.is_square()), "diagmat(): matrice
s must be square" );
arma_debug_assert_same_size(A, B, "matrix schur product");
// not using out.zeros() as 'out' might be an alias of A and/or B.
// the off-diagonal elements are zeroed at the end
out.set_size(A.n_rows, A.n_rows);
for(u32 i=0; i<A.n_rows; ++i)
{
out.at(i,i) = A.at(i,i) * B.at(i,i);
}
op_diagmat::zero_offdiag(out);
}
template<typename T1, typename T2>
inline
void
op_diagmat::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T1,T2, g
lue_times>, op_diagmat>& in)
{
arma_extra_debug_sigprint();
const unwrap_check<T1> tmp1(in.m.A, out);
const unwrap_check<T2> tmp2(in.m.B, out);
typedef typename T1::elem_type eT;
const Mat<eT>& A = tmp1.M;
const Mat<eT>& B = tmp2.M;
arma_debug_check( (A.n_rows != B.n_cols), "diagmat(): result of multiplic
ation is not square" );
arma_debug_assert_mul_size(A, B, "matrix multiplication");
// out is cleared here, as we've made sure that A and B are not aliases o
f 'out'
out.zeros(A.n_rows, A.n_rows);
for(u32 i=0; i<A.n_rows; ++i)
{
const eT* B_colmem = B.colptr(i);
eT val = eT(0);
for(u32 j=0; j<A.n_cols; ++j)
{ {
val += A.at(i,j) * B_colmem[j]; // no aliasing
} out.zeros(N,N);
out.at(i,i) = val;
}
}
//
//
//
template<typename T1> for(u32 i=0; i<N; ++i)
inline {
void out.at(i,i) = A_mem[i];
op_diagmat_vec::apply(Mat<typename T1::elem_type>& out, const Op<T1, op_dia }
gmat_vec>& in) }
{ else
arma_extra_debug_sigprint(); {
// aliasing
const unwrap<T1> tmp(in.m);
typedef typename T1::elem_type eT; const podarray<eT> tmp(A_mem, N);
const Mat<eT>& X = tmp.M;
if(&out != &X) const eT* tmp_mem = tmp.memptr();
{
out.zeros(X.n_elem, X.n_elem);
const eT* X_mem = X.mem; out.zeros(N,N);
for(u32 i=0; i<X.n_elem; ++i) for(u32 i=0; i<N; ++i)
{ {
out.at(i,i) = X_mem[i]; out.at(i,i) = tmp_mem[i];
}
} }
} }
else else
{ {
podarray<eT> tmp_array(X.n_elem); // generate a diagonal matrix out of a matrix
for(u32 i=0; i<X.n_elem; ++i) arma_debug_check( (A.is_square() == false), "diagmat(): given matrix is
{ not square" );
tmp_array[i] = X[i];
} const u32 N = A.n_rows;
out.zeros(tmp_array.n_elem, tmp_array.n_elem); out.set_size(N,N);
for(u32 i=0; i<tmp_array.n_elem; ++i) for(u32 col=0; col<N; ++col)
{ {
out.at(i,i) = tmp_array[i]; for(u32 row=0; row<col; ++row) { out.at(row,col) = eT(0); }
}
out.at(col,col) = A.at(col,col);
for(u32 row=col+1; row<N; ++row) { out.at(row,col) = eT(0); }
}
} }
} }
//! @} //! @}
 End of changes. 22 change blocks. 
238 lines changed or deleted 39 lines changed or added


 op_diagmat_proto.hpp   op_diagmat_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 op_diagmat //! \addtogroup op_diagmat
//! @{ //! @{
//! convert a mat/rowvec/colvec to a diagonal matrix
class op_diagmat class op_diagmat
{ {
private:
template<typename eT>
inline static void zero_offdiag(Mat<eT>& X);
public:
template<typename T1>
inline static void apply(Mat<typename T1::elem_type>& out, const Op<T1,op
_diagmat>& in);
template<typename T1, typename T2>
inline static void apply(Mat<typename T1::elem_type>& out, const Op< Glue
<T1,T2, glue_div>, op_diagmat>& in);
template<typename T1, typename T2>
inline static void apply(Mat<typename T1::elem_type>& out, const Op< Glue
<T1,T2, glue_minus>, op_diagmat>& in);
template<typename T1, typename T2>
inline static void apply(Mat<typename T1::elem_type>& out, const Op< Glue
<T1,T2, glue_plus>, op_diagmat>& in);
template<typename T1, typename T2>
inline static void apply(Mat<typename T1::elem_type>& out, const Op< Glue
<T1,T2, glue_schur>, op_diagmat>& in);
template<typename T1, typename T2>
inline static void apply(Mat<typename T1::elem_type>& out, const Op< Glue
<T1,T2, glue_times>, op_diagmat>& in);
};
class op_diagmat_vec
{
public: public:
template<typename T1> template<typename T1>
inline static void apply(Mat<typename T1::elem_type>& out, const Op<T1,op _diagmat_vec>& in); inline static void apply(Mat<typename T1::elem_type>& out, const Op<T1,op _diagmat>& X);
}; };
//! @} //! @}
 End of changes. 4 change blocks. 
39 lines changed or deleted 3 lines changed or added


 op_dot_meat.hpp   op_dot_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 op_dot //! \addtogroup op_dot
//! @{ //! @{
//! for two arrays //! for two arrays
template<typename eT> template<typename eT>
inline inline
arma_hot
arma_pure arma_pure
eT eT
op_dot::direct_dot(const u32 n_elem, const eT* const A, const eT* const B) op_dot::direct_dot(const u32 n_elem, const eT* const A, const eT* const B)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
eT val1 = eT(0); eT val1 = eT(0);
eT val2 = eT(0); eT val2 = eT(0);
u32 i,j; u32 i,j;
skipping to change at line 48 skipping to change at line 50
{ {
val1 += A[i] * B[i]; val1 += A[i] * B[i];
} }
return val1+val2; return val1+val2;
} }
//! for three arrays //! for three arrays
template<typename eT> template<typename eT>
inline inline
arma_hot
arma_pure arma_pure
eT eT
op_dot::direct_dot(const u32 n_elem, const eT* const A, const eT* const B, const eT* C) op_dot::direct_dot(const u32 n_elem, const eT* const A, const eT* const B, const eT* C)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
eT val = eT(0); eT val = eT(0);
for(u32 i=0; i<n_elem; ++i) for(u32 i=0; i<n_elem; ++i)
{ {
val += A[i] * B[i] * C[i]; val += A[i] * B[i] * C[i];
} }
return val; return val;
} }
template<typename T1, typename T2> template<typename T1, typename T2>
arma_inline
arma_hot
typename T1::elem_type
op_dot::apply(const Base<typename T1::elem_type,T1>& X, const Base<typename
T1::elem_type,T2>& Y)
{
arma_extra_debug_sigprint();
if( (is_Mat<T1>::value == true) && (is_Mat<T2>::value == true) )
{
return op_dot::apply_unwrap(X,Y);
}
else
{
return op_dot::apply_proxy(X,Y);
}
}
template<typename T1, typename T2>
arma_inline
arma_hot
typename T1::elem_type
op_dot::apply_unwrap(const Base<typename T1::elem_type,T1>& X, const Base<t
ypename T1::elem_type,T2>& Y)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const unwrap<T1> tmp1(X.get_ref());
const unwrap<T2> tmp2(Y.get_ref());
const Mat<eT>& A = tmp1.M;
const Mat<eT>& B = tmp2.M;
arma_debug_check( (A.n_elem != B.n_elem), "dot(): objects must have the s
ame number of elements" );
return op_dot::direct_dot(A.n_elem, A.mem, B.mem);
}
template<typename T1, typename T2>
inline inline
arma_hot
typename T1::elem_type typename T1::elem_type
op_dot::apply(const Base<typename T1::elem_type,T1>& A_orig, const Base<typ ename T1::elem_type,T2>& B_orig) op_dot::apply_proxy(const Base<typename T1::elem_type,T1>& X, const Base<ty pename T1::elem_type,T2>& Y)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
const unwrap_to_elem_access<T1> A(A_orig.get_ref()); const Proxy<T1> A(X.get_ref());
const unwrap_to_elem_access<T2> B(B_orig.get_ref()); const Proxy<T2> B(Y.get_ref());
arma_debug_check( (A.M.n_elem != B.M.n_elem), "dot(): objects must have t he same number of elements" ); arma_debug_check( (A.n_elem != B.n_elem), "dot(): objects must have the s ame number of elements" );
const u32 n_elem = A.M.n_elem; const u32 n_elem = A.n_elem;
eT val = eT(0); eT val = eT(0);
for(u32 i=0; i<n_elem; ++i) for(u32 i=0; i<n_elem; ++i)
{ {
val += A[i] * B[i]; val += A[i] * B[i];
} }
return val; return val;
} }
//
template<typename T1, typename T2>
arma_inline
arma_hot
typename T1::elem_type
op_norm_dot::apply(const Base<typename T1::elem_type,T1>& X, const Base<typ
ename T1::elem_type,T2>& Y)
{
arma_extra_debug_sigprint();
if( (is_Mat<T1>::value == true) && (is_Mat<T2>::value == true) )
{
return op_norm_dot::apply_unwrap(X,Y);
}
else
{
return op_norm_dot::apply_proxy(X,Y);
}
}
template<typename T1, typename T2> template<typename T1, typename T2>
inline inline
arma_hot
typename T1::elem_type typename T1::elem_type
op_norm_dot::apply(const Base<typename T1::elem_type,T1>& A_orig, const Bas e<typename T1::elem_type,T2>& B_orig) op_norm_dot::apply_unwrap(const Base<typename T1::elem_type,T1>& X, const B ase<typename T1::elem_type,T2>& Y)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
const unwrap_to_elem_access<T1> A(A_orig.get_ref()); const unwrap<T1> tmp1(X.get_ref());
const unwrap_to_elem_access<T2> B(B_orig.get_ref()); const unwrap<T2> tmp2(Y.get_ref());
arma_debug_check( (A.M.n_elem != B.M.n_elem), "norm_dot(): objects must h const Mat<eT>& A = tmp1.M;
ave the same number of elements" ); const Mat<eT>& B = tmp2.M;
const u32 n_elem = A.M.n_elem; arma_debug_check( (A.n_elem != B.n_elem), "norm_dot(): objects must have
the same number of elements" );
const eT* A_mem = A.memptr();
const eT* B_mem = B.memptr();
const u32 N = A.n_elem;
eT acc1 = eT(0); eT acc1 = eT(0);
eT acc2 = eT(0); eT acc2 = eT(0);
eT acc3 = eT(0); eT acc3 = eT(0);
for(u32 i=0; i<n_elem; ++i) for(u32 i=0; i<N; ++i)
{
const eT tmpA = A_mem[i];
const eT tmpB = B_mem[i];
acc1 += tmpA * tmpA;
acc2 += tmpB * tmpB;
acc3 += tmpA * tmpB;
}
return acc3 / ( std::sqrt(acc1 * acc2) ); // TODO: this only makes sens
e for eT = float, double or complex
}
template<typename T1, typename T2>
inline
arma_hot
typename T1::elem_type
op_norm_dot::apply_proxy(const Base<typename T1::elem_type,T1>& X, const Ba
se<typename T1::elem_type,T2>& Y)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const Proxy<T1> A(X.get_ref());
const Proxy<T2> B(Y.get_ref());
arma_debug_check( (A.n_elem != B.n_elem), "norm_dot(): objects must have
the same number of elements" );
const u32 N = A.n_elem;
eT acc1 = eT(0);
eT acc2 = eT(0);
eT acc3 = eT(0);
for(u32 i=0; i<N; ++i)
{ {
const eT tmpA = A[i]; const eT tmpA = A[i];
const eT tmpB = B[i]; const eT tmpB = B[i];
acc1 += tmpA * tmpA; acc1 += tmpA * tmpA;
acc2 += tmpB * tmpB; acc2 += tmpB * tmpB;
acc3 += tmpA * tmpB; acc3 += tmpA * tmpB;
} }
return acc3 / ( std::sqrt(acc1 * acc2) ); // TODO: this only makes sens e for eT = float, double or complex return acc3 / ( std::sqrt(acc1 * acc2) ); // TODO: this only makes sens e for eT = float, double or complex
 End of changes. 16 change blocks. 
13 lines changed or deleted 124 lines changed or added


 op_dot_proto.hpp   op_dot_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 26 skipping to change at line 27
//! @{ //! @{
//! \brief //! \brief
//! dot product operation //! dot product operation
class op_dot class op_dot
{ {
public: public:
template<typename eT> template<typename eT>
inline arma_pure static eT direct_dot(const u32 n_elem, const eT* const A , const eT* const B); inline arma_hot arma_pure static eT direct_dot(const u32 n_elem, const eT * const A, const eT* const B);
template<typename eT> template<typename eT>
inline arma_pure static eT direct_dot(const u32 n_elem, const eT* const A , const eT* const B, const eT* C); inline arma_hot arma_pure static eT direct_dot(const u32 n_elem, const eT * const A, const eT* const B, const eT* C);
template<typename T1, typename T2> template<typename T1, typename T2>
inline static typename T1::elem_type apply(const Base<typename T1::elem_t arma_inline arma_hot static typename T1::elem_type apply(const Base<typen
ype,T1>& A_orig, const Base<typename T1::elem_type,T2>& B_orig); ame T1::elem_type,T1>& X, const Base<typename T1::elem_type,T2>& Y);
template<typename T1, typename T2>
inline arma_hot static typename T1::elem_type apply_unwrap(const Base<typ
ename T1::elem_type,T1>& X, const Base<typename T1::elem_type,T2>& Y);
template<typename T1, typename T2>
inline arma_hot static typename T1::elem_type apply_proxy (const Base<typ
ename T1::elem_type,T1>& X, const Base<typename T1::elem_type,T2>& Y);
}; };
//! \brief //! \brief
//! normalised dot product operation //! normalised dot product operation
class op_norm_dot class op_norm_dot
{ {
public: public:
template<typename T1, typename T2> template<typename T1, typename T2>
inline static typename T1::elem_type apply(const Base<typename T1::elem_t arma_inline arma_hot static typename T1::elem_type apply(const Base<typen
ype,T1>& A_orig, const Base<typename T1::elem_type,T2>& B_orig); ame T1::elem_type,T1>& X, const Base<typename T1::elem_type,T2>& Y);
template<typename T1, typename T2>
inline arma_hot static typename T1::elem_type apply_unwrap(const Base<typ
ename T1::elem_type,T1>& X, const Base<typename T1::elem_type,T2>& Y);
template<typename T1, typename T2>
inline arma_hot static typename T1::elem_type apply_proxy (const Base<typ
ename T1::elem_type,T1>& X, const Base<typename T1::elem_type,T2>& Y);
}; };
//! @} //! @}
 End of changes. 5 change blocks. 
7 lines changed or deleted 24 lines changed or added


 op_htrans_meat.hpp   op_htrans_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 op_htrans_proto.hpp   op_htrans_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 op_inv_meat.hpp   op_inv_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 32 skipping to change at line 33
op_inv::apply(Mat<eT>& out, const Mat<eT>& A) op_inv::apply(Mat<eT>& out, const Mat<eT>& A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
// no need to check for aliasing, due to: // no need to check for aliasing, due to:
// - auxlib::inv() copies A to out before inversion // - auxlib::inv() copies A to out before inversion
// - for 2x2 and 3x3 matrices the code is alias safe // - for 2x2 and 3x3 matrices the code is alias safe
arma_debug_check( !A.is_square(), "op_inv::apply(): matrix must be square " ); arma_debug_check( !A.is_square(), "op_inv::apply(): matrix must be square " );
if(&out != &A) const bool status = (&out != &A) ? auxlib::inv_noalias(out, A) : auxlib::
{ inv_inplace(out);
auxlib::inv_noalias(out, A);
} if(status == false)
else
{ {
auxlib::inv_inplace(out); arma_warn( true, "inv(): matrix appears to be singular" );
out.set_size(0,0);
} }
} }
//! immediate inverse of T1, storing the result in a dense matrix //! immediate inverse of T1, storing the result in a dense matrix
template<typename T1> template<typename T1>
inline inline
void void
op_inv::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_inv>& in) op_inv::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_inv>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap<T1> tmp(in.m);
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
const Mat<eT>& X = tmp.M;
op_inv::apply(out, X);
}
#if defined(ARMA_GOOD_COMPILER) const strip_diagmat<T1> strip(X.m);
//! inverse of diagmat(mat) if(strip.do_diagmat == true)
template<typename T1>
inline
void
op_inv::apply(Mat<typename T1::elem_type>& out, const Op< Op<T1,op_diagmat>
, op_inv>& in)
{
arma_extra_debug_sigprint();
const unwrap<T1> X_tmp(in.m.m);
typedef typename T1::elem_type eT;
const Mat<eT>& X = X_tmp.M;
arma_debug_check( !X.is_square(), "op_inv::apply(): matrix must be square
" );
if(&out != &X)
{ {
out.zeros(X.n_rows, X.n_rows); op_inv::apply_diag(out, strip.M);
for(u32 i=0; i<X.n_rows; ++i)
{
out.at(i,i) = 1.0 / X.at(i,i);
}
} }
else else
{ {
podarray<eT> tmp(X.n_rows); const unwrap<T1> tmp(X.m);
const Mat<eT>& A = tmp.M;
for(u32 i=0; i<X.n_rows; ++i)
{
tmp[i] = X.at(i,i);
}
out.zeros(X.n_rows, X.n_rows);
for(u32 i=0; i<X.n_rows; ++i)
{
out.at(i,i) = eT(1) / tmp.mem[i];
}
op_inv::apply(out, A);
} }
} }
template<typename eT> template<typename T1>
inline inline
void void
op_inv::apply_diagvec(Mat<eT>& out, const Mat<eT>& X) op_inv::apply_diag(Mat<typename T1::elem_type>& out, const Base<typename T1 ::elem_type, T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_check( !X.is_vec(), "op_inv::apply_diagvec(): internal error: can't interpret as a vector"); typedef typename T1::elem_type eT;
if(&out != &X) const diagmat_proxy_check<T1> A(X.get_ref(), out);
{
out.zeros(X.n_elem, X.n_elem);
for(u32 i=0; i<X.n_elem; ++i) const u32 N = A.n_elem;
{
out.at(i,i) = eT(1) / X.mem[i];
}
}
else
{
podarray<eT> tmp(X.n_elem);
for(u32 i=0; i<X.n_elem; ++i) out.set_size(N,N);
{
tmp[i] = X.mem[i];
}
out.zeros(X.n_elem, X.n_elem);
for(u32 i=0; i<X.n_elem; ++i)
{
out.at(i,i) = eT(1) / tmp.mem[i];
}
} for(u32 col=0; col<N; ++col)
{
for(u32 row=0; row<col; ++row) { out.at(row,col) = eT(0); }
} out.at(col,col) = eT(1) / A[col];
//! inverse of diagmat(colvec or rowvec) for(u32 row=col+1; row<N; ++row) { out.at(row,col) = eT(0); }
template<typename eT> }
inline
void
op_inv::apply(Mat<eT>& out, const Op< Op<Mat<eT>,op_diagmat_vec>, op_inv>&
in)
{
arma_extra_debug_sigprint();
const Mat<eT>& X = in.m.m;
op_inv::apply_diagvec(out, X);
} }
#endif
//! @} //! @}
 End of changes. 24 change blocks. 
93 lines changed or deleted 27 lines changed or added


 op_inv_proto.hpp   op_inv_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 32 skipping to change at line 33
public: public:
// mat // mat
template<typename eT> template<typename eT>
inline static void apply(Mat<eT>& out, const Mat<eT>& A); inline static void apply(Mat<eT>& out, const Mat<eT>& A);
template<typename T1> template<typename T1>
inline static void apply(Mat<typename T1::elem_type>& out, const Op<T1,op _inv>& in); inline static void apply(Mat<typename T1::elem_type>& out, const Op<T1,op _inv>& in);
#if defined(ARMA_GOOD_COMPILER)
template<typename T1> template<typename T1>
inline static void apply(Mat<typename T1::elem_type>& out, const Op< Op<T inline static void apply_diag(Mat<typename T1::elem_type>& out, const Bas
1,op_diagmat>, op_inv>& in); e<typename T1::elem_type, T1>& X);
template<typename eT>
inline static void apply_diagvec(Mat<eT>& out, const Mat<eT>& X);
template<typename eT>
inline static void apply(Mat<eT>& out, const Op< Op<Mat<eT>,op_diagmat_ve
c>, op_inv>& in);
#endif
}; };
//! @} //! @}
 End of changes. 3 change blocks. 
14 lines changed or deleted 4 lines changed or added


 op_max_meat.hpp   op_max_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 101 skipping to change at line 102
template<typename T1> template<typename T1>
inline inline
void void
op_max::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_max>& in) op_max::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_max>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
const unwrap_check<T1> tmp(in.m, out); const unwrap_check<T1> tmp(in.m, out);
const Mat<eT>& X = tmp.M; const Mat<eT>& X = tmp.M;
arma_debug_check( (X.n_elem == 0), "max(): given matrix has no elements" ); arma_debug_check( (X.n_elem == 0), "max(): given matrix has no elements" );
const u32 dim = in.aux_u32_a; const u32 dim = in.aux_u32_a;
arma_debug_check( (dim > 1), "max(): incorrect usage. dim must be 0 or 1" ); arma_debug_check( (dim > 1), "max(): incorrect usage. dim must be 0 or 1" );
if(dim == 0) if(dim == 0)
{ {
arma_extra_debug_print("op_max::apply(), dim = 0"); arma_extra_debug_print("op_max::apply(), dim = 0");
 End of changes. 2 change blocks. 
2 lines changed or deleted 3 lines changed or added


 op_max_proto.hpp   op_max_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 op_mean_meat.hpp   op_mean_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 op_mean_proto.hpp   op_mean_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 op_median_meat.hpp   op_median_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 op_median_proto.hpp   op_median_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 op_min_meat.hpp   op_min_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 op_min_proto.hpp   op_min_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 op_pinv_meat.hpp   op_pinv_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
skipping to change at line 35 skipping to change at line 35
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const u32 n_rows = A.n_rows; const u32 n_rows = A.n_rows;
const u32 n_cols = A.n_cols; const u32 n_cols = A.n_cols;
// SVD decomposition // SVD decomposition
Mat<eT> U; Mat<eT> U;
Col<eT> s; Col<eT> s;
Mat<eT> V; Mat<eT> V;
(n_cols > n_rows) ? svd(U,s,V,trans(A)) : svd(U,s,V,A); const bool status = (n_cols > n_rows) ? svd(U,s,V,trans(A)) : svd(U,s,V,A
);
if(status == false)
{
out.set_size(0,0);
return;
}
// set tolerance to default if it hasn't been specified as an argument // set tolerance to default if it hasn't been specified as an argument
if(tol == eT(0)) if(tol == eT(0))
{ {
tol = (std::max)(n_rows,n_cols) * op_eps::direct_eps(max(s)); tol = (std::max)(n_rows,n_cols) * eop_aux::direct_eps(max(s));
} }
// count non zero valued elements in s // count non zero valued elements in s
u32 count = 0; u32 count = 0;
for(u32 i = 0; i < s.n_elem; ++i) for(u32 i = 0; i < s.n_elem; ++i)
{ {
if(s[i] > tol) if(s[i] > tol)
{ {
++count; ++count;
} }
skipping to change at line 93 skipping to change at line 99
const u32 n_rows = A.n_rows; const u32 n_rows = A.n_rows;
const u32 n_cols = A.n_cols; const u32 n_cols = A.n_cols;
typedef typename std::complex<T> eT; typedef typename std::complex<T> eT;
// SVD decomposition // SVD decomposition
Mat<eT> U; Mat<eT> U;
Col< T> s; Col< T> s;
Mat<eT> V; Mat<eT> V;
(n_cols > n_rows) ? svd(U,s,V,htrans(A)) : svd(U,s,V,A); const bool status = (n_cols > n_rows) ? svd(U,s,V,htrans(A)) : svd(U,s,V,
A);
if(status == false)
{
out.set_size(0,0);
return;
}
// set tolerance to default if it hasn't been specified as an argument // set tolerance to default if it hasn't been specified as an argument
if(tol == T(0)) if(tol == T(0))
{ {
tol = (std::max)(n_rows,n_cols) * op_eps::direct_eps(max(s)); tol = (std::max)(n_rows,n_cols) * eop_aux::direct_eps(max(s));
} }
// count non zero valued elements in s // count non zero valued elements in s
u32 count = 0; u32 count = 0;
for(u32 i = 0; i < s.n_elem; ++i) for(u32 i = 0; i < s.n_elem; ++i)
{ {
if(s[i] > tol) if(s[i] > tol)
{ {
++count; ++count;
} }
 End of changes. 5 change blocks. 
6 lines changed or deleted 20 lines changed or added


 op_pinv_proto.hpp   op_pinv_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
 End of changes. 1 change blocks. 
2 lines changed or deleted 2 lines changed or added


 op_prod_meat.hpp   op_prod_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 op_prod_proto.hpp   op_prod_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 op_repmat_meat.hpp   op_repmat_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
 End of changes. 1 change blocks. 
2 lines changed or deleted 2 lines changed or added


 op_repmat_proto.hpp   op_repmat_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
 End of changes. 1 change blocks. 
2 lines changed or deleted 2 lines changed or added


 op_reshape_meat.hpp   op_reshape_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 op_reshape_proto.hpp   op_reshape_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 op_shuffle_meat.hpp   op_shuffle_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
 End of changes. 1 change blocks. 
2 lines changed or deleted 2 lines changed or added


 op_shuffle_proto.hpp   op_shuffle_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// Copyright (C) 2009 Dimitrios Bouzas // http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com) // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
// //
// 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
 End of changes. 1 change blocks. 
2 lines changed or deleted 2 lines changed or added


 op_sort_meat.hpp   op_sort_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 op_sort_proto.hpp   op_sort_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 op_stddev_meat.hpp   op_stddev_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 25 skipping to change at line 26
//! \addtogroup op_stddev //! \addtogroup op_stddev
//! @{ //! @{
//! \brief //! \brief
//! For each row or for each column, find the standard deviation. //! For each row or for each column, find the standard deviation.
//! The result is stored in a dense matrix that has either one column or on e row. //! The result is stored in a dense matrix that has either one column or on e row.
//! The dimension for which the standard deviations are found is set via th e stddev() function. //! The dimension for which the standard deviations are found is set via th e stddev() function.
template<typename eT> template<typename eT>
inline inline
void void
op_stddev::apply(Mat<eT>& out, const Mat<eT>& X, const u32 norm_type, const u32 dim) op_stddev::apply(Mat< typename get_pod_type<eT>::result >& out, const Mat<e T>& X, const u32 norm_type, const u32 dim)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_check( (X.n_elem == 0), "stddev(): given matrix has no element s" ); arma_debug_check( (X.n_elem == 0), "stddev(): given matrix has no element s" );
arma_debug_check( (norm_type > 1), "stddev(): incorrect usage. norm_type must be 0 or 1"); arma_debug_check( (norm_type > 1), "stddev(): incorrect usage. norm_type must be 0 or 1");
arma_debug_check( (dim > 1), "stddev(): incorrect usage. dim must b e 0 or 1" ); arma_debug_check( (dim > 1), "stddev(): incorrect usage. dim must b e 0 or 1" );
if(dim == 0) if(dim == 0)
{ {
skipping to change at line 50 skipping to change at line 51
for(u32 col=0; col<X.n_cols; ++col) for(u32 col=0; col<X.n_cols; ++col)
{ {
out[col] = std::sqrt( op_var::direct_var( X.colptr(col), X.n_rows, no rm_type ) ); out[col] = std::sqrt( op_var::direct_var( X.colptr(col), X.n_rows, no rm_type ) );
} }
} }
else else
if(dim == 1) if(dim == 1)
{ {
arma_extra_debug_print("op_stddev::apply(), dim = 1"); arma_extra_debug_print("op_stddev::apply(), dim = 1");
out.set_size(X.n_rows, 1); const u32 n_rows = X.n_rows;
const u32 n_cols = X.n_cols;
const eT norm_val = (norm_type == 0) ? ( (X.n_cols > 1) ? eT(X.n_cols-1 ) : eT(1) ) : eT(X.n_cols); out.set_size(n_rows, 1);
for(u32 row=0; row<X.n_rows; ++row) podarray<eT> tmp(n_cols);
{
eT acc1 = eT(0);
eT acc2 = eT(0);
for(u32 col=0; col<X.n_cols; ++col)
{
const eT tmp_val = X.at(row,col);
acc1 += tmp_val;
acc2 += tmp_val*tmp_val;
}
const eT sd_val = std::sqrt( (acc2 - acc1*acc1/eT(X.n_cols)) / norm_v
al );
out[row] = sd_val;
}
}
}
//! implementation for complex numbers eT* tmp_mem = tmp.memptr();
template<typename T>
inline
void
op_stddev::apply(Mat<T>& out, const Mat< std::complex<T> >& X, const u32 no
rm_type, const u32 dim)
{
arma_extra_debug_sigprint();
typedef typename std::complex<T> eT;
arma_debug_check( (X.n_elem == 0), "stddev(): given matrix has no element
s" );
arma_debug_check( (norm_type > 1), "stddev(): incorrect usage. norm_type
must be 0 or 1");
arma_debug_check( (dim > 1), "stddev(): incorrect usage. dim must b
e 0 or 1" );
if(dim == 0) for(u32 row=0; row<n_rows; ++row)
{
arma_extra_debug_print("op_stddev::apply(), dim = 0");
out.set_size(1, X.n_cols);
for(u32 col=0; col<X.n_cols; ++col)
{
out[col] = std::sqrt( op_var::direct_var( X.colptr(col), X.n_rows, no
rm_type ) );
}
}
else
if(dim == 1)
{
arma_extra_debug_print("op_stddev::apply(), dim = 1");
out.set_size(X.n_rows, 1);
const T norm_val = (norm_type == 0) ? ( (X.n_cols > 1) ? T(X.n_cols-1)
: T(1) ) : T(X.n_cols);
for(u32 row=0; row<X.n_rows; ++row)
{ {
eT acc1 = eT(0); for(u32 col=0; col<n_cols; ++col)
T acc2 = T(0);
for(u32 col=0; col<X.n_cols; ++col)
{ {
acc1 += X.at(row,col); tmp_mem[col] = X.at(row,col);
acc2 += std::norm(X.at(row,col));
} }
const T var_val = (acc2 - std::norm(acc1)/T(X.n_cols)) / norm_val; out[row] = std::sqrt( op_var::direct_var(tmp_mem, n_cols, norm_type)
);
out[row] = std::sqrt(var_val);
} }
} }
} }
//! @} //! @}
 End of changes. 10 change blocks. 
75 lines changed or deleted 13 lines changed or added


 op_stddev_proto.hpp   op_stddev_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 24 skipping to change at line 25
//! \addtogroup op_stddev //! \addtogroup op_stddev
//! @{ //! @{
//! Class for finding the standard deviation //! Class for finding the standard deviation
class op_stddev class op_stddev
{ {
public: public:
template<typename eT> template<typename eT>
inline static void apply(Mat<eT>& out, const Mat<eT>& X, const u32 norm_t inline static void apply(Mat< typename get_pod_type<eT>::result >& out, c
ype, const u32 dim); onst Mat<eT>& X, const u32 norm_type, const u32 dim);
template<typename T>
inline static void apply(Mat<T>& out, const Mat< std::complex<T> >& X, co
nst u32 norm_type, const u32 dim);
}; };
//! @} //! @}
 End of changes. 2 change blocks. 
7 lines changed or deleted 4 lines changed or added


 op_sum_meat.hpp   op_sum_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 57 skipping to change at line 58
eT val = eT(0); eT val = eT(0);
for(u32 row=0; row < X.n_rows; ++row) for(u32 row=0; row < X.n_rows; ++row)
{ {
val += X_colptr[row]; val += X_colptr[row];
} }
out.at(0,col) = val; out.at(0,col) = val;
} }
} }
else // traverse across columns (i.e. find the sum in each rows) else // traverse across columns (i.e. find the sum in each row)
{ {
out.set_size(X.n_rows, 1); out.set_size(X.n_rows, 1);
for(u32 row=0; row < X.n_rows; ++row) for(u32 row=0; row < X.n_rows; ++row)
{ {
eT val = eT(0); eT val = eT(0);
for(u32 col=0; col<X.n_cols; ++col) for(u32 col=0; col<X.n_cols; ++col)
{ {
val += X.at(row,col); val += X.at(row,col);
 End of changes. 2 change blocks. 
2 lines changed or deleted 3 lines changed or added


 op_sum_proto.hpp   op_sum_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 op_trans_meat.hpp   op_trans_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 133 skipping to change at line 134
} }
else else
{ {
const Mat<eT> A_copy = A; const Mat<eT> A_copy = A;
op_trans::apply_noalias(out, A_copy); op_trans::apply_noalias(out, A_copy);
} }
} }
} }
#if defined(ARMA_GOOD_COMPILER)
template<typename T1, typename T2>
inline
void
op_trans::apply(Mat<typename T1::elem_type>& out, const Op< Glue<T1,T2,glue
_plus>, op_trans>& in)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
isnt_same_type<eT, typename T2::elem_type>::check();
const unwrap_check<T1> tmp1(in.m.A, out);
const unwrap_check<T2> tmp2(in.m.B, out);
const Mat<eT>& A = tmp1.M;
const Mat<eT>& B = tmp2.M;
arma_debug_assert_same_size(A, B, "matrix addition");
out.set_size(A.n_cols, A.n_rows);
if( ( (A.n_rows == 1) || (A.n_cols == 1) ) && ( (B.n_rows == 1) || (B.n_c
ols == 1) ) )
{
for(u32 i=0; i<A.n_elem; ++i)
{
out[i] = A[i] + B[i];
}
}
else
{
const u32 A_n_cols = A.n_cols;
const u32 A_n_rows = A.n_rows;
for(u32 col=0; col<A_n_cols; ++col)
{
const u32 out_row = col;
for(u32 row=0; row<A_n_rows; ++row)
{
const u32 out_col = row;
out.at(out_row, out_col) = A.at(row,col) + B.at(row,col);
}
}
}
}
#endif
// inline void op_trans::apply_inplace(mat &X) // inline void op_trans::apply_inplace(mat &X)
// { // {
// arma_extra_debug_sigprint(); // arma_extra_debug_sigprint();
// //
// if((X.n_rows == 1) || (X.n_cols == 1)) // if((X.n_rows == 1) || (X.n_cols == 1))
// { // {
// const u32 old_n_rows = X.n_rows; // const u32 old_n_rows = X.n_rows;
// access::rw(X.n_rows) = X.n_cols; // access::rw(X.n_rows) = X.n_cols;
// access::rw(X.n_cols) = old_n_rows; // access::rw(X.n_cols) = old_n_rows;
// } // }
skipping to change at line 226 skipping to change at line 175
// access::rw(tmp.mem) = old_mem; // access::rw(tmp.mem) = old_mem;
// } // }
// else // else
// { // {
// X = tmp; // X = tmp;
// } // }
// } // }
// //
// } // }
template<typename T1>
inline
void
op_trans2::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_trans2>&
in)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const unwrap<T1> tmp(in.m);
op_trans::apply(out, tmp.M);
eT* out_mem = out.memptr();
const u32 n_elem = out.n_elem;
const eT k = in.aux;
for(u32 i=0; i<n_elem; ++i)
{
out_mem[i] *= k;
}
}
//! @} //! @}
 End of changes. 3 change blocks. 
55 lines changed or deleted 27 lines changed or added


 op_trans_proto.hpp   op_trans_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 33 skipping to change at line 34
template<typename eT> template<typename eT>
inline static void apply_noalias(Mat<eT>& out, const Mat<eT>& A); inline static void apply_noalias(Mat<eT>& out, const Mat<eT>& A);
template<typename eT> template<typename eT>
inline static void apply(Mat<eT>& out, const Mat<eT>& A); inline static void apply(Mat<eT>& out, const Mat<eT>& A);
template<typename T1> template<typename T1>
inline static void apply(Mat<typename T1::elem_type>& out, const Op<T1,op _trans>& in); inline static void apply(Mat<typename T1::elem_type>& out, const Op<T1,op _trans>& in);
#if defined(ARMA_GOOD_COMPILER) // inline static void apply_inplace(mat &out);
template<typename T1, typename T2>
inline static void apply(Mat<typename T1::elem_type>& out, const Op<Glue<
T1,T2,glue_plus>,op_trans>& in);
#endif };
// inline static void apply_inplace(mat &out); class op_trans2
{
public:
template<typename T1>
inline static void apply(Mat<typename T1::elem_type>& out, const Op<T1,op
_trans2>& in);
}; };
//! @} //! @}
 End of changes. 5 change blocks. 
8 lines changed or deleted 10 lines changed or added


 op_var_meat.hpp   op_var_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 27 skipping to change at line 28
//! find the variance of an array //! find the variance of an array
template<typename eT> template<typename eT>
inline inline
eT eT
op_var::direct_var(const eT* const X, const u32 n_elem, const u32 norm_type ) op_var::direct_var(const eT* const X, const u32 n_elem, const u32 norm_type )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
eT acc1 = eT(0); eT acc1 = eT(0);
for(u32 i=0; i<n_elem; ++i)
{
acc1 += X[i];
}
const eT div_val = (n_elem > 0) ? eT(n_elem) : eT(1);
acc1 /= div_val;
eT acc2 = eT(0); eT acc2 = eT(0);
eT acc3 = eT(0);
for(u32 i=0; i<n_elem; ++i) for(u32 i=0; i<n_elem; ++i)
{ {
const eT tmp_val = X[i]; const eT tmp = acc1 - X[i];
acc1 += tmp_val;
acc2 += tmp_val*tmp_val; acc2 += tmp*tmp;
acc3 += tmp;
} }
const eT norm_val = (norm_type == 0) ? ( (n_elem > 1) ? eT(n_elem-1) : eT (1) ) : eT(n_elem); const eT norm_val = (norm_type == 0) ? ( (n_elem > 1) ? eT(n_elem-1) : eT (1) ) : eT(n_elem);
const eT var_val = (acc2 - acc1*acc1/eT(n_elem)) / norm_val; const eT var_val = (acc2 - acc3*acc3/div_val) / norm_val;
return var_val; return var_val;
} }
//! find the variance of an array (version for complex numbers) //! find the variance of an array (version for complex numbers)
template<typename T> template<typename T>
inline inline
T T
op_var::direct_var(const std::complex<T>* const X, const u32 n_elem, const u32 norm_type) op_var::direct_var(const std::complex<T>* const X, const u32 n_elem, const u32 norm_type)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename std::complex<T> eT; typedef typename std::complex<T> eT;
eT acc1 = eT(0); eT acc1 = eT(0);
T acc2 = T(0);
for(u32 i=0; i<n_elem; ++i) for(u32 i=0; i<n_elem; ++i)
{ {
acc1 += X[i]; acc1 += X[i];
acc2 += std::norm(X[i]); }
const T div_val = (n_elem > 0) ? T(n_elem) : T(1);
acc1 /= div_val;
T acc2 = T(0);
eT acc3 = eT(0);
for(u32 i=0; i<n_elem; ++i)
{
const eT tmp = acc1 - X[i];
acc2 += std::norm(tmp);
acc3 += tmp;
} }
const T norm_val = (norm_type == 0) ? ( (n_elem > 1) ? T(n_elem-1) : T(1) ) : T(n_elem); const T norm_val = (norm_type == 0) ? ( (n_elem > 1) ? T(n_elem-1) : T(1) ) : T(n_elem);
const T var_val = (acc2 - std::norm(acc1)/T(n_elem)) / norm_val; const T var_val = (acc2 - std::norm(acc3)/div_val) / norm_val;
return var_val; return var_val;
} }
//! \brief //! find the variance of a subview_row
//! For each row or for each column, find the variance.
//! The result is stored in a dense matrix that has either one column or on
e row.
//! The dimension, for which the variances are found, is set via the var()
function.
template<typename eT> template<typename eT>
inline inline
void typename get_pod_type<eT>::result
op_var::apply(Mat<eT>& out, const Mat<eT>& X, const u32 norm_type, const u3 op_var::direct_var(const subview_row<eT>& X, const u32 norm_type)
2 dim)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_check( (X.n_elem == 0), "var(): given matrix has no elements" const u32 n_elem = X.n_elem;
);
arma_debug_check( (norm_type > 1), "var(): incorrect usage. norm_type mus
t be 0 or 1");
arma_debug_check( (dim > 1), "var(): incorrect usage. dim must be 0
or 1" );
if(dim == 0) podarray<eT> tmp(n_elem);
{
arma_extra_debug_print("op_var::apply(), dim = 0");
out.set_size(1, X.n_cols); eT* tmp_mem = tmp.memptr();
for(u32 col=0; col<X.n_cols; ++col) for(u32 i=0; i<n_elem; ++i)
{
out[col] = op_var::direct_var( X.colptr(col), X.n_rows, norm_type );
}
}
else
if(dim == 1)
{ {
arma_extra_debug_print("op_var::apply(), dim = 1"); tmp_mem[i] = X[i];
}
out.set_size(X.n_rows, 1); return op_var::direct_var(tmp_mem, n_elem, norm_type);
}
const eT norm_val = (norm_type == 0) ? ( (X.n_cols > 1) ? eT(X.n_cols-1 //! find the variance of a subview_col
) : eT(1) ) : eT(X.n_cols); template<typename eT>
inline
typename get_pod_type<eT>::result
op_var::direct_var(const subview_col<eT>& X, const u32 norm_type)
{
arma_extra_debug_sigprint();
for(u32 row=0; row<X.n_rows; ++row) return op_var::direct_var(X.colptr(0), X.n_elem, norm_type);
{ }
eT acc1 = eT(0);
eT acc2 = eT(0);
for(u32 col=0; col<X.n_cols; ++col) //! find the variance of a diagview
{ template<typename eT>
const eT tmp_val = X.at(row,col); inline
acc1 += tmp_val; typename get_pod_type<eT>::result
acc2 += tmp_val*tmp_val; op_var::direct_var(const diagview<eT>& X, const u32 norm_type)
} {
arma_extra_debug_sigprint();
const u32 n_elem = X.n_elem;
const eT var_val = (acc2 - acc1*acc1/eT(X.n_cols)) / norm_val; podarray<eT> tmp(n_elem);
out[row] = var_val; eT* tmp_mem = tmp.memptr();
}
for(u32 i=0; i<n_elem; ++i)
{
tmp_mem[i] = X[i];
} }
return op_var::direct_var(tmp_mem, n_elem, norm_type);
} }
//! implementation for complex numbers //! \brief
template<typename T> //! For each row or for each column, find the variance.
//! The result is stored in a dense matrix that has either one column or on
e row.
//! The dimension, for which the variances are found, is set via the var()
function.
template<typename eT>
inline inline
void void
op_var::apply(Mat<T>& out, const Mat< std::complex<T> >& X, const u32 norm_ type, const u32 dim) op_var::apply(Mat< typename get_pod_type<eT>::result >& out, const Mat<eT>& X, const u32 norm_type, const u32 dim)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename std::complex<T> eT;
arma_debug_check( (X.n_elem == 0), "var(): given matrix has no elements" ); arma_debug_check( (X.n_elem == 0), "var(): given matrix has no elements" );
arma_debug_check( (norm_type > 1), "var(): incorrect usage. norm_type mus t be 0 or 1"); arma_debug_check( (norm_type > 1), "var(): incorrect usage. norm_type mus t be 0 or 1");
arma_debug_check( (dim > 1), "var(): incorrect usage. dim must be 0 or 1" ); arma_debug_check( (dim > 1), "var(): incorrect usage. dim must be 0 or 1" );
if(dim == 0) if(dim == 0)
{ {
arma_extra_debug_print("op_var::apply(), dim = 0"); arma_extra_debug_print("op_var::apply(), dim = 0");
out.set_size(1, X.n_cols); out.set_size(1, X.n_cols);
skipping to change at line 155 skipping to change at line 178
for(u32 col=0; col<X.n_cols; ++col) for(u32 col=0; col<X.n_cols; ++col)
{ {
out[col] = op_var::direct_var( X.colptr(col), X.n_rows, norm_type ); out[col] = op_var::direct_var( X.colptr(col), X.n_rows, norm_type );
} }
} }
else else
if(dim == 1) if(dim == 1)
{ {
arma_extra_debug_print("op_var::apply(), dim = 1"); arma_extra_debug_print("op_var::apply(), dim = 1");
out.set_size(X.n_rows, 1); const u32 n_rows = X.n_rows;
const u32 n_cols = X.n_cols;
const T norm_val = (norm_type == 0) ? ( (X.n_cols > 1) ? T(X.n_cols-1) : T(1) ) : T(X.n_cols); out.set_size(n_rows, 1);
for(u32 row=0; row<X.n_rows; ++row) podarray<eT> tmp(n_cols);
{
eT acc1 = eT(0);
T acc2 = T(0);
for(u32 col=0; col<X.n_cols; ++col) eT* tmp_mem = tmp.memptr();
for(u32 row=0; row<n_rows; ++row)
{
for(u32 col=0; col<n_cols; ++col)
{ {
acc1 += X.at(row,col); tmp_mem[col] = X.at(row,col);
acc2 += std::norm(X.at(row,col));
} }
const T var_val = (acc2 - std::norm(acc1)/T(X.n_cols)) / norm_val; out[row] = op_var::direct_var(tmp_mem, n_cols, norm_type);
out[row] = var_val;
} }
} }
} }
//! find the variance of a subview
template<typename eT>
inline
eT
op_var::direct_var(const subview<eT>& X, const u32 norm_type)
{
arma_extra_debug_sigprint();
const u32 n_elem = X.n_elem;
eT acc1 = eT(0);
eT acc2 = eT(0);
for(u32 i=0; i<n_elem; ++i)
{
const eT tmp_val = X[i];
acc1 += tmp_val;
acc2 += tmp_val*tmp_val;
}
const eT norm_val = (norm_type == 0) ? ( (n_elem > 1) ? eT(n_elem-1) : eT
(1) ) : eT(n_elem);
const eT var_val = (acc2 - acc1*acc1/eT(n_elem)) / norm_val;
return var_val;
}
//! find the variance of a subview (version for complex numbers)
template<typename T>
inline
T
op_var::direct_var(const subview< std::complex<T> >& X, const u32 norm_type
)
{
arma_extra_debug_sigprint();
typedef typename std::complex<T> eT;
const u32 n_elem = X.n_elem;
eT acc1 = eT(0);
T acc2 = T(0);
for(u32 i=0; i<n_elem; ++i)
{
acc1 += X[i];
acc2 += std::norm(X[i]);
}
const T norm_val = (norm_type == 0) ? ( (n_elem > 1) ? T(n_elem-1) : T(1)
) : T(n_elem);
const T var_val = (acc2 - std::norm(acc1)/T(n_elem)) / norm_val;
return var_val;
}
//! find the variance of a diagview
template<typename eT>
inline
eT
op_var::direct_var(const diagview<eT>& X, const u32 norm_type)
{
arma_extra_debug_sigprint();
const u32 n_elem = X.n_elem;
eT acc1 = eT(0);
eT acc2 = eT(0);
for(u32 i=0; i<n_elem; ++i)
{
const eT tmp_val = X[i];
acc1 += tmp_val;
acc2 += tmp_val*tmp_val;
}
const eT norm_val = (norm_type == 0) ? ( (n_elem > 1) ? eT(n_elem-1) : eT
(1) ) : eT(n_elem);
const eT var_val = (acc2 - acc1*acc1/eT(n_elem)) / norm_val;
return var_val;
}
//! find the variance of a diagview (version for complex numbers)
template<typename T>
inline
T
op_var::direct_var(const diagview< std::complex<T> >& X, const u32 norm_typ
e)
{
arma_extra_debug_sigprint();
typedef typename std::complex<T> eT;
const u32 n_elem = X.n_elem;
eT acc1 = eT(0);
T acc2 = T(0);
for(u32 i=0; i<n_elem; ++i)
{
acc1 += X[i];
acc2 += std::norm(X[i]);
}
const T norm_val = (norm_type == 0) ? ( (n_elem > 1) ? T(n_elem-1) : T(1)
) : T(n_elem);
const T var_val = (acc2 - std::norm(acc1)/T(n_elem)) / norm_val;
return var_val;
}
//! @} //! @}
 End of changes. 33 change blocks. 
181 lines changed or deleted 86 lines changed or added


 op_var_proto.hpp   op_var_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 30 skipping to change at line 31
{ {
public: public:
template<typename eT> template<typename eT>
inline static eT direct_var(const eT* const X, const u32 N, const u32 nor m_type = 0); inline static eT direct_var(const eT* const X, const u32 N, const u32 nor m_type = 0);
template<typename T> template<typename T>
inline static T direct_var(const std::complex<T>* const X, const u32 N, c onst u32 norm_type = 0); inline static T direct_var(const std::complex<T>* const X, const u32 N, c onst u32 norm_type = 0);
template<typename eT> template<typename eT>
inline static void apply(Mat<eT>& out, const Mat<eT>& X, const u32 norm_t inline static typename get_pod_type<eT>::result direct_var(const subview_
ype, const u32 dim); row<eT>& X, const u32 norm_type = 0);
template<typename T>
inline static void apply(Mat<T>& out, const Mat< std::complex<T> >& X, co
nst u32 norm_type, const u32 dim);
template<typename eT> template<typename eT>
inline static eT direct_var(const subview<eT>& X, const u32 norm_type = 0 inline static typename get_pod_type<eT>::result direct_var(const subview_
); col<eT>& X, const u32 norm_type = 0);
template<typename T>
inline static T direct_var(const subview< std::complex<T> >& X, const u32
norm_type = 0);
template<typename eT> template<typename eT>
inline static eT direct_var(const diagview<eT>& X, const u32 norm_type = 0); inline static typename get_pod_type<eT>::result direct_var(const diagview <eT>& X, const u32 norm_type = 0);
template<typename T> template<typename eT>
inline static T direct_var(const diagview< std::complex<T> >& X, const u3 inline static void apply(Mat< typename get_pod_type<eT>::result >& out, c
2 norm_type = 0); onst Mat<eT>& X, const u32 norm_type, const u32 dim);
}; };
//! @} //! @}
 End of changes. 5 change blocks. 
17 lines changed or deleted 10 lines changed or added


 operator_cube_div.hpp   operator_cube_div.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 operator_cube_div //! \addtogroup operator_cube_div
//! @{ //! @{
//! Base / scalar //! BaseCube / scalar
template<typename T1> template<typename T1>
arma_inline arma_inline
const OpCube<T1, op_scalar_div_post> const eOpCube<T1, eop_cube_scalar_div_post>
operator/ operator/
(const BaseCube<typename T1::elem_type,T1>& X, const typename T1::elem_type (
k) const BaseCube<typename T1::elem_type,T1>& X,
const typename T1::elem_type k
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_scalar_div_post>(X.get_ref(), k); return eOpCube<T1, eop_cube_scalar_div_post>(X.get_ref(), k);
} }
//! OpCube<mat,op_ones_full> / scalar //! scalar / BaseCube
template<typename eT>
arma_inline
Cube<eT>
operator/
(const OpCube<Cube<eT>,op_ones_full>& X, const eT k)
{
arma_extra_debug_sigprint();
Cube<eT> tmp(X.aux_u32_a, X.aux_u32_b, X.aux_u32_c);
tmp.fill( eT(1)/k );
return tmp;
}
//! scalar / Base
template<typename T1> template<typename T1>
arma_inline arma_inline
const OpCube<T1, op_scalar_div_pre> const eOpCube<T1, eop_cube_scalar_div_pre>
operator/ operator/
(const typename T1::elem_type k, const BaseCube<typename T1::elem_type,T1>& (
X) const typename T1::elem_type k,
const BaseCube<typename T1::elem_type,T1>& X
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_scalar_div_pre>(X.get_ref(), k); return eOpCube<T1, eop_cube_scalar_div_pre>(X.get_ref(), k);
} }
// //! element-wise division of BaseCube objects with same element type
// element-wise division of Base objects with different element types
//
//! Base / Base
template<typename eT1, typename T1, typename eT2, typename T2>
arma_inline
Cube<typename promote_type<eT1,eT2>::result>
operator/
(const BaseCube<eT1,T1>& X, const BaseCube<eT2,T2>& Y)
{
arma_extra_debug_sigprint();
promote_type<eT1,eT2>::check();
const unwrap_cube<T1> tmp1(X.get_ref());
const unwrap_cube<T2> tmp2(Y.get_ref());
const Cube<eT1>& A = tmp1.M;
const Cube<eT2>& B = tmp2.M;
Cube< typename promote_type<eT1,eT2>::result > out;
glue_cube_div::apply_mixed(out, A, B);
return out;
}
//
// element-wise division of Base objects with same element types
//
template<typename T1, typename T2> template<typename T1, typename T2>
arma_inline arma_inline
const GlueCube<T1, T2, glue_cube_div> const eGlueCube<T1, T2, eglue_cube_div>
operator/ operator/
(const BaseCube<std::complex<double>,T1>& X, const BaseCube<std::complex<do (
uble>,T2>& Y) const BaseCube<typename T1::elem_type,T1>& X,
const BaseCube<typename T1::elem_type,T2>& Y
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_div>(X.get_ref(), Y.get_ref()); return eGlueCube<T1, T2, eglue_cube_div>(X.get_ref(), Y.get_ref());
} }
//! element-wise division of Base objects with different element types
template<typename T1, typename T2> template<typename T1, typename T2>
arma_inline arma_inline
const GlueCube<T1, T2, glue_cube_div> Cube<typename promote_type<typename T1::elem_type, typename T2::elem_type>: :result>
operator/ operator/
(const BaseCube<std::complex<float>,T1>& X, const BaseCube<std::complex<flo (
at>,T2>& Y) const BaseCube< typename force_different_type<typename T1::elem_type, typ
ename T2::elem_type>::T1_result, T1>& X,
const BaseCube< typename force_different_type<typename T1::elem_type, typ
ename T2::elem_type>::T2_result, T2>& Y
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_div>(X.get_ref(), Y.get_ref()); typedef typename T1::elem_type eT1;
} typedef typename T2::elem_type eT2;
template<typename T1, typename T2> typedef typename promote_type<eT1,eT2>::result out_eT;
arma_inline
const GlueCube<T1, T2, glue_cube_div>
operator/
(const BaseCube<double,T1>& X, const BaseCube<double,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_div>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const GlueCube<T1, T2, glue_cube_div>
operator/
(const BaseCube<float,T1>& X, const BaseCube<float,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_div>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2> promote_type<eT1,eT2>::check();
arma_inline
const GlueCube<T1, T2, glue_cube_div>
operator/
(const BaseCube<s32,T1>& X, const BaseCube<s32,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_div>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const GlueCube<T1, T2, glue_cube_div>
operator/
(const BaseCube<u32,T1>& X, const BaseCube<u32,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_div>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const GlueCube<T1, T2, glue_cube_div>
operator/
(const BaseCube<s16,T1>& X, const BaseCube<s16,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_div>(X.get_ref(), Y.get_ref()); const ProxyCube<T1> A(X.get_ref());
} const ProxyCube<T2> B(Y.get_ref());
template<typename T1, typename T2> arma_debug_assert_same_size(A, B, "element-wise cube division");
arma_inline
const GlueCube<T1, T2, glue_cube_div>
operator/
(const BaseCube<u16,T1>& X, const BaseCube<u16,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_div>(X.get_ref(), Y.get_ref()); Cube<out_eT> out(A.n_rows, A.n_cols, A.n_slices);
}
template<typename T1, typename T2> out_eT* out_mem = out.memptr();
arma_inline const u32 n_elem = out.n_elem;
const GlueCube<T1, T2, glue_cube_div>
operator/
(const BaseCube<s8,T1>& X, const BaseCube<s8,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_div>(X.get_ref(), Y.get_ref()); for(u32 i=0; i<n_elem; ++i)
} {
out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) / upgrade_val<eT1,eT2>::
template<typename T1, typename T2> apply(B[i]);
arma_inline }
const GlueCube<T1, T2, glue_cube_div>
operator/
(const BaseCube<u8,T1>& X, const BaseCube<u8,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_div>(X.get_ref(), Y.get_ref()); return out;
} }
//! @} //! @}
 End of changes. 25 change blocks. 
145 lines changed or deleted 47 lines changed or added


 operator_cube_minus.hpp   operator_cube_minus.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 operator_cube_minus //! \addtogroup operator_cube_minus
//! @{ //! @{
//! unary - //! unary -
template<typename T1> template<typename T1>
arma_inline arma_inline
const OpCube<T1, op_neg> const eOpCube<T1, eop_cube_neg>
operator- operator-
(const BaseCube<typename T1::elem_type,T1>& X) (
const BaseCube<typename T1::elem_type,T1>& X
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1,op_neg>(X.get_ref()); return eOpCube<T1, eop_cube_neg>(X.get_ref());
} }
//! cancellation of two consecutive negations: -(-T1) //! cancellation of two consecutive negations: -(-T1)
template<typename T1> template<typename T1>
arma_inline arma_inline
const T1& const T1&
operator- operator-
(const OpCube<T1, op_neg>& X) (
const eOpCube<T1, eop_cube_neg>& X
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return X.m; return X.m;
} }
//! Base - scalar //! BaseCube - scalar
template<typename T1> template<typename T1>
arma_inline arma_inline
const OpCube<T1, op_scalar_minus_post> const eOpCube<T1, eop_cube_scalar_minus_post>
operator- operator-
(const BaseCube<typename T1::elem_type,T1>& X, const typename T1::elem_type (
k) const BaseCube<typename T1::elem_type,T1>& X,
const typename T1::elem_type k
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_scalar_minus_post>(X.get_ref(), k); return eOpCube<T1, eop_cube_scalar_minus_post>(X.get_ref(), k);
} }
//! scalar - Base //! scalar - BaseCube
template<typename T1> template<typename T1>
arma_inline arma_inline
const OpCube<T1, op_scalar_minus_pre> const eOpCube<T1, eop_cube_scalar_minus_pre>
operator- operator-
(const typename T1::elem_type k, const BaseCube<typename T1::elem_type,T1>& (
X) const typename T1::elem_type k,
const BaseCube<typename T1::elem_type,T1>& X
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_scalar_minus_pre>(X.get_ref(), k); return eOpCube<T1, eop_cube_scalar_minus_pre>(X.get_ref(), k);
} }
//! Base - - Base = Base + Base //! subtraction of BaseCube objects with same element type
template<typename T1, typename T2> template<typename T1, typename T2>
arma_inline arma_inline
const GlueCube<T1, T2, glue_cube_plus> const eGlueCube<T1, T2, eglue_cube_minus>
operator- operator-
( (
const BaseCube<typename T1::elem_type, T1 >& X, const BaseCube<typename T1::elem_type,T1>& X,
const BaseCube<typename T1::elem_type, OpCube<T2,op_neg> >& Y const BaseCube<typename T1::elem_type,T2>& Y
) )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const T1& A = X.get_ref(); return eGlueCube<T1, T2, eglue_cube_minus>(X.get_ref(), Y.get_ref());
const T2& B = (Y.get_ref()).m;
return GlueCube<T1, T2, glue_cube_plus>(A,B);
} }
//! Base - OpCube<T2,op_neg> = Base + T2 //! subtraction of Base objects with different element types
template<typename T1, typename T2> template<typename T1, typename T2>
arma_inline arma_inline
const GlueCube<T1, T2, glue_cube_plus> Cube<typename promote_type<typename T1::elem_type, typename T2::elem_type>: :result>
operator- operator-
(const BaseCube<typename T2::elem_type,T1>& X, const OpCube<T2, op_neg>& Y) (
const BaseCube< typename force_different_type<typename T1::elem_type, typ
ename T2::elem_type>::T1_result, T1>& X,
const BaseCube< typename force_different_type<typename T1::elem_type, typ
ename T2::elem_type>::T2_result, T2>& Y
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_plus>(X.get_ref(), Y.m); typedef typename T1::elem_type eT1;
} typedef typename T2::elem_type eT2;
//
// subtraction of Base objects with different element types
//
//! Base - Base typedef typename promote_type<eT1,eT2>::result out_eT;
template<typename eT1, typename T1, typename eT2, typename T2>
arma_inline
Cube<typename promote_type<eT1,eT2>::result>
operator-
(const BaseCube<eT1,T1>& X, const BaseCube<eT2,T2>& Y)
{
arma_extra_debug_sigprint();
promote_type<eT1,eT2>::check(); promote_type<eT1,eT2>::check();
const unwrap_cube<T1> tmp1(X.get_ref()); const ProxyCube<T1> A(X.get_ref());
const unwrap_cube<T2> tmp2(Y.get_ref()); const ProxyCube<T2> B(Y.get_ref());
const Cube<eT1>& A = tmp1.M;
const Cube<eT2>& B = tmp2.M;
Cube< typename promote_type<eT1,eT2>::result > out;
glue_cube_minus::apply_mixed(out, A, B);
return out;
}
//
// subtraction of Base objects with same element types
//
template<typename T1, typename T2>
arma_inline
const GlueCube<T1, T2, glue_cube_minus>
operator-
(const BaseCube<std::complex<double>,T1>& X, const BaseCube<std::complex<do
uble>,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_minus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const GlueCube<T1, T2, glue_cube_minus>
operator-
(const BaseCube<std::complex<float>,T1>& X, const BaseCube<std::complex<flo
at>,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_minus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const GlueCube<T1, T2, glue_cube_minus>
operator-
(const BaseCube<double,T1>& X, const BaseCube<double,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_minus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const GlueCube<T1, T2, glue_cube_minus>
operator-
(const BaseCube<float,T1>& X, const BaseCube<float,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_minus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const GlueCube<T1, T2, glue_cube_minus>
operator-
(const BaseCube<s32,T1>& X, const BaseCube<s32,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_minus>(X.get_ref(), Y.get_ref()); arma_debug_assert_same_size(A, B, "cube subtraction");
}
template<typename T1, typename T2> Cube<out_eT> out(A.n_rows, A.n_cols, A.n_slices);
arma_inline
const GlueCube<T1, T2, glue_cube_minus>
operator-
(const BaseCube<u32,T1>& X, const BaseCube<u32,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_minus>(X.get_ref(), Y.get_ref()); out_eT* out_mem = out.memptr();
} const u32 n_elem = out.n_elem;
template<typename T1, typename T2> for(u32 i=0; i<n_elem; ++i)
arma_inline {
const GlueCube<T1, T2, glue_cube_minus> out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) - upgrade_val<eT1,eT2>::
operator- apply(B[i]);
(const BaseCube<s16,T1>& X, const BaseCube<s16,T2>& Y) }
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_minus>(X.get_ref(), Y.get_ref()); return out;
}
template<typename T1, typename T2>
arma_inline
const GlueCube<T1, T2, glue_cube_minus>
operator-
(const BaseCube<u16,T1>& X, const BaseCube<u16,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_minus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const GlueCube<T1, T2, glue_cube_minus>
operator-
(const BaseCube<s8,T1>& X, const BaseCube<s8,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_minus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const GlueCube<T1, T2, glue_cube_minus>
operator-
(const BaseCube<u8,T1>& X, const BaseCube<u8,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_minus>(X.get_ref(), Y.get_ref());
} }
//! @} //! @}
 End of changes. 28 change blocks. 
161 lines changed or deleted 52 lines changed or added


 operator_cube_plus.hpp   operator_cube_plus.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 23 skipping to change at line 24
// (see http://www.opensource.org/licenses for more info) // (see http://www.opensource.org/licenses for more info)
//! \addtogroup operator_cube_plus //! \addtogroup operator_cube_plus
//! @{ //! @{
//! unary plus operation (does nothing, but is required for completeness) //! unary plus operation (does nothing, but is required for completeness)
template<typename T1> template<typename T1>
arma_inline arma_inline
const BaseCube<typename T1::elem_type,T1>& const BaseCube<typename T1::elem_type,T1>&
operator+ operator+
(const BaseCube<typename T1::elem_type,T1>& X) (
const BaseCube<typename T1::elem_type,T1>& X
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return X; return X;
} }
//! Base + scalar //! BaseCube + scalar
template<typename T1> template<typename T1>
arma_inline arma_inline
const OpCube<T1, op_scalar_plus> const eOpCube<T1, eop_cube_scalar_plus>
operator+ operator+
(const BaseCube<typename T1::elem_type,T1>& X, const typename T1::elem_type (
k) const BaseCube<typename T1::elem_type,T1>& X,
const typename T1::elem_type k
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_scalar_plus>(X.get_ref(), k); return eOpCube<T1, eop_cube_scalar_plus>(X.get_ref(), k);
} }
//! op + scalar, level 2 //! scalar + BaseCube
template<typename T1> template<typename T1>
arma_inline arma_inline
const OpCube<T1,op_scalar_plus> const eOpCube<T1, eop_cube_scalar_plus>
operator+ operator+
(const OpCube<T1,op_scalar_plus>& X, const typename T1::elem_type k) (
const typename T1::elem_type k,
const BaseCube<typename T1::elem_type,T1>& X
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_scalar_plus>(X.m, X.aux + k); return eOpCube<T1, eop_cube_scalar_plus>(X.get_ref(), k);
} }
//! scalar + Base //! addition of BaseCube objects with same element type
template<typename T1>
arma_inline
const OpCube<T1, op_scalar_plus>
operator+
(const typename T1::elem_type k, const BaseCube<typename T1::elem_type,T1>&
X)
{
arma_extra_debug_sigprint();
return OpCube<T1, op_scalar_plus>(X.get_ref(), k); // NOTE: order is swa
pped
}
//
// addition of Base objects with different element types
//
//! Base + Base
template<typename eT1, typename T1, typename eT2, typename T2>
arma_inline
Cube<typename promote_type<eT1,eT2>::result>
operator+
(const BaseCube<eT1,T1>& X, const BaseCube<eT2,T2>& Y)
{
arma_extra_debug_sigprint();
promote_type<eT1,eT2>::check();
const unwrap_cube<T1> tmp1(X.get_ref());
const unwrap_cube<T2> tmp2(Y.get_ref());
const Cube<eT1>& A = tmp1.M;
const Cube<eT2>& B = tmp2.M;
Cube< typename promote_type<eT1,eT2>::result > out;
glue_cube_plus::apply_mixed(out, A, B);
return out;
}
//
// addition of Base objects with same element types
//
template<typename T1, typename T2> template<typename T1, typename T2>
arma_inline arma_inline
const GlueCube<T1, T2, glue_cube_plus> const eGlueCube<T1, T2, eglue_cube_plus>
operator+ operator+
(const BaseCube<std::complex<double>,T1>& X, const BaseCube<std::complex<do (
uble>,T2>& Y) const BaseCube<typename T1::elem_type,T1>& X,
const BaseCube<typename T1::elem_type,T2>& Y
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_plus>(X.get_ref(), Y.get_ref()); return eGlueCube<T1, T2, eglue_cube_plus>(X.get_ref(), Y.get_ref());
} }
//! addition of BaseCube objects with different element types
template<typename T1, typename T2> template<typename T1, typename T2>
arma_inline arma_inline
const GlueCube<T1, T2, glue_cube_plus> Cube<typename promote_type<typename T1::elem_type, typename T2::elem_type>: :result>
operator+ operator+
(const BaseCube<std::complex<float>,T1>& X, const BaseCube<std::complex<flo (
at>,T2>& Y) const BaseCube< typename force_different_type<typename T1::elem_type, typ
ename T2::elem_type>::T1_result, T1>& X,
const BaseCube< typename force_different_type<typename T1::elem_type, typ
ename T2::elem_type>::T2_result, T2>& Y
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_plus>(X.get_ref(), Y.get_ref()); typedef typename T1::elem_type eT1;
} typedef typename T2::elem_type eT2;
template<typename T1, typename T2> typedef typename promote_type<eT1,eT2>::result out_eT;
arma_inline
const GlueCube<T1, T2, glue_cube_plus>
operator+
(const BaseCube<double,T1>& X, const BaseCube<double,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_plus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const GlueCube<T1, T2, glue_cube_plus>
operator+
(const BaseCube<float,T1>& X, const BaseCube<float,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_plus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2> promote_type<eT1,eT2>::check();
arma_inline
const GlueCube<T1, T2, glue_cube_plus>
operator+
(const BaseCube<s32,T1>& X, const BaseCube<s32,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_plus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const GlueCube<T1, T2, glue_cube_plus>
operator+
(const BaseCube<u32,T1>& X, const BaseCube<u32,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_plus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const GlueCube<T1, T2, glue_cube_plus>
operator+
(const BaseCube<s16,T1>& X, const BaseCube<s16,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_plus>(X.get_ref(), Y.get_ref()); const ProxyCube<T1> A(X.get_ref());
} const ProxyCube<T2> B(Y.get_ref());
template<typename T1, typename T2> arma_debug_assert_same_size(A, B, "cube addition");
arma_inline
const GlueCube<T1, T2, glue_cube_plus>
operator+
(const BaseCube<u16,T1>& X, const BaseCube<u16,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_plus>(X.get_ref(), Y.get_ref()); Cube<out_eT> out(A.n_rows, A.n_cols, A.n_slices);
}
template<typename T1, typename T2> out_eT* out_mem = out.memptr();
arma_inline const u32 n_elem = out.n_elem;
const GlueCube<T1, T2, glue_cube_plus>
operator+
(const BaseCube<s8,T1>& X, const BaseCube<s8,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_plus>(X.get_ref(), Y.get_ref()); for(u32 i=0; i<n_elem; ++i)
} {
out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) + upgrade_val<eT1,eT2>::
template<typename T1, typename T2> apply(B[i]);
arma_inline }
const GlueCube<T1, T2, glue_cube_plus>
operator+
(const BaseCube<u8,T1>& X, const BaseCube<u8,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_plus>(X.get_ref(), Y.get_ref()); return out;
} }
//! @} //! @}
 End of changes. 26 change blocks. 
144 lines changed or deleted 50 lines changed or added


 operator_cube_relational.hpp   operator_cube_relational.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 operator_cube_relational //! \addtogroup operator_cube_relational
//! @{ //! @{
template<typename eT, typename T1, typename T2> template<typename T1, typename T2>
inline inline
ucube ucube
operator== operator==
(const BaseCube<eT,T1>& X, const BaseCube<eT,T2>& Y) (const BaseCube<typename T1::elem_type,T1>& X, const BaseCube<typename T1:: elem_type,T2>& Y)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap_cube<T1> tmp1(X.get_ref()); typedef typename ucube::elem_type ucube_eT;
const unwrap_cube<T2> tmp2(Y.get_ref());
const Cube<eT>& A = tmp1.M; const ProxyCube<T1> A(X.get_ref());
const Cube<eT>& B = tmp2.M; const ProxyCube<T2> B(Y.get_ref());
arma_debug_assert_same_size(A, B, "operator=="); arma_debug_assert_same_size(A, B, "operator==");
ucube out(A.n_rows, A.n_cols, A.n_slices); ucube out(A.n_rows, A.n_cols, A.n_slices);
const eT* A_mem = A.mem; ucube_eT* out_mem = out.memptr();
const eT* B_mem = B.mem;
typedef typename ucube::elem_type ucube_elem_type;
ucube_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] == B_mem[i]) if(A[i] == B[i])
{ {
out_mem[i] = ucube_elem_type(1); out_mem[i] = ucube_eT(1);
} }
else else
{ {
out_mem[i] = ucube_elem_type(0); out_mem[i] = ucube_eT(0);
} }
} }
return out; return out;
} }
template<typename eT, typename T1, typename T2> template<typename T1, typename T2>
inline inline
ucube ucube
operator!= operator!=
(const BaseCube<eT,T1>& X, const BaseCube<eT,T2>& Y) (const BaseCube<typename T1::elem_type,T1>& X, const BaseCube<typename T1:: elem_type,T2>& Y)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap_cube<T1> tmp1(X.get_ref()); typedef typename ucube::elem_type ucube_eT;
const unwrap_cube<T2> tmp2(Y.get_ref());
const Cube<eT>& A = tmp1.M; const ProxyCube<T1> A(X.get_ref());
const Cube<eT>& B = tmp2.M; const ProxyCube<T2> B(Y.get_ref());
arma_debug_assert_same_size(A, B, "operator!="); arma_debug_assert_same_size(A, B, "operator!=");
ucube out(A.n_rows, A.n_cols, A.n_slices); ucube out(A.n_rows, A.n_cols, A.n_slices);
const eT* A_mem = A.mem; ucube_eT* out_mem = out.memptr();
const eT* B_mem = B.mem;
typedef typename ucube::elem_type ucube_elem_type;
ucube_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] != B_mem[i]) if(A[i] != B[i])
{ {
out_mem[i] = ucube_elem_type(1); out_mem[i] = ucube_eT(1);
} }
else else
{ {
out_mem[i] = ucube_elem_type(0); out_mem[i] = ucube_eT(0);
} }
} }
return out; return out;
} }
template<typename eT, typename T1, typename T2> template<typename T1, typename T2>
inline inline
ucube ucube
operator>= operator>=
(const BaseCube<eT,T1>& X, const BaseCube<eT,T2>& Y) (const BaseCube<typename T1::elem_type,T1>& X, const BaseCube<typename T1:: elem_type,T2>& Y)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap_cube<T1> tmp1(X.get_ref()); typedef typename ucube::elem_type ucube_eT;
const unwrap_cube<T2> tmp2(Y.get_ref());
const Cube<eT>& A = tmp1.M; const ProxyCube<T1> A(X.get_ref());
const Cube<eT>& B = tmp2.M; const ProxyCube<T2> B(Y.get_ref());
arma_debug_assert_same_size(A, B, "operator>="); arma_debug_assert_same_size(A, B, "operator>=");
ucube out(A.n_rows, A.n_cols, A.n_slices); ucube out(A.n_rows, A.n_cols, A.n_slices);
const eT* A_mem = A.mem; ucube_eT* out_mem = out.memptr();
const eT* B_mem = B.mem;
typedef typename ucube::elem_type ucube_elem_type;
ucube_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] >= B_mem[i]) if(A[i] >= B[i])
{ {
out_mem[i] = ucube_elem_type(1); out_mem[i] = ucube_eT(1);
} }
else else
{ {
out_mem[i] = ucube_elem_type(0); out_mem[i] = ucube_eT(0);
} }
} }
return out; return out;
} }
template<typename eT, typename T1, typename T2> template<typename T1, typename T2>
inline inline
ucube ucube
operator<= operator<=
(const BaseCube<eT,T1>& X, const BaseCube<eT,T2>& Y) (const BaseCube<typename T1::elem_type,T1>& X, const BaseCube<typename T1:: elem_type,T2>& Y)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap_cube<T1> tmp1(X.get_ref()); typedef typename ucube::elem_type ucube_eT;
const unwrap_cube<T2> tmp2(Y.get_ref());
const Cube<eT>& A = tmp1.M; const ProxyCube<T1> A(X.get_ref());
const Cube<eT>& B = tmp2.M; const ProxyCube<T2> B(Y.get_ref());
arma_debug_assert_same_size(A, B, "operator<="); arma_debug_assert_same_size(A, B, "operator<=");
ucube out(A.n_rows, A.n_cols, A.n_slices); ucube out(A.n_rows, A.n_cols, A.n_slices);
const eT* A_mem = A.mem; ucube_eT* out_mem = out.memptr();
const eT* B_mem = B.mem;
typedef typename ucube::elem_type ucube_elem_type;
ucube_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] <= B_mem[i]) if(A[i] <= B[i])
{ {
out_mem[i] = ucube_elem_type(1); out_mem[i] = ucube_eT(1);
} }
else else
{ {
out_mem[i] = ucube_elem_type(0); out_mem[i] = ucube_eT(0);
} }
} }
return out; return out;
} }
template<typename eT, typename T1, typename T2> template<typename T1, typename T2>
inline inline
ucube ucube
operator> operator>
(const BaseCube<eT,T1>& X, const BaseCube<eT,T2>& Y) (const BaseCube<typename T1::elem_type,T1>& X, const BaseCube<typename T1:: elem_type,T2>& Y)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap_cube<T1> tmp1(X.get_ref()); typedef typename ucube::elem_type ucube_eT;
const unwrap_cube<T2> tmp2(Y.get_ref());
const Cube<eT>& A = tmp1.M; const ProxyCube<T1> A(X.get_ref());
const Cube<eT>& B = tmp2.M; const ProxyCube<T2> B(Y.get_ref());
arma_debug_assert_same_size(A, B, "operator>"); arma_debug_assert_same_size(A, B, "operator>");
ucube out(A.n_rows, A.n_cols, A.n_slices); ucube out(A.n_rows, A.n_cols, A.n_slices);
const eT* A_mem = A.mem; ucube_eT* out_mem = out.memptr();
const eT* B_mem = B.mem;
typedef typename ucube::elem_type ucube_elem_type;
ucube_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] > B_mem[i]) if(A[i] > B[i])
{ {
out_mem[i] = ucube_elem_type(1); out_mem[i] = ucube_eT(1);
} }
else else
{ {
out_mem[i] = ucube_elem_type(0); out_mem[i] = ucube_eT(0);
} }
} }
return out; return out;
} }
template<typename eT, typename T1, typename T2> template<typename T1, typename T2>
inline inline
ucube ucube
operator< operator<
(const BaseCube<eT,T1>& X, const BaseCube<eT,T2>& Y) (const BaseCube<typename T1::elem_type,T1>& X, const BaseCube<typename T1:: elem_type,T2>& Y)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap_cube<T1> tmp1(X.get_ref()); typedef typename ucube::elem_type ucube_eT;
const unwrap_cube<T2> tmp2(Y.get_ref());
const Cube<eT>& A = tmp1.M; const ProxyCube<T1> A(X.get_ref());
const Cube<eT>& B = tmp2.M; const ProxyCube<T2> B(Y.get_ref());
arma_debug_assert_same_size(A, B, "operator<"); arma_debug_assert_same_size(A, B, "operator<");
ucube out(A.n_rows, A.n_cols, A.n_slices); ucube out(A.n_rows, A.n_cols, A.n_slices);
const eT* A_mem = A.mem; ucube_eT* out_mem = out.memptr();
const eT* B_mem = B.mem;
typedef typename ucube::elem_type ucube_elem_type;
ucube_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] < B_mem[i]) if(A[i] < B[i])
{ {
out_mem[i] = ucube_elem_type(1); out_mem[i] = ucube_eT(1);
} }
else else
{ {
out_mem[i] = ucube_elem_type(0); out_mem[i] = ucube_eT(0);
} }
} }
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
ucube ucube
operator== operator==
(const BaseCube<typename T1::elem_type,T1>& X, const typename T1::elem_type val) (const BaseCube<typename T1::elem_type,T1>& X, const typename T1::elem_type val)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename ucube::elem_type ucube_eT;
const unwrap_cube<T1> tmp1(X.get_ref()); const ProxyCube<T1> A(X.get_ref());
const Cube<eT>& A = tmp1.M;
ucube out(A.n_rows, A.n_cols, A.n_slices); ucube out(A.n_rows, A.n_cols, A.n_slices);
const eT* A_mem = A.mem; ucube_eT* out_mem = out.memptr();
typedef typename ucube::elem_type ucube_elem_type;
ucube_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] == val) if(A[i] == val)
{ {
out_mem[i] = ucube_elem_type(1); out_mem[i] = ucube_eT(1);
} }
else else
{ {
out_mem[i] = ucube_elem_type(0); out_mem[i] = ucube_eT(0);
} }
} }
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
ucube ucube
operator!= operator!=
(const BaseCube<typename T1::elem_type,T1>& X, const typename T1::elem_type val) (const BaseCube<typename T1::elem_type,T1>& X, const typename T1::elem_type val)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename ucube::elem_type ucube_eT;
const unwrap_cube<T1> tmp1(X.get_ref()); const ProxyCube<T1> A(X.get_ref());
const Cube<eT>& A = tmp1.M;
ucube out(A.n_rows, A.n_cols, A.n_slices); ucube out(A.n_rows, A.n_cols, A.n_slices);
const eT* A_mem = A.mem; ucube_eT* out_mem = out.memptr();
typedef typename ucube::elem_type ucube_elem_type;
ucube_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] != val) if(A[i] != val)
{ {
out_mem[i] = ucube_elem_type(1); out_mem[i] = ucube_eT(1);
} }
else else
{ {
out_mem[i] = ucube_elem_type(0); out_mem[i] = ucube_eT(0);
} }
} }
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
ucube ucube
operator>= operator>=
(const BaseCube<typename T1::elem_type,T1>& X, const typename T1::elem_type val) (const BaseCube<typename T1::elem_type,T1>& X, const typename T1::elem_type val)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename ucube::elem_type ucube_eT;
const unwrap_cube<T1> tmp1(X.get_ref()); const ProxyCube<T1> A(X.get_ref());
const Cube<eT>& A = tmp1.M;
ucube out(A.n_rows, A.n_cols, A.n_slices); ucube out(A.n_rows, A.n_cols, A.n_slices);
const eT* A_mem = A.mem; ucube_eT* out_mem = out.memptr();
typedef typename ucube::elem_type ucube_elem_type;
ucube_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] >= val) if(A[i] >= val)
{ {
out_mem[i] = ucube_elem_type(1); out_mem[i] = ucube_eT(1);
} }
else else
{ {
out_mem[i] = ucube_elem_type(0); out_mem[i] = ucube_eT(0);
} }
} }
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
ucube ucube
operator<= operator<=
(const BaseCube<typename T1::elem_type,T1>& X, const typename T1::elem_type val) (const BaseCube<typename T1::elem_type,T1>& X, const typename T1::elem_type val)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename ucube::elem_type ucube_eT;
const unwrap_cube<T1> tmp1(X.get_ref()); const ProxyCube<T1> A(X.get_ref());
const Cube<eT>& A = tmp1.M;
ucube out(A.n_rows, A.n_cols, A.n_slices); ucube out(A.n_rows, A.n_cols, A.n_slices);
const eT* A_mem = A.mem; ucube_eT* out_mem = out.memptr();
typedef typename ucube::elem_type ucube_elem_type;
ucube_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] <= val) if(A[i] <= val)
{ {
out_mem[i] = ucube_elem_type(1); out_mem[i] = ucube_eT(1);
} }
else else
{ {
out_mem[i] = ucube_elem_type(0); out_mem[i] = ucube_eT(0);
} }
} }
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
ucube ucube
operator> operator>
(const BaseCube<typename T1::elem_type,T1>& X, const typename T1::elem_type val) (const BaseCube<typename T1::elem_type,T1>& X, const typename T1::elem_type val)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename ucube::elem_type ucube_eT;
const unwrap_cube<T1> tmp1(X.get_ref()); const ProxyCube<T1> A(X.get_ref());
const Cube<eT>& A = tmp1.M;
ucube out(A.n_rows, A.n_cols, A.n_slices); ucube out(A.n_rows, A.n_cols, A.n_slices);
const eT* A_mem = A.mem; ucube_eT* out_mem = out.memptr();
typedef typename ucube::elem_type ucube_elem_type;
ucube_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] > val) if(A[i] > val)
{ {
out_mem[i] = ucube_elem_type(1); out_mem[i] = ucube_eT(1);
} }
else else
{ {
out_mem[i] = ucube_elem_type(0); out_mem[i] = ucube_eT(0);
} }
} }
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
ucube ucube
operator< operator<
(const BaseCube<typename T1::elem_type,T1>& X, const typename T1::elem_type val) (const BaseCube<typename T1::elem_type,T1>& X, const typename T1::elem_type val)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename ucube::elem_type ucube_eT;
const unwrap_cube<T1> tmp1(X.get_ref()); const ProxyCube<T1> A(X.get_ref());
const Cube<eT>& A = tmp1.M;
ucube out(A.n_rows, A.n_cols, A.n_slices); ucube out(A.n_rows, A.n_cols, A.n_slices);
const eT* A_mem = A.mem; ucube_eT* out_mem = out.memptr();
typedef typename ucube::elem_type ucube_elem_type;
ucube_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] < val) if(A[i] < val)
{ {
out_mem[i] = ucube_elem_type(1); out_mem[i] = ucube_eT(1);
} }
else else
{ {
out_mem[i] = ucube_elem_type(0); out_mem[i] = ucube_eT(0);
} }
} }
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
ucube ucube
operator== operator==
skipping to change at line 488 skipping to change at line 435
} }
template<typename T1> template<typename T1>
inline inline
ucube ucube
operator>= operator>=
(const typename T1::elem_type val, const BaseCube<typename T1::elem_type,T1 >& X) (const typename T1::elem_type val, const BaseCube<typename T1::elem_type,T1 >& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename ucube::elem_type ucube_eT;
const unwrap_cube<T1> tmp1(X.get_ref()); const ProxyCube<T1> A(X.get_ref());
const Cube<eT>& A = tmp1.M;
ucube out(A.n_rows, A.n_cols, A.n_slices); ucube out(A.n_rows, A.n_cols, A.n_slices);
const eT* A_mem = A.mem; ucube_eT* out_mem = out.memptr();
typedef typename ucube::elem_type ucube_elem_type;
ucube_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(val >= A_mem[i]) if(val >= A[i])
{ {
out_mem[i] = ucube_elem_type(1); out_mem[i] = ucube_eT(1);
} }
else else
{ {
out_mem[i] = ucube_elem_type(0); out_mem[i] = ucube_eT(0);
} }
} }
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
ucube ucube
operator<= operator<=
(const typename T1::elem_type val, const BaseCube<typename T1::elem_type,T1 >& X) (const typename T1::elem_type val, const BaseCube<typename T1::elem_type,T1 >& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename ucube::elem_type ucube_eT;
const unwrap_cube<T1> tmp1(X.get_ref()); const ProxyCube<T1> A(X.get_ref());
const Cube<eT>& A = tmp1.M;
ucube out(A.n_rows, A.n_cols, A.n_slices); ucube out(A.n_rows, A.n_cols, A.n_slices);
const eT* A_mem = A.mem; ucube_eT* out_mem = out.memptr();
typedef typename ucube::elem_type ucube_elem_type;
ucube_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(val <= A_mem[i]) if(val <= A[i])
{ {
out_mem[i] = ucube_elem_type(1); out_mem[i] = ucube_eT(1);
} }
else else
{ {
out_mem[i] = ucube_elem_type(0); out_mem[i] = ucube_eT(0);
} }
} }
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
ucube ucube
operator> operator>
(const typename T1::elem_type val, const BaseCube<typename T1::elem_type,T1 >& X) (const typename T1::elem_type val, const BaseCube<typename T1::elem_type,T1 >& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename ucube::elem_type ucube_eT;
const unwrap_cube<T1> tmp1(X.get_ref()); const ProxyCube<T1> A(X.get_ref());
const Cube<eT>& A = tmp1.M;
ucube out(A.n_rows, A.n_cols, A.n_slices); ucube out(A.n_rows, A.n_cols, A.n_slices);
const eT* A_mem = A.mem; ucube_eT* out_mem = out.memptr();
typedef typename ucube::elem_type ucube_elem_type;
ucube_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(val > A_mem[i]) if(val > A[i])
{ {
out_mem[i] = ucube_elem_type(1); out_mem[i] = ucube_eT(1);
} }
else else
{ {
out_mem[i] = ucube_elem_type(0); out_mem[i] = ucube_eT(0);
} }
} }
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
ucube ucube
operator< operator<
(const typename T1::elem_type val, const BaseCube<typename T1::elem_type,T1 >& X) (const typename T1::elem_type val, const BaseCube<typename T1::elem_type,T1 >& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename ucube::elem_type ucube_eT;
const unwrap_cube<T1> tmp1(X.get_ref()); const ProxyCube<T1> A(X.get_ref());
const Cube<eT>& A = tmp1.M;
ucube out(A.n_rows, A.n_cols, A.n_slices); ucube out(A.n_rows, A.n_cols, A.n_slices);
const eT* A_mem = A.mem; ucube_eT* out_mem = out.memptr();
typedef typename ucube::elem_type ucube_elem_type;
ucube_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(val < A_mem[i]) if(val < A[i])
{ {
out_mem[i] = ucube_elem_type(1); out_mem[i] = ucube_eT(1);
} }
else else
{ {
out_mem[i] = ucube_elem_type(0); out_mem[i] = ucube_eT(0);
} }
} }
return out; return out;
} }
//! @} //! @}
 End of changes. 109 change blocks. 
185 lines changed or deleted 116 lines changed or added


 operator_cube_schur.hpp   operator_cube_schur.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 operator_cube_schur //! \addtogroup operator_cube_schur
//! @{ //! @{
// operator %, which we define it to do a schur product (element-wise multi plication) // operator %, which we define it to do a schur product (element-wise multi plication)
//! Base % Base //! element-wise multiplication of BaseCube objects with same element type
template<typename T1, typename T2> template<typename T1, typename T2>
arma_inline arma_inline
const GlueCube<T1, T2, glue_cube_schur> const eGlueCube<T1, T2, eglue_cube_schur>
operator% operator%
(const BaseCube<typename T1::elem_type,T1>& X, const BaseCube<typename T1:: (
elem_type,T2>& Y) const BaseCube<typename T1::elem_type,T1>& X,
const BaseCube<typename T1::elem_type,T2>& Y
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_schur>(X.get_ref(), Y.get_ref()); return eGlueCube<T1, T2, eglue_cube_schur>(X.get_ref(), Y.get_ref());
} }
// //! element-wise multiplication of BaseCube objects with different element
// schur product of Base objects with different element types types
//
//! Base % Base
template<typename eT1, typename T1, typename eT2, typename T2>
arma_inline
Cube<typename promote_type<eT1,eT2>::result>
operator%
(const BaseCube<eT1,T1>& X, const BaseCube<eT2,T2>& Y)
{
arma_extra_debug_sigprint();
promote_type<eT1,eT2>::check();
const unwrap_cube<T1> tmp1(X.get_ref());
const unwrap_cube<T2> tmp2(Y.get_ref());
const Cube<eT1>& A = tmp1.M;
const Cube<eT2>& B = tmp2.M;
Cube< typename promote_type<eT1,eT2>::result > out;
glue_cube_schur::apply_mixed(out, A, B);
return out;
}
//
// schur product of Base objects with same element types
//
template<typename T1, typename T2> template<typename T1, typename T2>
arma_inline arma_inline
const GlueCube<T1, T2, glue_cube_schur> Cube<typename promote_type<typename T1::elem_type, typename T2::elem_type>: :result>
operator% operator%
(const BaseCube<std::complex<double>,T1>& X, const BaseCube<std::complex<do (
uble>,T2>& Y) const BaseCube< typename force_different_type<typename T1::elem_type, typ
ename T2::elem_type>::T1_result, T1>& X,
const BaseCube< typename force_different_type<typename T1::elem_type, typ
ename T2::elem_type>::T2_result, T2>& Y
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_schur>(X.get_ref(), Y.get_ref()); typedef typename T1::elem_type eT1;
} typedef typename T2::elem_type eT2;
template<typename T1, typename T2> typedef typename promote_type<eT1,eT2>::result out_eT;
arma_inline
const GlueCube<T1, T2, glue_cube_schur>
operator%
(const BaseCube<std::complex<float>,T1>& X, const BaseCube<std::complex<flo
at>,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_schur>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const GlueCube<T1, T2, glue_cube_schur>
operator%
(const BaseCube<double,T1>& X, const BaseCube<double,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_schur>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const GlueCube<T1, T2, glue_cube_schur>
operator%
(const BaseCube<float,T1>& X, const BaseCube<float,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_schur>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2> promote_type<eT1,eT2>::check();
arma_inline
const GlueCube<T1, T2, glue_cube_schur>
operator%
(const BaseCube<s32,T1>& X, const BaseCube<s32,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_schur>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const GlueCube<T1, T2, glue_cube_schur>
operator%
(const BaseCube<u32,T1>& X, const BaseCube<u32,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_schur>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const GlueCube<T1, T2, glue_cube_schur>
operator%
(const BaseCube<s16,T1>& X, const BaseCube<s16,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_schur>(X.get_ref(), Y.get_ref()); const ProxyCube<T1> A(X.get_ref());
} const ProxyCube<T2> B(Y.get_ref());
template<typename T1, typename T2> arma_debug_assert_same_size(A, B, "element-wise cube multiplication");
arma_inline
const GlueCube<T1, T2, glue_cube_schur>
operator%
(const BaseCube<u16,T1>& X, const BaseCube<u16,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_schur>(X.get_ref(), Y.get_ref()); Cube<out_eT> out(A.n_rows, A.n_cols, A.n_slices);
}
template<typename T1, typename T2> out_eT* out_mem = out.memptr();
arma_inline const u32 n_elem = out.n_elem;
const GlueCube<T1, T2, glue_cube_schur>
operator%
(const BaseCube<s8,T1>& X, const BaseCube<s8,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_schur>(X.get_ref(), Y.get_ref()); for(u32 i=0; i<n_elem; ++i)
} {
out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) * upgrade_val<eT1,eT2>::
template<typename T1, typename T2> apply(B[i]);
arma_inline }
const GlueCube<T1, T2, glue_cube_schur>
operator%
(const BaseCube<u8,T1>& X, const BaseCube<u8,T2>& Y)
{
arma_extra_debug_sigprint();
return GlueCube<T1, T2, glue_cube_schur>(X.get_ref(), Y.get_ref()); return out;
} }
//! @} //! @}
 End of changes. 17 change blocks. 
133 lines changed or deleted 34 lines changed or added


 operator_cube_times.hpp   operator_cube_times.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 operator_cube_times //! \addtogroup operator_cube_times
//! @{ //! @{
//! BaseCube * scalar //! BaseCube * scalar
template<typename T1> template<typename T1>
arma_inline arma_inline
const OpCube<T1, op_scalar_times> const eOpCube<T1, eop_cube_scalar_times>
operator* operator*
(const BaseCube<typename T1::elem_type,T1>& X, const typename T1::elem_type (
k) const BaseCube<typename T1::elem_type,T1>& X,
const typename T1::elem_type k
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_scalar_times>(X.get_ref(),k); return eOpCube<T1, eop_cube_scalar_times>(X.get_ref(), k);
} }
//! op * scalar, level 2 //! scalar * BaseCube
template<typename T1> template<typename T1>
arma_inline arma_inline
const OpCube<T1,op_scalar_times> const eOpCube<T1, eop_cube_scalar_times>
operator* operator*
(const OpCube<T1,op_scalar_times>& X, const typename T1::elem_type k) (
const typename T1::elem_type k,
const BaseCube<typename T1::elem_type,T1>& X
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return OpCube<T1, op_scalar_times>(X.m, X.aux * k); return eOpCube<T1, eop_cube_scalar_times>(X.get_ref(), k);
}
//! OpCube<cube,op_ones_full> * scalar
template<typename eT>
arma_inline
Cube<eT>
operator*
(const OpCube<Cube<eT>,op_ones_full>& X, const eT k)
{
arma_extra_debug_sigprint();
Cube<eT> tmp(X.aux_u32_a, X.aux_u32_b, X.aux_u32_c);
tmp.fill(k);
return tmp;
}
//! scalar * Base
template<typename T1>
arma_inline
const OpCube<T1, op_scalar_times>
operator*
(const typename T1::elem_type k, const BaseCube<typename T1::elem_type,T1>&
X)
{
arma_extra_debug_sigprint();
return OpCube<T1, op_scalar_times>(X.get_ref(),k); // NOTE: order is swa
pped
}
//! scalar * OpCube<cube,op_ones_full>
template<typename eT>
arma_inline
Cube<eT>
operator*
(const eT k, const OpCube<Cube<eT>,op_ones_full>& X)
{
arma_extra_debug_sigprint();
Cube<eT> tmp(X.aux_u32_a, X.aux_u32_b, X.aux_u32_c);
tmp.fill(k);
return tmp;
} }
//! @} //! @}
 End of changes. 8 change blocks. 
53 lines changed or deleted 15 lines changed or added


 operator_div.hpp   operator_div.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 operator_div //! \addtogroup operator_div
//! @{ //! @{
//! Base / scalar //! Base / scalar
template<typename T1> template<typename T1>
arma_inline arma_inline
const Op<T1, op_scalar_div_post> const eOp<T1, eop_scalar_div_post>
operator/ operator/
(const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type k) (
const Base<typename T1::elem_type,T1>& X,
const typename T1::elem_type k
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_scalar_div_post>(X.get_ref(), k); return eOp<T1, eop_scalar_div_post>(X.get_ref(), k);
}
//! Op<mat,op_ones_full> / scalar
template<typename eT>
arma_inline
Mat<eT>
operator/
(const Op<Mat<eT>,op_ones_full>& X, const eT k)
{
arma_extra_debug_sigprint();
Mat<eT> tmp(X.aux_u32_a, X.aux_u32_b);
tmp.fill( eT(1)/k );
return tmp;
}
//! Op<mat,op_ones_diag> / scalar
template<typename eT>
arma_inline
Mat<eT>
operator/
(const Op<Mat<eT>,op_ones_diag>& X, const eT k)
{
arma_extra_debug_sigprint();
Mat<eT> out;
out.zeros(X.aux_u32_a, X.aux_u32_b);
const eT inv_k = eT(1)/k;
for(u32 i=0; i<out.n_rows; ++i)
{
out.at(i,i) = inv_k;
}
return out;
} }
//! scalar / Base //! scalar / Base
template<typename T1> template<typename T1>
arma_inline arma_inline
const Op<T1, op_scalar_div_pre> const eOp<T1, eop_scalar_div_pre>
operator/
(const typename T1::elem_type k, const Base<typename T1::elem_type,T1>& X)
{
arma_extra_debug_sigprint();
return Op<T1, op_scalar_div_pre>(X.get_ref(), k);
}
//
// element-wise division of Base objects with different element types
//
//! Base / Base
template<typename eT1, typename T1, typename eT2, typename T2>
arma_inline
Mat<typename promote_type<eT1,eT2>::result>
operator/
(const Base<eT1,T1>& X, const Base<eT2,T2>& Y)
{
arma_extra_debug_sigprint();
promote_type<eT1,eT2>::check();
const unwrap<T1> tmp1(X.get_ref());
const unwrap<T2> tmp2(Y.get_ref());
const Mat<eT1>& A = tmp1.M;
const Mat<eT2>& B = tmp2.M;
Mat< typename promote_type<eT1,eT2>::result > out;
glue_div::apply_mixed(out, A, B);
return out;
}
//
// element-wise division of Base objects with same element types
//
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_div>
operator/
(const Base<std::complex<double>,T1>& X, const Base<std::complex<double>,T2
>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_div>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_div>
operator/ operator/
(const Base<std::complex<float>,T1>& X, const Base<std::complex<float>,T2>& (
Y) const typename T1::elem_type k,
const Base<typename T1::elem_type,T1>& X
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Glue<T1, T2, glue_div>(X.get_ref(), Y.get_ref()); return eOp<T1, eop_scalar_div_pre>(X.get_ref(), k);
} }
//! element-wise division of Base objects with same element type
template<typename T1, typename T2> template<typename T1, typename T2>
arma_inline arma_inline
const Glue<T1, T2, glue_div> const eGlue<T1, T2, eglue_div>
operator/ operator/
(const Base<double,T1>& X, const Base<double,T2>& Y) (
const Base<typename T1::elem_type,T1>& X,
const Base<typename T1::elem_type,T2>& Y
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Glue<T1, T2, glue_div>(X.get_ref(), Y.get_ref()); return eGlue<T1, T2, eglue_div>(X.get_ref(), Y.get_ref());
} }
//! element-wise division of Base objects with different element types
template<typename T1, typename T2> template<typename T1, typename T2>
arma_inline arma_inline
const Glue<T1, T2, glue_div> Mat<typename promote_type<typename T1::elem_type, typename T2::elem_type>:: result>
operator/ operator/
(const Base<float,T1>& X, const Base<float,T2>& Y) (
const Base< typename force_different_type<typename T1::elem_type, typenam
e T2::elem_type>::T1_result, T1>& X,
const Base< typename force_different_type<typename T1::elem_type, typenam
e T2::elem_type>::T2_result, T2>& Y
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Glue<T1, T2, glue_div>(X.get_ref(), Y.get_ref()); typedef typename T1::elem_type eT1;
} typedef typename T2::elem_type eT2;
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_div>
operator/
(const Base<s32,T1>& X, const Base<s32,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_div>(X.get_ref(), Y.get_ref()); typedef typename promote_type<eT1,eT2>::result out_eT;
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_div>
operator/
(const Base<u32,T1>& X, const Base<u32,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_div>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_div>
operator/
(const Base<s16,T1>& X, const Base<s16,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_div>(X.get_ref(), Y.get_ref()); promote_type<eT1,eT2>::check();
}
template<typename T1, typename T2> const Proxy<T1> A(X.get_ref());
arma_inline const Proxy<T2> B(Y.get_ref());
const Glue<T1, T2, glue_div>
operator/
(const Base<u16,T1>& X, const Base<u16,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_div>(X.get_ref(), Y.get_ref()); arma_debug_assert_same_size(A, B, "element-wise matrix division");
}
template<typename T1, typename T2> Mat<out_eT> out(A.n_rows, A.n_cols);
arma_inline
const Glue<T1, T2, glue_div>
operator/
(const Base<s8,T1>& X, const Base<s8,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_div>(X.get_ref(), Y.get_ref()); out_eT* out_mem = out.memptr();
} const u32 n_elem = out.n_elem;
template<typename T1, typename T2> for(u32 i=0; i<n_elem; ++i)
arma_inline {
const Glue<T1, T2, glue_div> out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) / upgrade_val<eT1,eT2>::
operator/ apply(B[i]);
(const Base<u8,T1>& X, const Base<u8,T2>& Y) }
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_div>(X.get_ref(), Y.get_ref()); return out;
} }
//! @} //! @}
 End of changes. 23 change blocks. 
163 lines changed or deleted 45 lines changed or added


 operator_minus.hpp   operator_minus.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 operator_minus //! \addtogroup operator_minus
//! @{ //! @{
//! unary - //! unary -
template<typename T1> template<typename T1>
arma_inline arma_inline
const Op<T1, op_neg> const eOp<T1, eop_neg>
operator- operator-
(const Base<typename T1::elem_type,T1>& X) (const Base<typename T1::elem_type,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1,op_neg>(X.get_ref()); return eOp<T1,eop_neg>(X.get_ref());
} }
//! cancellation of two consecutive negations: -(-T1) //! cancellation of two consecutive negations: -(-T1)
template<typename T1> template<typename T1>
arma_inline arma_inline
const T1& const T1&
operator- operator-
(const Op<T1, op_neg>& X) (const eOp<T1, eop_neg>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return X.m; return X.m;
} }
//! Base - scalar //! Base - scalar
template<typename T1> template<typename T1>
arma_inline arma_inline
const Op<T1, op_scalar_minus_post> const eOp<T1, eop_scalar_minus_post>
operator- operator-
(const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type k) (
const Base<typename T1::elem_type,T1>& X,
const typename T1::elem_type k
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_scalar_minus_post>(X.get_ref(), k); return eOp<T1, eop_scalar_minus_post>(X.get_ref(), k);
} }
//! scalar - Base //! scalar - Base
template<typename T1> template<typename T1>
arma_inline arma_inline
const Op<T1, op_scalar_minus_pre> const eOp<T1, eop_scalar_minus_pre>
operator-
(const typename T1::elem_type k, const Base<typename T1::elem_type,T1>& X)
{
arma_extra_debug_sigprint();
return Op<T1, op_scalar_minus_pre>(X.get_ref(), k);
}
//! Base - - Base = Base + Base
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_plus>
operator- operator-
( (
const Base<typename T1::elem_type, T1 >& X, const typename T1::elem_type k,
const Base<typename T1::elem_type, Op<T2,op_neg> >& Y const Base<typename T1::elem_type,T1>& X
) )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const T1& A = X.get_ref(); return eOp<T1, eop_scalar_minus_pre>(X.get_ref(), k);
const T2& B = (Y.get_ref()).m;
return Glue<T1, T2, glue_plus>(A,B);
} }
//! Base - diagmat //! subtraction of Base objects with same element type
template<typename T1, typename T2> template<typename T1, typename T2>
arma_inline arma_inline
const Glue<T1, Op<T2,op_diagmat>, glue_minus_diag> const eGlue<T1, T2, eglue_minus>
operator- operator-
(const Base<typename T2::elem_type,T1>& X, const Op<T2,op_diagmat>& Y) (
const Base<typename T1::elem_type,T1>& X,
const Base<typename T1::elem_type,T2>& Y
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Glue<T1, Op<T1,op_diagmat>, glue_minus_diag>(X.get_ref(), Y); return eGlue<T1, T2, eglue_minus>(X.get_ref(), Y.get_ref());
} }
//! diagmat - Base //! subtraction of Base objects with different element types
template<typename T1, typename T2> template<typename T1, typename T2>
arma_inline arma_inline
const Glue< Op<T1,op_diagmat>, T2, glue_minus_diag> Mat<typename promote_type<typename T1::elem_type, typename T2::elem_type>:: result>
operator- operator-
(const Op<T1,op_diagmat>& X, const Base<typename T1::elem_type,T2>& Y) (
{ const Base< typename force_different_type<typename T1::elem_type, typenam
arma_extra_debug_sigprint(); e T2::elem_type>::T1_result, T1>& X,
const Base< typename force_different_type<typename T1::elem_type, typenam
return Glue< Op<T1,op_diagmat>, T2, glue_minus_diag>(X, Y.get_ref()); e T2::elem_type>::T2_result, T2>& Y
} )
//! diagmat - diagmat
template<typename T1, typename T2>
inline
Mat< typename promote_type<typename T1::elem_type, typename T2::elem_type>:
:result >
operator-
(const Op<T1, op_diagmat>& X, const Op<T2, op_diagmat>& Y)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT1; typedef typename T1::elem_type eT1;
typedef typename T2::elem_type eT2; typedef typename T2::elem_type eT2;
typedef typename promote_type<eT1,eT2>::result out_eT; typedef typename promote_type<eT1,eT2>::result out_eT;
promote_type<eT1,eT2>::check(); promote_type<eT1,eT2>::check();
const unwrap<T1> tmp1(X.m); const Proxy<T1> A(X.get_ref());
const unwrap<T2> tmp2(Y.m); const Proxy<T2> B(Y.get_ref());
const Mat<eT1> A(tmp1.M); arma_debug_assert_same_size(A, B, "matrix subtraction");
const Mat<eT2> B(tmp2.M);
arma_debug_assert_same_size(A.n_rows, A.n_cols, B.n_rows, B.n_cols, "matr ix subtraction"); Mat<out_eT> out(A.n_rows, A.n_cols);
Mat<out_eT> out(A.n_rows, A.n_rows); out_eT* out_mem = out.memptr();
out.zeros(); const u32 n_elem = out.n_elem;
for(u32 i=0; i<A.n_rows; ++i) for(u32 i=0; i<n_elem; ++i)
{ {
out.at(i,i) = upgrade_val<eT1,eT2>::apply( A.at(i,i) ) - upgrade_val<eT 1,eT2>::apply( B.at(i,i) ); out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) - upgrade_val<eT1,eT2>:: apply(B[i]);
} }
return out; return out;
} }
//! Base - Op<T2,op_neg> = Base + T2
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_plus>
operator-
(const Base<typename T2::elem_type,T1>& X, const Op<T2, op_neg>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_plus>(X.get_ref(), Y.m);
}
//! diagmat - Op<T2,op_neg> = diagmat + T2
template<typename T1, typename T2>
arma_inline
const Glue< Op<T1,op_diagmat>, T2, glue_plus_diag>
operator-
(
const Base<typename T1::elem_type, Op<T1,op_diagmat> >& X,
const Base<typename T1::elem_type, Op<T2,op_neg > >& Y
)
{
arma_extra_debug_sigprint();
return Glue< Op<T1,op_diagmat>, T2, glue_plus_diag>(X.get_ref(), (Y.get_r
ef()).m);
}
//
// subtraction of Base objects with different element types
//
//! Base - Base
template<typename eT1, typename T1, typename eT2, typename T2>
arma_inline
Mat<typename promote_type<eT1,eT2>::result>
operator-
(const Base<eT1,T1>& X, const Base<eT2,T2>& Y)
{
arma_extra_debug_sigprint();
promote_type<eT1,eT2>::check();
const unwrap<T1> tmp1(X.get_ref());
const unwrap<T2> tmp2(Y.get_ref());
const Mat<eT1>& A = tmp1.M;
const Mat<eT2>& B = tmp2.M;
Mat< typename promote_type<eT1,eT2>::result > out;
glue_minus::apply_mixed(out, A, B);
return out;
}
//
// subtraction of Base objects with same element types
//
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_minus>
operator-
(const Base<std::complex<double>,T1>& X, const Base<std::complex<double>,T2
>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_minus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_minus>
operator-
(const Base<std::complex<float>,T1>& X, const Base<std::complex<float>,T2>&
Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_minus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_minus>
operator-
(const Base<double,T1>& X, const Base<double,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_minus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_minus>
operator-
(const Base<float,T1>& X, const Base<float,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_minus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_minus>
operator-
(const Base<s32,T1>& X, const Base<s32,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_minus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_minus>
operator-
(const Base<u32,T1>& X, const Base<u32,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_minus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_minus>
operator-
(const Base<s16,T1>& X, const Base<s16,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_minus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_minus>
operator-
(const Base<u16,T1>& X, const Base<u16,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_minus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_minus>
operator-
(const Base<s8,T1>& X, const Base<s8,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_minus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_minus>
operator-
(const Base<u8,T1>& X, const Base<u8,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_minus>(X.get_ref(), Y.get_ref());
}
//! @} //! @}
 End of changes. 24 change blocks. 
226 lines changed or deleted 38 lines changed or added


 operator_ostream.hpp   operator_ostream.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 46 skipping to change at line 47
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap_cube<T1> tmp(X.get_ref()); const unwrap_cube<T1> tmp(X.get_ref());
arma_ostream::print(o, tmp.M, true); arma_ostream::print(o, tmp.M, true);
return o; return o;
} }
//! Print a diagonal matrix to the specified stream.
template<typename T1>
inline
std::ostream&
operator<< (std::ostream& o, const Op<T1,op_diagmat>& X)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const unwrap<T1> tmp(X.m);
const Mat<eT>& m = tmp.M;
arma_debug_check( ((m.is_vec() == false) && (m.is_square() == false)), "o
perator<<(): incompatible dimensions for diagmat operation" );
const arma_ostream_state stream_state(o);
const u32 cell_width = arma_ostream::modify_stream(o, m.mem, m.n_elem);
const u32 local_n_rows = (std::max)(m.n_rows, m.n_cols);
for(u32 row=0; row < local_n_rows; ++row)
{
for(u32 col=0; col < local_n_rows; ++col)
{
if(row != col)
{
o.width(cell_width);
if(is_complex<eT>::value == false)
{
o << "0.0";
}
else
{
o << "(0.0,0.0)";
}
}
else
{
const eT val = m.is_vec() ? m.mem[row] : m.at(row,row);
o.width(cell_width);
o << val;
}
}
o << '\n';
}
o.flush();
stream_state.restore(o);
return o;
}
//! Print the contents of a field to the specified stream. //! Print the contents of a field to the specified stream.
template<typename T1> template<typename T1>
inline inline
std::ostream& std::ostream&
operator<< (std::ostream& o, const field<T1>& X) operator<< (std::ostream& o, const field<T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_ostream::print(o, X); arma_ostream::print(o, X);
 End of changes. 2 change blocks. 
57 lines changed or deleted 2 lines changed or added


 operator_plus.hpp   operator_plus.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 33 skipping to change at line 34
(const Base<typename T1::elem_type,T1>& X) (const Base<typename T1::elem_type,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return X; return X;
} }
//! Base + scalar //! Base + scalar
template<typename T1> template<typename T1>
arma_inline arma_inline
const Op<T1, op_scalar_plus> const eOp<T1, eop_scalar_plus>
operator+ operator+
(const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type k) (const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type k)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_scalar_plus>(X.get_ref(), k); return eOp<T1, eop_scalar_plus>(X.get_ref(), k);
}
//! op + scalar, level 2
template<typename T1>
arma_inline
const Op<T1,op_scalar_plus>
operator+
(const Op<T1,op_scalar_plus>& X, const typename T1::elem_type k)
{
arma_extra_debug_sigprint();
return Op<T1, op_scalar_plus>(X.m, X.aux + k);
} }
//! scalar + Base //! scalar + Base
template<typename T1> template<typename T1>
arma_inline arma_inline
const Op<T1, op_scalar_plus> const eOp<T1, eop_scalar_plus>
operator+ operator+
(const typename T1::elem_type k, const Base<typename T1::elem_type,T1>& X) (const typename T1::elem_type k, const Base<typename T1::elem_type,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_scalar_plus>(X.get_ref(), k); // NOTE: order is swapped return eOp<T1, eop_scalar_plus>(X.get_ref(), k); // NOTE: order is swapp ed
} }
//! Base + diagmat //! addition of Base objects with same element type
template<typename T1, typename T2> template<typename T1, typename T2>
arma_inline arma_inline
const Glue<T1, Op<T2,op_diagmat>, glue_plus_diag> const eGlue<T1, T2, eglue_plus>
operator+ operator+
(const Base<typename T2::elem_type, T1>& X, const Op<T2,op_diagmat>& Y) (
const Base<typename T1::elem_type,T1>& X,
const Base<typename T1::elem_type,T2>& Y
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Glue<T1, Op<T2,op_diagmat>, glue_plus_diag>(X.get_ref(), Y); return eGlue<T1, T2, eglue_plus>(X.get_ref(), Y.get_ref());
} }
//! diagmat + Base //! addition of Base objects with different element types
template<typename T1, typename T2> template<typename T1, typename T2>
arma_inline arma_inline
const Glue<T1, Op<T2,op_diagmat>, glue_plus_diag> Mat<typename promote_type<typename T1::elem_type, typename T2::elem_type>::
operator+ result>
(const Op<T2,op_diagmat>& Y, const Base<typename T1::elem_type, T1>& X)
{
arma_extra_debug_sigprint();
return Glue<T1, Op<T2,op_diagmat>, glue_plus_diag>(X.get_ref(), Y); // N
OTE: order is swapped
}
//! diagmat + diagmat
template<typename T1, typename T2>
inline
Mat< typename promote_type<typename T1::elem_type, typename T2::elem_type>:
:result >
operator+ operator+
(const Op<T1, op_diagmat>& X, const Op<T2, op_diagmat>& Y) (
const Base< typename force_different_type<typename T1::elem_type, typenam
e T2::elem_type>::T1_result, T1>& X,
const Base< typename force_different_type<typename T1::elem_type, typenam
e T2::elem_type>::T2_result, T2>& Y
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT1; typedef typename T1::elem_type eT1;
typedef typename T2::elem_type eT2; typedef typename T2::elem_type eT2;
typedef typename promote_type<eT1,eT2>::result out_eT; typedef typename promote_type<eT1,eT2>::result out_eT;
promote_type<eT1,eT2>::check(); promote_type<eT1,eT2>::check();
const unwrap<T1> tmp1(X.m); const Proxy<T1> A(X.get_ref());
const unwrap<T2> tmp2(Y.m); const Proxy<T2> B(Y.get_ref());
const Mat<eT1> A(tmp1.M); arma_debug_assert_same_size(A, B, "matrix addition");
const Mat<eT2> B(tmp2.M);
arma_debug_assert_same_size(A.n_rows, A.n_cols, B.n_rows, B.n_cols, "matr ix addition"); Mat<out_eT> out(A.n_rows, A.n_cols);
Mat<out_eT> out(A.n_rows, A.n_rows); out_eT* out_mem = out.memptr();
out.zeros(); const u32 n_elem = out.n_elem;
for(u32 i=0; i<A.n_rows; ++i) for(u32 i=0; i<n_elem; ++i)
{ {
out.at(i,i) = upgrade_val<eT1,eT2>::apply( A.at(i,i) ) + upgrade_val<eT 1,eT2>::apply( B.at(i,i) ); out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) + upgrade_val<eT1,eT2>:: apply(B[i]);
} }
return out; return out;
} }
//
// addition of Base objects with different element types
//
//! Base + Base
template<typename eT1, typename T1, typename eT2, typename T2>
arma_inline
Mat<typename promote_type<eT1,eT2>::result>
operator+
(const Base<eT1,T1>& X, const Base<eT2,T2>& Y)
{
arma_extra_debug_sigprint();
promote_type<eT1,eT2>::check();
const unwrap<T1> tmp1(X.get_ref());
const unwrap<T2> tmp2(Y.get_ref());
const Mat<eT1>& A = tmp1.M;
const Mat<eT2>& B = tmp2.M;
Mat< typename promote_type<eT1,eT2>::result > out;
glue_plus::apply_mixed(out, A, B);
return out;
}
//
// addition of Base objects with same element types
//
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_plus>
operator+
(const Base<std::complex<double>,T1>& X, const Base<std::complex<double>,T2
>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_plus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_plus>
operator+
(const Base<std::complex<float>,T1>& X, const Base<std::complex<float>,T2>&
Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_plus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_plus>
operator+
(const Base<double,T1>& X, const Base<double,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_plus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_plus>
operator+
(const Base<float,T1>& X, const Base<float,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_plus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_plus>
operator+
(const Base<s32,T1>& X, const Base<s32,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_plus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_plus>
operator+
(const Base<u32,T1>& X, const Base<u32,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_plus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_plus>
operator+
(const Base<s16,T1>& X, const Base<s16,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_plus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_plus>
operator+
(const Base<u16,T1>& X, const Base<u16,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_plus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_plus>
operator+
(const Base<s8,T1>& X, const Base<s8,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_plus>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_plus>
operator+
(const Base<u8,T1>& X, const Base<u8,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_plus>(X.get_ref(), Y.get_ref());
}
//! @} //! @}
 End of changes. 19 change blocks. 
190 lines changed or deleted 30 lines changed or added


 operator_relational.hpp   operator_relational.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 operator_relational //! \addtogroup operator_relational
//! @{ //! @{
template<typename eT, typename T1, typename T2> template<typename T1, typename T2>
inline inline
umat umat
operator== operator==
(const Base<eT,T1>& X, const Base<eT,T2>& Y) (const Base<typename T1::elem_type,T1>& X, const Base<typename T1::elem_typ e,T2>& Y)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap<T1> tmp1(X.get_ref()); typedef typename umat::elem_type umat_eT;
const unwrap<T2> tmp2(Y.get_ref());
const Mat<eT>& A = tmp1.M; const Proxy<T1> A(X.get_ref());
const Mat<eT>& B = tmp2.M; const Proxy<T2> B(Y.get_ref());
arma_debug_assert_same_size(A, B, "operator=="); arma_debug_assert_same_size(A, B, "operator==");
umat out(A.n_rows, A.n_cols); umat out(A.n_rows, A.n_cols);
const eT* A_mem = A.mem; umat_eT* out_mem = out.memptr();
const eT* B_mem = B.mem;
typedef typename umat::elem_type umat_elem_type;
umat_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] == B_mem[i]) if(A[i] == B[i])
{ {
out_mem[i] = umat_elem_type(1); out_mem[i] = umat_eT(1);
} }
else else
{ {
out_mem[i] = umat_elem_type(0); out_mem[i] = umat_eT(0);
} }
} }
return out; return out;
} }
template<typename eT, typename T1, typename T2> template<typename T1, typename T2>
inline inline
umat umat
operator!= operator!=
(const Base<eT,T1>& X, const Base<eT,T2>& Y) (const Base<typename T1::elem_type,T1>& X, const Base<typename T1::elem_typ e,T2>& Y)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap<T1> tmp1(X.get_ref()); typedef typename umat::elem_type umat_eT;
const unwrap<T2> tmp2(Y.get_ref());
const Mat<eT>& A = tmp1.M; const Proxy<T1> A(X.get_ref());
const Mat<eT>& B = tmp2.M; const Proxy<T2> B(Y.get_ref());
arma_debug_assert_same_size(A, B, "operator!="); arma_debug_assert_same_size(A, B, "operator!=");
umat out(A.n_rows, A.n_cols); umat out(A.n_rows, A.n_cols);
const eT* A_mem = A.mem; umat_eT* out_mem = out.memptr();
const eT* B_mem = B.mem;
typedef typename umat::elem_type umat_elem_type;
umat_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] != B_mem[i]) if(A[i] != B[i])
{ {
out_mem[i] = umat_elem_type(1); out_mem[i] = umat_eT(1);
} }
else else
{ {
out_mem[i] = umat_elem_type(0); out_mem[i] = umat_eT(0);
} }
} }
return out; return out;
} }
template<typename eT, typename T1, typename T2> template<typename T1, typename T2>
inline inline
umat umat
operator>= operator>=
(const Base<eT,T1>& X, const Base<eT,T2>& Y) (const Base<typename T1::elem_type,T1>& X, const Base<typename T1::elem_typ e,T2>& Y)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap<T1> tmp1(X.get_ref()); typedef typename umat::elem_type umat_eT;
const unwrap<T2> tmp2(Y.get_ref());
const Mat<eT>& A = tmp1.M; const Proxy<T1> A(X.get_ref());
const Mat<eT>& B = tmp2.M; const Proxy<T2> B(Y.get_ref());
arma_debug_assert_same_size(A, B, "operator>="); arma_debug_assert_same_size(A, B, "operator>=");
umat out(A.n_rows, A.n_cols); umat out(A.n_rows, A.n_cols);
const eT* A_mem = A.mem; umat_eT* out_mem = out.memptr();
const eT* B_mem = B.mem;
typedef typename umat::elem_type umat_elem_type;
umat_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] >= B_mem[i]) if(A[i] >= B[i])
{ {
out_mem[i] = umat_elem_type(1); out_mem[i] = umat_eT(1);
} }
else else
{ {
out_mem[i] = umat_elem_type(0); out_mem[i] = umat_eT(0);
} }
} }
return out; return out;
} }
template<typename eT, typename T1, typename T2> template<typename T1, typename T2>
inline inline
umat umat
operator<= operator<=
(const Base<eT,T1>& X, const Base<eT,T2>& Y) (const Base<typename T1::elem_type,T1>& X, const Base<typename T1::elem_typ e,T2>& Y)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap<T1> tmp1(X.get_ref()); typedef typename umat::elem_type umat_eT;
const unwrap<T2> tmp2(Y.get_ref());
const Mat<eT>& A = tmp1.M; const Proxy<T1> A(X.get_ref());
const Mat<eT>& B = tmp2.M; const Proxy<T2> B(Y.get_ref());
arma_debug_assert_same_size(A, B, "operator<="); arma_debug_assert_same_size(A, B, "operator<=");
umat out(A.n_rows, A.n_cols); umat out(A.n_rows, A.n_cols);
const eT* A_mem = A.mem; umat_eT* out_mem = out.memptr();
const eT* B_mem = B.mem;
typedef typename umat::elem_type umat_elem_type;
umat_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] <= B_mem[i]) if(A[i] <= B[i])
{ {
out_mem[i] = umat_elem_type(1); out_mem[i] = umat_eT(1);
} }
else else
{ {
out_mem[i] = umat_elem_type(0); out_mem[i] = umat_eT(0);
} }
} }
return out; return out;
} }
template<typename eT, typename T1, typename T2> template<typename T1, typename T2>
inline inline
umat umat
operator> operator>
(const Base<eT,T1>& X, const Base<eT,T2>& Y) (const Base<typename T1::elem_type,T1>& X, const Base<typename T1::elem_typ e,T2>& Y)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap<T1> tmp1(X.get_ref()); typedef typename umat::elem_type umat_eT;
const unwrap<T2> tmp2(Y.get_ref());
const Mat<eT>& A = tmp1.M; const Proxy<T1> A(X.get_ref());
const Mat<eT>& B = tmp2.M; const Proxy<T2> B(Y.get_ref());
arma_debug_assert_same_size(A, B, "operator>"); arma_debug_assert_same_size(A, B, "operator>");
umat out(A.n_rows, A.n_cols); umat out(A.n_rows, A.n_cols);
const eT* A_mem = A.mem; umat_eT* out_mem = out.memptr();
const eT* B_mem = B.mem;
typedef typename umat::elem_type umat_elem_type;
umat_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] > B_mem[i]) if(A[i] > B[i])
{ {
out_mem[i] = umat_elem_type(1); out_mem[i] = umat_eT(1);
} }
else else
{ {
out_mem[i] = umat_elem_type(0); out_mem[i] = umat_eT(0);
} }
} }
return out; return out;
} }
template<typename eT, typename T1, typename T2> template<typename T1, typename T2>
inline inline
umat umat
operator< operator<
(const Base<eT,T1>& X, const Base<eT,T2>& Y) (const Base<typename T1::elem_type,T1>& X, const Base<typename T1::elem_typ e,T2>& Y)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap<T1> tmp1(X.get_ref()); typedef typename umat::elem_type umat_eT;
const unwrap<T2> tmp2(Y.get_ref());
const Mat<eT>& A = tmp1.M; const Proxy<T1> A(X.get_ref());
const Mat<eT>& B = tmp2.M; const Proxy<T2> B(Y.get_ref());
arma_debug_assert_same_size(A, B, "operator<"); arma_debug_assert_same_size(A, B, "operator<");
umat out(A.n_rows, A.n_cols); umat out(A.n_rows, A.n_cols);
const eT* A_mem = A.mem; umat_eT* out_mem = out.memptr();
const eT* B_mem = B.mem;
typedef typename umat::elem_type umat_elem_type;
umat_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] < B_mem[i]) if(A[i] < B[i])
{ {
out_mem[i] = umat_elem_type(1); out_mem[i] = umat_eT(1);
} }
else else
{ {
out_mem[i] = umat_elem_type(0); out_mem[i] = umat_eT(0);
} }
} }
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
umat umat
operator== operator==
(const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type val ) (const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type val )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename umat::elem_type umat_eT;
const unwrap<T1> tmp1(X.get_ref()); const Proxy<T1> A(X.get_ref());
const Mat<eT>& A = tmp1.M;
umat out(A.n_rows, A.n_cols); umat out(A.n_rows, A.n_cols);
const eT* A_mem = A.mem; umat_eT* out_mem = out.memptr();
typedef typename umat::elem_type umat_elem_type;
umat_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] == val) if(A[i] == val)
{ {
out_mem[i] = umat_elem_type(1); out_mem[i] = umat_eT(1);
} }
else else
{ {
out_mem[i] = umat_elem_type(0); out_mem[i] = umat_eT(0);
} }
} }
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
umat umat
operator!= operator!=
(const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type val ) (const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type val )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename umat::elem_type umat_eT;
const unwrap<T1> tmp1(X.get_ref()); const Proxy<T1> A(X.get_ref());
const Mat<eT>& A = tmp1.M;
umat out(A.n_rows, A.n_cols); umat out(A.n_rows, A.n_cols);
const eT* A_mem = A.mem; umat_eT* out_mem = out.memptr();
typedef typename umat::elem_type umat_elem_type;
umat_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] != val) if(A[i] != val)
{ {
out_mem[i] = umat_elem_type(1); out_mem[i] = umat_eT(1);
} }
else else
{ {
out_mem[i] = umat_elem_type(0); out_mem[i] = umat_eT(0);
} }
} }
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
umat umat
operator>= operator>=
(const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type val ) (const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type val )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename umat::elem_type umat_eT;
const unwrap<T1> tmp1(X.get_ref()); const Proxy<T1> A(X.get_ref());
const Mat<eT>& A = tmp1.M;
umat out(A.n_rows, A.n_cols); umat out(A.n_rows, A.n_cols);
const eT* A_mem = A.mem; umat_eT* out_mem = out.memptr();
typedef typename umat::elem_type umat_elem_type;
umat_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] >= val) if(A[i] >= val)
{ {
out_mem[i] = umat_elem_type(1); out_mem[i] = umat_eT(1);
} }
else else
{ {
out_mem[i] = umat_elem_type(0); out_mem[i] = umat_eT(0);
} }
} }
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
umat umat
operator<= operator<=
(const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type val ) (const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type val )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename umat::elem_type umat_eT;
const unwrap<T1> tmp1(X.get_ref()); const Proxy<T1> A(X.get_ref());
const Mat<eT>& A = tmp1.M;
umat out(A.n_rows, A.n_cols); umat out(A.n_rows, A.n_cols);
const eT* A_mem = A.mem; umat_eT* out_mem = out.memptr();
typedef typename umat::elem_type umat_elem_type;
umat_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] <= val) if(A[i] <= val)
{ {
out_mem[i] = umat_elem_type(1); out_mem[i] = umat_eT(1);
} }
else else
{ {
out_mem[i] = umat_elem_type(0); out_mem[i] = umat_eT(0);
} }
} }
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
umat umat
operator> operator>
(const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type val ) (const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type val )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename umat::elem_type umat_eT;
const unwrap<T1> tmp1(X.get_ref()); const Proxy<T1> A(X.get_ref());
const Mat<eT>& A = tmp1.M;
umat out(A.n_rows, A.n_cols); umat out(A.n_rows, A.n_cols);
const eT* A_mem = A.mem; umat_eT* out_mem = out.memptr();
typedef typename umat::elem_type umat_elem_type;
umat_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] > val) if(A[i] > val)
{ {
out_mem[i] = umat_elem_type(1); out_mem[i] = umat_eT(1);
} }
else else
{ {
out_mem[i] = umat_elem_type(0); out_mem[i] = umat_eT(0);
} }
} }
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
umat umat
operator< operator<
(const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type val ) (const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type val )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename umat::elem_type umat_eT;
const unwrap<T1> tmp1(X.get_ref()); const Proxy<T1> A(X.get_ref());
const Mat<eT>& A = tmp1.M;
umat out(A.n_rows, A.n_cols); umat out(A.n_rows, A.n_cols);
const eT* A_mem = A.mem; umat_eT* out_mem = out.memptr();
typedef typename umat::elem_type umat_elem_type;
umat_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(A_mem[i] < val) if(A[i] < val)
{ {
out_mem[i] = umat_elem_type(1); out_mem[i] = umat_eT(1);
} }
else else
{ {
out_mem[i] = umat_elem_type(0); out_mem[i] = umat_eT(0);
} }
} }
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
umat umat
operator== operator==
skipping to change at line 488 skipping to change at line 435
} }
template<typename T1> template<typename T1>
inline inline
umat umat
operator>= operator>=
(const typename T1::elem_type val, const Base<typename T1::elem_type,T1>& X ) (const typename T1::elem_type val, const Base<typename T1::elem_type,T1>& X )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename umat::elem_type umat_eT;
const unwrap<T1> tmp1(X.get_ref()); const Proxy<T1> A(X.get_ref());
const Mat<eT>& A = tmp1.M;
umat out(A.n_rows, A.n_cols); umat out(A.n_rows, A.n_cols);
const eT* A_mem = A.mem; umat_eT* out_mem = out.memptr();
typedef typename umat::elem_type umat_elem_type;
umat_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(val >= A_mem[i]) if(val >= A[i])
{ {
out_mem[i] = umat_elem_type(1); out_mem[i] = umat_eT(1);
} }
else else
{ {
out_mem[i] = umat_elem_type(0); out_mem[i] = umat_eT(0);
} }
} }
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
umat umat
operator<= operator<=
(const typename T1::elem_type val, const Base<typename T1::elem_type,T1>& X ) (const typename T1::elem_type val, const Base<typename T1::elem_type,T1>& X )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename umat::elem_type umat_eT;
const unwrap<T1> tmp1(X.get_ref()); const Proxy<T1> A(X.get_ref());
const Mat<eT>& A = tmp1.M;
umat out(A.n_rows, A.n_cols); umat out(A.n_rows, A.n_cols);
const eT* A_mem = A.mem; umat_eT* out_mem = out.memptr();
typedef typename umat::elem_type umat_elem_type;
umat_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(val <= A_mem[i]) if(val <= A[i])
{ {
out_mem[i] = umat_elem_type(1); out_mem[i] = umat_eT(1);
} }
else else
{ {
out_mem[i] = umat_elem_type(0); out_mem[i] = umat_eT(0);
} }
} }
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
umat umat
operator> operator>
(const typename T1::elem_type val, const Base<typename T1::elem_type,T1>& X ) (const typename T1::elem_type val, const Base<typename T1::elem_type,T1>& X )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename umat::elem_type umat_eT;
const unwrap<T1> tmp1(X.get_ref()); const Proxy<T1> A(X.get_ref());
const Mat<eT>& A = tmp1.M;
umat out(A.n_rows, A.n_cols); umat out(A.n_rows, A.n_cols);
const eT* A_mem = A.mem; umat_eT* out_mem = out.memptr();
typedef typename umat::elem_type umat_elem_type;
umat_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(val > A_mem[i]) if(val > A[i])
{ {
out_mem[i] = umat_elem_type(1); out_mem[i] = umat_eT(1);
} }
else else
{ {
out_mem[i] = umat_elem_type(0); out_mem[i] = umat_eT(0);
} }
} }
return out; return out;
} }
template<typename T1> template<typename T1>
inline inline
umat umat
operator< operator<
(const typename T1::elem_type val, const Base<typename T1::elem_type,T1>& X ) (const typename T1::elem_type val, const Base<typename T1::elem_type,T1>& X )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT; typedef typename umat::elem_type umat_eT;
const unwrap<T1> tmp1(X.get_ref()); const Proxy<T1> A(X.get_ref());
const Mat<eT>& A = tmp1.M;
umat out(A.n_rows, A.n_cols); umat out(A.n_rows, A.n_cols);
const eT* A_mem = A.mem; umat_eT* out_mem = out.memptr();
typedef typename umat::elem_type umat_elem_type;
umat_elem_type* out_mem = out.memptr();
for(u32 i=0; i<A.n_elem; ++i) for(u32 i=0; i<A.n_elem; ++i)
{ {
if(val < A_mem[i]) if(val < A[i])
{ {
out_mem[i] = umat_elem_type(1); out_mem[i] = umat_eT(1);
} }
else else
{ {
out_mem[i] = umat_elem_type(0); out_mem[i] = umat_eT(0);
} }
} }
return out; return out;
} }
//! @} //! @}
 End of changes. 109 change blocks. 
185 lines changed or deleted 116 lines changed or added


 operator_schur.hpp   operator_schur.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 operator_schur //! \addtogroup operator_schur
//! @{ //! @{
// operator %, which we define it to do a schur product (element-wise multi plication) // operator %, which we define it to do a schur product (element-wise multi plication)
//! Base % Base //! element-wise multiplication of Base objects with same element type
template<typename T1, typename T2> template<typename T1, typename T2>
arma_inline arma_inline
const Glue<T1, T2, glue_schur> const eGlue<T1, T2, eglue_schur>
operator% operator%
(const Base<typename T1::elem_type,T1>& X, const Base<typename T1::elem_typ (
e,T2>& Y) const Base<typename T1::elem_type,T1>& X,
const Base<typename T1::elem_type,T2>& Y
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Glue<T1, T2, glue_schur>(X.get_ref(), Y.get_ref()); return eGlue<T1, T2, eglue_schur>(X.get_ref(), Y.get_ref());
} }
//! Base % diagmat //! element-wise multiplication of Base objects with different element type s
template<typename T1, typename T2> template<typename T1, typename T2>
arma_inline arma_inline
const Glue<T1, Op<T2,op_diagmat>, glue_schur_diag> Mat<typename promote_type<typename T1::elem_type, typename T2::elem_type>:: result>
operator% operator%
(const Base<typename T2::elem_type,T1>& X, const Op<T2,op_diagmat>& Y) (
{ const Base< typename force_different_type<typename T1::elem_type, typenam
arma_extra_debug_sigprint(); e T2::elem_type>::T1_result, T1>& X,
const Base< typename force_different_type<typename T1::elem_type, typenam
return Glue<T1, Op<T2,op_diagmat>, glue_schur_diag>(X.get_ref(), Y); e T2::elem_type>::T2_result, T2>& Y
} )
//! diagmat % Base
template<typename T1, typename T2>
arma_inline
const Glue< Op<T1,op_diagmat>, T2, glue_schur_diag>
operator%
(const Op<T1,op_diagmat>& X, const Base<typename T1::elem_type,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue< Op<T1,op_diagmat>, T2, glue_schur_diag>(X, Y.get_ref());
}
//! diagmat % diagmat
template<typename T1, typename T2>
inline
Mat< typename promote_type<typename T1::elem_type, typename T2::elem_type>:
:result >
operator%
(const Op<T1, op_diagmat>& X, const Op<T2, op_diagmat>& Y)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT1; typedef typename T1::elem_type eT1;
typedef typename T2::elem_type eT2; typedef typename T2::elem_type eT2;
typedef typename promote_type<eT1,eT2>::result out_eT; typedef typename promote_type<eT1,eT2>::result out_eT;
promote_type<eT1,eT2>::check(); promote_type<eT1,eT2>::check();
const unwrap<T1> tmp1(X.m); const Proxy<T1> A(X.get_ref());
const unwrap<T2> tmp2(Y.m); const Proxy<T2> B(Y.get_ref());
const Mat<eT1> A(tmp1.M); arma_debug_assert_same_size(A, B, "element-wise matrix multiplication");
const Mat<eT2> B(tmp2.M);
arma_debug_assert_same_size(A.n_rows, A.n_cols, B.n_rows, B.n_cols, "elem ent-wise matrix multiplication"); Mat<out_eT> out(A.n_rows, A.n_cols);
Mat<out_eT> out(A.n_rows, A.n_rows); out_eT* out_mem = out.memptr();
out.zeros(); const u32 n_elem = out.n_elem;
for(u32 i=0; i<A.n_rows; ++i) for(u32 i=0; i<n_elem; ++i)
{ {
out.at(i,i) = upgrade_val<eT1,eT2>::apply( A.at(i,i) ) * upgrade_val<eT 1,eT2>::apply( B.at(i,i) ); out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) * upgrade_val<eT1,eT2>:: apply(B[i]);
} }
return out; return out;
} }
//
// schur product of Base objects with different element types
//
//! Base % Base
template<typename eT1, typename T1, typename eT2, typename T2>
arma_inline
Mat<typename promote_type<eT1,eT2>::result>
operator%
(const Base<eT1,T1>& X, const Base<eT2,T2>& Y)
{
arma_extra_debug_sigprint();
promote_type<eT1,eT2>::check();
const unwrap<T1> tmp1(X.get_ref());
const unwrap<T2> tmp2(Y.get_ref());
const Mat<eT1>& A = tmp1.M;
const Mat<eT2>& B = tmp2.M;
Mat< typename promote_type<eT1,eT2>::result > out;
glue_schur::apply_mixed(out, A, B);
return out;
}
//
// schur product of Base objects with same element types
//
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_schur>
operator%
(const Base<std::complex<double>,T1>& X, const Base<std::complex<double>,T2
>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_schur>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_schur>
operator%
(const Base<std::complex<float>,T1>& X, const Base<std::complex<float>,T2>&
Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_schur>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_schur>
operator%
(const Base<double,T1>& X, const Base<double,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_schur>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_schur>
operator%
(const Base<float,T1>& X, const Base<float,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_schur>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_schur>
operator%
(const Base<s32,T1>& X, const Base<s32,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_schur>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_schur>
operator%
(const Base<u32,T1>& X, const Base<u32,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_schur>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_schur>
operator%
(const Base<s16,T1>& X, const Base<s16,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_schur>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_schur>
operator%
(const Base<u16,T1>& X, const Base<u16,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_schur>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_schur>
operator%
(const Base<s8,T1>& X, const Base<s8,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_schur>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_schur>
operator%
(const Base<u8,T1>& X, const Base<u8,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_schur>(X.get_ref(), Y.get_ref());
}
//! @} //! @}
 End of changes. 15 change blocks. 
186 lines changed or deleted 25 lines changed or added


 operator_times.hpp   operator_times.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 operator_times //! \addtogroup operator_times
//! @{ //! @{
// "rowvec * colvec" and other combinations which result
// in a scalar are declared in "operator_times_dot.hpp"
//
// new operators
//! Base * scalar //! Base * scalar
template<typename T1> template<typename T1>
arma_inline arma_inline
const Op<T1, op_scalar_times> const eOp<T1, eop_scalar_times>
operator* operator*
(const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type k) (const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type k)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_scalar_times>(X.get_ref(),k); return eOp<T1, eop_scalar_times>(X.get_ref(),k);
}
//! op * scalar, level 2
template<typename T1>
arma_inline
const Op<T1,op_scalar_times>
operator*
(const Op<T1,op_scalar_times>& X, const typename T1::elem_type k)
{
arma_extra_debug_sigprint();
return Op<T1, op_scalar_times>(X.m, X.aux * k);
}
//! Op<mat,op_ones_full> * scalar
template<typename eT>
arma_inline
Mat<eT>
operator*
(const Op<Mat<eT>,op_ones_full>& X, const eT k)
{
arma_extra_debug_sigprint();
Mat<eT> tmp(X.aux_u32_a, X.aux_u32_b);
tmp.fill(k);
return tmp;
}
//! Op<mat,op_ones_diag> * scalar
template<typename eT>
arma_inline
Mat<eT>
operator*
(const Op<Mat<eT>,op_ones_diag>& X, const eT k)
{
arma_extra_debug_sigprint();
Mat<eT> out;
out.zeros(X.aux_u32_a, X.aux_u32_b);
for(u32 i=0; i<out.n_rows; ++i)
{
out.at(i,i) = k;
}
return out;
} }
//! scalar * Base //! scalar * Base
template<typename T1> template<typename T1>
arma_inline arma_inline
const Op<T1, op_scalar_times> const eOp<T1, eop_scalar_times>
operator* operator*
(const typename T1::elem_type k, const Base<typename T1::elem_type,T1>& X) (const typename T1::elem_type k, const Base<typename T1::elem_type,T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Op<T1, op_scalar_times>(X.get_ref(),k); // NOTE: order is swapped return eOp<T1, eop_scalar_times>(X.get_ref(),k); // NOTE: order is swapp ed
} }
//! scalar * Op<mat,op_ones_full> //! scalar * trans(T1)
template<typename eT> template<typename T1>
arma_inline arma_inline
Mat<eT> const Op<T1, op_trans2>
operator* operator*
(const eT k, const Op<Mat<eT>,op_ones_full>& X) (const typename T1::elem_type k, const Op<T1, op_trans>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
Mat<eT> tmp(X.aux_u32_a, X.aux_u32_b); return Op<T1, op_trans2>(X.m, k);
tmp.fill(k);
return tmp;
} }
//! scalar * Op<mat,op_ones_diag> //! trans(T1) * scalar
template<typename eT> template<typename T1>
arma_inline arma_inline
Mat<eT> const Op<T1, op_trans2>
operator* operator*
(const eT k, const Op<Mat<eT>,op_ones_diag>& X) (const Op<T1, op_trans>& X, const typename T1::elem_type k)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
Mat<eT> out; return Op<T1, op_trans2>(X.m, k);
out.zeros(X.aux_u32_a, X.aux_u32_b);
for(u32 i=0; i<out.n_rows; ++i)
out.at(i,i) = k;
return out;
} }
//! Base * diagmat //! Base * diagmat
template<typename T1, typename T2> template<typename T1, typename T2>
arma_inline arma_inline
const Glue<T1, Op<T2,op_diagmat>, glue_times_diag> const Glue<T1, Op<T2, op_diagmat>, glue_times_diag>
operator* operator*
(const Base<typename T2::elem_type, T1>& X, const Op<T2,op_diagmat>& Y) (const Base<typename T2::elem_type,T1>& X, const Op<T2, op_diagmat>& Y)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Glue<T1, Op<T2,op_diagmat>, glue_times_diag>(X.get_ref(), Y); return Glue<T1, Op<T2, op_diagmat>, glue_times_diag>(X.get_ref(), Y);
} }
//! diagmat * Base //! diagmat * Base
template<typename T1, typename T2> template<typename T1, typename T2>
arma_inline arma_inline
const Glue<Op<T1,op_diagmat>, T2, glue_times_diag> const Glue<Op<T1, op_diagmat>, T2, glue_times_diag>
operator* operator*
(const Op<T1,op_diagmat>& X, const Base<typename T1::elem_type, T2>& Y) (const Op<T1, op_diagmat>& X, const Base<typename T1::elem_type,T2>& Y)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Glue<Op<T1,op_diagmat>, T2, glue_times_diag>(X, Y.get_ref()); return Glue<Op<T1, op_diagmat>, T2, glue_times_diag>(X, Y.get_ref());
} }
//! diagmat * diagmat //! diagmat * diagmat
template<typename T1, typename T2> template<typename T1, typename T2>
inline arma_inline
Mat< typename promote_type<typename T1::elem_type, typename T2::elem_type>: :result > Mat< typename promote_type<typename T1::elem_type, typename T2::elem_type>: :result >
operator* operator*
(const Op<T1, op_diagmat>& X, const Op<T2, op_diagmat>& Y) (const Op<T1, op_diagmat>& X, const Op<T2, op_diagmat>& Y)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
typedef typename T1::elem_type eT1; typedef typename T1::elem_type eT1;
typedef typename T2::elem_type eT2; typedef typename T2::elem_type eT2;
typedef typename promote_type<eT1,eT2>::result out_eT; typedef typename promote_type<eT1,eT2>::result out_eT;
promote_type<eT1,eT2>::check(); promote_type<eT1,eT2>::check();
const unwrap<T1> tmp1(X.m); const diagmat_proxy<T1> A(X.m);
const unwrap<T2> tmp2(Y.m); const diagmat_proxy<T2> B(Y.m);
const Mat<eT1> A(tmp1.M); arma_debug_assert_mul_size(A.n_elem, A.n_elem, B.n_elem, B.n_elem, "matri
const Mat<eT2> B(tmp2.M); x multiply");
arma_debug_assert_same_size(A.n_rows, A.n_cols, B.n_rows, B.n_cols, "matr const u32 N = A.n_elem;
ix multiplication");
Mat<out_eT> out(N,N);
Mat<out_eT> out(A.n_rows, A.n_rows);
out.zeros(); out.zeros();
for(u32 i=0; i<A.n_rows; ++i) for(u32 i=0; i<N; ++i)
{ {
out.at(i,i) = upgrade_val<eT1,eT2>::apply( A.at(i,i) ) * upgrade_val<eT 1,eT2>::apply( B.at(i,i) ); out.at(i,i) = upgrade_val<eT1,eT2>::apply( A[i] ) * upgrade_val<eT1,eT2 >::apply( B[i] );
} }
return out; return out;
} }
//! colvec * rowvec //! multiplication of Base objects with same element type
template<typename eT> template<typename T1, typename T2>
arma_inline
const Glue<Col<eT>, Row<eT>, glue_times_vec>
operator*
(const Col<eT>& X, const Row<eT>& Y)
{
arma_extra_debug_sigprint();
return Glue<Col<eT>, Row<eT>, glue_times_vec>(X, Y);
}
//! Base * colvec
template<typename T1>
arma_inline
const Glue<T1, Col<typename T1::elem_type>, glue_times_vec>
operator*
(const Base<typename T1::elem_type,T1>& X, const Col<typename T1::elem_type
>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, Col<typename T1::elem_type>, glue_times_vec>(X.get_ref(),
Y);
}
//! Base * rowvec
template<typename T1>
arma_inline
const Glue<T1, Row<typename T1::elem_type>, glue_times_vec>
operator*
(const Base<typename T1::elem_type,T1>& X, const Row<typename T1::elem_type
>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, Row<typename T1::elem_type>, glue_times_vec>(X.get_ref(),
Y);
}
//! colvec * Base
template<typename T1>
arma_inline
const Glue<Col<typename T1::elem_type>, T1, glue_times_vec>
operator*
(const Col<typename T1::elem_type>& X, const Base<typename T1::elem_type,T1
>& Y)
{
arma_extra_debug_sigprint();
return Glue<Col<typename T1::elem_type>, T1, glue_times_vec>(X, Y.get_ref
());
}
//! rowvec * Base
template<typename T1>
arma_inline
const Glue<Row<typename T1::elem_type>, T1, glue_times_vec>
operator*
(const Row<typename T1::elem_type>& X, const Base<typename T1::elem_type,T1
>& Y)
{
arma_extra_debug_sigprint();
return Glue<Row<typename T1::elem_type>, T1, glue_times_vec>(X, Y.get_ref
());
}
//! diagmat * colvec
template<typename T1>
arma_inline
const Glue<Op<T1, op_diagmat>, Col<typename T1::elem_type>, glue_times_diag
>
operator*
(const Op<T1, op_diagmat>& X, const Col<typename T1::elem_type>& Y)
{
arma_extra_debug_sigprint();
return Glue<Op<T1, op_diagmat>, Col<typename T1::elem_type>, glue_times_d
iag>(X, Y);
}
//! diagmat * rowvec
template<typename T1>
arma_inline
const Glue<Op<T1, op_diagmat>, Row<typename T1::elem_type>, glue_times_diag
>
operator*
(const Op<T1, op_diagmat>& X, const Row<typename T1::elem_type>& Y)
{
arma_extra_debug_sigprint();
return Glue<Op<T1, op_diagmat>, Row<typename T1::elem_type>, glue_times_d
iag>(X, Y);
}
//! colvec * diagmat
template<typename T1>
arma_inline arma_inline
const Glue<Col<typename T1::elem_type>, Op<T1, op_diagmat>, glue_times_diag > const Glue<T1, T2, glue_times>
operator* operator*
(const Col<typename T1::elem_type>& X, const Op<T1, op_diagmat>& Y) (const Base<typename T1::elem_type,T1>& X, const Base<typename T1::elem_typ e,T2>& Y)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Glue<Col<typename T1::elem_type>, Op<T1, op_diagmat>, glue_times_d iag>(X, Y); return Glue<T1, T2, glue_times>(X.get_ref(), Y.get_ref());
} }
//! rowvec * diagmat //! multiplication of Base objects with different element types
template<typename T1> template<typename T1, typename T2>
arma_inline arma_inline
const Glue<Row<typename T1::elem_type>, Op<T1, op_diagmat>, glue_times_diag > Mat<typename promote_type<typename T1::elem_type, typename T2::elem_type>:: result>
operator* operator*
(const Row<typename T1::elem_type>& X, const Op<T1, op_diagmat>& Y) (
const Base< typename force_different_type<typename T1::elem_type, typenam
e T2::elem_type>::T1_result, T1>& X,
const Base< typename force_different_type<typename T1::elem_type, typenam
e T2::elem_type>::T2_result, T2>& Y
)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return Glue<Row<typename T1::elem_type>, Op<T1, op_diagmat>, glue_times_d typedef typename T1::elem_type eT1;
iag>(X, Y); typedef typename T2::elem_type eT2;
}
//
// multiplication of Base objects with different element types
//
//! Base * Base typedef typename promote_type<eT1,eT2>::result out_eT;
template<typename eT1, typename T1, typename eT2, typename T2>
arma_inline
Mat<typename promote_type<eT1,eT2>::result>
operator*
(const Base<eT1,T1>& X, const Base<eT2,T2>& Y)
{
arma_extra_debug_sigprint();
promote_type<eT1,eT2>::check(); promote_type<eT1,eT2>::check();
const unwrap<T1> tmp1(X.get_ref()); const unwrap<T1> tmp1(X.get_ref());
const unwrap<T2> tmp2(Y.get_ref()); const unwrap<T2> tmp2(Y.get_ref());
const Mat< eT1 >& A = tmp1.M; const Mat<eT1>& A = tmp1.M;
const Mat< eT2 >& B = tmp2.M; const Mat<eT2>& B = tmp2.M;
Mat< typename promote_type<eT1,eT2>::result > out; Mat<out_eT> out;
glue_times::apply_mixed(out, A, B); glue_times::apply_mixed(out, A, B);
return out; return out;
} }
//
// multiplication of Base objects with same element types
//
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_times>
operator*
(const Base<std::complex<double>,T1>& X, const Base<std::complex<double>,T2
>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_times>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_times>
operator*
(const Base<std::complex<float>,T1>& X, const Base<std::complex<float>,T2>&
Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_times>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_times>
operator*
(const Base<double,T1>& X, const Base<double,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_times>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_times>
operator*
(const Base<float,T1>& X, const Base<float,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_times>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_times>
operator*
(const Base<s32,T1>& X, const Base<s32,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_times>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_times>
operator*
(const Base<u32,T1>& X, const Base<u32,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_times>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_times>
operator*
(const Base<s16,T1>& X, const Base<s16,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_times>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_times>
operator*
(const Base<u16,T1>& X, const Base<u16,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_times>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_times>
operator*
(const Base<s8,T1>& X, const Base<s8,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_times>(X.get_ref(), Y.get_ref());
}
template<typename T1, typename T2>
arma_inline
const Glue<T1, T2, glue_times>
operator*
(const Base<u8,T1>& X, const Base<u8,T2>& Y)
{
arma_extra_debug_sigprint();
return Glue<T1, T2, glue_times>(X.get_ref(), Y.get_ref());
}
//! @} //! @}
 End of changes. 39 change blocks. 
332 lines changed or deleted 52 lines changed or added


 podarray_meat.hpp   podarray_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 podarray //! \addtogroup podarray
//! @{ //! @{
template<typename T1> template<typename eT>
inline inline
podarray<T1>::~podarray() podarray<eT>::~podarray()
{ {
arma_extra_debug_sigprint_this(this); arma_extra_debug_sigprint_this(this);
if(n_elem > sizeof(mem_local)/sizeof(T1) ) if(n_elem > sizeof(mem_local)/sizeof(eT) )
{ {
delete [] mem; delete [] mem;
} }
if(arma_config::debug == true) if(arma_config::debug == true)
{ {
access::rw(mem) = 0; access::rw(n_elem) = 0;
access::rw(mem) = 0;
} }
} }
template<typename T1> template<typename eT>
inline inline
podarray<T1>::podarray() podarray<eT>::podarray()
: n_elem(0) : n_elem(0)
, mem(0) , mem (0)
{ {
arma_extra_debug_sigprint_this(this); arma_extra_debug_sigprint_this(this);
} }
template<typename T1> template<typename eT>
inline inline
podarray<T1>::podarray(const podarray& x) podarray<eT>::podarray(const podarray& x)
: n_elem(0) : n_elem(0)
, mem(0) , mem (0)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
this->operator=(x); this->operator=(x);
} }
template<typename T1> template<typename eT>
inline inline
const podarray<T1>& const podarray<eT>&
podarray<T1>::operator=(const podarray& x) podarray<eT>::operator=(const podarray& x)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
if(this != &x) if(this != &x)
{ {
init(x.n_elem); init(x.n_elem);
for(u32 i=0; i<n_elem; ++i) for(u32 i=0; i<n_elem; ++i)
{ {
access::rw(mem[i]) = x.mem[i]; access::rw(mem[i]) = x.mem[i];
} }
} }
return *this; return *this;
} }
template<typename T1> template<typename eT>
arma_inline arma_inline
podarray<T1>::podarray(const u32 new_n_elem) podarray<eT>::podarray(const u32 new_n_elem)
: n_elem(0) : n_elem(0)
, mem(0) , mem (0)
{ {
arma_extra_debug_sigprint_this(this); arma_extra_debug_sigprint_this(this);
init(new_n_elem); init(new_n_elem);
} }
template<typename T1> template<typename eT>
arma_inline arma_inline
T1 podarray<eT>::podarray(const eT* X, const u32 new_n_elem)
podarray<T1>::operator[] (const u32 i) const : n_elem(0)
, mem (0)
{
arma_extra_debug_sigprint_this(this);
init(new_n_elem);
for(u32 i=0; i<n_elem; ++i)
{
access::rw(mem[i]) = X[i];
}
}
template<typename eT>
arma_inline
eT
podarray<eT>::operator[] (const u32 i) const
{ {
return mem[i]; return mem[i];
} }
template<typename T1> template<typename eT>
arma_inline arma_inline
T1& eT&
podarray<T1>::operator[] (const u32 i) podarray<eT>::operator[] (const u32 i)
{ {
return access::rw(mem[i]); return access::rw(mem[i]);
} }
template<typename T1> template<typename eT>
arma_inline arma_inline
T1 eT
podarray<T1>::operator() (const u32 i) const podarray<eT>::operator() (const u32 i) const
{ {
arma_debug_check( (i >= n_elem), "podarray::operator(): index out of boun ds"); arma_debug_check( (i >= n_elem), "podarray::operator(): index out of boun ds");
return mem[i]; return mem[i];
} }
template<typename T1> template<typename eT>
arma_inline arma_inline
T1& eT&
podarray<T1>::operator() (const u32 i) podarray<eT>::operator() (const u32 i)
{ {
arma_debug_check( (i >= n_elem), "podarray::operator(): index out of boun ds"); arma_debug_check( (i >= n_elem), "podarray::operator(): index out of boun ds");
return access::rw(mem[i]); return access::rw(mem[i]);
} }
template<typename T1> template<typename eT>
inline inline
void void
podarray<T1>::set_size(const u32 new_n_elem) podarray<eT>::set_size(const u32 new_n_elem)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
init(new_n_elem); init(new_n_elem);
} }
template<typename T1> template<typename eT>
inline inline
void void
podarray<T1>::fill(const T1 val) podarray<eT>::fill(const eT val)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
for(u32 i=0; i<n_elem; ++i) for(u32 i=0; i<n_elem; ++i)
{ {
access::rw(mem[i]) = val; access::rw(mem[i]) = val;
} }
} }
template<typename T1> template<typename eT>
inline inline
void void
podarray<T1>::zeros() podarray<eT>::zeros()
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
fill(0); fill(eT(0));
} }
template<typename T1> template<typename eT>
inline inline
void void
podarray<T1>::zeros(const u32 new_n_elem) podarray<eT>::zeros(const u32 new_n_elem)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
init(new_n_elem); init(new_n_elem);
fill(0); fill(0);
} }
template<typename T1> template<typename eT>
arma_inline arma_inline
T1* eT*
podarray<T1>::memptr() podarray<eT>::memptr()
{ {
return const_cast<T1*>(mem); return const_cast<eT*>(mem);
} }
template<typename T1> template<typename eT>
arma_inline arma_inline
const T1* const eT*
podarray<T1>::memptr() const podarray<eT>::memptr() const
{ {
return mem; return mem;
} }
template<typename T1> template<typename eT>
inline inline
void void
podarray<T1>::init(const u32 new_n_elem) podarray<eT>::init(const u32 new_n_elem)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
if(n_elem == new_n_elem) if(n_elem == new_n_elem)
{ {
return; return;
} }
if(n_elem > sizeof(mem_local)/sizeof(T1) ) if(n_elem > sizeof(mem_local)/sizeof(eT) )
{ {
delete [] mem; delete [] mem;
} }
if(new_n_elem <= sizeof(mem_local)/sizeof(T1) ) if(new_n_elem <= sizeof(mem_local)/sizeof(eT) )
{ {
access::rw(mem) = mem_local; access::rw(mem) = mem_local;
} }
else else
{ {
access::rw(mem) = new T1[new_n_elem]; access::rw(mem) = new eT[new_n_elem];
} }
access::rw(n_elem) = new_n_elem; access::rw(n_elem) = new_n_elem;
} }
//! @} //! @}
 End of changes. 44 change blocks. 
51 lines changed or deleted 68 lines changed or added


 podarray_proto.hpp   podarray_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 podarray //! \addtogroup podarray
//! @{ //! @{
//! A lightweight array for POD types. If the amount of memory requested is small, the stack is used. //! A lightweight array for POD types. If the amount of memory requested is small, the stack is used.
template<typename T1> template<typename eT>
class podarray class podarray
{ {
public: public:
//! number of elements held arma_aligned const u32 n_elem; //!< number of elements held
const u32 n_elem; arma_aligned const eT* const mem; //!< pointer to memory used by the o
bject
//! pointer to memory used by the object
arma_aligned const T1* const mem;
protected: protected:
//! Internal memory, to avoid calling the 'new' operator for small amount s of memory. //! Internal memory, to avoid calling the 'new' operator for small amount s of memory.
arma_aligned T1 mem_local[ 16 ]; arma_aligned eT mem_local[ 16 ];
public: public:
inline ~podarray(); inline ~podarray();
inline podarray(); inline podarray();
inline podarray (const podarray& x); inline podarray (const podarray& x);
inline const podarray& operator=(const podarray& x); inline const podarray& operator=(const podarray& x);
arma_inline explicit podarray(const u32 new_N); arma_inline explicit podarray(const u32 new_N);
arma_inline T1& operator[] (const u32 i); arma_inline explicit podarray(const eT* X, const u32 new_N);
arma_inline T1 operator[] (const u32 i) const;
arma_inline eT& operator[] (const u32 i);
arma_inline eT operator[] (const u32 i) const;
arma_inline T1& operator() (const u32 i); arma_inline eT& operator() (const u32 i);
arma_inline T1 operator() (const u32 i) const; arma_inline eT operator() (const u32 i) const;
inline void set_size(const u32 new_n_elem); inline void set_size(const u32 new_n_elem);
inline void fill(const T1 val);
inline void fill(const eT val);
inline void zeros(); inline void zeros();
inline void zeros(const u32 new_n_elem); inline void zeros(const u32 new_n_elem);
arma_inline T1* memptr(); arma_inline eT* memptr();
arma_inline const T1* memptr() const; arma_inline const eT* memptr() const;
protected: protected:
inline void init(const u32 new_n_elem); inline void init(const u32 new_n_elem);
}; };
//! @} //! @}
 End of changes. 8 change blocks. 
15 lines changed or deleted 17 lines changed or added


 running_stat_meat.hpp   running_stat_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 running_stat_proto.hpp   running_stat_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 49 skipping to change at line 50
//! Class for keeping statistics of a continuously sampled process / signal . //! Class for keeping statistics of a continuously sampled process / signal .
//! Useful if the storage of individual samples is not necessary or desired . //! Useful if the storage of individual samples is not necessary or desired .
//! Also useful if the number of samples is not known beforehand or exceeds //! Also useful if the number of samples is not known beforehand or exceeds
//! available memory. //! available memory.
template<typename eT> template<typename eT>
class running_stat class running_stat
{ {
public: public:
typedef typename get_pod_type<eT>::pod_type T; typedef typename get_pod_type<eT>::result T;
inline ~running_stat(); inline ~running_stat();
inline running_stat(); inline running_stat();
inline void operator() (const T sample); inline void operator() (const T sample);
inline void operator() (const std::complex<T>& sample); inline void operator() (const std::complex<T>& sample);
inline void reset(); inline void reset();
inline eT mean() const; inline eT mean() const;
 End of changes. 2 change blocks. 
2 lines changed or deleted 3 lines changed or added


 running_stat_vec_meat.hpp   running_stat_vec_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 36 skipping to change at line 37
: calc_cov(in_calc_cov) : calc_cov(in_calc_cov)
{ {
arma_extra_debug_sigprint_this(this); arma_extra_debug_sigprint_this(this);
} }
//! update statistics to reflect new sample //! update statistics to reflect new sample
template<typename eT> template<typename eT>
template<typename T1> template<typename T1>
inline inline
void void
running_stat_vec<eT>::operator() (const Base<typename get_pod_type<eT>::pod _type, T1>& X) running_stat_vec<eT>::operator() (const Base<typename get_pod_type<eT>::res ult, T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
//typedef typename get_pod_type<eT>::pod_type T; //typedef typename get_pod_type<eT>::result T;
const unwrap<T1> tmp(X.get_ref()); const unwrap<T1> tmp(X.get_ref());
const Mat<eT>& sample = tmp.M; const Mat<eT>& sample = tmp.M;
arma_check( (sample.is_finite() == false), "running_stat_vec: given sampl e has non-finite elements" ); arma_check( (sample.is_finite() == false), "running_stat_vec: given sampl e has non-finite elements" );
running_stat_vec_aux::update_stats(*this, sample); running_stat_vec_aux::update_stats(*this, sample);
} }
//! update statistics to reflect new sample (version for complex numbers) //! update statistics to reflect new sample (version for complex numbers)
template<typename eT> template<typename eT>
template<typename T1> template<typename T1>
inline inline
void void
running_stat_vec<eT>::operator() (const Base<std::complex<typename get_pod_ type<eT>::pod_type>, T1>& X) running_stat_vec<eT>::operator() (const Base<std::complex<typename get_pod_ type<eT>::result>, T1>& X)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
//typedef typename std::complex<typename get_pod_type<eT>::pod_type> eT; //typedef typename std::complex<typename get_pod_type<eT>::result> eT;
const unwrap<T1> tmp(X.get_ref()); const unwrap<T1> tmp(X.get_ref());
const Mat<eT>& sample = tmp.M; const Mat<eT>& sample = tmp.M;
arma_check( (sample.is_finite() == false), "running_stat_vec: given sampl e has non-finite elements" ); arma_check( (sample.is_finite() == false), "running_stat_vec: given sampl e has non-finite elements" );
running_stat_vec_aux::update_stats(*this, sample); running_stat_vec_aux::update_stats(*this, sample);
} }
//! set all statistics to zero //! set all statistics to zero
skipping to change at line 105 skipping to change at line 106
const const
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return r_mean; return r_mean;
} }
//! variance //! variance
template<typename eT> template<typename eT>
inline inline
Mat<typename get_pod_type<eT>::pod_type> Mat<typename get_pod_type<eT>::result>
running_stat_vec<eT>::var(const u32 norm_type) running_stat_vec<eT>::var(const u32 norm_type)
const const
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const T N = counter.value(); const T N = counter.value();
if(N > T(1)) if(N > T(1))
{ {
if(norm_type == 0) if(norm_type == 0)
skipping to change at line 127 skipping to change at line 128
return r_var; return r_var;
} }
else else
{ {
const T N_minus_1 = counter.value_minus_1(); const T N_minus_1 = counter.value_minus_1();
return (N_minus_1/N) * r_var; return (N_minus_1/N) * r_var;
} }
} }
else else
{ {
return zeros< Mat<typename get_pod_type<eT>::pod_type> >(r_mean.n_rows, r_mean.n_cols); return zeros< Mat<typename get_pod_type<eT>::result> >(r_mean.n_rows, r _mean.n_cols);
} }
} }
//! standard deviation //! standard deviation
template<typename eT> template<typename eT>
inline inline
Mat<typename get_pod_type<eT>::pod_type> Mat<typename get_pod_type<eT>::result>
running_stat_vec<eT>::stddev(const u32 norm_type) running_stat_vec<eT>::stddev(const u32 norm_type)
const const
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
return sqrt( (*this).var(norm_type) ); return sqrt( (*this).var(norm_type) );
} }
//! covariance //! covariance
template<typename eT> template<typename eT>
 End of changes. 8 change blocks. 
8 lines changed or deleted 9 lines changed or added


 running_stat_vec_proto.hpp   running_stat_vec_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 27 skipping to change at line 28
//! Class for keeping statistics of a continuously sampled process / signal . //! Class for keeping statistics of a continuously sampled process / signal .
//! Useful if the storage of individual samples is not necessary or desired . //! Useful if the storage of individual samples is not necessary or desired .
//! Also useful if the number of samples is not known beforehand or exceeds //! Also useful if the number of samples is not known beforehand or exceeds
//! available memory. //! available memory.
template<typename eT> template<typename eT>
class running_stat_vec class running_stat_vec
{ {
public: public:
typedef typename get_pod_type<eT>::pod_type T; typedef typename get_pod_type<eT>::result T;
inline ~running_stat_vec(); inline ~running_stat_vec();
inline running_stat_vec(const bool in_calc_cov = false); inline running_stat_vec(const bool in_calc_cov = false);
template<typename T1> inline void operator() (const Base< T , T1>& X); template<typename T1> inline void operator() (const Base< T , T1>& X);
template<typename T1> inline void operator() (const Base< std::complex<T> , T1>& X); template<typename T1> inline void operator() (const Base< std::complex<T> , T1>& X);
inline void reset(); inline void reset();
inline Mat<eT> mean() const; inline Mat<eT> mean() const;
 End of changes. 2 change blocks. 
2 lines changed or deleted 3 lines changed or added


 static_assert.hpp   static_assert.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 static_assert //! \addtogroup static_assert
//! @{ //! @{
//! Classes for primitive compile time assertions (until C++0x) //! Classes for primitive compile time assertions (until the next version o
template<bool> f C++)
struct arma_static_assert; template<bool> struct arma_static_assert;
template<> struct arma_static_assert<true> {};
template<>
struct arma_static_assert<true>
{
};
template<bool val> template<bool val>
struct arma_type_check struct arma_type_check
{ {
arma_inline static void apply() arma_inline static void apply()
{ {
arma_static_assert<!val> ERROR___INCORRECT_TYPE; arma_static_assert<!val> ERROR___INCORRECT_TYPE;
ERROR___INCORRECT_TYPE = ERROR___INCORRECT_TYPE; ERROR___INCORRECT_TYPE = ERROR___INCORRECT_TYPE;
} }
}; };
//
//
//
template<bool, class arma_class>
struct arma_apply_proxy;
template<class arma_class>
struct arma_apply_proxy<false, arma_class>
{
public:
//template<typename T1> inline static void apply(const T1&);
template<typename Tout, typename T1, typename T2>
inline static void apply(Tout& out, const T1& A, const T2& B)
{
arma_static_assert<false> ERROR___INCORRECT_TYPE;
ERROR___INCORRECT_TYPE = ERROR___INCORRECT_TYPE;
}
};
template<class arma_class>
struct arma_apply_proxy<true, arma_class>
{
template<typename Tout, typename T1, typename T2>
inline static void apply(Tout& out, const T1& A, const T2& B)
{
arma_class::apply(out, A,B);
}
};
//! @} //! @}
 End of changes. 3 change blocks. 
42 lines changed or deleted 6 lines changed or added


 subview_cube_meat.hpp   subview_cube_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 338 skipping to change at line 339
inline inline
void void
subview_cube<eT>::operator= (const subview_cube<eT>& x_in) subview_cube<eT>::operator= (const subview_cube<eT>& x_in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const bool overlap = check_overlap(x_in); const bool overlap = check_overlap(x_in);
Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m) : 0; Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m) : 0;
const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT> (*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x _in.aux_col2, x_in.aux_slice2) : 0; const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT> (*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x _in.aux_col2, x_in.aux_slice2) : 0;
const subview_cube<eT>& x = overlap ? (*tmp_subview_cube) : x_in; const subview_cube<eT>& x = overlap ? (*tmp_subview_cube) : x_in;
subview_cube<eT>& t = *this; subview_cube<eT>& t = *this;
arma_debug_assert_same_size(t, x, "copy into subcube"); arma_debug_assert_same_size(t, x, "copy into subcube");
for(u32 slice = 0; slice < t.n_slices; ++slice) for(u32 slice = 0; slice < t.n_slices; ++slice)
{ {
for(u32 col = 0; col < t.n_cols; ++col) for(u32 col = 0; col < t.n_cols; ++col)
{ {
eT* t_coldata = t.slice_colptr(slice,col); eT* t_coldata = t.slice_colptr(slice,col);
skipping to change at line 377 skipping to change at line 378
inline inline
void void
subview_cube<eT>::operator+= (const subview_cube<eT>& x_in) subview_cube<eT>::operator+= (const subview_cube<eT>& x_in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const bool overlap = check_overlap(x_in); const bool overlap = check_overlap(x_in);
Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m) : 0; Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m) : 0;
const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT> (*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x _in.aux_col2, x_in.aux_slice2) : 0; const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT> (*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x _in.aux_col2, x_in.aux_slice2) : 0;
const subview_cube<eT>& x = overlap ? (*tmp_subview_cube) : x_in; const subview_cube<eT>& x = overlap ? (*tmp_subview_cube) : x_in;
subview_cube<eT>& t = *this; subview_cube<eT>& t = *this;
arma_debug_assert_same_size(t, x, "cube addition"); arma_debug_assert_same_size(t, x, "cube addition");
for(u32 slice = 0; slice < t.n_slices; ++slice) for(u32 slice = 0; slice < t.n_slices; ++slice)
{ {
for(u32 col = 0; col < t.n_cols; ++col) for(u32 col = 0; col < t.n_cols; ++col)
{ {
eT* t_coldata = t.slice_colptr(slice,col); eT* t_coldata = t.slice_colptr(slice,col);
skipping to change at line 416 skipping to change at line 417
inline inline
void void
subview_cube<eT>::operator-= (const subview_cube<eT>& x_in) subview_cube<eT>::operator-= (const subview_cube<eT>& x_in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const bool overlap = check_overlap(x_in); const bool overlap = check_overlap(x_in);
Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m) : 0; Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m) : 0;
const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT> (*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x _in.aux_col2, x_in.aux_slice2) : 0; const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT> (*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x _in.aux_col2, x_in.aux_slice2) : 0;
const subview_cube<eT>& x = overlap ? (*tmp_subview_cube) : x_in; const subview_cube<eT>& x = overlap ? (*tmp_subview_cube) : x_in;
subview_cube<eT>& t = *this; subview_cube<eT>& t = *this;
arma_debug_assert_same_size(t, x, "cube subtraction"); arma_debug_assert_same_size(t, x, "cube subtraction");
for(u32 slice = 0; slice < t.n_slices; ++slice) for(u32 slice = 0; slice < t.n_slices; ++slice)
{ {
for(u32 col = 0; col < t.n_cols; ++col) for(u32 col = 0; col < t.n_cols; ++col)
{ {
eT* t_coldata = t.slice_colptr(slice,col); eT* t_coldata = t.slice_colptr(slice,col);
skipping to change at line 455 skipping to change at line 456
inline inline
void void
subview_cube<eT>::operator%= (const subview_cube<eT>& x_in) subview_cube<eT>::operator%= (const subview_cube<eT>& x_in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const bool overlap = check_overlap(x_in); const bool overlap = check_overlap(x_in);
Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m) : 0; Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m) : 0;
const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT> (*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x _in.aux_col2, x_in.aux_slice2) : 0; const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT> (*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x _in.aux_col2, x_in.aux_slice2) : 0;
const subview_cube<eT>& x = overlap ? (*tmp_subview_cube) : x_in; const subview_cube<eT>& x = overlap ? (*tmp_subview_cube) : x_in;
subview_cube<eT>& t = *this; subview_cube<eT>& t = *this;
arma_debug_assert_same_size(t, x, "element-wise cube multiplication"); arma_debug_assert_same_size(t, x, "element-wise cube multiplication");
for(u32 slice = 0; slice < t.n_slices; ++slice) for(u32 slice = 0; slice < t.n_slices; ++slice)
{ {
for(u32 col = 0; col < t.n_cols; ++col) for(u32 col = 0; col < t.n_cols; ++col)
{ {
eT* t_coldata = t.slice_colptr(slice,col); eT* t_coldata = t.slice_colptr(slice,col);
skipping to change at line 494 skipping to change at line 495
inline inline
void void
subview_cube<eT>::operator/= (const subview_cube<eT>& x_in) subview_cube<eT>::operator/= (const subview_cube<eT>& x_in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const bool overlap = check_overlap(x_in); const bool overlap = check_overlap(x_in);
Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m) : 0; Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m) : 0;
const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT> (*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x _in.aux_col2, x_in.aux_slice2) : 0; const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT> (*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.aux_row2, x _in.aux_col2, x_in.aux_slice2) : 0;
const subview_cube<eT>& x = overlap ? (*tmp_subview_cube) : x_in; const subview_cube<eT>& x = overlap ? (*tmp_subview_cube) : x_in;
subview_cube<eT>& t = *this; subview_cube<eT>& t = *this;
arma_debug_assert_same_size(t, x, "element-wise cube division"); arma_debug_assert_same_size(t, x, "element-wise cube division");
for(u32 slice = 0; slice < t.n_slices; ++slice) for(u32 slice = 0; slice < t.n_slices; ++slice)
{ {
for(u32 col = 0; col < t.n_cols; ++col) for(u32 col = 0; col < t.n_cols; ++col)
{ {
eT* t_coldata = t.slice_colptr(slice,col); eT* t_coldata = t.slice_colptr(slice,col);
skipping to change at line 971 skipping to change at line 972
//! cube X += Y.subcube(...) //! cube X += Y.subcube(...)
template<typename eT> template<typename eT>
inline inline
void void
subview_cube<eT>::plus_inplace(Cube<eT>& out, const subview_cube<eT>& in) subview_cube<eT>::plus_inplace(Cube<eT>& out, const subview_cube<eT>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_assert_same_size(out, in, "cube addition"); arma_debug_assert_same_size(out, in, "cube addition");
if(&out != &in.m) const u32 n_rows = out.n_rows;
{ const u32 n_cols = out.n_cols;
const u32 n_rows = out.n_rows; const u32 n_slices = out.n_slices;
const u32 n_cols = out.n_cols;
const u32 n_slices = out.n_slices;
for(u32 slice = 0; slice<n_slices; ++slice) for(u32 slice = 0; slice<n_slices; ++slice)
{
for(u32 col = 0; col<n_cols; ++col)
{ {
for(u32 col = 0; col<n_cols; ++col) eT* out_coldata = out.slice_colptr(slice,col);
{ const eT* in_coldata = in.slice_colptr(slice,col);
eT* out_coldata = out.slice_colptr(slice,col);
const eT* in_coldata = in.slice_colptr(slice,col);
for(u32 row = 0; row<n_rows; ++row) for(u32 row = 0; row<n_rows; ++row)
{ {
out_coldata[row] += in_coldata[row]; out_coldata[row] += in_coldata[row];
}
} }
} }
} }
else
{
// X += X.subcube(...)
// this only makes sense if X and X.subcube(...) are the same size
eT* out_mem = out.memptr();
for(u32 i=0; i<out.n_elem; ++i)
{
out_mem[i] *= eT(2);
}
}
} }
//! cube X -= Y.subcube(...) //! cube X -= Y.subcube(...)
template<typename eT> template<typename eT>
inline inline
void void
subview_cube<eT>::minus_inplace(Cube<eT>& out, const subview_cube<eT>& in) subview_cube<eT>::minus_inplace(Cube<eT>& out, const subview_cube<eT>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_assert_same_size(out, in, "cube subtraction"); arma_debug_assert_same_size(out, in, "cube subtraction");
if(&out != &in.m) const u32 n_rows = out.n_rows;
{ const u32 n_cols = out.n_cols;
const u32 n_rows = out.n_rows; const u32 n_slices = out.n_slices;
const u32 n_cols = out.n_cols;
const u32 n_slices = out.n_slices;
for(u32 slice = 0; slice<n_slices; ++slice) for(u32 slice = 0; slice<n_slices; ++slice)
{
for(u32 col = 0; col<n_cols; ++col)
{ {
for(u32 col = 0; col<n_cols; ++col) eT* out_coldata = out.slice_colptr(slice,col);
{ const eT* in_coldata = in.slice_colptr(slice,col);
eT* out_coldata = out.slice_colptr(slice,col);
const eT* in_coldata = in.slice_colptr(slice,col);
for(u32 row = 0; row<n_rows; ++row) for(u32 row = 0; row<n_rows; ++row)
{ {
out_coldata[row] -= in_coldata[row]; out_coldata[row] -= in_coldata[row];
}
} }
} }
} }
else
{
// X -= X.subcube(...)
// this only makes sense if X and X.subcube(...) are the same size
out.zeros();
}
} }
//! cube X %= Y.subcube(...) //! cube X %= Y.subcube(...)
template<typename eT> template<typename eT>
inline inline
void void
subview_cube<eT>::schur_inplace(Cube<eT>& out, const subview_cube<eT>& in) subview_cube<eT>::schur_inplace(Cube<eT>& out, const subview_cube<eT>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_assert_same_size(out, in, "cube schur product"); arma_debug_assert_same_size(out, in, "cube schur product");
if(&out != &in.m) const u32 n_rows = out.n_rows;
{ const u32 n_cols = out.n_cols;
const u32 n_rows = out.n_rows; const u32 n_slices = out.n_slices;
const u32 n_cols = out.n_cols;
const u32 n_slices = out.n_slices;
for(u32 slice = 0; slice<n_slices; ++slice) for(u32 slice = 0; slice<n_slices; ++slice)
{
for(u32 col = 0; col<n_cols; ++col)
{ {
for(u32 col = 0; col<n_cols; ++col) eT* out_coldata = out.slice_colptr(slice,col);
{ const eT* in_coldata = in.slice_colptr(slice,col);
eT* out_coldata = out.slice_colptr(slice,col);
const eT* in_coldata = in.slice_colptr(slice,col);
for(u32 row = 0; row<n_rows; ++row) for(u32 row = 0; row<n_rows; ++row)
{ {
out_coldata[row] *= in_coldata[row]; out_coldata[row] *= in_coldata[row];
}
} }
} }
} }
else
{
// X %= X.subcube(...)
// this only makes sense if X and X.subcube(...) are the same size
eT* out_mem = out.memptr();
for(u32 i=0; i<out.n_elem; ++i)
{
const eT tmp = out_mem[i];
out_mem[i] = tmp*tmp;
}
}
} }
//! cube X /= Y.subcube(...) //! cube X /= Y.subcube(...)
template<typename eT> template<typename eT>
inline inline
void void
subview_cube<eT>::div_inplace(Cube<eT>& out, const subview_cube<eT>& in) subview_cube<eT>::div_inplace(Cube<eT>& out, const subview_cube<eT>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_assert_same_size(out, in, "element-wise cube division"); arma_debug_assert_same_size(out, in, "element-wise cube division");
if(&out != &in.m) const u32 n_rows = out.n_rows;
{ const u32 n_cols = out.n_cols;
const u32 n_rows = out.n_rows; const u32 n_slices = out.n_slices;
const u32 n_cols = out.n_cols;
const u32 n_slices = out.n_slices;
for(u32 slice = 0; slice<n_slices; ++slice) for(u32 slice = 0; slice<n_slices; ++slice)
{
for(u32 col = 0; col<n_cols; ++col)
{ {
for(u32 col = 0; col<n_cols; ++col) eT* out_coldata = out.slice_colptr(slice,col);
{ const eT* in_coldata = in.slice_colptr(slice,col);
eT* out_coldata = out.slice_colptr(slice,col);
const eT* in_coldata = in.slice_colptr(slice,col);
for(u32 row = 0; row<n_rows; ++row) for(u32 row = 0; row<n_rows; ++row)
{ {
out_coldata[row] /= in_coldata[row]; out_coldata[row] /= in_coldata[row];
}
} }
} }
} }
else
{
// X /= X.subcube(...)
// this only makes sense if X and X.subcube(...) are the same size
eT* out_mem = out.memptr();
for(u32 i=0; i<out.n_elem; ++i)
{
const eT tmp = out_mem[i];
out_mem[i] = tmp/tmp; // using tmp/tmp as tmp might be zero
}
}
} }
//! mat X += Y.subcube(...) //! mat X += Y.subcube(...)
template<typename eT> template<typename eT>
inline inline
void void
subview_cube<eT>::plus_inplace(Mat<eT>& out, const subview_cube<eT>& in) subview_cube<eT>::plus_inplace(Mat<eT>& out, const subview_cube<eT>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
 End of changes. 26 change blocks. 
111 lines changed or deleted 51 lines changed or added


 subview_cube_proto.hpp   subview_cube_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 28 skipping to change at line 29
//! Class for storing data required to construct or apply operations to a s ubcube //! Class for storing data required to construct or apply operations to a s ubcube
//! (i.e. where the subcube starts and ends as well as a reference/pointer to the original cube), //! (i.e. where the subcube starts and ends as well as a reference/pointer to the original cube),
template<typename eT> template<typename eT>
class subview_cube : public BaseCube<eT, subview_cube<eT> > class subview_cube : public BaseCube<eT, subview_cube<eT> >
{ {
public: arma_aligned const Cube<eT>& m; public: arma_aligned const Cube<eT>& m;
protected: arma_aligned Cube<eT>* m_ptr; protected: arma_aligned Cube<eT>* m_ptr;
public: public:
typedef eT elem_type; typedef eT elem_type;
typedef typename get_pod_type<elem_type>::pod_type pod_type; typedef typename get_pod_type<elem_type>::result pod_type;
const u32 aux_row1; const u32 aux_row1;
const u32 aux_col1; const u32 aux_col1;
const u32 aux_slice1; const u32 aux_slice1;
const u32 aux_row2; const u32 aux_row2;
const u32 aux_col2; const u32 aux_col2;
const u32 aux_slice2; const u32 aux_slice2;
const u32 n_rows; const u32 n_rows;
 End of changes. 2 change blocks. 
3 lines changed or deleted 4 lines changed or added


 subview_field_meat.hpp   subview_field_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 subview_field_proto.hpp   subview_field_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 subview_meat.hpp   subview_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 164 skipping to change at line 165
} }
template<typename eT> template<typename eT>
template<typename T1> template<typename T1>
inline inline
void void
subview<eT>::operator= (const Base<eT,T1>& in) subview<eT>::operator= (const Base<eT,T1>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap<T1> tmp(in.get_ref()); const Proxy<T1> x(in.get_ref());
const Mat<eT>& x = tmp.M; subview<eT>& t = *this;
subview<eT>& t = *this;
arma_debug_assert_same_size(t, x, "insert into submatrix"); arma_debug_assert_same_size(t, x, "insert into submatrix");
for(u32 col = 0; col<t.n_cols; ++col) for(u32 col = 0; col<t.n_cols; ++col)
{ {
eT* t_coldata = t.colptr(col); eT* t_coldata = t.colptr(col);
const eT* x_coldata = x.colptr(col);
for(u32 row = 0; row<t.n_rows; ++row) for(u32 row = 0; row<t.n_rows; ++row)
{ {
t_coldata[row] = x_coldata[row]; t_coldata[row] = x.at(row,col);
} }
} }
} }
template<typename eT> template<typename eT>
template<typename T1> template<typename T1>
inline inline
void void
subview<eT>::operator+= (const Base<eT,T1>& in) subview<eT>::operator+= (const Base<eT,T1>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap<T1> tmp(in.get_ref()); const Proxy<T1> x(in.get_ref());
const Mat<eT>& x = tmp.M; subview<eT>& t = *this;
subview<eT>& t = *this;
arma_debug_assert_same_size(t, x, "matrix addition"); arma_debug_assert_same_size(t, x, "matrix addition");
for(u32 col = 0; col<t.n_cols; ++col) for(u32 col = 0; col<t.n_cols; ++col)
{ {
eT* t_coldata = t.colptr(col); eT* t_coldata = t.colptr(col);
const eT* x_coldata = x.colptr(col);
for(u32 row = 0; row<t.n_rows; ++row) for(u32 row = 0; row<t.n_rows; ++row)
{ {
t_coldata[row] += x_coldata[row]; t_coldata[row] += x.at(row,col);
} }
} }
} }
template<typename eT> template<typename eT>
template<typename T1> template<typename T1>
inline inline
void void
subview<eT>::operator-= (const Base<eT,T1>& in) subview<eT>::operator-= (const Base<eT,T1>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap<T1> tmp(in.get_ref()); const Proxy<T1> x(in.get_ref());
const Mat<eT>& x = tmp.M; subview<eT>& t = *this;
subview<eT>& t = *this;
arma_debug_assert_same_size(t, x, "matrix subtraction"); arma_debug_assert_same_size(t, x, "matrix subtraction");
for(u32 col = 0; col<t.n_cols; ++col) for(u32 col = 0; col<t.n_cols; ++col)
{ {
eT* t_coldata = t.colptr(col); eT* t_coldata = t.colptr(col);
const eT* x_coldata = x.colptr(col);
for(u32 row = 0; row<t.n_rows; ++row) for(u32 row = 0; row<t.n_rows; ++row)
{ {
t_coldata[row] -= x_coldata[row]; t_coldata[row] -= x.at(row,col);
} }
} }
} }
template<typename eT> template<typename eT>
template<typename T1> template<typename T1>
inline inline
void void
subview<eT>::operator%= (const Base<eT,T1>& in) subview<eT>::operator%= (const Base<eT,T1>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap<T1> tmp(in.get_ref()); const Proxy<T1> x(in.get_ref());
const Mat<eT>& x = tmp.M; subview<eT>& t = *this;
subview<eT>& t = *this;
arma_debug_assert_same_size(t, x, "matrix schur product"); arma_debug_assert_same_size(t, x, "matrix schur product");
for(u32 col = 0; col<t.n_cols; ++col) for(u32 col = 0; col<t.n_cols; ++col)
{ {
eT* t_coldata = t.colptr(col); eT* t_coldata = t.colptr(col);
const eT* x_coldata = x.colptr(col);
for(u32 row = 0; row<t.n_rows; ++row) for(u32 row = 0; row<t.n_rows; ++row)
{ {
t_coldata[row] *= x_coldata[row]; t_coldata[row] *= x.at(row,col);
} }
} }
} }
template<typename eT> template<typename eT>
template<typename T1> template<typename T1>
inline inline
void void
subview<eT>::operator/= (const Base<eT,T1>& in) subview<eT>::operator/= (const Base<eT,T1>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const unwrap<T1> tmp(in.get_ref()); const Proxy<T1> x(in.get_ref());
const Mat<eT>& x = tmp.M; subview<eT>& t = *this;
subview<eT>& t = *this;
arma_debug_assert_same_size(t, x, "element-wise matrix division"); arma_debug_assert_same_size(t, x, "element-wise matrix division");
for(u32 col = 0; col<t.n_cols; ++col) for(u32 col = 0; col<t.n_cols; ++col)
{ {
eT* t_coldata = t.colptr(col); eT* t_coldata = t.colptr(col);
const eT* x_coldata = x.colptr(col);
for(u32 row = 0; row<t.n_rows; ++row) for(u32 row = 0; row<t.n_rows; ++row)
{ {
t_coldata[row] /= x_coldata[row]; t_coldata[row] /= x.at(row,col);
} }
} }
} }
//! x.submat(...) = y.submat(...) //! x.submat(...) = y.submat(...)
template<typename eT> template<typename eT>
inline inline
void void
subview<eT>::operator= (const subview<eT>& x_in) subview<eT>::operator= (const subview<eT>& x_in)
skipping to change at line 404 skipping to change at line 395
{ {
delete tmp_subview; delete tmp_subview;
delete tmp_mat; delete tmp_mat;
} }
} }
template<typename eT> template<typename eT>
inline inline
void void
subview<eT>::operator%= (const subview<eT>&amp; x_in) subview<eT>::operator%= (const subview& x_in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const bool overlap = check_overlap(x_in); const bool overlap = check_overlap(x_in);
Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0;
const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux _row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0; const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux _row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0;
const subview<eT>& x = overlap ? (*tmp_subview) : x_in; const subview<eT>& x = overlap ? (*tmp_subview) : x_in;
subview<eT>& t = *this; subview<eT>& t = *this;
skipping to change at line 440 skipping to change at line 431
{ {
delete tmp_subview; delete tmp_subview;
delete tmp_mat; delete tmp_mat;
} }
} }
template<typename eT> template<typename eT>
inline inline
void void
subview<eT>::operator/= (const subview<eT>&amp; x_in) subview<eT>::operator/= (const subview& x_in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
const bool overlap = check_overlap(x_in); const bool overlap = check_overlap(x_in);
Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0;
const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux _row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0; const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux _row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0;
const subview<eT>& x = overlap ? (*tmp_subview) : x_in; const subview<eT>& x = overlap ? (*tmp_subview) : x_in;
subview<eT>& t = *this; subview<eT>& t = *this;
skipping to change at line 556 skipping to change at line 547
const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
return m.mem[index]; return m.mem[index];
} }
template<typename eT> template<typename eT>
arma_inline arma_inline
eT& eT&
subview<eT>::operator()(const u32 in_row, const u32 in_col) subview<eT>::operator()(const u32 in_row, const u32 in_col)
{ {
arma_check( (m_ptr == 0), "subview::operator(): matrix is read-only"); arma_check( (m_ptr == 0), "subview::operator(): matrix is read-only");
arma_debug_check( ( (n_elem == 0) || (in_row >= n_rows) || (in_col >= n_c ols)), "subview::operator(): index out of bounds"); arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview::o perator(): index out of bounds");
const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
return access::rw( (*m_ptr).mem[index] ); return access::rw( (*m_ptr).mem[index] );
} }
template<typename eT> template<typename eT>
arma_inline arma_inline
eT eT
subview<eT>::operator()(const u32 in_row, const u32 in_col) const subview<eT>::operator()(const u32 in_row, const u32 in_col) const
{ {
arma_debug_check( ( (n_elem == 0) || (in_row >= n_rows) || (in_col >= n_c ols)), "subview::operator(): index out of bounds"); arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview::o perator(): index out of bounds");
const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
return m.mem[index]; return m.mem[index];
} }
template<typename eT> template<typename eT>
arma_inline arma_inline
eT& eT&
subview<eT>::at(const u32 in_row, const u32 in_col) subview<eT>::at(const u32 in_row, const u32 in_col)
{ {
skipping to change at line 737 skipping to change at line 728
//! X += Y.submat(...) //! X += Y.submat(...)
template<typename eT> template<typename eT>
inline inline
void void
subview<eT>::plus_inplace(Mat<eT>& out, const subview<eT>& in) subview<eT>::plus_inplace(Mat<eT>& out, const subview<eT>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_assert_same_size(out, in, "matrix addition"); arma_debug_assert_same_size(out, in, "matrix addition");
if(&out != &in.m) const u32 n_rows = out.n_rows;
{ const u32 n_cols = out.n_cols;
const u32 n_rows = out.n_rows;
const u32 n_cols = out.n_cols;
for(u32 col = 0; col<n_cols; ++col)
{
eT* out_coldata = out.colptr(col);
const eT* in_coldata = in.colptr(col);
for(u32 row = 0; row<n_rows; ++row) for(u32 col = 0; col<n_cols; ++col)
{
out_coldata[row] += in_coldata[row];
}
}
}
else
{ {
// X += X.submat(...) eT* out_coldata = out.colptr(col);
// this only makes sense if X and X.submat(...) are the same size const eT* in_coldata = in.colptr(col);
eT* out_mem = out.memptr();
for(u32 i=0; i<out.n_elem; ++i) for(u32 row = 0; row<n_rows; ++row)
{ {
out_mem[i] *= eT(2); out_coldata[row] += in_coldata[row];
} }
} }
} }
//! X -= Y.submat(...) //! X -= Y.submat(...)
template<typename eT> template<typename eT>
inline inline
void void
subview<eT>::minus_inplace(Mat<eT>& out, const subview<eT>& in) subview<eT>::minus_inplace(Mat<eT>& out, const subview<eT>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_assert_same_size(out, in, "matrix subtraction"); arma_debug_assert_same_size(out, in, "matrix subtraction");
if(&out != &in.m) const u32 n_rows = out.n_rows;
const u32 n_cols = out.n_cols;
for(u32 col = 0; col<n_cols; ++col)
{ {
const u32 n_rows = out.n_rows; eT* out_coldata = out.colptr(col);
const u32 n_cols = out.n_cols; const eT* in_coldata = in.colptr(col);
for(u32 col = 0; col<n_cols; ++col) for(u32 row = 0; row<n_rows; ++row)
{ {
eT* out_coldata = out.colptr(col); out_coldata[row] -= in_coldata[row];
const eT* in_coldata = in.colptr(col);
for(u32 row = 0; row<n_rows; ++row)
{
out_coldata[row] -= in_coldata[row];
}
} }
} }
else
{
out.zeros();
}
}
//! X *= Y.submat(...)
template<typename eT>
inline
void
subview<eT>::times_inplace(Mat<eT>& out, const subview<eT>& in)
{
arma_extra_debug_sigprint();
arma_debug_assert_mul_size(out, in, "matrix multiply");
if(&out != &in.m)
{
glue_times::apply_inplace(out, Mat<eT>(in));
}
else
{
glue_times::apply_inplace(out, out);
}
} }
//! X %= Y.submat(...) //! X %= Y.submat(...)
template<typename eT> template<typename eT>
inline inline
void void
subview<eT>::schur_inplace(Mat<eT>& out, const subview<eT>& in) subview<eT>::schur_inplace(Mat<eT>& out, const subview<eT>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_assert_same_size(out, in, "matrix schur product"); arma_debug_assert_same_size(out, in, "matrix schur product");
if(&out != &in.m) const u32 n_rows = out.n_rows;
{ const u32 n_cols = out.n_cols;
const u32 n_rows = out.n_rows;
const u32 n_cols = out.n_cols;
for(u32 col = 0; col<n_cols; ++col)
{
eT* out_coldata = out.colptr(col);
const eT* in_coldata = in.colptr(col);
for(u32 row = 0; row<n_rows; ++row) for(u32 col = 0; col<n_cols; ++col)
{
out_coldata[row] *= in_coldata[row];
}
}
}
else
{ {
eT* out_mem = out.memptr(); eT* out_coldata = out.colptr(col);
const eT* in_coldata = in.colptr(col);
for(u32 i=0; i<out.n_elem; ++i) for(u32 row = 0; row<n_rows; ++row)
{ {
const eT tmp = out_mem[i]; out_coldata[row] *= in_coldata[row];
out_mem[i] = tmp*tmp;
} }
} }
} }
//! X /= Y.submat(...) //! X /= Y.submat(...)
template<typename eT> template<typename eT>
inline inline
void void
subview<eT>::div_inplace(Mat<eT>& out, const subview<eT>& in) subview<eT>::div_inplace(Mat<eT>& out, const subview<eT>& in)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_debug_assert_same_size(out, in, "element-wise matrix division"); arma_debug_assert_same_size(out, in, "element-wise matrix division");
if(&out != &in.m) const u32 n_rows = out.n_rows;
{ const u32 n_cols = out.n_cols;
const u32 n_rows = out.n_rows;
const u32 n_cols = out.n_cols;
for(u32 col = 0; col<n_cols; ++col)
{
eT* out_coldata = out.colptr(col);
const eT* in_coldata = in.colptr(col);
for(u32 row = 0; row<n_rows; ++row) for(u32 col = 0; col<n_cols; ++col)
{
out_coldata[row] /= in_coldata[row];
}
}
}
else
{ {
eT* out_mem = out.memptr(); eT* out_coldata = out.colptr(col);
const eT* in_coldata = in.colptr(col);
for(u32 i=0; i<out.n_elem; ++i) for(u32 row = 0; row<n_rows; ++row)
{ {
const eT tmp = out_mem[i]; out_coldata[row] /= in_coldata[row];
out_mem[i] = tmp/tmp; // using tmp/tmp as tmp might be zero
} }
} }
} }
// //
// //
// //
template<typename eT> template<typename eT>
arma_inline arma_inline
subview_col<eT>::subview_col(const Mat<eT>& in_m, const u32 in_col) subview_col<eT>::subview_col(const Mat<eT>& in_m, const u32 in_col)
: subview<eT>(in_m, 0, in_col, in_m.n_rows-1, in_col) : subview<eT>(in_m, 0, in_col, in_m.n_rows-1, in_col)
 End of changes. 48 change blocks. 
137 lines changed or deleted 55 lines changed or added


 subview_proto.hpp   subview_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 28 skipping to change at line 29
//! Class for storing data required to construct or apply operations to a s ubmatrix //! Class for storing data required to construct or apply operations to a s ubmatrix
//! (i.e. where the submatrix starts and ends as well as a reference/pointe r to the original matrix), //! (i.e. where the submatrix starts and ends as well as a reference/pointe r to the original matrix),
template<typename eT> template<typename eT>
class subview : public Base<eT, subview<eT> > class subview : public Base<eT, subview<eT> >
{ {
public: arma_aligned const Mat<eT>& m; public: arma_aligned const Mat<eT>& m;
protected: arma_aligned Mat<eT>* m_ptr; protected: arma_aligned Mat<eT>* m_ptr;
public: public:
typedef eT elem_type; typedef eT elem_type;
typedef typename get_pod_type<elem_type>::pod_type pod_type; typedef typename get_pod_type<elem_type>::result pod_type;
const u32 aux_row1; const u32 aux_row1;
const u32 aux_col1; const u32 aux_col1;
const u32 aux_row2; const u32 aux_row2;
const u32 aux_col2; const u32 aux_col2;
const u32 n_rows; const u32 n_rows;
const u32 n_cols; const u32 n_cols;
const u32 n_elem; const u32 n_elem;
skipping to change at line 71 skipping to change at line 72
inline void operator= (const subview& x); inline void operator= (const subview& x);
inline void operator+= (const subview& x); inline void operator+= (const subview& x);
inline void operator-= (const subview& x); inline void operator-= (const subview& x);
inline void operator%= (const subview& x); inline void operator%= (const subview& x);
inline void operator/= (const subview& x); inline void operator/= (const subview& x);
inline static void extract(Mat<eT>& out, const subview& in); inline static void extract(Mat<eT>& out, const subview& in);
inline static void plus_inplace(Mat<eT>& out, const subview& in); inline static void plus_inplace(Mat<eT>& out, const subview& in);
inline static void times_inplace(Mat<eT>& out, const subview& in);
inline static void minus_inplace(Mat<eT>& out, const subview& in); inline static void minus_inplace(Mat<eT>& out, const subview& in);
inline static void schur_inplace(Mat<eT>& out, const subview& in); inline static void schur_inplace(Mat<eT>& out, const subview& in);
inline static void div_inplace(Mat<eT>& out, const subview& in); inline static void div_inplace(Mat<eT>& out, const subview& in);
inline void fill(const eT val); inline void fill(const eT val);
inline void zeros(); inline void zeros();
arma_inline eT& operator[](const u32 i); arma_inline eT& operator[](const u32 i);
arma_inline eT operator[](const u32 i) const; arma_inline eT operator[](const u32 i) const;
skipping to change at line 109 skipping to change at line 109
friend class Mat<eT>; friend class Mat<eT>;
subview(); subview();
}; };
template<typename eT> template<typename eT>
class subview_col : public subview<eT> class subview_col : public subview<eT>
{ {
public: public:
typedef eT elem_type; typedef eT elem_type;
typedef typename get_pod_type<elem_type>::pod_type pod_type; typedef typename get_pod_type<elem_type>::result pod_type;
inline void operator= (const subview<eT>& x); inline void operator= (const subview<eT>& x);
inline void operator= (const subview_col& x); inline void operator= (const subview_col& x);
template<typename T1> template<typename T1>
inline void operator= (const Base<eT,T1>& x); inline void operator= (const Base<eT,T1>& x);
protected: protected:
arma_inline subview_col(const Mat<eT>& in_m, const u32 in_col); arma_inline subview_col(const Mat<eT>& in_m, const u32 in_col);
skipping to change at line 139 skipping to change at line 139
friend class Col<eT>; friend class Col<eT>;
subview_col(); subview_col();
}; };
template<typename eT> template<typename eT>
class subview_row : public subview<eT> class subview_row : public subview<eT>
{ {
public: public:
typedef eT elem_type; typedef eT elem_type;
typedef typename get_pod_type<elem_type>::pod_type pod_type; typedef typename get_pod_type<elem_type>::result pod_type;
inline void operator= (const subview<eT>& x); inline void operator= (const subview<eT>& x);
inline void operator= (const subview_row& x); inline void operator= (const subview_row& x);
template<typename T1> template<typename T1>
inline void operator= (const Base<eT,T1>& x); inline void operator= (const Base<eT,T1>& x);
protected: protected:
arma_inline subview_row(const Mat<eT>& in_m, const u32 in_row); arma_inline subview_row(const Mat<eT>& in_m, const u32 in_row);
 End of changes. 5 change blocks. 
8 lines changed or deleted 8 lines changed or added


 syslib_proto.hpp   syslib_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 23 skipping to change at line 24
// (see http://www.opensource.org/licenses for more info) // (see http://www.opensource.org/licenses for more info)
//! \addtogroup syslib //! \addtogroup syslib
//! @{ //! @{
class syslib class syslib
{ {
public: public:
template<typename eT> template<typename eT>
arma_inline arma_hot
inline
static static
void void
copy_elem(eT* dest, const eT* src, const u32 n_elem) copy_elem(eT* dest, const eT* src, const u32 n_elem)
{ {
if( n_elem <= (128/sizeof(eT)) ) if( n_elem <= (128/sizeof(eT)) )
{ {
for(u32 i=0; i<n_elem; ++i) for(u32 i=0; i<n_elem; ++i)
{ {
dest[i] = src[i]; dest[i] = src[i];
} }
 End of changes. 2 change blocks. 
2 lines changed or deleted 4 lines changed or added


 traits.hpp   traits.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 traits //! \addtogroup traits
//! @{ //! @{
template<typename T1> template<typename T1>
struct get_pod_type struct get_pod_type
{ typedef T1 pod_type; }; { typedef T1 result; };
template<typename T2> template<typename T2>
struct get_pod_type< std::complex<T2> > struct get_pod_type< std::complex<T2> >
{ typedef T2 pod_type; }; { typedef T2 result; };
template<typename T> template<typename T>
struct is_Mat_only struct is_Mat_only
{ static const bool value = false; }; { static const bool value = false; };
template<typename eT> template<typename eT>
struct is_Mat_only< Mat<eT> > struct is_Mat_only< Mat<eT> >
{ static const bool value = true; }; { static const bool value = true; };
template<typename T> template<typename T>
skipping to change at line 146 skipping to change at line 147
{ static const bool value = true; }; { static const bool value = true; };
template<typename T> template<typename T>
struct is_glue_times struct is_glue_times
{ static const bool value = false; }; { static const bool value = false; };
template<typename T1, typename T2> template<typename T1, typename T2>
struct is_glue_times< Glue<T1,T2,glue_times> > struct is_glue_times< Glue<T1,T2,glue_times> >
{ static const bool value = true; }; { static const bool value = true; };
template<typename T>
struct is_glue_times_diag
{ static const bool value = false; };
template<typename T1, typename T2>
struct is_glue_times_diag< Glue<T1,T2,glue_times_diag> >
{ static const bool value = true; };
//
//
//
template<typename T>
struct is_eOp
{ static const bool value = false; };
template<typename T1, typename eop_type>
struct is_eOp< eOp<T1,eop_type> >
{ static const bool value = true; };
template<typename T>
struct is_eGlue
{ static const bool value = false; };
template<typename T1, typename T2, typename eglue_type>
struct is_eGlue< eGlue<T1,T2,eglue_type> >
{ static const bool value = true; };
template<typename T>
struct is_op_diagmat
{ static const bool value = false; };
template<typename T1>
struct is_op_diagmat< Op<T1,op_diagmat> >
{ static const bool value = true; };
// //
// //
// //
template<typename T1> template<typename T1>
struct is_arma_type struct is_arma_type
{ {
static const bool value static const bool value
= is_Mat<T1>::value = is_Mat<T1>::value
|| is_Op<T1>::value || is_Op<T1>::value
|| is_Glue<T1>::value || is_Glue<T1>::value
|| is_subview<T1>::value || is_subview<T1>::value
|| is_diagview<T1>::value || is_diagview<T1>::value
|| is_eOp<T1>::value
|| is_eGlue<T1>::value
; ;
}; };
template<typename T1> template<typename T1>
struct is_arma_cube_type struct is_arma_cube_type
{ {
static const bool value static const bool value
= is_Cube<T1>::value = is_Cube<T1>::value
|| is_OpCube<T1>::value || is_OpCube<T1>::value
|| is_GlueCube<T1>::value || is_GlueCube<T1>::value
skipping to change at line 418 skipping to change at line 457
static const bool value = (T(-1) < T(0)); static const bool value = (T(-1) < T(0));
}; };
template<typename T> template<typename T>
struct is_non_integral struct is_non_integral
{ {
static const bool value = (T(1.0) != T(1.1)); static const bool value = (T(1.0) != T(1.1));
}; };
// //
// type promotion
template<typename T1, typename T2>
struct promote_type
{
inline static void check()
{
arma_static_assert<false> ERROR___UNSUPPORTED_MIXTURE_OF_TYPES;
ERROR___UNSUPPORTED_MIXTURE_OF_TYPES = ERROR___UNSUPPORTED_MIXTURE_OF_T
YPES;
}
typedef T1 result;
};
struct promote_type_ok
{
arma_inline static void check() {}
};
template<typename T>
struct promote_type<T, T> : public promote_type_ok { typedef T result; };
template<typename T>
struct promote_type<std::complex<T>, T> : public promote_type_ok {
typedef std::complex<T> result; };
template<>
struct promote_type<std::complex<double>, std::complex<float> > : public pr
omote_type_ok { typedef std::complex<double> result; };
template<>
struct promote_type<std::complex<double>, float> : public promote_type_ok {
typedef std::complex<double> result; };
template<>
struct promote_type<std::complex<float>, double> : public promote_type_ok {
typedef std::complex<double> result; };
template<typename T>
struct promote_type<std::complex<T>, s32> : public promote_type_ok { typede
f std::complex<T> result; };
template<typename T>
struct promote_type<std::complex<T>, u32> : public promote_type_ok { typede
f std::complex<T> result; };
template<typename T>
struct promote_type<std::complex<T>, s16> : public promote_type_ok { typede
f std::complex<T> result; };
template<typename T>
struct promote_type<std::complex<T>, u16> : public promote_type_ok { typede
f std::complex<T> result; };
template<typename T>
struct promote_type<std::complex<T>, s8> : public promote_type_ok { typede
f std::complex<T> result; };
template<typename T>
struct promote_type<std::complex<T>, u8> : public promote_type_ok { typede
f std::complex<T> result; };
template<> struct promote_type<double, float> : public promote_type_ok { ty
pedef double result; };
template<> struct promote_type<double, s32 > : public promote_type_ok { ty
pedef double result; };
template<> struct promote_type<double, u32 > : public promote_type_ok { ty
pedef double result; };
template<> struct promote_type<double, s16 > : public promote_type_ok { ty
pedef double result; };
template<> struct promote_type<double, u16 > : public promote_type_ok { ty
pedef double result; };
template<> struct promote_type<double, s8 > : public promote_type_ok { ty
pedef double result; };
template<> struct promote_type<double, u8 > : public promote_type_ok { ty
pedef double result; };
template<> struct promote_type<float, s32> : public promote_type_ok { typed
ef float result; };
template<> struct promote_type<float, u32> : public promote_type_ok { typed
ef float result; };
template<> struct promote_type<float, s16> : public promote_type_ok { typed
ef float result; };
template<> struct promote_type<float, u16> : public promote_type_ok { typed
ef float result; };
template<> struct promote_type<float, s8 > : public promote_type_ok { typed
ef float result; };
template<> struct promote_type<float, u8 > : public promote_type_ok { typed
ef float result; };
template<> struct promote_type<s32, u32> : public promote_type_ok { typedef
s32 result; }; // float ?
template<> struct promote_type<s32, s16> : public promote_type_ok { typedef
s32 result; };
template<> struct promote_type<s32, u16> : public promote_type_ok { typedef
s32 result; };
template<> struct promote_type<s32, s8 > : public promote_type_ok { typedef
s32 result; };
template<> struct promote_type<s32, u8 > : public promote_type_ok { typedef
s32 result; };
template<> struct promote_type<u32, s16> : public promote_type_ok { typedef
s32 result; }; // float ?
template<> struct promote_type<u32, u16> : public promote_type_ok { typedef
u32 result; };
template<> struct promote_type<u32, s8 > : public promote_type_ok { typedef
s32 result; }; // float ?
template<> struct promote_type<u32, u8 > : public promote_type_ok { typedef
u32 result; };
template<> struct promote_type<s16, u16> : public promote_type_ok { typedef
s16 result; }; // s32 ?
template<> struct promote_type<s16, s8 > : public promote_type_ok { typedef
s16 result; };
template<> struct promote_type<s16, u8 > : public promote_type_ok { typedef
s16 result; };
template<> struct promote_type<u16, s8> : public promote_type_ok { typedef
s16 result; }; // s32 ?
template<> struct promote_type<u16, u8> : public promote_type_ok { typedef
u16 result; };
template<> struct promote_type<s8, u8> : public promote_type_ok { typedef s
8 result; }; // s16 ?
//
// type promotion, mirrored versions
template<typename T> class arma_junk_class;
struct promote_type<T, std::complex<T> > : public promote_type_ok { typedef
std::complex<T> result; };
template<>
struct promote_type<std::complex<float>, std::complex<double> > : public pr
omote_type_ok { typedef std::complex<double> result; };
template<>
struct promote_type<float, std::complex<double> > : public promote_type_ok
{ typedef std::complex<double> result; };
template<>
struct promote_type<double, std::complex<float> > : public promote_type_ok
{ typedef std::complex<double> result; };
template<typename T>
struct promote_type<s32, std::complex<T> > : public promote_type_ok { typed
ef std::complex<T> result; };
template<typename T>
struct promote_type<u32, std::complex<T> > : public promote_type_ok { typed
ef std::complex<T> result; };
template<typename T>
struct promote_type<s16, std::complex<T> > : public promote_type_ok { typed
ef std::complex<T> result; };
template<typename T>
struct promote_type<u16, std::complex<T> > : public promote_type_ok { typed
ef std::complex<T> result; };
template<typename T>
struct promote_type<s8, std::complex<T> > : public promote_type_ok { typed
ef std::complex<T> result; };
template<typename T>
struct promote_type<u8, std::complex<T> > : public promote_type_ok { typed
ef std::complex<T> result; };
template<> struct promote_type<float, double> : public promote_type_ok { ty
pedef double result; };
template<> struct promote_type<s32 , double> : public promote_type_ok { ty
pedef double result; };
template<> struct promote_type<u32 , double> : public promote_type_ok { ty
pedef double result; };
template<> struct promote_type<s16 , double> : public promote_type_ok { ty
pedef double result; };
template<> struct promote_type<u16 , double> : public promote_type_ok { ty
pedef double result; };
template<> struct promote_type<s8 , double> : public promote_type_ok { ty
pedef double result; };
template<> struct promote_type<u8 , double> : public promote_type_ok { ty
pedef double result; };
template<> struct promote_type<s32, float> : public promote_type_ok { typed
ef float result; };
template<> struct promote_type<u32, float> : public promote_type_ok { typed
ef float result; };
template<> struct promote_type<s16, float> : public promote_type_ok { typed
ef float result; };
template<> struct promote_type<u16, float> : public promote_type_ok { typed
ef float result; };
template<> struct promote_type<s8 , float> : public promote_type_ok { typed
ef float result; };
template<> struct promote_type<u8 , float> : public promote_type_ok { typed
ef float result; };
template<> struct promote_type<u32, s32> : public promote_type_ok { typedef
s32 result; }; // float ?
template<> struct promote_type<s16, s32> : public promote_type_ok { typedef
s32 result; };
template<> struct promote_type<u16, s32> : public promote_type_ok { typedef
s32 result; };
template<> struct promote_type<s8 , s32> : public promote_type_ok { typedef
s32 result; };
template<> struct promote_type<u8 , s32> : public promote_type_ok { typedef
s32 result; };
template<> struct promote_type<s16, u32> : public promote_type_ok { typedef
s32 result; }; // float ?
template<> struct promote_type<u16, u32> : public promote_type_ok { typedef
u32 result; };
template<> struct promote_type<s8 , u32> : public promote_type_ok { typedef
s32 result; }; // float ?
template<> struct promote_type<u8 , u32> : public promote_type_ok { typedef
u32 result; };
template<> struct promote_type<u16, s16> : public promote_type_ok { typedef
s16 result; }; // s32 ?
template<> struct promote_type<s8 , s16> : public promote_type_ok { typedef
s16 result; };
template<> struct promote_type<u8 , s16> : public promote_type_ok { typedef
s16 result; };
template<> struct promote_type<s8, u16> : public promote_type_ok { typedef
s16 result; }; // s32 ?
template<> struct promote_type<u8, u16> : public promote_type_ok { typedef
u16 result; };
template<> struct promote_type<u8, s8> : public promote_type_ok { typedef s
8 result; }; // s16 ?
//
//
//
//! upgrade_val is used to ensure an operation such as multiplication is po
ssible between two types.
//! values are upgraded only where necessary.
//! used by:
//! glue_div::apply_mixed(), glue_minus::apply_mixed(), glue_plus::apply_mi
xed(), glue_schur::apply_mixed()
//! and glue_times::apply_mixed() via gemm_mixed().
template<typename T1, typename T2> template<typename T1, typename T2>
struct upgrade_val struct force_different_type
{ {
typedef typename promote_type<T1,T2>::result T1_result; typedef T1 T1_result;
typedef typename promote_type<T1,T2>::result T2_result; typedef T2 T2_result;
arma_inline
static
const typename promote_type<T1,T2>::result
apply(const T1 x)
{
typedef typename promote_type<T1,T2>::result out_type;
return out_type(x);
}
arma_inline
static
const typename promote_type<T1,T2>::result
apply(const T2 x)
{
typedef typename promote_type<T1,T2>::result out_type;
return out_type(x);
}
}; };
// template<> template<typename T1>
template<typename T> struct force_different_type<T1,T1>
struct upgrade_val<T,T>
{
typedef T T1_result;
typedef T T2_result;
arma_inline static const T& apply(const T& x) { return x; }
};
//! upgrade a type to allow multiplication with a complex type
//! e.g. the int in "int * complex<double>" is upgraded to a double
// template<>
template<typename T, typename T2>
struct upgrade_val< std::complex<T>, T2 >
{
typedef std::complex<T> T1_result;
typedef T T2_result;
arma_inline static const std::complex<T>& apply(const std::complex<T>& x)
{ return x; }
arma_inline static const T apply(const T2 x)
{ return T(x); }
};
// template<>
template<typename T1, typename T>
struct upgrade_val< T1, std::complex<T> >
{
typedef T T1_result;
typedef std::complex<T> T2_result;
arma_inline static const T apply(const T1 x)
{ return T(x); }
arma_inline static const std::complex<T>& apply(const std::complex<T>& x)
{ return x; }
};
//! ensure we don't lose precision when multiplying a complex number with a
higher precision real number
template<>
struct upgrade_val< std::complex<float>, double >
{
typedef std::complex<double> T1_result;
typedef double T2_result;
arma_inline static const std::complex<double> apply(const std::complex<fl
oat>& x) { return std::complex<double>(x); }
arma_inline static const double apply(const double x)
{ return x; }
};
template<>
struct upgrade_val< double, std::complex<float> >
{
typedef double T1_result;
typedef std::complex<float> T2_result;
arma_inline static const double apply(const double x)
{ return x; }
arma_inline static const std::complex<double> apply(const std::complex<fl
oat>& x) { return std::complex<double>(x); }
};
//! ensure we don't lose precision when multiplying complex numbers with di
fferent underlying types
template<>
struct upgrade_val< std::complex<float>, std::complex<double> >
{
typedef std::complex<double> T1_result;
typedef std::complex<double> T2_result;
arma_inline static const std::complex<double> apply(const std::complex<f
loat>& x) { return std::complex<double>(x); }
arma_inline static const std::complex<double>& apply(const std::complex<d
ouble>& x) { return x; }
};
template<>
struct upgrade_val< std::complex<double>, std::complex<float> >
{
typedef std::complex<double> T1_result;
typedef std::complex<double> T2_result;
arma_inline static const std::complex<double>& apply(const std::complex<d
ouble>& x) { return x; }
arma_inline static const std::complex<double> apply(const std::complex<f
loat>& x) { return std::complex<double>(x); }
};
//! work around limitations in the complex class (at least as present in gc
c 4.1 & 4.3)
template<>
struct upgrade_val< std::complex<double>, float >
{
typedef std::complex<double> T1_result;
typedef double T2_result;
arma_inline static const std::complex<double>& apply(const std::complex<d
ouble>& x) { return x; }
arma_inline static const double apply(const float x)
{ return double(x); }
};
template<>
struct upgrade_val< float, std::complex<double> >
{ {
typedef double T1_result; typedef T1 T1_result;
typedef std::complex<double> T2_result; typedef arma_junk_class T2_result;
arma_inline static const double apply(const float x)
{ return double(x); }
arma_inline static const std::complex<double>& apply(const std::complex<d
ouble>& x) { return x; }
}; };
//! @} //! @}
 End of changes. 11 change blocks. 
380 lines changed or deleted 50 lines changed or added


 typedef.hpp   typedef.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 unwrap.hpp   unwrap.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 unwrap //! \addtogroup unwrap
//! @{ //! @{
template<typename T1> template<typename T1>
class unwrap class unwrap
{ {
public: public:
inline unwrap(const T1& A)
typedef typename T1::elem_type eT;
inline unwrap(const T1& A) // TODO: change this to Base ?
: M(A)
{ {
arma_type_check< is_arma_type<T1>::value == false >::apply(); arma_extra_debug_sigprint();
} }
const Mat<eT> M;
}; };
//template<>
template<typename eT> template<typename eT>
class unwrap< Mat<eT> > class unwrap< Mat<eT> >
{ {
public: public:
inline unwrap(const Mat<eT>& A) inline unwrap(const Mat<eT>& A)
: M(A) : M(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
const Mat<eT>& M; const Mat<eT>& M;
}; };
//template<>
template<typename eT> template<typename eT>
class unwrap< Row<eT> > class unwrap< Row<eT> >
{ {
public: public:
inline unwrap(const Row<eT>& A) inline unwrap(const Row<eT>& A)
: M(A) : M(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
const Row<eT>& M; const Row<eT>& M;
}; };
//template<>
template<typename eT> template<typename eT>
class unwrap< Col<eT> > class unwrap< Col<eT> >
{ {
public: public:
inline unwrap(const Col<eT>& A) inline unwrap(const Col<eT>& A)
: M(A) : M(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
const Col<eT>& M; const Col<eT>& M;
}; };
template<typename T1, typename op_type> //
class unwrap< Op<T1, op_type> > //
{ //
public:
inline unwrap(const Op<T1, op_type>& A)
: M(A)
{
arma_extra_debug_sigprint();
}
typedef typename T1::elem_type elem_type;
const Mat<elem_type> M;
};
template<typename T1, typename T2, typename glue_type> template<typename T1>
class unwrap< Glue<T1, T2, glue_type> > class unwrap_check
{ {
public: public:
inline unwrap(const Glue<T1, T2, glue_type>& A) typedef typename T1::elem_type eT;
inline
unwrap_check(const T1& A, const Mat<eT>& B)
: M(A) : M(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
typedef typename T1::elem_type elem_type; inline
const Mat<elem_type> M; ~unwrap_check()
};
//template<>
template<typename eT>
class unwrap< subview<eT> >
{
public:
inline unwrap(const subview<eT>& A)
: M(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
const Mat<eT> M; const Mat<eT> M;
}; };
//template<>
template<typename eT> template<typename eT>
class unwrap< diagview<eT> > class unwrap_check< Mat<eT> >
{ {
public: public:
inline unwrap(const diagview<eT> & A) inline
: M(A) unwrap_check(const Mat<eT>& A, const Mat<eT>& B)
: M_local( (&A == &B) ? new Mat<eT>(A) : 0 )
, M ( (&A == &B) ? (*M_local) : A )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
const Mat<eT> M; inline
~unwrap_check()
};
//
//
//
template<typename T1>
class unwrap_to_elem_access
{
public:
inline unwrap_to_elem_access(const T1& A)
{
arma_type_check< is_arma_type<T1>::value == false >::apply();
}
};
//template<>
template<typename eT>
class unwrap_to_elem_access< Mat<eT> >
{
public:
inline unwrap_to_elem_access(const Mat<eT>& A)
: M(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
}
inline eT operator[](const u32 i) const { return M[i]; } if(M_local)
inline eT operator()(const u32 i) const { return M(i); } {
delete M_local;
inline eT operator()(const u32 in_row, const u32 in_col) const { return }
M(in_row,in_col); } }
inline eT at(const u32 in_row, const u32 in_col) const { return
M.at(in_row,in_col); }
// the order below is important
const Mat<eT>* M_local;
const Mat<eT>& M; const Mat<eT>& M;
}; };
//template<>
template<typename eT> template<typename eT>
class unwrap_to_elem_access< Row<eT> > class unwrap_check< Row<eT> >
{ {
public: public:
inline unwrap_to_elem_access(const Row<eT>& A) inline
: M(A) unwrap_check(const Row<eT>& A, const Mat<eT>& B)
: M_local( (&A == reinterpret_cast<const Row<eT>*>(&B)) ? new Row<eT>(A
) : 0 )
, M ( (&A == reinterpret_cast<const Row<eT>*>(&B)) ? (*M_local)
: A )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
inline eT operator[](const u32 i) const { return M[i]; } inline
inline eT operator()(const u32 i) const { return M(i); } ~unwrap_check()
{
arma_extra_debug_sigprint();
inline eT operator()(const u32 in_row, const u32 in_col) const { return if(M_local)
M(in_row,in_col); } {
inline eT at(const u32 in_row, const u32 in_col) const { return delete M_local;
M.at(in_row,in_col); } }
}
// the order below is important
const Row<eT>* M_local;
const Row<eT>& M; const Row<eT>& M;
}; };
//template<>
template<typename eT> template<typename eT>
class unwrap_to_elem_access< Op< Row<eT>, op_trans> > class unwrap_check< Col<eT> >
{ {
public: public:
// NOTE: inline
// currently accessing M.n_rows and M.n_cols will give wrong results unwrap_check(const Col<eT>& A, const Mat<eT>& B)
: M_local( (&A == reinterpret_cast<const Col<eT>*>(&B)) ? new Col<eT>(A
inline unwrap_to_elem_access(const Op<Row<eT>, op_trans>& A) ) : 0 )
: M(A.m) , M ( (&A == reinterpret_cast<const Col<eT>*>(&B)) ? (*M_local)
: A )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
inline eT operator[](const u32 i) const { return M[i]; } inline
inline eT operator()(const u32 i) const { return M(i); } ~unwrap_check()
{
arma_extra_debug_sigprint();
inline eT operator()(const u32 in_row, const u32 in_col) const { return if(M_local)
M(in_row,in_col); } {
inline eT at(const u32 in_row, const u32 in_col) const { return delete M_local;
M.at(in_row,in_col); } }
}
const Row<eT>& M; // the order below is important
const Col<eT>* M_local;
const Col<eT>& M;
}; };
//template<> //
template<typename eT>
class unwrap_to_elem_access< Col<eT> > template<typename T1>
class partial_unwrap
{ {
public: public:
inline unwrap_to_elem_access(const Col<eT>& A) typedef typename T1::elem_type eT;
: M(A)
inline partial_unwrap(const T1& A) // TODO: change this to Base ?
: do_trans(false)
, do_times(false)
, val (1)
, M (A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
inline eT operator[](const u32 i) const { return M[i]; } inline
inline eT operator()(const u32 i) const { return M(i); } ~partial_unwrap()
{
inline eT operator()(const u32 in_row, const u32 in_col) const { return arma_extra_debug_sigprint();
M(in_row,in_col); } }
inline eT at(const u32 in_row, const u32 in_col) const { return
M.at(in_row,in_col); }
const Col<eT>& M;
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT> M;
}; };
//template<> template<typename T1>
template<typename eT> class partial_unwrap< Op<T1, op_trans> >
class unwrap_to_elem_access< Op<Col<eT>, op_trans> >
{ {
public: public:
inline unwrap_to_elem_access(const Op<Col<eT>, op_trans>& A) typedef typename T1::elem_type eT;
: M(A.m)
inline
partial_unwrap(const Op<T1,op_trans>& A)
: do_trans(true)
, do_times(false)
, val (1)
, M (A.m)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
inline eT operator[](const u32 i) const { return M[i]; } inline
inline eT operator()(const u32 i) const { return M(i); } ~partial_unwrap()
{
// NOTE: use of in_row and in_col is swapped (due to transpose operation) arma_extra_debug_sigprint();
inline eT at(const u32 in_row, const u32 in_col) const { return }
M.at(in_col,in_row); }
inline eT operator()(const u32 in_row, const u32 in_col) const { return
M(in_col,in_row); }
const Col<eT>& M;
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT> M;
}; };
template<typename T1, typename op_type> template<typename T1>
class unwrap_to_elem_access< Op<T1, op_type> > class partial_unwrap< Op<T1, op_trans2> >
{ {
public: public:
typedef typename T1::elem_type elem_type;
inline unwrap_to_elem_access(const Op<T1, op_type>& A) typedef typename T1::elem_type eT;
: M(A)
inline
partial_unwrap(const Op<T1,op_trans2>& A)
: do_trans(true)
, do_times(true)
, val (A.aux)
, M (A.m)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
inline elem_type operator[](const u32 i) const { return M[i]; } inline
inline elem_type operator()(const u32 i) const { return M(i); } ~partial_unwrap()
{
inline elem_type operator()(const u32 in_row, const u32 in_col) const { arma_extra_debug_sigprint();
return M(in_row,in_col); } }
inline elem_type at(const u32 in_row, const u32 in_col) const {
return M.at(in_row,in_col); }
const Mat<elem_type> M;
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT> M;
}; };
template<typename T1, typename T2, typename glue_type> template<typename T1>
class unwrap_to_elem_access< Glue<T1, T2, glue_type> > class partial_unwrap< eOp<T1, eop_scalar_times> >
{ {
public: public:
typedef typename T1::elem_type elem_type;
inline unwrap_to_elem_access(const Glue<T1, T2, glue_type>& A) typedef typename T1::elem_type eT;
: M(A)
inline
partial_unwrap(const eOp<T1,eop_scalar_times>& A)
: do_trans(false)
, do_times(true)
, val (A.aux)
, M (A.P.Q)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
inline elem_type operator[](const u32 i) const { return M[i]; } inline
inline elem_type operator()(const u32 i) const { return M(i); } ~partial_unwrap()
{
inline elem_type operator()(const u32 in_row, const u32 in_col) const { arma_extra_debug_sigprint();
return M(in_row,in_col); } }
inline elem_type at(const u32 in_row, const u32 in_col) const {
return M.at(in_row,in_col); }
const Mat<elem_type> M;
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT> M;
}; };
//template<>
template<typename eT> template<typename eT>
class unwrap_to_elem_access< subview<eT> > class partial_unwrap< Mat<eT> >
{ {
public: public:
inline unwrap_to_elem_access(const subview<eT>& A) inline
: M(A) partial_unwrap(const Mat<eT>& A)
: do_trans(false)
, do_times(false)
, val (1)
, M (A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
inline eT operator[](const u32 i) const { return M[i]; } inline
inline eT operator()(const u32 i) const { return M(i); } ~partial_unwrap()
{
inline eT operator()(const u32 in_row, const u32 in_col) const { return M arma_extra_debug_sigprint();
(in_row,in_col); } }
inline eT at(const u32 in_row, const u32 in_col) const { return M
.at(in_row,in_col); }
const subview<eT>& M;
};
//
//
//
template<typename T1> const bool do_trans;
class unwrap_check const bool do_times;
{ const eT val;
private: const Mat<eT>& M;
template<typename eT> inline unwrap_check(const T1& A, const Mat<eT>& B);
template<typename eT> inline unwrap_check(const T1& A, const Row<eT>& B);
template<typename eT> inline unwrap_check(const T1& A, const Col<eT>& B);
template<typename eT> inline unwrap_check(const T1& A, const subview<eT>&
B);
template<typename eT> inline unwrap_check(const T1& A, const diagview<eT>
& B);
}; };
//template <>
template<typename eT> template<typename eT>
class unwrap_check< Mat<eT> > class partial_unwrap< Op< Mat<eT>, op_trans> >
{ {
public: public:
inline inline
unwrap_check(const Mat<eT>& A, const Mat<eT>& B) partial_unwrap(const Op< Mat<eT>, op_trans>& A)
: M_local( (&A == reinterpret_cast<const Mat<eT>*>(&B)) ? new Mat<eT>(A : do_trans(true)
) : 0 ) , do_times(false)
, M ( (&A == reinterpret_cast<const Mat<eT>*>(&B)) ? (*M_local) , val (1)
: A ) , M (A.m)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
inline inline
unwrap_check(const Mat<eT>& A, const Row<eT>& B) ~partial_unwrap()
: M_local( (&A == reinterpret_cast<const Mat<eT>*>(&B)) ? new Mat<eT>(A
) : 0 )
, M ( (&A == reinterpret_cast<const Mat<eT>*>(&B)) ? (*M_local)
: A )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT>& M;
};
template<typename eT>
class partial_unwrap< Op< Mat<eT>, op_trans2> >
{
public:
inline inline
unwrap_check(const Mat<eT>& A, const Col<eT>& B) partial_unwrap(const Op< Mat<eT>, op_trans2>& A)
: M_local( (&A == reinterpret_cast<const Mat<eT>*>(&B)) ? new Mat<eT>(A : do_trans(true)
) : 0 ) , do_times(true)
, M ( (&A == reinterpret_cast<const Mat<eT>*>(&B)) ? (*M_local) , val (A.aux)
: A ) , M (A.m)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
inline inline
unwrap_check(const Mat<eT>& A, const subview<eT>& B) ~partial_unwrap()
: M_local( (&A == reinterpret_cast<const Mat<eT>*>(&B.m)) ? new Mat<eT>
(A) : 0 )
, M ( (&A == reinterpret_cast<const Mat<eT>*>(&B.m)) ? (*M_local)
: A )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT>& M;
};
template<typename eT>
class partial_unwrap< eOp<Mat<eT>, eop_scalar_times> >
{
public:
inline inline
unwrap_check(const Mat<eT>& A, const diagview<eT>& B) partial_unwrap(const eOp<Mat<eT>,eop_scalar_times>& A)
: M_local( (&A == reinterpret_cast<const Mat<eT>*>(&B.m)) ? new Mat<eT> : do_trans(false)
(A) : 0 ) , do_times(true)
, M ( (&A == reinterpret_cast<const Mat<eT>*>(&B.m)) ? (*M_local) , val (A.aux)
: A ) , M (A.P.Q)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
inline inline
~unwrap_check() ~partial_unwrap()
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
if(M_local)
{
delete M_local;
}
} }
// the order below is important const bool do_trans;
const Mat<eT>* M_local; const bool do_times;
const eT val;
const Mat<eT>& M; const Mat<eT>& M;
}; };
//template <>
template<typename eT> template<typename eT>
class unwrap_check< Row<eT> > class partial_unwrap< Row<eT> >
{ {
public: public:
inline inline
unwrap_check(const Row<eT>& A, const Mat<eT>& B) partial_unwrap(const Row<eT>& A)
: M_local( (&A == reinterpret_cast<const Row<eT>*>(&B)) ? new Row<eT>(A : do_trans(false)
) : 0 ) , do_times(false)
, M ( (&A == reinterpret_cast<const Row<eT>*>(&B)) ? (*M_local) , val (1)
: A ) , M (A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
inline inline
unwrap_check(const Row<eT>& A, const Row<eT>& B) ~partial_unwrap()
: M_local( (&A == reinterpret_cast<const Row<eT>*>(&B)) ? new Row<eT>(A
) : 0 )
, M ( (&A == reinterpret_cast<const Row<eT>*>(&B)) ? (*M_local)
: A )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT>& M;
};
template<typename eT>
class partial_unwrap< Op< Row<eT>, op_trans> >
{
public:
inline inline
unwrap_check(const Row<eT>& A, const Col<eT>& B) partial_unwrap(const Op< Row<eT>, op_trans>& A)
: M_local( (&A == reinterpret_cast<const Row<eT>*>(&B)) ? new Row<eT>(A : do_trans(true)
) : 0 ) , do_times(false)
, M ( (&A == reinterpret_cast<const Row<eT>*>(&B)) ? (*M_local) , val (1)
: A ) , M (A.m)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
inline inline
unwrap_check(const Row<eT>& A, const subview<eT>& B) ~partial_unwrap()
: M_local( (&A == reinterpret_cast<const Row<eT>*>(&B.m)) ? new Row<eT>
(A) : 0 )
, M ( (&A == reinterpret_cast<const Row<eT>*>(&B.m)) ? (*M_local)
: A )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT>& M;
};
template<typename eT>
class partial_unwrap< Op< Row<eT>, op_trans2> >
{
public:
inline inline
unwrap_check(const Row<eT>& A, const diagview<eT>& B) partial_unwrap(const Op< Row<eT>, op_trans2>& A)
: M_local( (&A == reinterpret_cast<const Row<eT>*>(&B.m)) ? new Row<eT> : do_trans(true)
(A) : 0 ) , do_times(true)
, M ( (&A == reinterpret_cast<const Row<eT>*>(&B.m)) ? (*M_local) , val (A.aux)
: A ) , M (A.m)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
inline inline
~unwrap_check() ~partial_unwrap()
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
if(M_local)
delete M_local;
} }
// the order below is important const bool do_trans;
const Row<eT>* M_local; const bool do_times;
const Row<eT>& M; const eT val;
const Mat<eT>& M;
}; };
//template <>
template<typename eT> template<typename eT>
class unwrap_check< Col<eT> > class partial_unwrap< eOp<Row<eT>, eop_scalar_times> >
{ {
public: public:
inline inline
unwrap_check(const Col<eT>& A, const Mat<eT>& B) partial_unwrap(const eOp<Row<eT>,eop_scalar_times>& A)
: M_local( (&A == reinterpret_cast<const Col<eT>*>(&B)) ? new Col<eT>(A : do_trans(false)
) : 0 ) , do_times(true)
, M ( (&A == reinterpret_cast<const Col<eT>*>(&B)) ? (*M_local) , val (A.aux)
: A ) , M (A.P.Q)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
inline inline
unwrap_check(const Col<eT>& A, const Row<eT>& B) ~partial_unwrap()
: M_local( (&A == reinterpret_cast<const Col<eT>*>(&B)) ? new Col<eT>(A
) : 0 )
, M ( (&A == reinterpret_cast<const Col<eT>*>(&B)) ? (*M_local)
: A )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT>& M;
};
template<typename eT>
class partial_unwrap< Col<eT> >
{
public:
inline inline
unwrap_check(const Col<eT>& A, const Col<eT>& B) partial_unwrap(const Col<eT>& A)
: M_local( (&A == reinterpret_cast<const Col<eT>*>(&B)) ? new Col<eT>(A : do_trans(false)
) : 0 ) , do_times(false)
, M ( (&A == reinterpret_cast<const Col<eT>*>(&B)) ? (*M_local) , val (1)
: A ) , M (A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
inline inline
unwrap_check(const Col<eT>& A, const subview<eT>& B) ~partial_unwrap()
: M_local( (&A == reinterpret_cast<const Col<eT>*>(&B.m)) ? new Col<eT>
(A) : 0 )
, M ( (&A == reinterpret_cast<const Col<eT>*>(&B.m)) ? (*M_local)
: A )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT>& M;
};
template<typename eT>
class partial_unwrap< Op< Col<eT>, op_trans> >
{
public:
inline inline
unwrap_check(const Col<eT>& A, const diagview<eT>& B) partial_unwrap(const Op< Col<eT>, op_trans>& A)
: M_local( (&A == reinterpret_cast<const Col<eT>*>(&B.m)) ? new Col<eT> : do_trans(true)
(A) : 0 ) , do_times(false)
, M ( (&A == reinterpret_cast<const Col<eT>*>(&B.m)) ? (*M_local) , val (1)
: A ) , M (A.m)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
inline inline
~unwrap_check() ~partial_unwrap()
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
if(M_local)
delete M_local;
} }
// the order below is important const bool do_trans;
const Col<eT>* M_local; const bool do_times;
const Col<eT>& M; const eT val;
const Mat<eT>& M;
}; };
template<typename T1, typename op_type> template<typename eT>
class unwrap_check< Op<T1, op_type> > class partial_unwrap< Op< Col<eT>, op_trans2> >
{ {
public: public:
typedef typename T1::elem_type elem_type;
//template<typename eT>
inline inline
unwrap_check(const Op<T1,op_type>& A, const Mat<elem_type>& B) partial_unwrap(const Op< Col<eT>, op_trans2>& A)
: M(A) : do_trans(true)
, do_times(true)
, val (A.aux)
, M (A.m)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
//template<typename eT>
inline inline
unwrap_check(const Op<T1,op_type>& A, const Row<elem_type>& B) ~partial_unwrap()
: M(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
//template<typename eT> const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT>& M;
};
template<typename eT>
class partial_unwrap< eOp<Col<eT>, eop_scalar_times> >
{
public:
inline inline
unwrap_check(const Op<T1,op_type>& A, const Col<elem_type>& B) partial_unwrap(const eOp<Col<eT>,eop_scalar_times>& A)
: M(A) : do_trans(false)
, do_times(true)
, val (A.aux)
, M (A.P.Q)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
inline inline
~unwrap_check() ~partial_unwrap()
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
const Mat<elem_type> M; const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT>& M;
}; };
template<typename T1, typename T2, typename glue_type> //
class unwrap_check< Glue<T1, T2, glue_type> >
template<typename T1>
class partial_unwrap_check
{ {
public: public:
typedef typename T1::elem_type elem_type;
inline typedef typename T1::elem_type eT;
unwrap_check(const Glue<T1, T2, glue_type>& A, const Mat<elem_type>& B)
: M(A) inline partial_unwrap_check(const T1& A, const Mat<eT>& B)
: do_trans(false)
, do_times(false)
, val (1)
, M (A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
inline inline
unwrap_check(const Glue<T1, T2, glue_type>& A, const Row<elem_type>& B) ~partial_unwrap_check()
: M(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT> M;
};
template<typename T1>
class partial_unwrap_check< Op<T1, op_trans> >
{
public:
typedef typename T1::elem_type eT;
inline inline
unwrap_check(const Glue<T1, T2, glue_type>& A, const Col<elem_type>& B) partial_unwrap_check(const Op<T1,op_trans>& A, const Mat<eT>& B)
: M(A) : do_trans(true)
, do_times(false)
, val (1)
, M (A.m)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
inline inline
~unwrap_check() ~partial_unwrap_check()
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
const Mat<elem_type> M; const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT> M;
}; };
//template<> template<typename T1>
template<typename eT> class partial_unwrap_check< Op<T1, op_trans2> >
class unwrap_check< subview<eT> >
{ {
public: public:
template<typename T2> typedef typename T1::elem_type eT;
inline unwrap_check(const subview<eT>& A, const T2& junk)
: M(A) inline
partial_unwrap_check(const Op<T1,op_trans2>& A, const Mat<eT>& B)
: do_trans(true)
, do_times(true)
, val (A.aux)
, M (A.m)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
const Mat<eT> M; inline
~partial_unwrap_check()
};
//template<>
template<typename eT>
class unwrap_check< diagview<eT> >
{
public:
template<typename T2>
inline unwrap_check(const diagview<eT> & A, const T2& junk)
: M(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT> M; const Mat<eT> M;
}; };
//! if the given object in not a matrix, unwrap it into the given 'out' mat
rix (i.e. do not create another matrix)
//! and provide a reference to the 'out' matrix.
//! if the given object is a matrix, set the size of the 'out' matrix to be
the same as the given object
//! and provide a reference to the given object.
template<typename T1> template<typename T1>
class unwrap_write class partial_unwrap_check< eOp<T1, eop_scalar_times> >
{
private:
template<typename eT> inline unwrap_write(Mat<eT>& out, const T1& in
);
template<typename eT> inline unwrap_write(Row<eT>& out, const T1& in
);
template<typename eT> inline unwrap_write(Col<eT>& out, const T1& in
);
template<typename eT> inline unwrap_write(subview<eT>& out, const T1& in
);
template<typename eT> inline unwrap_write(diagview<eT>& out, const T1& in
);
};
//template <>
template<typename eT>
class unwrap_write< Mat<eT> >
{ {
public: public:
typedef typename T1::elem_type eT;
inline inline
unwrap_write(Mat<eT>& out, const Mat<eT>& A) partial_unwrap_check(const eOp<T1,eop_scalar_times>& A, const Mat<eT>& B)
: M(A) : do_trans(false)
, do_times(true)
, val (A.aux)
, M (A.P.Q)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
out.copy_size(A);
} }
inline inline
unwrap_write(Row<eT>& out, const Mat<eT>& A) ~partial_unwrap_check()
: M(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
out.copy_size(A);
} }
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT> M;
};
template<typename eT>
class partial_unwrap_check< Mat<eT> >
{
public:
inline inline
unwrap_write(Col<eT>& out, const Mat<eT>& A) partial_unwrap_check(const Mat<eT>& A, const Mat<eT>& B)
: M(A) : do_trans(false)
, do_times(false)
, val (1)
, M_local ( (&A == &B) ? new Mat<eT>(A) : 0 )
, M ( (&A == &B) ? (*M_local) : A )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
out.copy_size(A);
} }
inline inline
~unwrap_write() ~partial_unwrap_check()
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
if(M_local)
{
delete M_local;
}
} }
// the order below is important
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT>* M_local;
const Mat<eT>& M; const Mat<eT>& M;
}; };
//template <>
template<typename eT> template<typename eT>
class unwrap_write< Row<eT> > class partial_unwrap_check< Op< Mat<eT>, op_trans> >
{ {
public: public:
inline inline
unwrap_write(Mat<eT>& out, const Row<eT>& A) partial_unwrap_check(const Op< Mat<eT>, op_trans>& A, const Mat<eT>& B)
: M(A) : do_trans(true)
, do_times(false)
, val (1)
, M_local ( (&A.m == &B) ? new Mat<eT>(A.m) : 0 )
, M ( (&A.m == &B) ? (*M_local) : A.m )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
out.copy_size(A);
} }
inline inline
unwrap_write(Row<eT>& out, const Row<eT>& A) ~partial_unwrap_check()
: M(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
out.copy_size(A);
}
inline if(M_local)
unwrap_write(Col<eT>& out, const Row<eT>& A) {
: M(A) delete M_local;
{ }
arma_extra_debug_sigprint();
out.copy_size(A);
}
inline
~unwrap_write()
{
} }
const Row<eT>& M; // the order below is important
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT>* M_local;
const Mat<eT>& M;
}; };
//template <>
template<typename eT> template<typename eT>
class unwrap_write< Col<eT> > class partial_unwrap_check< Op< Mat<eT>, op_trans2> >
{ {
public: public:
inline inline
unwrap_write(Mat<eT>& out, const Col<eT>& A) partial_unwrap_check(const Op< Mat<eT>, op_trans2>& A, const Mat<eT>& B)
: M(A) : do_trans(true)
, do_times(true)
, val (A.aux)
, M_local ( (&A.m == &B) ? new Mat<eT>(A.m) : 0 )
, M ( (&A.m == &B) ? (*M_local) : A.m )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
out.copy_size(A);
} }
inline inline
unwrap_write(Row<eT>& out, const Col<eT>& A) ~partial_unwrap_check()
: M(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
out.copy_size(A);
if(M_local)
{
delete M_local;
}
} }
// the order below is important
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT>* M_local;
const Mat<eT>& M;
};
template<typename eT>
class partial_unwrap_check< eOp<Mat<eT>, eop_scalar_times> >
{
public:
inline inline
unwrap_write(Col<eT>& out, const Col<eT>& A) partial_unwrap_check(const eOp<Mat<eT>,eop_scalar_times>& A, const Mat<eT
: M(A) >& B)
: do_trans(false)
, do_times(true)
, val (A.aux)
, M (A.P.Q)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
out.copy_size(A);
} }
inline inline
~unwrap_write() ~partial_unwrap_check()
{ {
arma_extra_debug_sigprint();
} }
const Col<eT>& M; const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT>& M;
}; };
template<typename T1, typename op_type> template<typename eT>
class unwrap_write< Op<T1, op_type> > class partial_unwrap_check< Row<eT> >
{ {
public: public:
typedef typename T1::elem_type eT;
//template<typename eT>
inline inline
unwrap_write(Mat<eT>& out, const Op<T1,op_type>& A) partial_unwrap_check(const Row<eT>& A, const Mat<eT>& B)
: M(out) : do_trans(false)
, do_times(false)
, val (1)
, M_local ( (&A == &B) ? new Mat<eT>(A) : 0 )
, M ( (&A == &B) ? (*M_local) : A )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
out = A;
} }
//template<typename eT>
inline inline
unwrap_write(Row<eT>& out, const Op<T1,op_type>& A) ~partial_unwrap_check()
: M(out)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
out = A;
if(M_local)
{
delete M_local;
}
} }
//template<typename eT> // the order below is important
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT>* M_local;
const Mat<eT>& M;
};
template<typename eT>
class partial_unwrap_check< Op< Row<eT>, op_trans> >
{
public:
inline inline
unwrap_write(Col<eT>& out, const Op<T1,op_type>& A) partial_unwrap_check(const Op< Row<eT>, op_trans>& A, const Mat<eT>& B)
: M(out) : do_trans(true)
, do_times(false)
, val (1)
, M_local ( (&A.m == &B) ? new Mat<eT>(A.m) : 0 )
, M ( (&A.m == &B) ? (*M_local) : A.m )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
out = A;
} }
inline inline
~unwrap_write() ~partial_unwrap_check()
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
if(M_local)
{
delete M_local;
}
} }
// the order below is important
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT>* M_local;
const Mat<eT>& M; const Mat<eT>& M;
}; };
template<typename T1, typename T2, typename glue_type> template<typename eT>
class unwrap_write< Glue<T1, T2, glue_type> > class partial_unwrap_check< Op< Row<eT>, op_trans2> >
{ {
public: public:
typedef typename T1::elem_type eT;
inline inline
unwrap_write(Mat<eT>& out, const Glue<T1, T2, glue_type>& A) partial_unwrap_check(const Op< Row<eT>, op_trans2>& A, const Mat<eT>& B)
: M(out) : do_trans(true)
, do_times(true)
, val (A.aux)
, M_local ( (&A.m == &B) ? new Mat<eT>(A.m) : 0 )
, M ( (&A.m == &B) ? (*M_local) : A.m )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
out = A;
} }
inline inline
unwrap_write(Row<eT>& out, const Glue<T1, T2, glue_type>& A) ~partial_unwrap_check()
: M(out)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
out = A;
if(M_local)
{
delete M_local;
}
} }
// the order below is important
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT>* M_local;
const Mat<eT>& M;
};
template<typename eT>
class partial_unwrap_check< eOp<Row<eT>, eop_scalar_times> >
{
public:
inline inline
unwrap_write(Col<eT>& out, const Glue<T1, T2, glue_type>& A) partial_unwrap_check(const eOp<Row<eT>,eop_scalar_times>& A, const Mat<eT
: M(out) >& B)
: do_trans(false)
, do_times(true)
, val (A.aux)
, M (A.P.Q)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
out = A;
} }
inline inline
~unwrap_write() ~partial_unwrap_check()
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT>& M; const Mat<eT>& M;
}; };
//template<>
template<typename eT> template<typename eT>
class unwrap_write< subview<eT> > class partial_unwrap_check< Col<eT> >
{ {
public: public:
inline inline
unwrap_write(Mat<eT>& out, const subview<eT>& A) partial_unwrap_check(const Col<eT>& A, const Mat<eT>& B)
: M(out) : do_trans(false)
, do_times(false)
, val (1)
, M_local ( (&A == &B) ? new Mat<eT>(A) : 0 )
, M ( (&A == &B) ? (*M_local) : A )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
out = A;
} }
inline inline
unwrap_write(Row<eT>& out, const subview<eT>& A) ~partial_unwrap_check()
: M(out)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
out = A;
if(M_local)
{
delete M_local;
}
} }
// the order below is important
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT>* M_local;
const Mat<eT>& M;
};
template<typename eT>
class partial_unwrap_check< Op< Col<eT>, op_trans> >
{
public:
inline inline
unwrap_write(Col<eT>& out, const subview<eT>& A) partial_unwrap_check(const Op< Col<eT>, op_trans>& A, const Mat<eT>& B)
: M(out) : do_trans(true)
, do_times(false)
, val (1)
, M_local ( (&A.m == &B) ? new Mat<eT>(A.m) : 0 )
, M ( (&A.m == &B) ? (*M_local) : A.m )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
out = A;
} }
inline inline
~unwrap_write() ~partial_unwrap_check()
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
if(M_local)
{
delete M_local;
}
} }
// the order below is important
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT>* M_local;
const Mat<eT>& M; const Mat<eT>& M;
}; };
//template<>
template<typename eT> template<typename eT>
class unwrap_write< diagview<eT> > class partial_unwrap_check< Op< Col<eT>, op_trans2> >
{ {
public: public:
inline inline
unwrap_write(Mat<eT>& out, const diagview<eT>& A) partial_unwrap_check(const Op< Mat<eT>, op_trans2>& A, const Mat<eT>& B)
: M(out) : do_trans(true)
, do_times(true)
, val (A.aux)
, M_local ( (&A.m == &B) ? new Mat<eT>(A.m) : 0 )
, M ( (&A.m == &B) ? (*M_local) : A.m )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
out = A;
} }
inline inline
unwrap_write(Row<eT>& out, const diagview<eT>& A) ~partial_unwrap_check()
: M(out)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
out = A;
if(M_local)
{
delete M_local;
}
} }
// the order below is important
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT>* M_local;
const Mat<eT>& M;
};
template<typename eT>
class partial_unwrap_check< eOp<Col<eT>, eop_scalar_times> >
{
public:
inline inline
unwrap_write(Col<eT>& out, const diagview<eT>& A) partial_unwrap_check(const eOp<Col<eT>,eop_scalar_times>& A, const Mat<eT
: M(out) >& B)
: do_trans(false)
, do_times(true)
, val (A.aux)
, M (A.P.Q)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
out = A;
} }
inline inline
~unwrap_write() ~partial_unwrap_check()
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
const bool do_trans;
const bool do_times;
const eT val;
const Mat<eT>& M; const Mat<eT>& M;
}; };
//! @} //! @}
 End of changes. 202 change blocks. 
470 lines changed or deleted 631 lines changed or added


 unwrap_cube.hpp   unwrap_cube.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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 unwrap_cube //! \addtogroup unwrap_cube
//! @{ //! @{
template<typename T1> template<typename T1>
class unwrap_cube class unwrap_cube
{ {
public: public:
inline unwrap_cube(const T1& A)
{
arma_type_check< is_arma_cube_type<T1>::value == false >::apply();
}
};
template<typename eT> typedef typename T1::elem_type eT;
class unwrap_cube< Cube<eT> >
{
public:
inline unwrap_cube(const Cube<eT>& A) inline
unwrap_cube(const T1& A)
: M(A) : M(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
const Cube<eT>& M; const Cube<eT> M;
}; };
template<typename T1, typename op_type> template<typename eT>
class unwrap_cube< OpCube<T1, op_type> > class unwrap_cube< Cube<eT> >
{ {
public: public:
inline unwrap_cube(const OpCube<T1, op_type>& A) inline
unwrap_cube(const Cube<eT>& A)
: M(A) : M(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
typedef typename T1::elem_type elem_type; const Cube<eT>& M;
const Cube<elem_type> M;
}; };
template<typename T1, typename T2, typename glue_cube_type> //
class unwrap_cube< GlueCube<T1, T2, glue_cube_type> > //
{ //
public:
inline unwrap_cube(const GlueCube<T1, T2, glue_cube_type>& A)
: M(A)
{
arma_extra_debug_sigprint();
}
typedef typename T1::elem_type elem_type;
const Cube<elem_type> M;
};
template<typename eT> template<typename T1>
class unwrap_cube< subview_cube<eT> > class unwrap_cube_check
{ {
public: typedef typename T1::elem_type eT;
inline unwrap_cube(const subview_cube<eT>& A) inline
unwrap_cube_check(const T1& A, const Cube<eT>& B)
: M(A) : M(A)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
arma_type_check< is_arma_cube_type<T1>::value == false >::apply();
} }
const Cube<eT> M; const Cube<eT> M;
};
//
//
//
template<typename T1>
class unwrap_cube_check
{
private:
template<typename eT> inline unwrap_cube_check(const T1& A, const Cube<eT
>& B);
template<typename eT> inline unwrap_cube_check(const T1& A, const subview
_cube<eT>& B);
}; };
template<typename eT> template<typename eT>
class unwrap_cube_check< Cube<eT> > class unwrap_cube_check< Cube<eT> >
{ {
public: public:
inline inline
unwrap_cube_check(const Cube<eT>& A, const Cube<eT>& B) unwrap_cube_check(const Cube<eT>& A, const Cube<eT>& B)
: M_local( (&A == reinterpret_cast<const Cube<eT>*>(&B)) ? new Cube<eT> : M_local( (&A == &B) ? new Cube<eT>(A) : 0 )
(A) : 0 ) , M ( (&A == &B) ? (*M_local) : A )
, M ( (&A == reinterpret_cast<const Cube<eT>*>(&B)) ? (*M_local)
: A )
{
arma_extra_debug_sigprint();
}
inline
unwrap_cube_check(const Cube<eT>& A, const subview_cube<eT>& B)
: M_local( (&A == reinterpret_cast<const Cube<eT>*>(&B.m)) ? new Cube<e
T>(A) : 0 )
, M ( (&A == reinterpret_cast<const Cube<eT>*>(&B.m)) ? (*M_local)
: A )
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
} }
inline inline
~unwrap_cube_check() ~unwrap_cube_check()
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
if(M_local) if(M_local)
skipping to change at line 140 skipping to change at line 102
delete M_local; delete M_local;
} }
} }
// the order below is important // the order below is important
const Cube<eT>* M_local; const Cube<eT>* M_local;
const Cube<eT>& M; const Cube<eT>& M;
}; };
template<typename T1, typename op_type>
class unwrap_cube_check< OpCube<T1, op_type> >
{
public:
typedef typename T1::elem_type elem_type;
inline
unwrap_cube_check(const OpCube<T1,op_type>& A, const Cube<elem_type>& B)
: M(A)
{
arma_extra_debug_sigprint();
}
inline
~unwrap_cube_check()
{
arma_extra_debug_sigprint();
}
const Cube<elem_type> M;
};
template<typename T1, typename T2, typename glue_cube_type>
class unwrap_cube_check< GlueCube<T1, T2, glue_cube_type> >
{
public:
typedef typename T1::elem_type elem_type;
inline
unwrap_cube_check(const GlueCube<T1, T2, glue_cube_type>& A, const Cube<e
lem_type>& B)
: M(A)
{
arma_extra_debug_sigprint();
}
inline
~unwrap_cube_check()
{
arma_extra_debug_sigprint();
}
const Cube<elem_type> M;
};
template<typename eT>
class unwrap_cube_check< subview_cube<eT> >
{
public:
template<typename T2>
inline unwrap_cube_check(const subview_cube<eT>& A, const T2& junk)
: M(A)
{
arma_extra_debug_sigprint();
}
const Cube<eT> M;
};
//! if the given object in not a cube, unwrap it into the given 'out' cube
(i.e. do not create another cube)
//! and provide a reference to the 'out' cube.
//! if the given object is a cube, set the size of the 'out' cube to be the
same as the given object
//! and provide a reference to the given object.
template<typename T1>
class unwrap_cube_write
{
private:
template<typename eT> inline unwrap_cube_write(Cube<eT>& out, const T1& i
n);
};
//template <>
template<typename eT>
class unwrap_cube_write< Cube<eT> >
{
public:
inline
unwrap_cube_write(Cube<eT>& out, const Cube<eT>& A)
: M(A)
{
arma_extra_debug_sigprint();
out.copy_size(A);
}
inline
~unwrap_cube_write()
{
arma_extra_debug_sigprint();
}
const Cube<eT>& M;
};
template<typename T1, typename op_type>
class unwrap_cube_write< OpCube<T1, op_type> >
{
public:
typedef typename T1::elem_type eT;
//template<typename eT>
inline
unwrap_cube_write(Cube<eT>& out, const OpCube<T1,op_type>& A)
: M(out)
{
arma_extra_debug_sigprint();
out = A;
}
inline
~unwrap_cube_write()
{
arma_extra_debug_sigprint();
}
const Cube<eT>& M;
};
template<typename T1, typename T2, typename glue_type>
class unwrap_cube_write< GlueCube<T1, T2, glue_type> >
{
public:
typedef typename T1::elem_type eT;
inline
unwrap_cube_write(Cube<eT>& out, const GlueCube<T1, T2, glue_type>& A)
: M(out)
{
arma_extra_debug_sigprint();
out = A;
}
inline
~unwrap_cube_write()
{
arma_extra_debug_sigprint();
}
const Cube<eT>& M;
};
//template<>
template<typename eT>
class unwrap_cube_write< subview_cube<eT> >
{
public:
inline
unwrap_cube_write(Cube<eT>& out, const subview_cube<eT>& A)
: M(out)
{
arma_extra_debug_sigprint();
out = A;
}
inline
~unwrap_cube_write()
{
arma_extra_debug_sigprint();
}
const Cube<eT>& M;
};
//! @} //! @}
 End of changes. 16 change blocks. 
238 lines changed or deleted 23 lines changed or added


 wall_clock_meat.hpp   wall_clock_meat.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 2 lines changed or added


 wall_clock_proto.hpp   wall_clock_proto.hpp 
// Copyright (C) 2009 NICTA // Copyright (C) 2010 NICTA and the authors listed below
// http://nicta.com.au
// //
// Authors: // Authors:
// - Conrad Sanderson (conradsand at ieee dot org) // - Conrad Sanderson (conradsand at ieee dot org)
// //
// 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
skipping to change at line 23 skipping to change at line 24
// (see http://www.opensource.org/licenses for more info) // (see http://www.opensource.org/licenses for more info)
//! \addtogroup wall_clock //! \addtogroup wall_clock
//! @{ //! @{
//! Class for measuring time intervals //! Class for measuring time intervals
class wall_clock class wall_clock
{ {
public: public:
inline wall_clock(); inline wall_clock();
inline ~wall_clock(); inline ~wall_clock();
inline void tic(); //!< start the timer inline void tic(); //!< start the timer
inline double toc(); //!< return the number of seconds since the last ca ll to tic() inline double toc(); //!< return the number of seconds since the last ca ll to tic()
private: private:
bool valid; bool valid;
#if defined(ARMA_USE_BOOST_DATE) #if defined(ARMA_USE_BOOST_DATE)
 End of changes. 2 change blocks. 
2 lines changed or deleted 3 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/