| arma_ostream_meat.hpp | | arma_ostream_meat.hpp | |
|
| // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) | | // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2008-2010 Conrad Sanderson | | // Copyright (C) 2008-2011 Conrad Sanderson | |
| // | | // | |
| // This file is part of the Armadillo C++ library. | | // This file is part of the Armadillo C++ library. | |
| // It is provided without any warranty of fitness | | // It is provided without any warranty of fitness | |
| // for any purpose. You can redistribute this file | | // for any purpose. You can redistribute this file | |
| // and/or modify it under the terms of the GNU | | // and/or modify it under the terms of the GNU | |
| // Lesser General Public License (LGPL) as published | | // Lesser General Public License (LGPL) as published | |
| // by the Free Software Foundation, either version 3 | | // by the Free Software Foundation, either version 3 | |
| // of the License or (at your option) any later version. | | // of the License or (at your option) any later version. | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| | | | |
| skipping to change at line 132 | | skipping to change at line 132 | |
| 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; | |
| } | | } | |
| | | | |
|
| | | template<typename eT> | |
| | | inline | |
| | | void | |
| | | arma_ostream::print_elem_zero(std::ostream& o) | |
| | | { | |
| | | const std::streamsize orig_precision = o.precision(); | |
| | | | |
| | | o.precision(0); | |
| | | | |
| | | o << eT(0); | |
| | | | |
| | | o.precision(orig_precision); | |
| | | } | |
| | | | |
| //! 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) | |
| { | | { | |
| if(x != eT(0)) | | if(x != eT(0)) | |
| { | | { | |
| o << x; | | o << x; | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| const std::streamsize orig_precision = o.precision(); | | arma_ostream::print_elem_zero<eT>(o); | |
| | | | |
| 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 ! | | | |
| template<typename T> | | template<typename T> | |
|
| arma_inline | | inline | |
| void | | void | |
| arma_ostream::print_elem(std::ostream& o, const std::complex<T>& x) | | arma_ostream::print_elem(std::ostream& o, const std::complex<T>& x) | |
| { | | { | |
| if( (x.real() != T(0)) || (x.imag() != T(0)) ) | | if( (x.real() != T(0)) || (x.imag() != T(0)) ) | |
| { | | { | |
| std::ostringstream ss; | | std::ostringstream ss; | |
| ss.flags(o.flags()); | | ss.flags(o.flags()); | |
| //ss.imbue(o.getloc()); | | //ss.imbue(o.getloc()); | |
| ss.precision(o.precision()); | | ss.precision(o.precision()); | |
| | | | |
| | | | |
| skipping to change at line 187 | | skipping to change at line 194 | |
| //! 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(); | |
| | | | |
| const arma_ostream_state stream_state(o); | | const arma_ostream_state stream_state(o); | |
| | | | |
|
| u32 cell_width; | | const u32 cell_width = modify ? arma_ostream::modify_stream(o, m.memptr()
, m.n_elem) : o.width(); | |
| | | | |
|
| if(modify == true) | | const u32 m_n_rows = m.n_rows; | |
| { | | const u32 m_n_cols = m.n_cols; | |
| cell_width = arma_ostream::modify_stream(o, m.memptr(), m.n_elem); | | | |
| } | | | |
| else | | | |
| { | | | |
| cell_width = o.width(); // copy the user's cell width | | | |
| } | | | |
| | | | |
|
| if(cell_width > 0) | | if(m_n_cols > 0) | |
| { | | { | |
|
| for(u32 row=0; row < m.n_rows; ++row) | | if(cell_width > 0) | |
| { | | { | |
|
| for(u32 col=0; col < m.n_cols; ++col) | | for(u32 row=0; row < m_n_rows; ++row) | |
| { | | { | |
|
| // the cell width appears to be reset after each element is printed | | for(u32 col=0; col < m_n_cols; ++col) | |
| , | | { | |
| // hence we need to restore it | | // the cell width appears to be reset after each element is print | |
| o.width(cell_width); | | ed, | |
| arma_ostream::print_elem(o, m.at(row,col)); | | // hence we need to restore it | |
| } | | o.width(cell_width); | |
| | | arma_ostream::print_elem(o, m.at(row,col)); | |
| | | } | |
| | | | |
|
| o << '\n'; | | o << '\n'; | |
| | | } | |
| } | | } | |
|
| } | | else | |
| else | | | |
| { | | | |
| for(u32 row=0; row < m.n_rows; ++row) | | | |
| { | | { | |
|
| for(u32 col=0; col < m.n_cols-1; ++col) | | for(u32 row=0; row < m_n_rows; ++row) | |
| { | | { | |
|
| arma_ostream::print_elem(o, m.at(row,col)); | | for(u32 col=0; col < m_n_cols-1; ++col) | |
| o << ' '; | | { | |
| } | | arma_ostream::print_elem(o, m.at(row,col)); | |
| | | o << ' '; | |
| | | } | |
| | | | |
|
| arma_ostream::print_elem(o, m.at(row, m.n_cols-1)); | | arma_ostream::print_elem(o, m.at(row, m_n_cols-1)); | |
| o << '\n'; | | o << '\n'; | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| o.flush(); | | o.flush(); | |
| stream_state.restore(o); | | stream_state.restore(o); | |
| } | | } | |
| | | | |
| //! Print a cube to the specified stream | | //! Print a cube to the specified stream | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| arma_ostream::print(std::ostream& o, const Cube<eT>& x, const bool modify) | | arma_ostream::print(std::ostream& o, const Cube<eT>& x, const bool modify) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const arma_ostream_state stream_state(o); | | const arma_ostream_state stream_state(o); | |
| | | | |
|
| u32 cell_width; | | const u32 cell_width = modify ? arma_ostream::modify_stream(o, x.memptr() | |
| | | , x.n_elem) : o.width(); | |
| if(modify == true) | | | |
| { | | | |
| cell_width = arma_ostream::modify_stream(o, x.memptr(), x.n_elem); | | | |
| } | | | |
| else | | | |
| { | | | |
| cell_width = o.width(); | | | |
| } | | | |
| | | | |
| for(u32 slice=0; slice < x.n_slices; ++slice) | | for(u32 slice=0; slice < x.n_slices; ++slice) | |
| { | | { | |
| o << "[cube slice " << slice << ']' << '\n'; | | o << "[cube slice " << slice << ']' << '\n'; | |
| o.width(cell_width); | | o.width(cell_width); | |
| arma_ostream::print(o, x.slice(slice), false); | | arma_ostream::print(o, x.slice(slice), false); | |
| o << '\n'; | | o << '\n'; | |
| } | | } | |
| | | | |
| stream_state.restore(o); | | stream_state.restore(o); | |
| | | | |
| skipping to change at line 277 | | skipping to change at line 272 | |
| inline | | inline | |
| void | | void | |
| arma_ostream::print(std::ostream& o, const field<oT>& x) | | arma_ostream::print(std::ostream& o, const field<oT>& x) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const arma_ostream_state stream_state(o); | | const arma_ostream_state stream_state(o); | |
| | | | |
| const std::streamsize cell_width = o.width(); | | const std::streamsize cell_width = o.width(); | |
| | | | |
|
| for(u32 col=0; col<x.n_cols; ++col) | | const u32 x_n_rows = x.n_rows; | |
| | | const u32 x_n_cols = x.n_cols; | |
| | | | |
| | | for(u32 col=0; col<x_n_cols; ++col) | |
| { | | { | |
| o << "[field column " << col << ']' << '\n'; | | o << "[field column " << col << ']' << '\n'; | |
|
| for(u32 row=0; row<x.n_rows; ++row) | | | |
| | | for(u32 row=0; row<x_n_rows; ++row) | |
| { | | { | |
| o.width(cell_width); | | o.width(cell_width); | |
| o << x.at(row,col) << '\n'; | | o << x.at(row,col) << '\n'; | |
| } | | } | |
| | | | |
| o << '\n'; | | o << '\n'; | |
| } | | } | |
| | | | |
| o.flush(); | | o.flush(); | |
| stream_state.restore(o); | | stream_state.restore(o); | |
| | | | |
| skipping to change at line 306 | | skipping to change at line 305 | |
| inline | | inline | |
| void | | void | |
| arma_ostream::print(std::ostream& o, const subview_field<oT>& x) | | arma_ostream::print(std::ostream& o, const subview_field<oT>& x) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const arma_ostream_state stream_state(o); | | const arma_ostream_state stream_state(o); | |
| | | | |
| const std::streamsize cell_width = o.width(); | | const std::streamsize cell_width = o.width(); | |
| | | | |
|
| for(u32 col=0; col<x.n_cols; ++col) | | const u32 x_n_rows = x.n_rows; | |
| | | const u32 x_n_cols = x.n_cols; | |
| | | | |
| | | for(u32 col=0; col<x_n_cols; ++col) | |
| { | | { | |
|
| o << "[subfield column " << col << ']' << '\n'; | | o << "[field column " << col << ']' << '\n'; | |
| for(u32 row=0; row<x.n_rows; ++row) | | for(u32 row=0; row<x_n_rows; ++row) | |
| { | | { | |
| o.width(cell_width); | | o.width(cell_width); | |
| o << x.at(row,col) << '\n'; | | o << x.at(row,col) << '\n'; | |
| } | | } | |
| | | | |
| o << '\n'; | | o << '\n'; | |
| } | | } | |
| | | | |
| o.flush(); | | o.flush(); | |
| stream_state.restore(o); | | stream_state.restore(o); | |
| | | | |
End of changes. 21 change blocks. |
| 55 lines changed or deleted | | 58 lines changed or added | |
|
| constants.hpp | | constants.hpp | |
|
| // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) | | // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2008-2010 Conrad Sanderson | | // Copyright (C) 2008-2011 Conrad Sanderson | |
| // | | // | |
| // This file is part of the Armadillo C++ library. | | // This file is part of the Armadillo C++ library. | |
| // It is provided without any warranty of fitness | | // It is provided without any warranty of fitness | |
| // for any purpose. You can redistribute this file | | // for any purpose. You can redistribute this file | |
| // and/or modify it under the terms of the GNU | | // and/or modify it under the terms of the GNU | |
| // Lesser General Public License (LGPL) as published | | // Lesser General Public License (LGPL) as published | |
| // by the Free Software Foundation, either version 3 | | // by the Free Software Foundation, either version 3 | |
| // of the License or (at your option) any later version. | | // of the License or (at your option) any later version. | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| //! \addtogroup constants | | //! \addtogroup constants | |
| //! @{ | | //! @{ | |
| | | | |
|
| // the long lengths of the constants are for future support of "long double | | namespace priv | |
| " | | { | |
| // and any smart compiler that does high-precision computation at compile-t | | class Math_helper | |
| ime | | { | |
| | | public: | |
| | | | |
| | | template<typename eT> | |
| | | static | |
| | | typename arma_float_only<eT>::result | |
| | | nan(typename arma_float_only<eT>::result* junk = 0) | |
| | | { | |
| | | arma_ignore(junk); | |
| | | | |
| | | if(std::numeric_limits<eT>::has_quiet_NaN == true) | |
| | | { | |
| | | return std::numeric_limits<eT>::quiet_NaN(); | |
| | | } | |
| | | else | |
| | | { | |
| | | const eT a = eT(0); | |
| | | const eT b = eT(0); | |
| | | | |
| | | return a / b; | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | static | |
| | | typename arma_cx_only<eT>::result | |
| | | nan(typename arma_cx_only<eT>::result* junk = 0) | |
| | | { | |
| | | arma_ignore(junk); | |
| | | | |
| | | typedef typename get_pod_type<eT>::result T; | |
| | | | |
| | | return eT( Math_helper::nan<T>(), Math_helper::nan<T>() ); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | static | |
| | | typename arma_integral_only<eT>::result | |
| | | nan(typename arma_integral_only<eT>::result* junk = 0) | |
| | | { | |
| | | arma_ignore(junk); | |
| | | | |
| | | return eT(0); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | static | |
| | | typename arma_float_only<eT>::result | |
| | | inf(typename arma_float_only<eT>::result* junk = 0) | |
| | | { | |
| | | arma_ignore(junk); | |
| | | | |
| | | if(std::numeric_limits<eT>::has_infinity == true) | |
| | | { | |
| | | return std::numeric_limits<eT>::infinity(); | |
| | | } | |
| | | else | |
| | | { | |
| | | const eT a = eT(1); | |
| | | const eT b = eT(0); | |
| | | | |
| | | return a / b; | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | static | |
| | | typename arma_cx_only<eT>::result | |
| | | inf(typename arma_cx_only<eT>::result* junk = 0) | |
| | | { | |
| | | arma_ignore(junk); | |
| | | | |
| | | typedef typename get_pod_type<eT>::result T; | |
| | | | |
| | | return eT( Math_helper::inf<T>(), Math_helper::inf<T>() ); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | static | |
| | | typename arma_integral_only<eT>::result | |
| | | inf(typename arma_integral_only<eT>::result* junk = 0) | |
| | | { | |
| | | arma_ignore(junk); | |
| | | | |
| | | return std::numeric_limits<eT>::max(); | |
| | | } | |
| | | | |
| | | }; | |
| | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| class Math | | class Math | |
| { | | { | |
| public: | | public: | |
| | | | |
|
| | | // the long lengths of the constants are for future support of "long doub | |
| | | le" | |
| | | // and any smart compiler that does high-precision computation at compile | |
| | | -time | |
| | | | |
| //! ratio of any circle's circumference to its diameter | | //! ratio of any circle's circumference to its diameter | |
|
| static const eT pi() { return eT(3.1415926535897932384626433832795
028841971693993751058209749445923078164062862089986280348253421170679); } | | static eT pi() { return eT(3.1415926535897932384626433832795028841
971693993751058209749445923078164062862089986280348253421170679); } | |
| | | | |
| //! base of the natural logarithm | | //! base of the natural logarithm | |
|
| static const eT e() { return eT(2.7182818284590452353602874713526
624977572470936999595749669676277240766303535475945713821785251664274); } | | static eT e() { return eT(2.7182818284590452353602874713526624977
572470936999595749669676277240766303535475945713821785251664274); } | |
| | | | |
| //! Euler's constant, aka Euler-Mascheroni constant | | //! Euler's constant, aka Euler-Mascheroni constant | |
|
| static const eT euler() { return eT(0.5772156649015328606065120900824
024310421593359399235988057672348848677267776646709369470632917467495); } | | static eT euler() { return eT(0.5772156649015328606065120900824024310
421593359399235988057672348848677267776646709369470632917467495); } | |
| | | | |
| //! golden ratio | | //! golden ratio | |
|
| static const eT gratio() { return eT(1.6180339887498948482045868343656
381177203091798057628621354486227052604628189024497072072041893911374); } | | static eT gratio() { return eT(1.6180339887498948482045868343656381177
203091798057628621354486227052604628189024497072072041893911374); } | |
| | | | |
| //! square root of 2 | | //! square root of 2 | |
|
| static const eT sqrt2() { return eT(1.4142135623730950488016887242096
980785696718753769480731766797379907324784621070388503875343276415727); } | | static eT sqrt2() { return eT(1.4142135623730950488016887242096980785
696718753769480731766797379907324784621070388503875343276415727); } | |
| | | | |
| //! the difference between 1 and the least value greater than 1 that is r
epresentable | | //! the difference between 1 and the least value greater than 1 that is r
epresentable | |
|
| static const eT eps() { return std::numeric_limits<eT>::epsilon();
} | | static eT eps() { return std::numeric_limits<eT>::epsilon(); } | |
| | | | |
| //! log of the minimum representable value | | //! log of the minimum representable value | |
|
| static const eT log_min() { static const eT out = std::log(std::numeric
_limits<eT>::min()); return out; } | | static eT log_min() { static const eT out = std::log(std::numeric_limit
s<eT>::min()); return out; } | |
| | | | |
| //! log of the maximum representable value | | //! log of the maximum representable value | |
|
| static const eT log_max() { static const eT out = std::log(std::numeric | | static eT log_max() { static const eT out = std::log(std::numeric_limit | |
| _limits<eT>::max()); return out; } | | s<eT>::max()); return out; } | |
| | | | |
| | | //! "not a number" | |
| | | static eT nan() { return priv::Math_helper::nan<eT>(); } | |
| | | | |
| | | //! infinity | |
| | | static eT inf() { return priv::Math_helper::inf<eT>(); } | |
| }; | | }; | |
| | | | |
| //! Physical constants taken from NIST and WolframAlpha on 2009-06-23 | | //! Physical constants taken from NIST and WolframAlpha on 2009-06-23 | |
| //! http://physics.nist.gov/cuu/Constants | | //! http://physics.nist.gov/cuu/Constants | |
| //! http://www.wolframalpha.com | | //! http://www.wolframalpha.com | |
| //! See also http://en.wikipedia.org/wiki/Physical_constant | | //! See also http://en.wikipedia.org/wiki/Physical_constant | |
| template<typename eT> | | template<typename eT> | |
| class Phy | | class Phy | |
| { | | { | |
| public: | | public: | |
| | | | |
| //! atomic mass constant (in kg) | | //! atomic mass constant (in kg) | |
|
| static const eT m_u() { return eT(1.660538782e-27); } | | static eT m_u() { return eT(1.660538782e-27); } | |
| | | | |
| //! Avogadro constant | | //! Avogadro constant | |
|
| static const eT N_A() { return eT(6.02214179e23); } | | static eT N_A() { return eT(6.02214179e23); } | |
| | | | |
| //! Boltzmann constant (in joules per kelvin) | | //! Boltzmann constant (in joules per kelvin) | |
|
| static const eT k() { return eT(1.3806504e-23); } | | static eT k() { return eT(1.3806504e-23); } | |
| | | | |
| //! Boltzmann constant (in eV/K) | | //! Boltzmann constant (in eV/K) | |
|
| static const eT k_evk() { return eT(8.617343e-5); } | | static eT k_evk() { return eT(8.617343e-5); } | |
| | | | |
| //! Bohr radius (in meters) | | //! Bohr radius (in meters) | |
|
| static const eT a_0() { return eT(0.52917720859e-10); } | | static eT a_0() { return eT(0.52917720859e-10); } | |
| | | | |
| //! Bohr magneton | | //! Bohr magneton | |
|
| static const eT mu_B() { return(927.400915e-26); } | | static eT mu_B() { return(927.400915e-26); } | |
| | | | |
| //! characteristic impedance of vacuum (in ohms) | | //! characteristic impedance of vacuum (in ohms) | |
|
| static const eT Z_0() { return eT(3.76730313461771e-2); } | | static eT Z_0() { return eT(3.76730313461771e-2); } | |
| | | | |
| //! conductance quantum (in siemens) | | //! conductance quantum (in siemens) | |
|
| static const eT G_0() { return eT(7.7480917004e-5); } | | static eT G_0() { return eT(7.7480917004e-5); } | |
| | | | |
| //! Coulomb's constant (in meters per farad) | | //! Coulomb's constant (in meters per farad) | |
|
| static const eT k_e() { return eT(8.9875517873681764e9); } | | static eT k_e() { return eT(8.9875517873681764e9); } | |
| | | | |
| //! electric constant (in farads per meter) | | //! electric constant (in farads per meter) | |
|
| static const eT eps_0() { return eT(8.85418781762039e-12); } | | static eT eps_0() { return eT(8.85418781762039e-12); } | |
| | | | |
| //! electron mass (in kg) | | //! electron mass (in kg) | |
|
| static const eT m_e() { return eT(9.10938215e-31); } | | static eT m_e() { return eT(9.10938215e-31); } | |
| | | | |
| //! electron volt (in joules) | | //! electron volt (in joules) | |
|
| static const eT eV() { return eT(1.602176487e-19); } | | static eT eV() { return eT(1.602176487e-19); } | |
| | | | |
| //! elementary charge (in coulombs) | | //! elementary charge (in coulombs) | |
|
| static const eT e() { return eT(1.602176487e-19); } | | static eT e() { return eT(1.602176487e-19); } | |
| | | | |
| //! Faraday constant (in coulombs) | | //! Faraday constant (in coulombs) | |
|
| static const eT F() { return eT(96485.3399); } | | static eT F() { return eT(96485.3399); } | |
| | | | |
| //! fine-structure constant | | //! fine-structure constant | |
|
| static const eT alpha() { return eT(7.2973525376e-3); } | | static eT alpha() { return eT(7.2973525376e-3); } | |
| | | | |
| //! inverse fine-structure constant | | //! inverse fine-structure constant | |
|
| static const eT alpha_inv() { return eT(137.035999679); } | | static eT alpha_inv() { return eT(137.035999679); } | |
| | | | |
| //! Josephson constant | | //! Josephson constant | |
|
| static const eT K_J() { return eT(483597.891e9); } | | static eT K_J() { return eT(483597.891e9); } | |
| | | | |
| //! magnetic constant (in henries per meter) | | //! magnetic constant (in henries per meter) | |
|
| static const eT mu_0() { return eT(1.25663706143592e-06); } | | static eT mu_0() { return eT(1.25663706143592e-06); } | |
| | | | |
| //! magnetic flux quantum (in webers) | | //! magnetic flux quantum (in webers) | |
|
| static const eT phi_0() { return eT(2.067833667e-15); } | | static eT phi_0() { return eT(2.067833667e-15); } | |
| | | | |
| //! molar gas constant (in joules per mole kelvin) | | //! molar gas constant (in joules per mole kelvin) | |
|
| static const eT R() { return eT(8.314472); } | | static eT R() { return eT(8.314472); } | |
| | | | |
| //! Newtonian constant of gravitation (in newton square meters per kilogr
am squared) | | //! Newtonian constant of gravitation (in newton square meters per kilogr
am squared) | |
|
| static const eT G() { return eT(6.67428e-11); } | | static eT G() { return eT(6.67428e-11); } | |
| | | | |
| //! Planck constant (in joule seconds) | | //! Planck constant (in joule seconds) | |
|
| static const eT h() { return eT(6.62606896e-34); } | | static eT h() { return eT(6.62606896e-34); } | |
| | | | |
| //! Planck constant over 2 pi, aka reduced Planck constant (in joule seco
nds) | | //! Planck constant over 2 pi, aka reduced Planck constant (in joule seco
nds) | |
|
| static const eT h_bar() { return eT(1.054571628e-34); } | | static eT h_bar() { return eT(1.054571628e-34); } | |
| | | | |
| //! proton mass (in kg) | | //! proton mass (in kg) | |
|
| static const eT m_p() { return eT(1.672621637e-27); } | | static eT m_p() { return eT(1.672621637e-27); } | |
| | | | |
| //! Rydberg constant (in reciprocal meters) | | //! Rydberg constant (in reciprocal meters) | |
|
| static const eT R_inf() { return eT(10973731.568527); } | | static eT R_inf() { return eT(10973731.568527); } | |
| | | | |
| //! speed of light in vacuum (in meters per second) | | //! speed of light in vacuum (in meters per second) | |
|
| static const eT c_0() { return eT(299792458.0); } | | static eT c_0() { return eT(299792458.0); } | |
| | | | |
| //! Stefan-Boltzmann constant | | //! Stefan-Boltzmann constant | |
|
| static const eT sigma() { return eT(5.670400e-8); } | | static eT sigma() { return eT(5.670400e-8); } | |
| | | | |
| //! von Klitzing constant (in ohms) | | //! von Klitzing constant (in ohms) | |
|
| static const eT R_k() { return eT(25812.807557); } | | static eT R_k() { return eT(25812.807557); } | |
| | | | |
| //! Wien wavelength displacement law constant | | //! Wien wavelength displacement law constant | |
|
| static const eT b() { return eT(2.8977685e-3); } | | static 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; | |
| | | | |
|
| | | namespace priv | |
| | | { | |
| | | | |
| | | template<typename eT> | |
| | | static | |
| | | arma_inline | |
| | | arma_hot | |
| | | typename arma_float_only<eT>::result | |
| | | most_neg(typename arma_float_only<eT>::result* junk = 0) | |
| | | { | |
| | | arma_ignore(junk); | |
| | | | |
| | | if(std::numeric_limits<eT>::has_infinity == true) | |
| | | { | |
| | | return -(std::numeric_limits<eT>::infinity()); | |
| | | } | |
| | | else | |
| | | { | |
| | | const eT a = eT(1); | |
| | | const eT b = eT(0); | |
| | | | |
| | | return -(a / b); | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | static | |
| | | arma_inline | |
| | | arma_hot | |
| | | typename arma_integral_only<eT>::result | |
| | | most_neg(typename arma_integral_only<eT>::result* junk = 0) | |
| | | { | |
| | | arma_ignore(junk); | |
| | | | |
| | | return std::numeric_limits<eT>::min(); | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | static | |
| | | arma_inline | |
| | | arma_hot | |
| | | typename arma_float_only<eT>::result | |
| | | most_pos(typename arma_float_only<eT>::result* junk = 0) | |
| | | { | |
| | | arma_ignore(junk); | |
| | | | |
| | | if(std::numeric_limits<eT>::has_infinity == true) | |
| | | { | |
| | | return std::numeric_limits<eT>::infinity(); | |
| | | } | |
| | | else | |
| | | { | |
| | | const eT a = eT(1); | |
| | | const eT b = eT(0); | |
| | | | |
| | | return a / b; | |
| | | } | |
| | | } | |
| | | | |
| | | template<typename eT> | |
| | | static | |
| | | arma_inline | |
| | | arma_hot | |
| | | typename arma_integral_only<eT>::result | |
| | | most_pos(typename arma_integral_only<eT>::result* junk = 0) | |
| | | { | |
| | | arma_ignore(junk); | |
| | | | |
| | | return std::numeric_limits<eT>::max(); | |
| | | } | |
| | | | |
| | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 41 change blocks. |
| 44 lines changed or deleted | | 216 lines changed or added | |
|
| diskio_meat.hpp | | diskio_meat.hpp | |
|
| // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) | | // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2008-2010 Conrad Sanderson | | // Copyright (C) 2008-2011 Conrad Sanderson | |
| // Copyright (C) 2009-2010 Ian Cullinan | | // Copyright (C) 2009-2010 Ian Cullinan | |
| // | | // | |
| // 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 322 | | skipping to change at line 322 | |
| const u32 N = ( (pos1 >= 0) && (pos2 >= 0) ) ? u32(pos2 - pos1) : 0; | | const u32 N = ( (pos1 >= 0) && (pos2 >= 0) ) ? u32(pos2 - pos1) : 0; | |
| | | | |
| f.clear(); | | f.clear(); | |
| f.seekg(pos1); | | f.seekg(pos1); | |
| | | | |
| podarray<unsigned char> data(N); | | podarray<unsigned char> data(N); | |
| | | | |
| unsigned char* ptr = data.memptr(); | | unsigned char* ptr = data.memptr(); | |
| | | | |
| f.clear(); | | f.clear(); | |
|
| f.read(reinterpret_cast<char*>(ptr), N); | | f.read( reinterpret_cast<char*>(ptr), std::streamsize(N) ); | |
| | | | |
| bool has_non_text_val = false; | | bool has_non_text_val = false; | |
| | | | |
| if(f.good() == true) | | if(f.good() == true) | |
| { | | { | |
| for(u32 i=0; i<N; ++i) | | for(u32 i=0; i<N; ++i) | |
| { | | { | |
| const unsigned char val = ptr[i]; | | const unsigned char val = ptr[i]; | |
| | | | |
| // the range checking can be made more elaborate | | // the range checking can be made more elaborate | |
| | | | |
| skipping to change at line 585 | | skipping to change at line 585 | |
| return save_okay; | | return save_okay; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| diskio::save_raw_binary(const Mat<eT>& x, std::ostream& f) | | diskio::save_raw_binary(const Mat<eT>& x, std::ostream& f) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| f.write(reinterpret_cast<const char*>(x.mem), x.n_elem*sizeof(eT)); | | f.write( reinterpret_cast<const char*>(x.mem), std::streamsize(x.n_elem*s
izeof(eT)) ); | |
| | | | |
| return f.good(); | | return f.good(); | |
| } | | } | |
| | | | |
| //! 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 | |
| bool | | bool | |
| 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) | |
| | | | |
| skipping to change at line 713 | | skipping to change at line 713 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| diskio::save_arma_binary(const Mat<eT>& x, std::ostream& f) | | diskio::save_arma_binary(const Mat<eT>& x, std::ostream& f) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| f << diskio::gen_bin_header(x) << '\n'; | | f << diskio::gen_bin_header(x) << '\n'; | |
| f << x.n_rows << ' ' << x.n_cols << '\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), std::streamsize(x.n_elem*s
izeof(eT)) ); | |
| | | | |
| return f.good(); | | return f.good(); | |
| } | | } | |
| | | | |
| //! Save a matrix as a PGM greyscale image | | //! Save a matrix as a PGM greyscale image | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| 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) | |
| { | | { | |
| | | | |
| skipping to change at line 779 | | skipping to change at line 779 | |
| | | | |
| 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) | |
| { | | { | |
| tmp[i] = u8( x.at(row,col) ); // TODO: add round() ? | | tmp[i] = u8( x.at(row,col) ); // TODO: add round() ? | |
| ++i; | | ++i; | |
| } | | } | |
| } | | } | |
| | | | |
|
| f.write(reinterpret_cast<const char*>(tmp.mem), n_elem); | | f.write(reinterpret_cast<const char*>(tmp.mem), std::streamsize(n_elem) )
; | |
| | | | |
| return f.good(); | | return f.good(); | |
| } | | } | |
| | | | |
| //! Save a matrix as a PGM greyscale image | | //! Save a matrix as a PGM greyscale image | |
| template<typename T> | | template<typename T> | |
| inline | | inline | |
| bool | | bool | |
| diskio::save_pgm_binary(const Mat< std::complex<T> >& x, const std::string&
final_name) | | diskio::save_pgm_binary(const Mat< std::complex<T> >& x, const std::string&
final_name) | |
| { | | { | |
| | | | |
| skipping to change at line 968 | | skipping to change at line 968 | |
| | | | |
| const u32 N = ( (pos1 >= 0) && (pos2 >= 0) ) ? u32(pos2 - pos1) : 0; | | const u32 N = ( (pos1 >= 0) && (pos2 >= 0) ) ? u32(pos2 - pos1) : 0; | |
| | | | |
| f.clear(); | | f.clear(); | |
| //f.seekg(0, ios::beg); | | //f.seekg(0, ios::beg); | |
| f.seekg(pos1); | | f.seekg(pos1); | |
| | | | |
| x.set_size(N / sizeof(eT), 1); | | x.set_size(N / sizeof(eT), 1); | |
| | | | |
| f.clear(); | | f.clear(); | |
|
| f.read( reinterpret_cast<char *>(x.memptr()), N); | | f.read( reinterpret_cast<char *>(x.memptr()), std::streamsize(N) ); | |
| | | | |
| return f.good(); | | return f.good(); | |
| } | | } | |
| | | | |
| //! 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 | |
| bool | | bool | |
| diskio::load_arma_ascii(Mat<eT>& x, const std::string& name, std::string& e
rr_msg) | | diskio::load_arma_ascii(Mat<eT>& x, const std::string& name, std::string& e
rr_msg) | |
| | | | |
| skipping to change at line 1083 | | skipping to change at line 1083 | |
| 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 Win
dows machine a newline could be two characters | | //f.seekg(1, ios::cur); // NOTE: this may not be portable, as on a Win
dows machine a newline could be two characters | |
| f.get(); | | 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()), std::streamsize(x.n_elem*
sizeof(eT)) ); | |
| | | | |
| load_okay = f.good(); | | load_okay = f.good(); | |
| } | | } | |
| else | | else | |
| { | | { | |
| load_okay = false; | | load_okay = false; | |
| err_msg = "incorrect header in "; | | err_msg = "incorrect header in "; | |
| } | | } | |
| | | | |
| return load_okay; | | return load_okay; | |
| | | | |
| skipping to change at line 1176 | | skipping to change at line 1176 | |
| | | | |
| if( (f_maxval > 0) || (f_maxval <= 65535) ) | | if( (f_maxval > 0) || (f_maxval <= 65535) ) | |
| { | | { | |
| x.set_size(f_n_rows,f_n_cols); | | x.set_size(f_n_rows,f_n_cols); | |
| | | | |
| if(f_maxval <= 255) | | if(f_maxval <= 255) | |
| { | | { | |
| const u32 n_elem = f_n_cols*f_n_rows; | | const u32 n_elem = f_n_cols*f_n_rows; | |
| podarray<u8> tmp(n_elem); | | podarray<u8> tmp(n_elem); | |
| | | | |
|
| f.read( reinterpret_cast<char*>(tmp.memptr()), n_elem); | | f.read( reinterpret_cast<char*>(tmp.memptr()), std::streamsize(n_el
em) ); | |
| | | | |
| u32 i = 0; | | u32 i = 0; | |
| | | | |
| //cout << "f_n_cols = " << f_n_cols << endl; | | //cout << "f_n_cols = " << f_n_cols << endl; | |
| //cout << "f_n_rows = " << f_n_rows << endl; | | //cout << "f_n_rows = " << f_n_rows << endl; | |
| | | | |
| 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) | |
| { | | { | |
| | | | |
| skipping to change at line 1198 | | skipping to change at line 1198 | |
| ++i; | | ++i; | |
| } | | } | |
| } | | } | |
| | | | |
| } | | } | |
| else | | else | |
| { | | { | |
| const u32 n_elem = f_n_cols*f_n_rows; | | const u32 n_elem = f_n_cols*f_n_rows; | |
| podarray<u16> tmp(n_elem); | | podarray<u16> tmp(n_elem); | |
| | | | |
|
| f.read( reinterpret_cast<char *>(tmp.memptr()), n_elem*2); | | f.read( reinterpret_cast<char *>(tmp.memptr()), std::streamsize(n_e
lem*2) ); | |
| | | | |
| 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) = eT(tmp[i]); | | x.at(row,col) = eT(tmp[i]); | |
| ++i; | | ++i; | |
| } | | } | |
| | | | |
| skipping to change at line 1304 | | skipping to change at line 1304 | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| static const std::string ARMA_MAT_TXT = "ARMA_MAT_TXT"; | | static const std::string ARMA_MAT_TXT = "ARMA_MAT_TXT"; | |
| static const std::string ARMA_MAT_BIN = "ARMA_MAT_BIN"; | | static const std::string ARMA_MAT_BIN = "ARMA_MAT_BIN"; | |
| static const std::string P5 = "P5"; | | static const std::string P5 = "P5"; | |
| | | | |
| podarray<char> raw_header(ARMA_MAT_TXT.length() + 1); | | podarray<char> raw_header(ARMA_MAT_TXT.length() + 1); | |
| | | | |
| std::streampos pos = f.tellg(); | | std::streampos pos = f.tellg(); | |
| | | | |
|
| f.read(raw_header.memptr(), ARMA_MAT_TXT.length()); | | f.read( raw_header.memptr(), std::streamsize(ARMA_MAT_TXT.length()) ); | |
| raw_header[ARMA_MAT_TXT.length()] = '\0'; | | raw_header[ARMA_MAT_TXT.length()] = '\0'; | |
| | | | |
| f.clear(); | | f.clear(); | |
| f.seekg(pos); | | f.seekg(pos); | |
| | | | |
| const std::string header = raw_header.mem; | | const std::string header = raw_header.mem; | |
| | | | |
| if(ARMA_MAT_TXT == header.substr(0,ARMA_MAT_TXT.length())) | | if(ARMA_MAT_TXT == header.substr(0,ARMA_MAT_TXT.length())) | |
| { | | { | |
| return load_arma_ascii(x, f, err_msg); | | return load_arma_ascii(x, f, err_msg); | |
| | | | |
| skipping to change at line 1450 | | skipping to change at line 1450 | |
| return save_okay; | | return save_okay; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| diskio::save_raw_binary(const Cube<eT>& x, std::ostream& f) | | diskio::save_raw_binary(const Cube<eT>& x, std::ostream& f) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| f.write(reinterpret_cast<const char*>(x.mem), x.n_elem*sizeof(eT)); | | f.write( reinterpret_cast<const char*>(x.mem), std::streamsize(x.n_elem*s
izeof(eT)) ); | |
| | | | |
| return f.good(); | | return f.good(); | |
| } | | } | |
| | | | |
| //! 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 | |
| bool | | bool | |
| diskio::save_arma_ascii(const Cube<eT>& x, const std::string& final_name) | | diskio::save_arma_ascii(const Cube<eT>& x, const std::string& final_name) | |
| | | | |
| skipping to change at line 1581 | | skipping to change at line 1581 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| diskio::save_arma_binary(const Cube<eT>& x, std::ostream& f) | | diskio::save_arma_binary(const Cube<eT>& x, std::ostream& f) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| f << diskio::gen_bin_header(x) << '\n'; | | f << diskio::gen_bin_header(x) << '\n'; | |
| f << x.n_rows << ' ' << x.n_cols << ' ' << x.n_slices << '\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)); | | f.write( reinterpret_cast<const char*>(x.mem), std::streamsize(x.n_elem*s
izeof(eT)) ); | |
| | | | |
| return f.good(); | | return f.good(); | |
| } | | } | |
| | | | |
| //! 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 | |
| bool | | bool | |
| diskio::load_raw_ascii(Cube<eT>& x, const std::string& name, std::string& e
rr_msg) | | diskio::load_raw_ascii(Cube<eT>& x, const std::string& name, std::string& e
rr_msg) | |
| | | | |
| skipping to change at line 1687 | | skipping to change at line 1687 | |
| | | | |
| const u32 N = ( (pos1 >= 0) && (pos2 >= 0) ) ? u32(pos2 - pos1) : 0; | | const u32 N = ( (pos1 >= 0) && (pos2 >= 0) ) ? u32(pos2 - pos1) : 0; | |
| | | | |
| f.clear(); | | f.clear(); | |
| //f.seekg(0, ios::beg); | | //f.seekg(0, ios::beg); | |
| f.seekg(pos1); | | f.seekg(pos1); | |
| | | | |
| x.set_size(N / sizeof(eT), 1, 1); | | x.set_size(N / sizeof(eT), 1, 1); | |
| | | | |
| f.clear(); | | f.clear(); | |
|
| f.read( reinterpret_cast<char *>(x.memptr()), N); | | f.read( reinterpret_cast<char *>(x.memptr()), std::streamsize(N) ); | |
| | | | |
| return f.good(); | | return f.good(); | |
| } | | } | |
| | | | |
| //! 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 | |
| bool | | bool | |
| diskio::load_arma_ascii(Cube<eT>& x, const std::string& name, std::string&
err_msg) | | diskio::load_arma_ascii(Cube<eT>& x, const std::string& name, std::string&
err_msg) | |
| | | | |
| skipping to change at line 1809 | | skipping to change at line 1809 | |
| 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 Win
dows machine a newline could be two characters | | //f.seekg(1, ios::cur); // NOTE: this may not be portable, as on a Win
dows machine a newline could be two characters | |
| f.get(); | | 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()), std::streamsize(x.n_elem*
sizeof(eT)) ); | |
| | | | |
| load_okay = f.good(); | | load_okay = f.good(); | |
| } | | } | |
| else | | else | |
| { | | { | |
| load_okay = false; | | load_okay = false; | |
| err_msg = "incorrect header in "; | | err_msg = "incorrect header in "; | |
| } | | } | |
| | | | |
| return load_okay; | | return load_okay; | |
| | | | |
| skipping to change at line 1860 | | skipping to change at line 1860 | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| static const std::string ARMA_CUB_TXT = "ARMA_CUB_TXT"; | | static const std::string ARMA_CUB_TXT = "ARMA_CUB_TXT"; | |
| static const std::string ARMA_CUB_BIN = "ARMA_CUB_BIN"; | | static const std::string ARMA_CUB_BIN = "ARMA_CUB_BIN"; | |
| static const std::string P6 = "P6"; | | static const std::string P6 = "P6"; | |
| | | | |
| podarray<char> raw_header(ARMA_CUB_TXT.length() + 1); | | podarray<char> raw_header(ARMA_CUB_TXT.length() + 1); | |
| | | | |
| std::streampos pos = f.tellg(); | | std::streampos pos = f.tellg(); | |
| | | | |
|
| f.read(raw_header.memptr(), ARMA_CUB_TXT.length()); | | f.read( raw_header.memptr(), std::streamsize(ARMA_CUB_TXT.length()) ); | |
| raw_header[ARMA_CUB_TXT.length()] = '\0'; | | raw_header[ARMA_CUB_TXT.length()] = '\0'; | |
| | | | |
| f.clear(); | | f.clear(); | |
| f.seekg(pos); | | f.seekg(pos); | |
| | | | |
| const std::string header = raw_header.mem; | | const std::string header = raw_header.mem; | |
| | | | |
| if(ARMA_CUB_TXT == header.substr(0, ARMA_CUB_TXT.length())) | | if(ARMA_CUB_TXT == header.substr(0, ARMA_CUB_TXT.length())) | |
| { | | { | |
| return load_arma_ascii(x, f, err_msg); | | return load_arma_ascii(x, f, err_msg); | |
| | | | |
| skipping to change at line 2202 | | skipping to change at line 2202 | |
| | | | |
| arma_type_check<is_Mat<T1>::value == false>::apply(); | | arma_type_check<is_Mat<T1>::value == false>::apply(); | |
| | | | |
| static const std::string ARMA_FLD_BIN = "ARMA_FLD_BIN"; | | static const std::string ARMA_FLD_BIN = "ARMA_FLD_BIN"; | |
| static const std::string P6 = "P6"; | | static const std::string P6 = "P6"; | |
| | | | |
| podarray<char> raw_header(ARMA_FLD_BIN.length() + 1); | | podarray<char> raw_header(ARMA_FLD_BIN.length() + 1); | |
| | | | |
| std::streampos pos = f.tellg(); | | std::streampos pos = f.tellg(); | |
| | | | |
|
| f.read(raw_header.memptr(), ARMA_FLD_BIN.length()); | | f.read( raw_header.memptr(), std::streamsize(ARMA_FLD_BIN.length()) ); | |
| | | | |
| f.clear(); | | f.clear(); | |
| f.seekg(pos); | | f.seekg(pos); | |
| | | | |
| raw_header[ARMA_FLD_BIN.length()] = '\0'; | | raw_header[ARMA_FLD_BIN.length()] = '\0'; | |
| | | | |
| const std::string header = raw_header.mem; | | const std::string header = raw_header.mem; | |
| | | | |
| if(ARMA_FLD_BIN == header.substr(0, ARMA_FLD_BIN.length())) | | if(ARMA_FLD_BIN == header.substr(0, ARMA_FLD_BIN.length())) | |
| { | | { | |
| | | | |
| skipping to change at line 2289 | | skipping to change at line 2289 | |
| | | | |
| if( (f_maxval > 0) || (f_maxval <= 65535) ) | | if( (f_maxval > 0) || (f_maxval <= 65535) ) | |
| { | | { | |
| x.set_size(f_n_rows, f_n_cols, 3); | | x.set_size(f_n_rows, f_n_cols, 3); | |
| | | | |
| if(f_maxval <= 255) | | if(f_maxval <= 255) | |
| { | | { | |
| const u32 n_elem = 3*f_n_cols*f_n_rows; | | const u32 n_elem = 3*f_n_cols*f_n_rows; | |
| podarray<u8> tmp(n_elem); | | podarray<u8> tmp(n_elem); | |
| | | | |
|
| f.read( reinterpret_cast<char*>(tmp.memptr()), n_elem); | | f.read( reinterpret_cast<char*>(tmp.memptr()), std::streamsize(n_el
em) ); | |
| | | | |
| u32 i = 0; | | u32 i = 0; | |
| | | | |
| //cout << "f_n_cols = " << f_n_cols << endl; | | //cout << "f_n_cols = " << f_n_cols << endl; | |
| //cout << "f_n_rows = " << f_n_rows << endl; | | //cout << "f_n_rows = " << f_n_rows << endl; | |
| | | | |
| 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) | |
| { | | { | |
| | | | |
| skipping to change at line 2313 | | skipping to change at line 2313 | |
| i+=3; | | i+=3; | |
| } | | } | |
| | | | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| const u32 n_elem = 3*f_n_cols*f_n_rows; | | const u32 n_elem = 3*f_n_cols*f_n_rows; | |
| podarray<u16> tmp(n_elem); | | podarray<u16> tmp(n_elem); | |
| | | | |
|
| f.read( reinterpret_cast<char *>(tmp.memptr()), 2*n_elem); | | f.read( reinterpret_cast<char *>(tmp.memptr()), std::streamsize(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,0) = eT(tmp[i+0]); | |
| x.at(row,col,1) = eT(tmp[i+1]); | | x.at(row,col,1) = eT(tmp[i+1]); | |
| x.at(row,col,2) = eT(tmp[i+2]); | | x.at(row,col,2) = eT(tmp[i+2]); | |
| | | | |
| skipping to change at line 2412 | | skipping to change at line 2412 | |
| | | | |
| i+=3; | | i+=3; | |
| } | | } | |
| } | | } | |
| | | | |
| f << "P6" << '\n'; | | f << "P6" << '\n'; | |
| f << x.n_cols << '\n'; | | f << x.n_cols << '\n'; | |
| f << x.n_rows << '\n'; | | f << x.n_rows << '\n'; | |
| f << 255 << '\n'; | | f << 255 << '\n'; | |
| | | | |
|
| f.write(reinterpret_cast<const char*>(tmp.mem), n_elem); | | f.write( reinterpret_cast<const char*>(tmp.mem), std::streamsize(n_elem)
); | |
| | | | |
| return f.good(); | | return f.good(); | |
| } | | } | |
| | | | |
| // | | // | |
| // handling of PPM images by fields | | // handling of PPM images by fields | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| bool | | bool | |
| | | | |
| skipping to change at line 2489 | | skipping to change at line 2489 | |
| | | | |
| R.set_size(f_n_rows,f_n_cols); | | R.set_size(f_n_rows,f_n_cols); | |
| G.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); | | B.set_size(f_n_rows,f_n_cols); | |
| | | | |
| if(f_maxval <= 255) | | if(f_maxval <= 255) | |
| { | | { | |
| const u32 n_elem = 3*f_n_cols*f_n_rows; | | const u32 n_elem = 3*f_n_cols*f_n_rows; | |
| podarray<u8> tmp(n_elem); | | podarray<u8> tmp(n_elem); | |
| | | | |
|
| f.read( reinterpret_cast<char*>(tmp.memptr()), n_elem); | | f.read( reinterpret_cast<char*>(tmp.memptr()), std::streamsize(n_el
em) ); | |
| | | | |
| u32 i = 0; | | u32 i = 0; | |
| | | | |
| //cout << "f_n_cols = " << f_n_cols << endl; | | //cout << "f_n_cols = " << f_n_cols << endl; | |
| //cout << "f_n_rows = " << f_n_rows << endl; | | //cout << "f_n_rows = " << f_n_rows << endl; | |
| | | | |
| 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) | |
| { | | { | |
| | | | |
| skipping to change at line 2513 | | skipping to change at line 2513 | |
| i+=3; | | i+=3; | |
| } | | } | |
| | | | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| const u32 n_elem = 3*f_n_cols*f_n_rows; | | const u32 n_elem = 3*f_n_cols*f_n_rows; | |
| podarray<u16> tmp(n_elem); | | podarray<u16> tmp(n_elem); | |
| | | | |
|
| f.read( reinterpret_cast<char *>(tmp.memptr()), 2*n_elem); | | f.read( reinterpret_cast<char *>(tmp.memptr()), std::streamsize(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]); | | R.at(row,col) = eT(tmp[i+0]); | |
| G.at(row,col) = eT(tmp[i+1]); | | G.at(row,col) = eT(tmp[i+1]); | |
| B.at(row,col) = eT(tmp[i+2]); | | B.at(row,col) = eT(tmp[i+2]); | |
| | | | |
| skipping to change at line 2631 | | skipping to change at line 2631 | |
| 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+0] = u8( access::tmp_real( R.at(row,col) ) ); | |
| tmp[i+1] = u8( access::tmp_real( G.at(row,col) ) ); | | tmp[i+1] = u8( access::tmp_real( G.at(row,col) ) ); | |
| tmp[i+2] = u8( access::tmp_real( B.at(row,col) ) ); | | tmp[i+2] = u8( access::tmp_real( 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), std::streamsize(n_elem)
); | |
| | | | |
| return f.good(); | | return f.good(); | |
| } | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 22 change blocks. |
| 23 lines changed or deleted | | 23 lines changed or added | |
|
| eglue_core_meat.hpp | | eglue_core_meat.hpp | |
|
| // Copyright (C) 2010 NICTA (www.nicta.com.au) | | // Copyright (C) 2010-2011 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2010 Conrad Sanderson | | // Copyright (C) 2010-2011 Conrad Sanderson | |
| // | | // | |
| // This file is part of the Armadillo C++ library. | | // This file is part of the Armadillo C++ library. | |
| // It is provided without any warranty of fitness | | // It is provided without any warranty of fitness | |
| // for any purpose. You can redistribute this file | | // for any purpose. You can redistribute this file | |
| // and/or modify it under the terms of the GNU | | // and/or modify it under the terms of the GNU | |
| // Lesser General Public License (LGPL) as published | | // Lesser General Public License (LGPL) as published | |
| // by the Free Software Foundation, either version 3 | | // by the Free Software Foundation, either version 3 | |
| // of the License or (at your option) any later version. | | // of the License or (at your option) any later version. | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| | | | |
| skipping to change at line 44 | | skipping to change at line 44 | |
| inline static const char* text() { return "element-wise division"; } | | inline static const char* text() { return "element-wise division"; } | |
| }; | | }; | |
| | | | |
| class eglue_schur : public eglue_core<eglue_schur> | | class eglue_schur : public eglue_core<eglue_schur> | |
| { | | { | |
| public: | | public: | |
| | | | |
| inline static const char* text() { return "element-wise multiplication";
} | | inline static const char* text() { return "element-wise multiplication";
} | |
| }; | | }; | |
| | | | |
|
| | | #undef arma_applier | |
| | | #undef operatorA | |
| | | #undef operatorB | |
| | | | |
| | | #define arma_applier(operatorA, operatorB) \ | |
| | | {\ | |
| | | u32 i,j;\ | |
| | | \ | |
| | | for(i=0, j=1; j<n_elem; i+=2, j+=2)\ | |
| | | {\ | |
| | | eT tmp_i = P1[i];\ | |
| | | eT tmp_j = P1[j];\ | |
| | | \ | |
| | | tmp_i operatorB##= P2[i];\ | |
| | | tmp_j operatorB##= P2[j];\ | |
| | | \ | |
| | | out_mem[i] operatorA tmp_i;\ | |
| | | out_mem[j] operatorA tmp_j;\ | |
| | | }\ | |
| | | \ | |
| | | if(i < n_elem)\ | |
| | | {\ | |
| | | out_mem[i] operatorA P1[i] operatorB P2[i];\ | |
| | | }\ | |
| | | } | |
| | | | |
| // | | // | |
| // matrices | | // matrices | |
| | | | |
| template<typename eglue_type> | | template<typename eglue_type> | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| void | | void | |
| eglue_core<eglue_type>::apply(Mat<typename T1::elem_type>& out, const eGlue
<T1, T2, eglue_type>& x) | | eglue_core<eglue_type>::apply(Mat<typename T1::elem_type>& out, const eGlue
<T1, T2, eglue_type>& x) | |
| { | | { | |
| | | | |
| skipping to change at line 68 | | skipping to change at line 94 | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| typedef typename Proxy<T1>::ea_type ea_type1; | | typedef typename Proxy<T1>::ea_type ea_type1; | |
| typedef typename Proxy<T2>::ea_type ea_type2; | | typedef typename Proxy<T2>::ea_type ea_type2; | |
| | | | |
| ea_type1 P1 = x.P1.get_ea(); | | ea_type1 P1 = x.P1.get_ea(); | |
| ea_type2 P2 = x.P2.get_ea(); | | ea_type2 P2 = x.P2.get_ea(); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const u32 n_elem = out.n_elem; | | const u32 n_elem = out.n_elem; | |
| | | | |
|
| #undef arma_applier | | if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_appl | |
| #define arma_applier(operator) \ | | ier(=, +); } | |
| {\ | | else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_appl | |
| u32 i,j;\ | | ier(=, -); } | |
| \ | | else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_appl | |
| for(i=0, j=1; j<n_elem; i+=2, j+=2)\ | | ier(=, /); } | |
| {\ | | else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_appl | |
| eT tmp_i = P1[i];\ | | ier(=, *); } | |
| eT tmp_j = P1[j];\ | | | |
| \ | | | |
| tmp_i operator##= P2[i];\ | | | |
| tmp_j operator##= P2[j];\ | | | |
| \ | | | |
| out_mem[i] = tmp_i;\ | | | |
| out_mem[j] = tmp_j;\ | | | |
| }\ | | | |
| \ | | | |
| if(i < n_elem)\ | | | |
| {\ | | | |
| out_mem[i] = P1[i] operator P2[i];\ | | | |
| }\ | | | |
| } | | | |
| | | | |
| if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_appl | | | |
| ier(+); } | | | |
| else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_appl | | | |
| ier(-); } | | | |
| else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_appl | | | |
| ier(/); } | | | |
| else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_appl | | | |
| ier(*); } | | | |
| else | | else | |
| { | | { | |
| arma_stop("eglue_core::apply_proxy(): unhandled eglue_type"); | | arma_stop("eglue_core::apply_proxy(): unhandled eglue_type"); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eglue_type> | | template<typename eglue_type> | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| | | | |
| skipping to change at line 122 | | skipping to change at line 125 | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| typedef typename Proxy<T1>::ea_type ea_type1; | | typedef typename Proxy<T1>::ea_type ea_type1; | |
| typedef typename Proxy<T2>::ea_type ea_type2; | | typedef typename Proxy<T2>::ea_type ea_type2; | |
| | | | |
| ea_type1 P1 = x.P1.get_ea(); | | ea_type1 P1 = x.P1.get_ea(); | |
| ea_type2 P2 = x.P2.get_ea(); | | ea_type2 P2 = x.P2.get_ea(); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const u32 n_elem = out.n_elem; | | const u32 n_elem = out.n_elem; | |
| | | | |
|
| #undef arma_applier | | if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_appl | |
| #define arma_applier(operator) \ | | ier(+=, +); } | |
| {\ | | else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_appl | |
| u32 i,j;\ | | ier(+=, -); } | |
| \ | | else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_appl | |
| for(i=0, j=1; j<n_elem; i+=2, j+=2)\ | | ier(+=, /); } | |
| {\ | | else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_appl | |
| eT tmp_i = P1[i];\ | | ier(+=, *); } | |
| eT tmp_j = P1[j];\ | | | |
| \ | | | |
| tmp_i operator##= P2[i];\ | | | |
| tmp_j operator##= P2[j];\ | | | |
| \ | | | |
| out_mem[i] += tmp_i;\ | | | |
| out_mem[j] += tmp_j;\ | | | |
| }\ | | | |
| \ | | | |
| if(i < n_elem)\ | | | |
| {\ | | | |
| out_mem[i] += P1[i] operator P2[i];\ | | | |
| }\ | | | |
| } | | | |
| | | | |
| if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_appl | | | |
| ier(+); } | | | |
| else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_appl | | | |
| ier(-); } | | | |
| else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_appl | | | |
| ier(/); } | | | |
| else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_appl | | | |
| ier(*); } | | | |
| else | | else | |
| { | | { | |
| arma_stop("eglue_core::apply_inplace_plus(): unhandled eglue_type"); | | arma_stop("eglue_core::apply_inplace_plus(): unhandled eglue_type"); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eglue_type> | | template<typename eglue_type> | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| | | | |
| skipping to change at line 176 | | skipping to change at line 156 | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| typedef typename Proxy<T1>::ea_type ea_type1; | | typedef typename Proxy<T1>::ea_type ea_type1; | |
| typedef typename Proxy<T2>::ea_type ea_type2; | | typedef typename Proxy<T2>::ea_type ea_type2; | |
| | | | |
| ea_type1 P1 = x.P1.get_ea(); | | ea_type1 P1 = x.P1.get_ea(); | |
| ea_type2 P2 = x.P2.get_ea(); | | ea_type2 P2 = x.P2.get_ea(); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const u32 n_elem = out.n_elem; | | const u32 n_elem = out.n_elem; | |
| | | | |
|
| #undef arma_applier | | if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_appl | |
| #define arma_applier(operator) \ | | ier(-=, +); } | |
| {\ | | else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_appl | |
| u32 i,j;\ | | ier(-=, -); } | |
| \ | | else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_appl | |
| for(i=0, j=1; j<n_elem; i+=2, j+=2)\ | | ier(-=, /); } | |
| {\ | | else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_appl | |
| eT tmp_i = P1[i];\ | | ier(-=, *); } | |
| eT tmp_j = P1[j];\ | | | |
| \ | | | |
| tmp_i operator##= P2[i];\ | | | |
| tmp_j operator##= P2[j];\ | | | |
| \ | | | |
| out_mem[i] -= tmp_i;\ | | | |
| out_mem[j] -= tmp_j;\ | | | |
| }\ | | | |
| \ | | | |
| if(i < n_elem)\ | | | |
| {\ | | | |
| out_mem[i] -= P1[i] operator P2[i];\ | | | |
| }\ | | | |
| } | | | |
| | | | |
| if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_appl | | | |
| ier(+); } | | | |
| else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_appl | | | |
| ier(-); } | | | |
| else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_appl | | | |
| ier(/); } | | | |
| else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_appl | | | |
| ier(*); } | | | |
| else | | else | |
| { | | { | |
| arma_stop("eglue_core::apply_inplace_minus(): unhandled eglue_type"); | | arma_stop("eglue_core::apply_inplace_minus(): unhandled eglue_type"); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eglue_type> | | template<typename eglue_type> | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| | | | |
| skipping to change at line 230 | | skipping to change at line 187 | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| typedef typename Proxy<T1>::ea_type ea_type1; | | typedef typename Proxy<T1>::ea_type ea_type1; | |
| typedef typename Proxy<T2>::ea_type ea_type2; | | typedef typename Proxy<T2>::ea_type ea_type2; | |
| | | | |
| ea_type1 P1 = x.P1.get_ea(); | | ea_type1 P1 = x.P1.get_ea(); | |
| ea_type2 P2 = x.P2.get_ea(); | | ea_type2 P2 = x.P2.get_ea(); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const u32 n_elem = out.n_elem; | | const u32 n_elem = out.n_elem; | |
| | | | |
|
| #undef arma_applier | | if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_appl | |
| #define arma_applier(operator) \ | | ier(*=, +); } | |
| {\ | | else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_appl | |
| u32 i,j;\ | | ier(*=, -); } | |
| \ | | else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_appl | |
| for(i=0, j=1; j<n_elem; i+=2, j+=2)\ | | ier(*=, /); } | |
| {\ | | else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_appl | |
| eT tmp_i = P1[i];\ | | ier(*=, *); } | |
| eT tmp_j = P1[j];\ | | | |
| \ | | | |
| tmp_i operator##= P2[i];\ | | | |
| tmp_j operator##= P2[j];\ | | | |
| \ | | | |
| out_mem[i] *= tmp_i;\ | | | |
| out_mem[j] *= tmp_j;\ | | | |
| }\ | | | |
| \ | | | |
| if(i < n_elem)\ | | | |
| {\ | | | |
| out_mem[i] *= P1[i] operator P2[i];\ | | | |
| }\ | | | |
| } | | | |
| | | | |
| if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_appl | | | |
| ier(+); } | | | |
| else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_appl | | | |
| ier(-); } | | | |
| else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_appl | | | |
| ier(/); } | | | |
| else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_appl | | | |
| ier(*); } | | | |
| else | | else | |
| { | | { | |
| arma_stop("eglue_core::apply_inplace_schur(): unhandled eglue_type"); | | arma_stop("eglue_core::apply_inplace_schur(): unhandled eglue_type"); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eglue_type> | | template<typename eglue_type> | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| | | | |
| skipping to change at line 284 | | skipping to change at line 218 | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| typedef typename Proxy<T1>::ea_type ea_type1; | | typedef typename Proxy<T1>::ea_type ea_type1; | |
| typedef typename Proxy<T2>::ea_type ea_type2; | | typedef typename Proxy<T2>::ea_type ea_type2; | |
| | | | |
| ea_type1 P1 = x.P1.get_ea(); | | ea_type1 P1 = x.P1.get_ea(); | |
| ea_type2 P2 = x.P2.get_ea(); | | ea_type2 P2 = x.P2.get_ea(); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const u32 n_elem = out.n_elem; | | const u32 n_elem = out.n_elem; | |
| | | | |
|
| #undef arma_applier | | if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_appl | |
| #define arma_applier(operator) \ | | ier(/=, +); } | |
| {\ | | else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_appl | |
| u32 i,j;\ | | ier(/=, -); } | |
| \ | | else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_appl | |
| for(i=0, j=1; j<n_elem; i+=2, j+=2)\ | | ier(/=, /); } | |
| {\ | | else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_appl | |
| eT tmp_i = P1[i];\ | | ier(/=, *); } | |
| eT tmp_j = P1[j];\ | | | |
| \ | | | |
| tmp_i operator##= P2[i];\ | | | |
| tmp_j operator##= P2[j];\ | | | |
| \ | | | |
| out_mem[i] /= tmp_i;\ | | | |
| out_mem[j] /= tmp_j;\ | | | |
| }\ | | | |
| \ | | | |
| if(i < n_elem)\ | | | |
| {\ | | | |
| out_mem[i] /= P1[i] operator P2[i];\ | | | |
| }\ | | | |
| } | | | |
| | | | |
| if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_appl | | | |
| ier(+); } | | | |
| else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_appl | | | |
| ier(-); } | | | |
| else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_appl | | | |
| ier(/); } | | | |
| else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_appl | | | |
| ier(*); } | | | |
| else | | else | |
| { | | { | |
| arma_stop("eglue_core::apply_inplace_div(): unhandled eglue_type"); | | arma_stop("eglue_core::apply_inplace_div(): unhandled eglue_type"); | |
| } | | } | |
| } | | } | |
| | | | |
| // | | // | |
| // cubes | | // cubes | |
| | | | |
| template<typename eglue_type> | | template<typename eglue_type> | |
| | | | |
| skipping to change at line 341 | | skipping to change at line 252 | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| typedef typename ProxyCube<T1>::ea_type ea_type1; | | typedef typename ProxyCube<T1>::ea_type ea_type1; | |
| typedef typename ProxyCube<T2>::ea_type ea_type2; | | typedef typename ProxyCube<T2>::ea_type ea_type2; | |
| | | | |
| ea_type1 P1 = x.P1.get_ea(); | | ea_type1 P1 = x.P1.get_ea(); | |
| ea_type2 P2 = x.P2.get_ea(); | | ea_type2 P2 = x.P2.get_ea(); | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| const u32 n_elem = out.n_elem; | | const u32 n_elem = out.n_elem; | |
| | | | |
|
| #undef arma_applier | | if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_appl | |
| #define arma_applier(operator) \ | | ier(=, +); } | |
| {\ | | else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_appl | |
| u32 i,j;\ | | ier(=, -); } | |
| \ | | else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_appl | |
| for(i=0, j=1; j<n_elem; i+=2, j+=2)\ | | ier(=, /); } | |
| {\ | | else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_appl | |
| eT tmp_i = P1[i];\ | | ier(=, *); } | |
| eT tmp_j = P1[j];\ | | | |
| \ | | | |
| tmp_i operator##= P2[i];\ | | | |
| tmp_j operator##= P2[j];\ | | | |
| \ | | | |
| out_mem[i] = tmp_i;\ | | | |
| out_mem[j] = tmp_j;\ | | | |
| }\ | | | |
| \ | | | |
| if(i < n_elem)\ | | | |
| {\ | | | |
| out_mem[i] = P1[i] operator P2[i];\ | | | |
| }\ | | | |
| } | | | |
| | | | |
| if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_appl | | | |
| ier(+); } | | | |
| else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_appl | | | |
| ier(-); } | | | |
| else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_appl | | | |
| ier(/); } | | | |
| else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_appl | | | |
| ier(*); } | | | |
| else | | else | |
| { | | { | |
| arma_stop("eglue_core::apply(): unhandled eglue_type"); | | arma_stop("eglue_core::apply(): unhandled eglue_type"); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eglue_type> | | template<typename eglue_type> | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| | | | |
| skipping to change at line 395 | | skipping to change at line 283 | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| typedef typename ProxyCube<T1>::ea_type ea_type1; | | typedef typename ProxyCube<T1>::ea_type ea_type1; | |
| typedef typename ProxyCube<T2>::ea_type ea_type2; | | typedef typename ProxyCube<T2>::ea_type ea_type2; | |
| | | | |
| ea_type1 P1 = x.P1.get_ea(); | | ea_type1 P1 = x.P1.get_ea(); | |
| ea_type2 P2 = x.P2.get_ea(); | | ea_type2 P2 = x.P2.get_ea(); | |
| | | | |
| const u32 n_elem = out.n_elem; | | const u32 n_elem = out.n_elem; | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
|
| #undef arma_applier | | if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_appl | |
| #define arma_applier(operator) \ | | ier(+=, +); } | |
| {\ | | else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_appl | |
| u32 i,j;\ | | ier(+=, -); } | |
| \ | | else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_appl | |
| for(i=0, j=1; j<n_elem; i+=2, j+=2)\ | | ier(+=, /); } | |
| {\ | | else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_appl | |
| eT tmp_i = P1[i];\ | | ier(+=, *); } | |
| eT tmp_j = P1[j];\ | | | |
| \ | | | |
| tmp_i operator##= P2[i];\ | | | |
| tmp_j operator##= P2[j];\ | | | |
| \ | | | |
| out_mem[i] += tmp_i;\ | | | |
| out_mem[j] += tmp_j;\ | | | |
| }\ | | | |
| \ | | | |
| if(i < n_elem)\ | | | |
| {\ | | | |
| out_mem[i] += P1[i] operator P2[i];\ | | | |
| }\ | | | |
| } | | | |
| | | | |
| if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_appl | | | |
| ier(+); } | | | |
| else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_appl | | | |
| ier(-); } | | | |
| else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_appl | | | |
| ier(/); } | | | |
| else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_appl | | | |
| ier(*); } | | | |
| else | | else | |
| { | | { | |
| arma_stop("eglue_core::apply_inplace_plus(): unhandled eglue_type"); | | arma_stop("eglue_core::apply_inplace_plus(): unhandled eglue_type"); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eglue_type> | | template<typename eglue_type> | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| | | | |
| skipping to change at line 449 | | skipping to change at line 314 | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| typedef typename ProxyCube<T1>::ea_type ea_type1; | | typedef typename ProxyCube<T1>::ea_type ea_type1; | |
| typedef typename ProxyCube<T2>::ea_type ea_type2; | | typedef typename ProxyCube<T2>::ea_type ea_type2; | |
| | | | |
| ea_type1 P1 = x.P1.get_ea(); | | ea_type1 P1 = x.P1.get_ea(); | |
| ea_type2 P2 = x.P2.get_ea(); | | ea_type2 P2 = x.P2.get_ea(); | |
| | | | |
| const u32 n_elem = out.n_elem; | | const u32 n_elem = out.n_elem; | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
|
| #undef arma_applier | | if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_appl | |
| #define arma_applier(operator) \ | | ier(-=, +); } | |
| {\ | | else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_appl | |
| u32 i,j;\ | | ier(-=, -); } | |
| \ | | else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_appl | |
| for(i=0, j=1; j<n_elem; i+=2, j+=2)\ | | ier(-=, /); } | |
| {\ | | else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_appl | |
| eT tmp_i = P1[i];\ | | ier(-=, *); } | |
| eT tmp_j = P1[j];\ | | | |
| \ | | | |
| tmp_i operator##= P2[i];\ | | | |
| tmp_j operator##= P2[j];\ | | | |
| \ | | | |
| out_mem[i] -= tmp_i;\ | | | |
| out_mem[j] -= tmp_j;\ | | | |
| }\ | | | |
| \ | | | |
| if(i < n_elem)\ | | | |
| {\ | | | |
| out_mem[i] -= P1[i] operator P2[i];\ | | | |
| }\ | | | |
| } | | | |
| | | | |
| if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_appl | | | |
| ier(+); } | | | |
| else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_appl | | | |
| ier(-); } | | | |
| else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_appl | | | |
| ier(/); } | | | |
| else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_appl | | | |
| ier(*); } | | | |
| else | | else | |
| { | | { | |
| arma_stop("eglue_core::apply_inplace_minus(): unhandled eglue_type"); | | arma_stop("eglue_core::apply_inplace_minus(): unhandled eglue_type"); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eglue_type> | | template<typename eglue_type> | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| | | | |
| skipping to change at line 503 | | skipping to change at line 345 | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| typedef typename ProxyCube<T1>::ea_type ea_type1; | | typedef typename ProxyCube<T1>::ea_type ea_type1; | |
| typedef typename ProxyCube<T2>::ea_type ea_type2; | | typedef typename ProxyCube<T2>::ea_type ea_type2; | |
| | | | |
| ea_type1 P1 = x.P1.get_ea(); | | ea_type1 P1 = x.P1.get_ea(); | |
| ea_type2 P2 = x.P2.get_ea(); | | ea_type2 P2 = x.P2.get_ea(); | |
| | | | |
| const u32 n_elem = out.n_elem; | | const u32 n_elem = out.n_elem; | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
|
| #undef arma_applier | | if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_appl | |
| #define arma_applier(operator) \ | | ier(*=, +); } | |
| {\ | | else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_appl | |
| u32 i,j;\ | | ier(*=, -); } | |
| \ | | else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_appl | |
| for(i=0, j=1; j<n_elem; i+=2, j+=2)\ | | ier(*=, /); } | |
| {\ | | else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_appl | |
| eT tmp_i = P1[i];\ | | ier(*=, *); } | |
| eT tmp_j = P1[j];\ | | | |
| \ | | | |
| tmp_i operator##= P2[i];\ | | | |
| tmp_j operator##= P2[j];\ | | | |
| \ | | | |
| out_mem[i] *= tmp_i;\ | | | |
| out_mem[j] *= tmp_j;\ | | | |
| }\ | | | |
| \ | | | |
| if(i < n_elem)\ | | | |
| {\ | | | |
| out_mem[i] *= P1[i] operator P2[i];\ | | | |
| }\ | | | |
| } | | | |
| | | | |
| if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_appl | | | |
| ier(+); } | | | |
| else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_appl | | | |
| ier(-); } | | | |
| else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_appl | | | |
| ier(/); } | | | |
| else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_appl | | | |
| ier(*); } | | | |
| else | | else | |
| { | | { | |
| arma_stop("eglue_core::apply_inplace_schur(): unhandled eglue_type"); | | arma_stop("eglue_core::apply_inplace_schur(): unhandled eglue_type"); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eglue_type> | | template<typename eglue_type> | |
| template<typename T1, typename T2> | | template<typename T1, typename T2> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| | | | |
| skipping to change at line 557 | | skipping to change at line 376 | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| typedef typename ProxyCube<T1>::ea_type ea_type1; | | typedef typename ProxyCube<T1>::ea_type ea_type1; | |
| typedef typename ProxyCube<T2>::ea_type ea_type2; | | typedef typename ProxyCube<T2>::ea_type ea_type2; | |
| | | | |
| ea_type1 P1 = x.P1.get_ea(); | | ea_type1 P1 = x.P1.get_ea(); | |
| ea_type2 P2 = x.P2.get_ea(); | | ea_type2 P2 = x.P2.get_ea(); | |
| | | | |
| const u32 n_elem = out.n_elem; | | const u32 n_elem = out.n_elem; | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
|
| #undef arma_applier | | if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_appl | |
| #define arma_applier(operator) \ | | ier(/=, +); } | |
| {\ | | else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_appl | |
| u32 i,j;\ | | ier(/=, -); } | |
| \ | | else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_appl | |
| for(i=0, j=1; j<n_elem; i+=2, j+=2)\ | | ier(/=, /); } | |
| {\ | | else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_appl | |
| eT tmp_i = P1[i];\ | | ier(/=, *); } | |
| eT tmp_j = P1[j];\ | | | |
| \ | | | |
| tmp_i operator##= P2[i];\ | | | |
| tmp_j operator##= P2[j];\ | | | |
| \ | | | |
| out_mem[i] /= tmp_i;\ | | | |
| out_mem[j] /= tmp_j;\ | | | |
| }\ | | | |
| \ | | | |
| if(i < n_elem)\ | | | |
| {\ | | | |
| out_mem[i] /= P1[i] operator P2[i];\ | | | |
| }\ | | | |
| } | | | |
| | | | |
| if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_appl | | | |
| ier(+); } | | | |
| else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_appl | | | |
| ier(-); } | | | |
| else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_appl | | | |
| ier(/); } | | | |
| else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_appl | | | |
| ier(*); } | | | |
| else | | else | |
| { | | { | |
| arma_stop("eglue_core::apply_inplace_div(): unhandled eglue_type"); | | arma_stop("eglue_core::apply_inplace_div(): unhandled eglue_type"); | |
| } | | } | |
| } | | } | |
| | | | |
|
| | | #undef arma_applier | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 13 change blocks. |
| 312 lines changed or deleted | | 110 lines changed or added | |
|
| eop_aux.hpp | | eop_aux.hpp | |
|
| // Copyright (C) 2010 NICTA (www.nicta.com.au) | | // Copyright (C) 2010-2011 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2010 Conrad Sanderson | | // Copyright (C) 2010-2011 Conrad Sanderson | |
| // | | // | |
| // This file is part of the Armadillo C++ library. | | // This file is part of the Armadillo C++ library. | |
| // It is provided without any warranty of fitness | | // It is provided without any warranty of fitness | |
| // for any purpose. You can redistribute this file | | // for any purpose. You can redistribute this file | |
| // and/or modify it under the terms of the GNU | | // and/or modify it under the terms of the GNU | |
| // Lesser General Public License (LGPL) as published | | // Lesser General Public License (LGPL) as published | |
| // by the Free Software Foundation, either version 3 | | // by the Free Software Foundation, either version 3 | |
| // of the License or (at your option) any later version. | | // of the License or (at your option) any later version. | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| | | | |
| skipping to change at line 131 | | skipping to change at line 131 | |
| template<typename eT> arma_inline static typename arma_cx_only<eT>::resul
t atan (const eT x) { return arma_atan(x); } | | template<typename eT> arma_inline static typename arma_cx_only<eT>::resul
t atan (const eT x) { return arma_atan(x); } | |
| | | | |
| template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result acosh (const eT x) { return eT( arma_acosh(double(x)) ); } | | template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result acosh (const eT x) { return eT( arma_acosh(double(x)) ); } | |
| template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result asinh (const eT x) { return eT( arma_asinh(double(x)) ); } | | template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result asinh (const eT x) { return eT( arma_asinh(double(x)) ); } | |
| template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result atanh (const eT x) { return eT( arma_atanh(double(x)) ); } | | template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result atanh (const eT x) { return eT( arma_atanh(double(x)) ); } | |
| | | | |
| template<typename eT> arma_inline static typename arma_float_or_cx_only<e
T>::result acosh (const eT x) { return arma_acosh(x); } | | template<typename eT> arma_inline static typename arma_float_or_cx_only<e
T>::result acosh (const eT x) { return arma_acosh(x); } | |
| template<typename eT> arma_inline static typename arma_float_or_cx_only<e
T>::result asinh (const eT x) { return arma_asinh(x); } | | template<typename eT> arma_inline static typename arma_float_or_cx_only<e
T>::result asinh (const eT x) { return arma_asinh(x); } | |
| template<typename eT> arma_inline static typename arma_float_or_cx_only<e
T>::result atanh (const eT x) { return arma_atanh(x); } | | template<typename eT> arma_inline static typename arma_float_or_cx_only<e
T>::result atanh (const eT x) { return arma_atanh(x); } | |
| | | | |
|
| template<typename eT> arma_inline static typename arma_not_cx<eT>::result | | template<typename eT> arma_inline static typename arma_not_cx<eT>::result | |
| conj(const eT x) { return x; } | | conj(const eT x) { return x; } | |
| template<typename T> arma_inline static std::complex<T> | | template<typename T> arma_inline static std::complex<T> | |
| conj(const std::complex<T> x) { return std::conj(x); } | | conj(const std::complex<T>& x) { return std::conj(x); } | |
| | | | |
| template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result sqrt (const eT x) { return eT( std::sqrt (double(x)) ); } | | template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result sqrt (const eT x) { return eT( std::sqrt (double(x)) ); } | |
| template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result log10 (const eT x) { return eT( std::log10(double(x)) ); } | | template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result log10 (const eT x) { return eT( std::log10(double(x)) ); } | |
| template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result log (const eT x) { return eT( std::log (double(x)) ); } | | template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result log (const eT x) { return eT( std::log (double(x)) ); } | |
| template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result exp (const eT x) { return eT( std::exp (double(x)) ); } | | template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result exp (const eT x) { return eT( std::exp (double(x)) ); } | |
| template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result cos (const eT x) { return eT( std::cos (double(x)) ); } | | template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result cos (const eT x) { return eT( std::cos (double(x)) ); } | |
| template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result sin (const eT x) { return eT( std::sin (double(x)) ); } | | template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result sin (const eT x) { return eT( std::sin (double(x)) ); } | |
| template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result tan (const eT x) { return eT( std::tan (double(x)) ); } | | template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result tan (const eT x) { return eT( std::tan (double(x)) ); } | |
| template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result cosh (const eT x) { return eT( std::cosh (double(x)) ); } | | template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result cosh (const eT x) { return eT( std::cosh (double(x)) ); } | |
| template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result sinh (const eT x) { return eT( std::sinh (double(x)) ); } | | template<typename eT> arma_inline static typename arma_integral_only<eT>:
:result sinh (const eT x) { return eT( std::sinh (double(x)) ); } | |
| | | | |
| skipping to change at line 159 | | skipping to change at line 159 | |
| template<typename eT> arma_inline static typename arma_float_or_cx_only<e
T>::result cos (const eT x) { return std::cos (x); } | | template<typename eT> arma_inline static typename arma_float_or_cx_only<e
T>::result cos (const eT x) { return std::cos (x); } | |
| template<typename eT> arma_inline static typename arma_float_or_cx_only<e
T>::result sin (const eT x) { return std::sin (x); } | | template<typename eT> arma_inline static typename arma_float_or_cx_only<e
T>::result sin (const eT x) { return std::sin (x); } | |
| template<typename eT> arma_inline static typename arma_float_or_cx_only<e
T>::result tan (const eT x) { return std::tan (x); } | | template<typename eT> arma_inline static typename arma_float_or_cx_only<e
T>::result tan (const eT x) { return std::tan (x); } | |
| template<typename eT> arma_inline static typename arma_float_or_cx_only<e
T>::result cosh (const eT x) { return std::cosh (x); } | | template<typename eT> arma_inline static typename arma_float_or_cx_only<e
T>::result cosh (const eT x) { return std::cosh (x); } | |
| template<typename eT> arma_inline static typename arma_float_or_cx_only<e
T>::result sinh (const eT x) { return std::sinh (x); } | | template<typename eT> arma_inline static typename arma_float_or_cx_only<e
T>::result sinh (const eT x) { return std::sinh (x); } | |
| template<typename eT> arma_inline static typename arma_float_or_cx_only<e
T>::result tanh (const eT x) { return std::tanh (x); } | | template<typename eT> arma_inline static typename arma_float_or_cx_only<e
T>::result tanh (const eT x) { return std::tanh (x); } | |
| | | | |
| template<typename eT> arma_inline static typename arma_unsigned_integral_
only<eT>::result neg (const eT x) { return x; } | | template<typename eT> arma_inline static typename arma_unsigned_integral_
only<eT>::result neg (const eT x) { return x; } | |
| template<typename eT> arma_inline static typename arma_signed_only<eT>::r
esult neg (const eT x) { return -x; } | | template<typename eT> arma_inline static typename arma_signed_only<eT>::r
esult neg (const eT x) { return -x; } | |
| | | | |
|
| | | template<typename eT> arma_inline static typename arma_integral_only<eT>: | |
| | | :result floor(const eT x) { return x; | |
| | | } | |
| | | template<typename eT> arma_inline static typename arma_float_only<eT>::re | |
| | | sult floor(const eT x) { return std::floor(x); | |
| | | } | |
| | | template<typename eT> arma_inline static typename arma_cx_only<eT>::resul | |
| | | t floor(const eT& x) { return eT( std::floor(x.real()), std::floor(x. | |
| | | imag()) ); } | |
| | | | |
| | | template<typename eT> arma_inline static typename arma_integral_only<eT>: | |
| | | :result ceil(const eT x) { return x; | |
| | | } | |
| | | template<typename eT> arma_inline static typename arma_float_only<eT>::re | |
| | | sult ceil(const eT x) { return std::ceil(x); | |
| | | } | |
| | | template<typename eT> arma_inline static typename arma_cx_only<eT>::resul | |
| | | t ceil(const eT& x) { return eT( std::ceil(x.real()), std::ceil(x.im | |
| | | ag()) ); } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| static | | static | |
| typename arma_integral_only<eT>::result | | typename arma_integral_only<eT>::result | |
| log2 (const eT x) | | log2 (const eT x) | |
| { | | { | |
| return eT( std::log(double(x))/ double(0.69314718055994530942) ); | | return eT( std::log(double(x))/ double(0.69314718055994530942) ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| | | | |
End of changes. 3 change blocks. |
| 6 lines changed or deleted | | 26 lines changed or added | |
|
| eop_core_meat.hpp | | eop_core_meat.hpp | |
|
| // Copyright (C) 2010 NICTA (www.nicta.com.au) | | // Copyright (C) 2010-2011 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2010 Conrad Sanderson | | // Copyright (C) 2010-2011 Conrad Sanderson | |
| // | | // | |
| // This file is part of the Armadillo C++ library. | | // This file is part of the Armadillo C++ library. | |
| // It is provided without any warranty of fitness | | // It is provided without any warranty of fitness | |
| // for any purpose. You can redistribute this file | | // for any purpose. You can redistribute this file | |
| // and/or modify it under the terms of the GNU | | // and/or modify it under the terms of the GNU | |
| // Lesser General Public License (LGPL) as published | | // Lesser General Public License (LGPL) as published | |
| // by the Free Software Foundation, either version 3 | | // by the Free Software Foundation, either version 3 | |
| // of the License or (at your option) any later version. | | // of the License or (at your option) any later version. | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| | | | |
| skipping to change at line 86 | | skipping to change at line 86 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const u32 n_rows = x.get_n_rows(); | | const u32 n_rows = x.get_n_rows(); | |
| const u32 n_cols = x.get_n_cols(); | | const u32 n_cols = x.get_n_cols(); | |
| | | | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "addi
tion"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "addi
tion"); | |
| | | | |
|
| | | eT* out_mem = out.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| if(is_generator<eop_type>::value == true) | | if(is_generator<eop_type>::value == true) | |
| { | | { | |
| if(is_same_type<eop_type, eop_ones_diag>::value == true) | | if(is_same_type<eop_type, eop_ones_diag>::value == true) | |
| { | | { | |
| const u32 N = (std::min)(n_rows, n_cols); | | const u32 N = (std::min)(n_rows, n_cols); | |
| | | | |
| for(u32 i=0; i<N; ++i) | | for(u32 i=0; i<N; ++i) | |
| { | | { | |
| out.at(i,i) += eT(1); | | out.at(i,i) += eT(1); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| eT* out_mem = out.memptr(); | | | |
| const u32 n_elem = out.n_elem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_mem[i] += eop_aux::generate<eT,eop_type>(); | | out_mem[i] += eop_aux::generate<eT,eop_type>(); | |
| } | | } | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| typedef typename Proxy<T1>::ea_type ea_type; | | typedef typename Proxy<T1>::ea_type ea_type; | |
| | | | |
|
| const eT k = x.aux; | | const eT k = x.aux; | |
| ea_type P = x.P.get_ea(); | | ea_type P = x.P.get_ea(); | |
| eT* out_mem = out.memptr(); | | | |
| const u32 n_elem = out.n_elem; | | | |
| | | | |
| u32 i,j; | | u32 i,j; | |
| | | | |
| for(i=0, j=1; j<n_elem; i+=2, j+=2) | | for(i=0, j=1; j<n_elem; i+=2, j+=2) | |
| { | | { | |
| const eT tmp_i = eop_core<eop_type>::process(P[i], k); | | const eT tmp_i = eop_core<eop_type>::process(P[i], k); | |
| const eT tmp_j = eop_core<eop_type>::process(P[j], k); | | const eT tmp_j = eop_core<eop_type>::process(P[j], k); | |
| | | | |
| out_mem[i] += tmp_i; | | out_mem[i] += tmp_i; | |
| out_mem[j] += tmp_j; | | out_mem[j] += tmp_j; | |
| | | | |
| skipping to change at line 151 | | skipping to change at line 149 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const u32 n_rows = x.get_n_rows(); | | const u32 n_rows = x.get_n_rows(); | |
| const u32 n_cols = x.get_n_cols(); | | const u32 n_cols = x.get_n_cols(); | |
| | | | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "subt
raction"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "subt
raction"); | |
| | | | |
|
| | | eT* out_mem = out.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| if(is_generator<eop_type>::value == true) | | if(is_generator<eop_type>::value == true) | |
| { | | { | |
| if(is_same_type<eop_type, eop_ones_diag>::value == true) | | if(is_same_type<eop_type, eop_ones_diag>::value == true) | |
| { | | { | |
| const u32 N = (std::min)(n_rows, n_cols); | | const u32 N = (std::min)(n_rows, n_cols); | |
| | | | |
| for(u32 i=0; i<N; ++i) | | for(u32 i=0; i<N; ++i) | |
| { | | { | |
| out.at(i,i) -= eT(1); | | out.at(i,i) -= eT(1); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| eT* out_mem = out.memptr(); | | | |
| const u32 n_elem = out.n_elem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_mem[i] -= eop_aux::generate<eT,eop_type>(); | | out_mem[i] -= eop_aux::generate<eT,eop_type>(); | |
| } | | } | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| typedef typename Proxy<T1>::ea_type ea_type; | | typedef typename Proxy<T1>::ea_type ea_type; | |
| | | | |
|
| const eT k = x.aux; | | const eT k = x.aux; | |
| ea_type P = x.P.get_ea(); | | ea_type P = x.P.get_ea(); | |
| eT* out_mem = out.memptr(); | | | |
| const u32 n_elem = out.n_elem; | | | |
| | | | |
| u32 i,j; | | u32 i,j; | |
| | | | |
| for(i=0, j=1; j<n_elem; i+=2, j+=2) | | for(i=0, j=1; j<n_elem; i+=2, j+=2) | |
| { | | { | |
| const eT tmp_i = eop_core<eop_type>::process(P[i], k); | | const eT tmp_i = eop_core<eop_type>::process(P[i], k); | |
| const eT tmp_j = eop_core<eop_type>::process(P[j], k); | | const eT tmp_j = eop_core<eop_type>::process(P[j], k); | |
| | | | |
| out_mem[i] -= tmp_i; | | out_mem[i] -= tmp_i; | |
| out_mem[j] -= tmp_j; | | out_mem[j] -= tmp_j; | |
| | | | |
| skipping to change at line 216 | | skipping to change at line 212 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const u32 n_rows = x.get_n_rows(); | | const u32 n_rows = x.get_n_rows(); | |
| const u32 n_cols = x.get_n_cols(); | | const u32 n_cols = x.get_n_cols(); | |
| | | | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "elem
ent-wise multiplication"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "elem
ent-wise multiplication"); | |
| | | | |
|
| | | eT* out_mem = out.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| if(is_generator<eop_type>::value == true) | | if(is_generator<eop_type>::value == true) | |
| { | | { | |
| if(is_same_type<eop_type, eop_ones_diag>::value == true) | | if(is_same_type<eop_type, eop_ones_diag>::value == true) | |
| { | | { | |
| const u32 N = (std::min)(n_rows, n_cols); | | const u32 N = (std::min)(n_rows, n_cols); | |
| | | | |
| for(u32 i=0; i<N; ++i) | | for(u32 i=0; i<N; ++i) | |
| { | | { | |
| for(u32 row=0; row<i; ++row) { out.at(row,i) = eT(0); } | | for(u32 row=0; row<i; ++row) { out.at(row,i) = eT(0); } | |
| for(u32 row=i+1; row<n_rows; ++row) { out.at(row,i) = eT(0); } | | for(u32 row=i+1; row<n_rows; ++row) { out.at(row,i) = eT(0); } | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| eT* out_mem = out.memptr(); | | | |
| const u32 n_elem = out.n_elem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_mem[i] *= eop_aux::generate<eT,eop_type>(); | | out_mem[i] *= eop_aux::generate<eT,eop_type>(); | |
| } | | } | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| typedef typename Proxy<T1>::ea_type ea_type; | | typedef typename Proxy<T1>::ea_type ea_type; | |
| | | | |
|
| const eT k = x.aux; | | const eT k = x.aux; | |
| ea_type P = x.P.get_ea(); | | ea_type P = x.P.get_ea(); | |
| eT* out_mem = out.memptr(); | | | |
| const u32 n_elem = out.n_elem; | | | |
| | | | |
| u32 i,j; | | u32 i,j; | |
| | | | |
| for(i=0, j=1; j<n_elem; i+=2, j+=2) | | for(i=0, j=1; j<n_elem; i+=2, j+=2) | |
| { | | { | |
| const eT tmp_i = eop_core<eop_type>::process(P[i], k); | | const eT tmp_i = eop_core<eop_type>::process(P[i], k); | |
| const eT tmp_j = eop_core<eop_type>::process(P[j], k); | | const eT tmp_j = eop_core<eop_type>::process(P[j], k); | |
| | | | |
| out_mem[i] *= tmp_i; | | out_mem[i] *= tmp_i; | |
| out_mem[j] *= tmp_j; | | out_mem[j] *= tmp_j; | |
| | | | |
| skipping to change at line 301 | | skipping to change at line 295 | |
| for(u32 i=0; i<N; ++i) | | for(u32 i=0; i<N; ++i) | |
| { | | { | |
| const eT zero = eT(0); | | const eT zero = eT(0); | |
| | | | |
| for(u32 row=0; row<i; ++row) { out.at(row,i) /= zero; } | | for(u32 row=0; row<i; ++row) { out.at(row,i) /= zero; } | |
| for(u32 row=i+1; row<n_rows; ++row) { out.at(row,i) /= zero; } | | for(u32 row=i+1; row<n_rows; ++row) { out.at(row,i) /= zero; } | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| eT* out_mem = out.memptr(); | | | |
| const u32 n_elem = out.n_elem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_mem[i] /= eop_aux::generate<eT,eop_type>(); | | out_mem[i] /= eop_aux::generate<eT,eop_type>(); | |
| } | | } | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| typedef typename Proxy<T1>::ea_type ea_type; | | typedef typename Proxy<T1>::ea_type ea_type; | |
| | | | |
|
| const eT k = x.aux; | | const eT k = x.aux; | |
| ea_type P = x.P.get_ea(); | | ea_type P = x.P.get_ea(); | |
| eT* out_mem = out.memptr(); | | | |
| const u32 n_elem = out.n_elem; | | | |
| | | | |
| u32 i,j; | | u32 i,j; | |
| | | | |
| for(i=0, j=1; j<n_elem; i+=2, j+=2) | | for(i=0, j=1; j<n_elem; i+=2, j+=2) | |
| { | | { | |
| const eT tmp_i = eop_core<eop_type>::process(P[i], k); | | const eT tmp_i = eop_core<eop_type>::process(P[i], k); | |
| const eT tmp_j = eop_core<eop_type>::process(P[j], k); | | const eT tmp_j = eop_core<eop_type>::process(P[j], k); | |
| | | | |
| out_mem[i] /= tmp_i; | | out_mem[i] /= tmp_i; | |
| out_mem[j] /= tmp_j; | | out_mem[j] /= tmp_j; | |
| | | | |
| skipping to change at line 405 | | skipping to change at line 394 | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const u32 n_rows = x.get_n_rows(); | | const u32 n_rows = x.get_n_rows(); | |
| const u32 n_cols = x.get_n_cols(); | | const u32 n_cols = x.get_n_cols(); | |
| const u32 n_slices = x.get_n_slices(); | | const u32 n_slices = x.get_n_slices(); | |
| | | | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "addition"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "addition"); | |
| | | | |
|
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| if(is_generator<eop_type>::value == true) | | if(is_generator<eop_type>::value == true) | |
| { | | { | |
|
| eT* out_mem = out.memptr(); | | | |
| const u32 n_elem = out.n_elem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_mem[i] += eop_aux::generate<eT,eop_type>(); | | out_mem[i] += eop_aux::generate<eT,eop_type>(); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| typedef typename ProxyCube<T1>::ea_type ea_type; | | typedef typename ProxyCube<T1>::ea_type ea_type; | |
| | | | |
|
| const eT k = x.aux; | | const eT k = x.aux; | |
| ea_type P = x.P.get_ea(); | | ea_type P = x.P.get_ea(); | |
| eT* out_mem = out.memptr(); | | | |
| const u32 n_elem = out.n_elem; | | | |
| | | | |
| u32 i,j; | | u32 i,j; | |
| | | | |
| for(i=0, j=1; j<n_elem; i+=2, j+=2) | | for(i=0, j=1; j<n_elem; i+=2, j+=2) | |
| { | | { | |
| const eT tmp_i = eop_core<eop_type>::process(P[i], k); | | const eT tmp_i = eop_core<eop_type>::process(P[i], k); | |
| const eT tmp_j = eop_core<eop_type>::process(P[j], k); | | const eT tmp_j = eop_core<eop_type>::process(P[j], k); | |
| | | | |
| out_mem[i] += tmp_i; | | out_mem[i] += tmp_i; | |
| out_mem[j] += tmp_j; | | out_mem[j] += tmp_j; | |
| | | | |
| skipping to change at line 461 | | skipping to change at line 446 | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const u32 n_rows = x.get_n_rows(); | | const u32 n_rows = x.get_n_rows(); | |
| const u32 n_cols = x.get_n_cols(); | | const u32 n_cols = x.get_n_cols(); | |
| const u32 n_slices = x.get_n_slices(); | | const u32 n_slices = x.get_n_slices(); | |
| | | | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "subtraction"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "subtraction"); | |
| | | | |
|
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| if(is_generator<eop_type>::value == true) | | if(is_generator<eop_type>::value == true) | |
| { | | { | |
|
| eT* out_mem = out.memptr(); | | | |
| const u32 n_elem = out.n_elem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_mem[i] -= eop_aux::generate<eT,eop_type>(); | | out_mem[i] -= eop_aux::generate<eT,eop_type>(); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| typedef typename ProxyCube<T1>::ea_type ea_type; | | typedef typename ProxyCube<T1>::ea_type ea_type; | |
| | | | |
|
| const eT k = x.aux; | | const eT k = x.aux; | |
| ea_type P = x.P.get_ea(); | | ea_type P = x.P.get_ea(); | |
| eT* out_mem = out.memptr(); | | | |
| const u32 n_elem = out.n_elem; | | | |
| | | | |
| u32 i,j; | | u32 i,j; | |
| | | | |
| for(i=0, j=1; j<n_elem; i+=2, j+=2) | | for(i=0, j=1; j<n_elem; i+=2, j+=2) | |
| { | | { | |
| const eT tmp_i = eop_core<eop_type>::process(P[i], k); | | const eT tmp_i = eop_core<eop_type>::process(P[i], k); | |
| const eT tmp_j = eop_core<eop_type>::process(P[j], k); | | const eT tmp_j = eop_core<eop_type>::process(P[j], k); | |
| | | | |
| out_mem[i] -= tmp_i; | | out_mem[i] -= tmp_i; | |
| out_mem[j] -= tmp_j; | | out_mem[j] -= tmp_j; | |
| | | | |
| skipping to change at line 517 | | skipping to change at line 498 | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const u32 n_rows = x.get_n_rows(); | | const u32 n_rows = x.get_n_rows(); | |
| const u32 n_cols = x.get_n_cols(); | | const u32 n_cols = x.get_n_cols(); | |
| const u32 n_slices = x.get_n_slices(); | | const u32 n_slices = x.get_n_slices(); | |
| | | | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "element-wise multiplication"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "element-wise multiplication"); | |
| | | | |
|
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| if(is_generator<eop_type>::value == true) | | if(is_generator<eop_type>::value == true) | |
| { | | { | |
|
| eT* out_mem = out.memptr(); | | | |
| const u32 n_elem = out.n_elem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_mem[i] *= eop_aux::generate<eT,eop_type>(); | | out_mem[i] *= eop_aux::generate<eT,eop_type>(); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| typedef typename ProxyCube<T1>::ea_type ea_type; | | typedef typename ProxyCube<T1>::ea_type ea_type; | |
| | | | |
|
| const eT k = x.aux; | | const eT k = x.aux; | |
| ea_type P = x.P.get_ea(); | | ea_type P = x.P.get_ea(); | |
| eT* out_mem = out.memptr(); | | | |
| const u32 n_elem = out.n_elem; | | | |
| | | | |
| u32 i,j; | | u32 i,j; | |
| | | | |
| for(i=0, j=1; j<n_elem; i+=2, j+=2) | | for(i=0, j=1; j<n_elem; i+=2, j+=2) | |
| { | | { | |
| const eT tmp_i = eop_core<eop_type>::process(P[i], k); | | const eT tmp_i = eop_core<eop_type>::process(P[i], k); | |
| const eT tmp_j = eop_core<eop_type>::process(P[j], k); | | const eT tmp_j = eop_core<eop_type>::process(P[j], k); | |
| | | | |
| out_mem[i] *= tmp_i; | | out_mem[i] *= tmp_i; | |
| out_mem[j] *= tmp_j; | | out_mem[j] *= tmp_j; | |
| | | | |
| skipping to change at line 573 | | skipping to change at line 550 | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const u32 n_rows = x.get_n_rows(); | | const u32 n_rows = x.get_n_rows(); | |
| const u32 n_cols = x.get_n_cols(); | | const u32 n_cols = x.get_n_cols(); | |
| const u32 n_slices = x.get_n_slices(); | | const u32 n_slices = x.get_n_slices(); | |
| | | | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "element-wise division"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "element-wise division"); | |
| | | | |
|
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | const u32 n_elem = out.n_elem; | |
| | | | |
| if(is_generator<eop_type>::value == true) | | if(is_generator<eop_type>::value == true) | |
| { | | { | |
|
| eT* out_mem = out.memptr(); | | | |
| const u32 n_elem = out.n_elem; | | | |
| | | | |
| for(u32 i=0; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| out_mem[i] /= eop_aux::generate<eT,eop_type>(); | | out_mem[i] /= eop_aux::generate<eT,eop_type>(); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| typedef typename ProxyCube<T1>::ea_type ea_type; | | typedef typename ProxyCube<T1>::ea_type ea_type; | |
| | | | |
|
| const eT k = x.aux; | | const eT k = x.aux; | |
| ea_type P = x.P.get_ea(); | | ea_type P = x.P.get_ea(); | |
| eT* out_mem = out.memptr(); | | | |
| const u32 n_elem = out.n_elem; | | | |
| | | | |
| u32 i,j; | | u32 i,j; | |
| | | | |
| for(i=0, j=1; j<n_elem; i+=2, j+=2) | | for(i=0, j=1; j<n_elem; i+=2, j+=2) | |
| { | | { | |
| const eT tmp_i = eop_core<eop_type>::process(P[i], k); | | const eT tmp_i = eop_core<eop_type>::process(P[i], k); | |
| const eT tmp_j = eop_core<eop_type>::process(P[j], k); | | const eT tmp_j = eop_core<eop_type>::process(P[j], k); | |
| | | | |
| out_mem[i] /= tmp_i; | | out_mem[i] /= tmp_i; | |
| out_mem[j] /= tmp_j; | | out_mem[j] /= tmp_j; | |
| | | | |
| skipping to change at line 729 | | skipping to change at line 702 | |
| | | | |
| template<> template<typename eT> arma_hot arma_pure arma_inline eT | | template<> template<typename eT> arma_hot arma_pure arma_inline eT | |
| eop_core<eop_abs >::process(const eT val, const eT ) { return
eop_aux::arma_abs(val); } | | eop_core<eop_abs >::process(const eT val, const eT ) { return
eop_aux::arma_abs(val); } | |
| | | | |
| template<> template<typename eT> arma_hot arma_pure arma_inline eT | | template<> template<typename eT> arma_hot arma_pure arma_inline eT | |
| eop_core<eop_conj >::process(const eT val, const eT ) { return
eop_aux::conj(val); } | | eop_core<eop_conj >::process(const eT val, const eT ) { return
eop_aux::conj(val); } | |
| | | | |
| template<> template<typename eT> arma_hot arma_pure arma_inline eT | | template<> template<typename eT> arma_hot arma_pure arma_inline eT | |
| eop_core<eop_pow >::process(const eT val, const eT k) { return
eop_aux::pow(val, k); } | | eop_core<eop_pow >::process(const eT val, const eT k) { return
eop_aux::pow(val, k); } | |
| | | | |
|
| | | template<> template<typename eT> arma_hot arma_pure arma_inline eT | |
| | | eop_core<eop_floor >::process(const eT val, const eT ) { return | |
| | | eop_aux::floor(val); } | |
| | | | |
| | | template<> template<typename eT> arma_hot arma_pure arma_inline eT | |
| | | eop_core<eop_ceil >::process(const eT val, const eT ) { return | |
| | | eop_aux::ceil(val); } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 25 change blocks. |
| 62 lines changed or deleted | | 43 lines changed or added | |
|
| op_max_meat.hpp | | op_max_meat.hpp | |
|
| // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) | | // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2008-2010 Conrad Sanderson | | // Copyright (C) 2008-2011 Conrad Sanderson | |
| // | | // | |
| // This file is part of the Armadillo C++ library. | | // This file is part of the Armadillo C++ library. | |
| // It is provided without any warranty of fitness | | // It is provided without any warranty of fitness | |
| // for any purpose. You can redistribute this file | | // for any purpose. You can redistribute this file | |
| // and/or modify it under the terms of the GNU | | // and/or modify it under the terms of the GNU | |
| // Lesser General Public License (LGPL) as published | | // Lesser General Public License (LGPL) as published | |
| // by the Free Software Foundation, either version 3 | | // by the Free Software Foundation, either version 3 | |
| // of the License or (at your option) any later version. | | // of the License or (at your option) any later version. | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| | | | |
| skipping to change at line 25 | | skipping to change at line 25 | |
| | | | |
| //! find the maximum value in an array | | //! find the maximum value in an array | |
| template<typename eT> | | template<typename eT> | |
| arma_pure | | arma_pure | |
| inline | | inline | |
| eT | | eT | |
| op_max::direct_max(const eT* const X, const u32 n_elem) | | op_max::direct_max(const eT* const X, const u32 n_elem) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| eT max_val = X[0]; | | eT max_val = (n_elem != 1) ? priv::most_neg<eT>() : X[0]; | |
| | | | |
| u32 i,j; | | u32 i,j; | |
| | | | |
|
| for(i=1, j=2; j<n_elem; i+=2, j+=2) | | for(i=0, j=1; j<n_elem; i+=2, j+=2) | |
| { | | { | |
| const eT X_i = X[i]; | | const eT X_i = X[i]; | |
|
| | | const eT X_j = X[j]; | |
| | | | |
| if(X_i > max_val) | | if(X_i > max_val) | |
| { | | { | |
| max_val = X_i; | | max_val = X_i; | |
| } | | } | |
| | | | |
|
| const eT X_j = X[j]; | | | |
| | | | |
| if(X_j > max_val) | | if(X_j > max_val) | |
| { | | { | |
| max_val = X_j; | | max_val = X_j; | |
| } | | } | |
| } | | } | |
| | | | |
| if(i < n_elem) | | if(i < n_elem) | |
| { | | { | |
| const eT X_i = X[i]; | | const eT X_i = X[i]; | |
| | | | |
| | | | |
| skipping to change at line 68 | | skipping to change at line 67 | |
| | | | |
| //! find the maximum value in a subview | | //! find the maximum value in a subview | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
| op_max::direct_max(const subview<eT>& X) | | op_max::direct_max(const subview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const u32 X_n_elem = X.n_elem; | | const u32 X_n_elem = X.n_elem; | |
|
| eT max_val = X[0]; | | eT max_val = (X_n_elem != 1) ? priv::most_neg<eT>() : X[0]; | |
| | | | |
|
| for(u32 i=1; i<X_n_elem; ++i) | | for(u32 i=0; i<X_n_elem; ++i) | |
| { | | { | |
| eT tmp_val = X[i]; | | eT tmp_val = X[i]; | |
| | | | |
| if(tmp_val > max_val) | | if(tmp_val > max_val) | |
| { | | { | |
| max_val = tmp_val; | | max_val = tmp_val; | |
| } | | } | |
| } | | } | |
| | | | |
| return max_val; | | return max_val; | |
| | | | |
| skipping to change at line 92 | | skipping to change at line 91 | |
| | | | |
| //! find the maximum value in a diagview | | //! find the maximum value in a diagview | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
| op_max::direct_max(const diagview<eT>& X) | | op_max::direct_max(const diagview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const u32 X_n_elem = X.n_elem; | | const u32 X_n_elem = X.n_elem; | |
|
| eT max_val = X[0]; | | eT max_val = (X_n_elem != 1) ? priv::most_neg<eT>() : X[0]; | |
| | | | |
|
| for(u32 i=1; i<X_n_elem; ++i) | | for(u32 i=0; i<X_n_elem; ++i) | |
| { | | { | |
| eT tmp_val = X[i]; | | eT tmp_val = X[i]; | |
| | | | |
| if(tmp_val > max_val) | | if(tmp_val > max_val) | |
| { | | { | |
| max_val = tmp_val; | | max_val = tmp_val; | |
| } | | } | |
| } | | } | |
| | | | |
| return max_val; | | return max_val; | |
| | | | |
| skipping to change at line 151 | | skipping to change at line 150 | |
| } | | } | |
| else | | else | |
| if(dim == 1) | | if(dim == 1) | |
| { | | { | |
| arma_extra_debug_print("op_max::apply(), dim = 1"); | | arma_extra_debug_print("op_max::apply(), dim = 1"); | |
| | | | |
| 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 max_val = X.at(row,0); | | eT max_val = (X_n_cols != 1) ? priv::most_neg<eT>() : X.at(row,0); | |
| | | | |
|
| for(u32 col=1; col<X_n_cols; ++col) | | for(u32 col=0; col<X_n_cols; ++col) | |
| { | | { | |
| const eT tmp_val = X.at(row,col); | | const eT tmp_val = X.at(row,col); | |
| | | | |
| if(tmp_val > max_val) | | if(tmp_val > max_val) | |
| { | | { | |
| max_val = tmp_val; | | max_val = tmp_val; | |
| } | | } | |
| } | | } | |
| | | | |
| out[row] = max_val; | | out[row] = max_val; | |
|
| | | | |
| } | | } | |
|
| | | | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| //! Find the maximum value in an array (version for complex numbers) | | //! Find the maximum value in an array (version for complex numbers) | |
| template<typename T> | | template<typename T> | |
| inline | | inline | |
| std::complex<T> | | std::complex<T> | |
| op_max::direct_max(const std::complex<T>* const X, const u32 n_elem) | | op_max::direct_max(const std::complex<T>* const X, const u32 n_elem) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| u32 index = 0; | | u32 index = 0; | |
|
| T max_val = std::abs(X[index]); | | T max_val = (n_elem != 1) ? priv::most_neg<T>() : std::abs(X[0]); | |
| | | | |
|
| for(u32 i=1; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| const T tmp_val = std::abs(X[i]); | | const T tmp_val = std::abs(X[i]); | |
| | | | |
| if(tmp_val > max_val) | | if(tmp_val > max_val) | |
| { | | { | |
| max_val = tmp_val; | | max_val = tmp_val; | |
| index = i; | | index = i; | |
| } | | } | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 206 | | skipping to change at line 202 | |
| //! Find the maximum value in a subview (version for complex numbers) | | //! Find the maximum value in a subview (version for complex numbers) | |
| template<typename T> | | template<typename T> | |
| inline | | inline | |
| std::complex<T> | | std::complex<T> | |
| op_max::direct_max(const subview< std::complex<T> >& X) | | op_max::direct_max(const subview< std::complex<T> >& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const u32 X_n_elem = X.n_elem; | | const u32 X_n_elem = X.n_elem; | |
| u32 index = 0; | | u32 index = 0; | |
|
| T max_val = std::abs(X[index]); | | T max_val = (X_n_elem != 1) ? priv::most_neg<T>() : std::abs(X[0
]); | |
| | | | |
|
| for(u32 i=1; i<X_n_elem; ++i) | | for(u32 i=0; i<X_n_elem; ++i) | |
| { | | { | |
| const T tmp_val = std::abs(X[i]); | | const T tmp_val = std::abs(X[i]); | |
| | | | |
| if(tmp_val > max_val) | | if(tmp_val > max_val) | |
| { | | { | |
| max_val = tmp_val; | | max_val = tmp_val; | |
| index = i; | | index = i; | |
| } | | } | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 232 | | skipping to change at line 228 | |
| //! Find the maximum value in a diagview (version for complex numbers) | | //! Find the maximum value in a diagview (version for complex numbers) | |
| template<typename T> | | template<typename T> | |
| inline | | inline | |
| std::complex<T> | | std::complex<T> | |
| op_max::direct_max(const diagview< std::complex<T> >& X) | | op_max::direct_max(const diagview< std::complex<T> >& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const u32 X_n_elem = X.n_elem; | | const u32 X_n_elem = X.n_elem; | |
| u32 index = 0; | | u32 index = 0; | |
|
| T max_val = std::abs(X[index]); | | T max_val = (X_n_elem != 1) ? priv::most_neg<T>() : std::abs(X[0
]); | |
| | | | |
|
| for(u32 i=1; i<X_n_elem; ++i) | | for(u32 i=0; i<X_n_elem; ++i) | |
| { | | { | |
| const T tmp_val = std::abs(X[i]); | | const T tmp_val = std::abs(X[i]); | |
| | | | |
| if(tmp_val > max_val) | | if(tmp_val > max_val) | |
| { | | { | |
| max_val = tmp_val; | | max_val = tmp_val; | |
| index = i; | | index = i; | |
| } | | } | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 289 | | skipping to change at line 285 | |
| else | | else | |
| if(dim == 1) // row-wise max | | if(dim == 1) // row-wise max | |
| { | | { | |
| arma_extra_debug_print("op_max::apply(), dim = 1"); | | arma_extra_debug_print("op_max::apply(), dim = 1"); | |
| | | | |
| 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) | |
| { | | { | |
| u32 index = 0; | | u32 index = 0; | |
|
| T max_val = std::abs(X.at(row,index)); | | T max_val = (X_n_cols != 1) ? priv::most_neg<T>() : std::abs(X.at(r
ow,0)); | |
| | | | |
|
| for(u32 col=1; col<X.n_cols; ++col) | | for(u32 col=0; col<X_n_cols; ++col) | |
| { | | { | |
| const T tmp_val = std::abs(X.at(row,col)); | | const T tmp_val = std::abs(X.at(row,col)); | |
| | | | |
| if(tmp_val > max_val) | | if(tmp_val > max_val) | |
| { | | { | |
| max_val = tmp_val; | | max_val = tmp_val; | |
| index = col; | | index = col; | |
| } | | } | |
| } | | } | |
| | | | |
| | | | |
End of changes. 22 change blocks. |
| 23 lines changed or deleted | | 19 lines changed or added | |
|
| op_mean_meat.hpp | | op_mean_meat.hpp | |
|
| // Copyright (C) 2009-2010 NICTA (www.nicta.com.au) | | // Copyright (C) 2009-2011 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2009-2010 Conrad Sanderson | | // Copyright (C) 2009-2011 Conrad Sanderson | |
| // | | // | |
| // This file is part of the Armadillo C++ library. | | // This file is part of the Armadillo C++ library. | |
| // It is provided without any warranty of fitness | | // It is provided without any warranty of fitness | |
| // for any purpose. You can redistribute this file | | // for any purpose. You can redistribute this file | |
| // and/or modify it under the terms of the GNU | | // and/or modify it under the terms of the GNU | |
| // Lesser General Public License (LGPL) as published | | // Lesser General Public License (LGPL) as published | |
| // by the Free Software Foundation, either version 3 | | // by the Free Software Foundation, either version 3 | |
| // of the License or (at your option) any later version. | | // of the License or (at your option) any later version. | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| | | | |
| skipping to change at line 25 | | skipping to change at line 25 | |
| | | | |
| //! find the mean value of an array | | //! find the mean value of an array | |
| template<typename eT> | | template<typename eT> | |
| arma_pure | | arma_pure | |
| inline | | inline | |
| eT | | eT | |
| op_mean::direct_mean(const eT* const X, const u32 n_elem) | | op_mean::direct_mean(const eT* const X, const u32 n_elem) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| eT val = eT(0); | | typedef typename get_pod_type<eT>::result T; | |
| | | | |
|
| u32 i,j; | | return arrayops::accumulate(X, n_elem) / T(n_elem); | |
| | | | |
| for(i=0, j=1; j<n_elem; i+=2, j+=2) | | | |
| { | | | |
| val += X[i]; | | | |
| val += X[j]; | | | |
| } | | | |
| | | | |
| if(i < n_elem) | | | |
| { | | | |
| val += X[i]; | | | |
| } | | | |
| | | | |
| return val / eT(n_elem); | | | |
| } | | } | |
| | | | |
| //! find the mean value of a subview | | //! find the mean value of a subview | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
| op_mean::direct_mean(const subview<eT>& X) | | op_mean::direct_mean(const subview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | typedef typename get_pod_type<eT>::result T; | |
| | | | |
| const u32 X_n_elem = X.n_elem; | | const u32 X_n_elem = X.n_elem; | |
| eT val = eT(0); | | eT val = eT(0); | |
| | | | |
| for(u32 i=0; i<X_n_elem; ++i) | | for(u32 i=0; i<X_n_elem; ++i) | |
| { | | { | |
| val += X[i]; | | val += X[i]; | |
| } | | } | |
| | | | |
|
| return val / eT(X_n_elem); | | return val / T(X_n_elem); | |
| } | | } | |
| | | | |
| //! find the mean value of a diagview | | //! find the mean value of a diagview | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
| op_mean::direct_mean(const diagview<eT>& X) | | op_mean::direct_mean(const diagview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | typedef typename get_pod_type<eT>::result T; | |
| | | | |
| const u32 X_n_elem = X.n_elem; | | const u32 X_n_elem = X.n_elem; | |
| eT val = eT(0); | | eT val = eT(0); | |
| | | | |
| for(u32 i=0; i<X_n_elem; ++i) | | for(u32 i=0; i<X_n_elem; ++i) | |
| { | | { | |
| val += X[i]; | | val += X[i]; | |
| } | | } | |
| | | | |
|
| return val / eT(X_n_elem); | | return val / T(X_n_elem); | |
| } | | } | |
| | | | |
| //! \brief | | //! \brief | |
| //! For each row or for each column, find the mean value. | | //! For each row or for each column, find the mean value. | |
| //! 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 means are found, is set via the mean() fun
ction. | | //! The dimension, for which the means are found, is set via the mean() fun
ction. | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| op_mean::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_mean>& in) | | op_mean::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_mean>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | typedef typename get_pod_type<eT>::result T; | |
| | | | |
| 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), "mean(): given matrix has no elements"
); | | arma_debug_check( (X.n_elem == 0), "mean(): given matrix has no elements"
); | |
| | | | |
| const u32 dim = in.aux_u32_a; | | const u32 dim = in.aux_u32_a; | |
| arma_debug_check( (dim > 1), "mean(): incorrect usage. dim must be 0 or 1
"); | | arma_debug_check( (dim > 1), "mean(): incorrect usage. dim must be 0 or 1
"); | |
| | | | |
| const u32 X_n_rows = X.n_rows; | | const u32 X_n_rows = X.n_rows; | |
| | | | |
| skipping to change at line 132 | | skipping to change at line 124 | |
| | | | |
| 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); | |
| } | | } | |
| | | | |
|
| out[row] = val / eT(X_n_cols); | | out[row] = val / T(X_n_cols); | |
| | | | |
| } | | } | |
|
| | | | |
| } | | } | |
|
| | | | |
| } | | } | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 11 change blocks. |
| 24 lines changed or deleted | | 13 lines changed or added | |
|
| op_min_meat.hpp | | op_min_meat.hpp | |
|
| // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) | | // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2008-2010 Conrad Sanderson | | // Copyright (C) 2008-2011 Conrad Sanderson | |
| // | | // | |
| // This file is part of the Armadillo C++ library. | | // This file is part of the Armadillo C++ library. | |
| // It is provided without any warranty of fitness | | // It is provided without any warranty of fitness | |
| // for any purpose. You can redistribute this file | | // for any purpose. You can redistribute this file | |
| // and/or modify it under the terms of the GNU | | // and/or modify it under the terms of the GNU | |
| // Lesser General Public License (LGPL) as published | | // Lesser General Public License (LGPL) as published | |
| // by the Free Software Foundation, either version 3 | | // by the Free Software Foundation, either version 3 | |
| // of the License or (at your option) any later version. | | // of the License or (at your option) any later version. | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| | | | |
| skipping to change at line 25 | | skipping to change at line 25 | |
| | | | |
| //! Find the minimum value in an array | | //! Find the minimum value in an array | |
| template<typename eT> | | template<typename eT> | |
| arma_pure | | arma_pure | |
| inline | | inline | |
| eT | | eT | |
| op_min::direct_min(const eT* const X, const u32 n_elem) | | op_min::direct_min(const eT* const X, const u32 n_elem) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| eT min_val = X[0]; | | eT min_val = (n_elem != 1) ? priv::most_pos<eT>() : X[0]; | |
| | | | |
| u32 i,j; | | u32 i,j; | |
| | | | |
|
| for(i=1, j=2; j<n_elem; i+=2, j+=2) | | for(i=0, j=1; j<n_elem; i+=2, j+=2) | |
| { | | { | |
| const eT X_i = X[i]; | | const eT X_i = X[i]; | |
|
| | | const eT X_j = X[j]; | |
| | | | |
| if(X_i < min_val) | | if(X_i < min_val) | |
| { | | { | |
| min_val = X_i; | | min_val = X_i; | |
| } | | } | |
| | | | |
|
| const eT X_j = X[j]; | | | |
| | | | |
| if(X_j < min_val) | | if(X_j < min_val) | |
| { | | { | |
| min_val = X_j; | | min_val = X_j; | |
| } | | } | |
| } | | } | |
| | | | |
| if(i < n_elem) | | if(i < n_elem) | |
| { | | { | |
| const eT X_i = X[i]; | | const eT X_i = X[i]; | |
| | | | |
| | | | |
| skipping to change at line 68 | | skipping to change at line 67 | |
| | | | |
| //! find the minimum value in a subview | | //! find the minimum value in a subview | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
| op_min::direct_min(const subview<eT>& X) | | op_min::direct_min(const subview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const u32 X_n_elem = X.n_elem; | | const u32 X_n_elem = X.n_elem; | |
|
| eT min_val = X[0]; | | | |
| | | | |
|
| for(u32 i=1; i<X_n_elem; ++i) | | eT min_val = (X_n_elem != 1) ? priv::most_pos<eT>() : X[0]; | |
| | | | |
| | | for(u32 i=0; i<X_n_elem; ++i) | |
| { | | { | |
| eT tmp_val = X[i]; | | eT tmp_val = X[i]; | |
| | | | |
| if(tmp_val < min_val) | | if(tmp_val < min_val) | |
| { | | { | |
| min_val = tmp_val; | | min_val = tmp_val; | |
| } | | } | |
| } | | } | |
| | | | |
| return min_val; | | return min_val; | |
| | | | |
| skipping to change at line 92 | | skipping to change at line 92 | |
| | | | |
| //! find the minimum value in a diagview | | //! find the minimum value in a diagview | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
| op_min::direct_min(const diagview<eT>& X) | | op_min::direct_min(const diagview<eT>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const u32 X_n_elem = X.n_elem; | | const u32 X_n_elem = X.n_elem; | |
|
| eT min_val = X[0]; | | | |
| | | | |
|
| for(u32 i=1; i<X_n_elem; ++i) | | eT min_val = (X_n_elem != 1) ? priv::most_pos<eT>() : X[0]; | |
| | | | |
| | | for(u32 i=0; i<X_n_elem; ++i) | |
| { | | { | |
| eT tmp_val = X[i]; | | eT tmp_val = X[i]; | |
| | | | |
| if(tmp_val < min_val) | | if(tmp_val < min_val) | |
| { | | { | |
| min_val = tmp_val; | | min_val = tmp_val; | |
| } | | } | |
| } | | } | |
| | | | |
| return min_val; | | return min_val; | |
| | | | |
| skipping to change at line 129 | | skipping to change at line 130 | |
| const Mat<eT>& X = tmp.M; | | const Mat<eT>& X = tmp.M; | |
| | | | |
| arma_debug_check( (X.n_elem == 0), "min(): given matrix has no elements"
); | | arma_debug_check( (X.n_elem == 0), "min(): given matrix has no elements"
); | |
| | | | |
| const u32 dim = in.aux_u32_a; | | const u32 dim = in.aux_u32_a; | |
| arma_debug_check( (dim > 1), "min(): incorrect usage. dim must be 0 or 1"
); | | arma_debug_check( (dim > 1), "min(): incorrect usage. dim must be 0 or 1"
); | |
| | | | |
| const u32 X_n_rows = X.n_rows; | | const u32 X_n_rows = X.n_rows; | |
| const u32 X_n_cols = X.n_cols; | | const u32 X_n_cols = X.n_cols; | |
| | | | |
|
| if(dim == 0) // column-wise min | | if(dim == 0) // min in each column | |
| { | | { | |
| arma_extra_debug_print("op_min::apply(), dim = 0"); | | arma_extra_debug_print("op_min::apply(), dim = 0"); | |
| | | | |
| out.set_size(1, X_n_cols); | | out.set_size(1, X_n_cols); | |
| | | | |
| for(u32 col=0; col<X_n_cols; ++col) | | for(u32 col=0; col<X_n_cols; ++col) | |
| { | | { | |
| out[col] = op_min::direct_min( X.colptr(col), X_n_rows ); | | out[col] = op_min::direct_min( X.colptr(col), X_n_rows ); | |
| } | | } | |
| } | | } | |
| else | | else | |
|
| if(dim == 1) // row-wise min | | if(dim == 1) // min in each row | |
| { | | { | |
| arma_extra_debug_print("op_min::apply(), dim = 1"); | | arma_extra_debug_print("op_min::apply(), dim = 1"); | |
| | | | |
| 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 min_val = X.at(row,0); | | eT min_val = (X_n_cols != 1) ? priv::most_pos<eT>() : X.at(row,0); | |
| | | | |
|
| for(u32 col=1; col<X_n_cols; ++col) | | for(u32 col=0; col<X_n_cols; ++col) | |
| { | | { | |
| const eT tmp_val = X.at(row,col); | | const eT tmp_val = X.at(row,col); | |
| | | | |
| if(tmp_val < min_val) | | if(tmp_val < min_val) | |
| { | | { | |
| min_val = tmp_val; | | min_val = tmp_val; | |
| } | | } | |
| } | | } | |
| | | | |
| out[row] = min_val; | | out[row] = min_val; | |
|
| | | | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| //! Find the minimum value in an array (version for complex numbers) | | //! Find the minimum value in an array (version for complex numbers) | |
| template<typename T> | | template<typename T> | |
| inline | | inline | |
| std::complex<T> | | std::complex<T> | |
| op_min::direct_min(const std::complex<T>* const X, const u32 n_elem) | | op_min::direct_min(const std::complex<T>* const X, const u32 n_elem) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| u32 index = 0; | | u32 index = 0; | |
|
| T min_val = std::abs(X[index]); | | T min_val = (n_elem != 1) ? priv::most_pos<T>() : std::abs(X[0]); | |
| | | | |
|
| for(u32 i=1; i<n_elem; ++i) | | for(u32 i=0; i<n_elem; ++i) | |
| { | | { | |
| const T tmp_val = std::abs(X[i]); | | const T tmp_val = std::abs(X[i]); | |
| | | | |
| if(tmp_val < min_val) | | if(tmp_val < min_val) | |
| { | | { | |
| min_val = tmp_val; | | min_val = tmp_val; | |
| index = i; | | index = i; | |
| } | | } | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 204 | | skipping to change at line 204 | |
| //! Find the minimum value in a subview (version for complex numbers) | | //! Find the minimum value in a subview (version for complex numbers) | |
| template<typename T> | | template<typename T> | |
| inline | | inline | |
| std::complex<T> | | std::complex<T> | |
| op_min::direct_min(const subview< std::complex<T> >& X) | | op_min::direct_min(const subview< std::complex<T> >& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const u32 X_n_elem = X.n_elem; | | const u32 X_n_elem = X.n_elem; | |
| u32 index = 0; | | u32 index = 0; | |
|
| T min_val = std::abs(X[index]); | | T min_val = (X_n_elem != 1) ? priv::most_pos<T>() : std::abs(X[0
]); | |
| | | | |
|
| for(u32 i=1; i<X_n_elem; ++i) | | for(u32 i=0; i<X_n_elem; ++i) | |
| { | | { | |
| const T tmp_val = std::abs(X[i]); | | const T tmp_val = std::abs(X[i]); | |
| | | | |
| if(tmp_val < min_val) | | if(tmp_val < min_val) | |
| { | | { | |
| min_val = tmp_val; | | min_val = tmp_val; | |
| index = i; | | index = i; | |
| } | | } | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 230 | | skipping to change at line 230 | |
| //! Find the minimum value in a diagview (version for complex numbers) | | //! Find the minimum value in a diagview (version for complex numbers) | |
| template<typename T> | | template<typename T> | |
| inline | | inline | |
| std::complex<T> | | std::complex<T> | |
| op_min::direct_min(const diagview< std::complex<T> >& X) | | op_min::direct_min(const diagview< std::complex<T> >& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const u32 X_n_elem = X.n_elem; | | const u32 X_n_elem = X.n_elem; | |
| u32 index = 0; | | u32 index = 0; | |
|
| T min_val = std::abs(X[index]); | | T min_val = (X_n_elem != 1) ? priv::most_pos<T>() : std::abs(X[0
]); | |
| | | | |
|
| for(u32 i=1; i<X_n_elem; ++i) | | for(u32 i=0; i<X_n_elem; ++i) | |
| { | | { | |
| const T tmp_val = std::abs(X[i]); | | const T tmp_val = std::abs(X[i]); | |
| | | | |
| if(tmp_val < min_val) | | if(tmp_val < min_val) | |
| { | | { | |
| min_val = tmp_val; | | min_val = tmp_val; | |
| index = i; | | index = i; | |
| } | | } | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 287 | | skipping to change at line 287 | |
| else | | else | |
| if(dim == 1) // row-wise min | | if(dim == 1) // row-wise min | |
| { | | { | |
| arma_extra_debug_print("op_min::apply(), dim = 1"); | | arma_extra_debug_print("op_min::apply(), dim = 1"); | |
| | | | |
| 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) | |
| { | | { | |
| u32 index = 0; | | u32 index = 0; | |
|
| T min_val = std::abs(X.at(row,index)); | | T min_val = (X_n_cols != 1) ? priv::most_pos<T>() : std::abs(X.at(r
ow,0)); | |
| | | | |
|
| for(u32 col=1; col<X.n_cols; ++col) | | for(u32 col=0; col<X_n_cols; ++col) | |
| { | | { | |
| const T tmp_val = std::abs(X.at(row,col)); | | const T tmp_val = std::abs(X.at(row,col)); | |
| | | | |
| if(tmp_val < min_val) | | if(tmp_val < min_val) | |
| { | | { | |
| min_val = tmp_val; | | min_val = tmp_val; | |
| index = col; | | index = col; | |
| } | | } | |
| } | | } | |
| | | | |
| | | | |
End of changes. 22 change blocks. |
| 23 lines changed or deleted | | 23 lines changed or added | |
|