Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions inst/include/current/armadillo_bits/diskio_bones.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ struct diskio

template<typename eT> inline static std::streamsize prepare_stream(std::ostream& f);

template<typename eT> inline static constexpr eT real_as_int_lower_limit();
template<typename eT> inline static constexpr eT real_as_int_upper_limit();


//
// matrix saving
Expand Down
79 changes: 52 additions & 27 deletions inst/include/current/armadillo_bits/diskio_meat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,32 @@ diskio::prepare_stream(std::ostream& f)

return cell_width;
}



template<typename eT>
inline
constexpr
eT
diskio::real_as_int_lower_limit()
{
constexpr eT eT_int_accuracy_lower_limit = -( (is_fp16<eT>::value) ? eT(0x800) : ( (is_float<eT>::value) ? eT(0x1000000) : eT(0x20000000000000) ) );

return (std::max)( eT(std::numeric_limits<int>::lowest()), eT_int_accuracy_lower_limit );
}



template<typename eT>
inline
constexpr
eT
diskio::real_as_int_upper_limit()
{
constexpr eT eT_int_accuracy_upper_limit = (is_fp16<eT>::value) ? eT(0x800) : ( (is_float<eT>::value) ? eT(0x1000000) : eT(0x20000000000000) );

return (std::min)( eT(std::numeric_limits<int>::max()), eT_int_accuracy_upper_limit );
}



Expand Down Expand Up @@ -935,16 +960,16 @@ diskio::save_csv_ascii(const Mat<eT>& x, std::ostream& f, const char separator)
uword x_n_rows = x.n_rows;
uword x_n_cols = x.n_cols;

const eT eT_int_lowest = eT(std::numeric_limits<int>::lowest());
const eT eT_int_max = eT(std::numeric_limits<int>::max());
constexpr eT eT_int_lower = diskio::real_as_int_lower_limit<eT>();
constexpr eT eT_int_upper = diskio::real_as_int_upper_limit<eT>();

for(uword row=0; row < x_n_rows; ++row)
{
for(uword col=0; col < x_n_cols; ++col)
{
const eT val = x.at(row,col);

const bool is_real_int = (is_real<eT>::yes) && arma_isfinite(val) && (val > eT_int_lowest) && (val < eT_int_max) && (eT(int(val)) == val);
const bool is_real_int = (is_real<eT>::yes) && arma_isfinite(val) && (val > eT_int_lower) && (val < eT_int_upper) && (eT(int(val)) == val);

(is_real_int) ? arma_ostream::raw_print_elem(f, int(val)) : arma_ostream::raw_print_elem(f, val);

Expand Down Expand Up @@ -977,8 +1002,8 @@ diskio::save_csv_ascii(const Mat< std::complex<T> >& x, std::ostream& f, const c

diskio::prepare_stream<eT>(f);

const T T_int_lowest = T(std::numeric_limits<int>::lowest());
const T T_int_max = T(std::numeric_limits<int>::max());
constexpr T T_int_lower = diskio::real_as_int_lower_limit<T>();
constexpr T T_int_upper = diskio::real_as_int_upper_limit<T>();

uword x_n_rows = x.n_rows;
uword x_n_cols = x.n_cols;
Expand All @@ -994,8 +1019,8 @@ diskio::save_csv_ascii(const Mat< std::complex<T> >& x, std::ostream& f, const c
const T abs_i = (val_i < T(0)) ? T(-val_i) : T(val_i);
const char sgn_i = (val_i < T(0)) ? char('-') : char('+');

const bool val_r_is_real_int = (is_real<T>::yes) && arma_isfinite(val_r) && (val_r > T_int_lowest) && (val_r < T_int_max) && (T(int(val_r)) == val_r);
const bool abs_i_is_real_int = (is_real<T>::yes) && arma_isfinite(abs_i) && (abs_i < T_int_max) && (T(int(abs_i)) == abs_i);
const bool val_r_is_real_int = (is_real<T>::yes) && arma_isfinite(val_r) && (val_r > T_int_lower) && (val_r < T_int_upper) && (T(int(val_r)) == val_r);
const bool abs_i_is_real_int = (is_real<T>::yes) && arma_isfinite(abs_i) && (abs_i < T_int_upper) && (T(int(abs_i)) == abs_i);

(val_r_is_real_int) ? arma_ostream::raw_print_elem(f, int(val_r)) : arma_ostream::raw_print_elem(f, val_r);

Expand Down Expand Up @@ -1061,9 +1086,9 @@ diskio::save_coord_ascii(const Mat<eT>& x, std::ostream& f)

diskio::prepare_stream<eT>(f);

const eT eT_zero = eT(0);
const eT eT_int_lowest = eT(std::numeric_limits<int>::lowest());
const eT eT_int_max = eT(std::numeric_limits<int>::max());
constexpr eT eT_zero = eT(0);
constexpr eT eT_int_lower = diskio::real_as_int_lower_limit<eT>();
constexpr eT eT_int_upper = diskio::real_as_int_upper_limit<eT>();

for(uword col=0; col < x.n_cols; ++col)
for(uword row=0; row < x.n_rows; ++row)
Expand All @@ -1075,7 +1100,7 @@ diskio::save_coord_ascii(const Mat<eT>& x, std::ostream& f)
f << row; f.put(' ');
f << col; f.put(' ');

const bool is_real_int = (is_real<eT>::yes) && arma_isfinite(val) && (val > eT_int_lowest) && (val < eT_int_max) && (eT(int(val)) == val);
const bool is_real_int = (is_real<eT>::yes) && arma_isfinite(val) && (val > eT_int_lower) && (val < eT_int_upper) && (eT(int(val)) == val);

(is_real_int) ? arma_ostream::raw_print_elem(f, int(val)) : arma_ostream::raw_print_elem(f, val);

Expand Down Expand Up @@ -1116,9 +1141,9 @@ diskio::save_coord_ascii(const Mat< std::complex<T> >& x, std::ostream& f)

diskio::prepare_stream<eT>(f);

const eT eT_zero = eT(0);
const T T_int_lowest = T(std::numeric_limits<int>::lowest());
const T T_int_max = T(std::numeric_limits<int>::max());
constexpr eT eT_zero = eT(0);
constexpr T T_int_lower = diskio::real_as_int_lower_limit<T>();
constexpr T T_int_upper = diskio::real_as_int_upper_limit<T>();

for(uword col=0; col < x.n_cols; ++col)
for(uword row=0; row < x.n_rows; ++row)
Expand All @@ -1133,8 +1158,8 @@ diskio::save_coord_ascii(const Mat< std::complex<T> >& x, std::ostream& f)
const T val_r = std::real(val);
const T val_i = std::imag(val);

const bool val_r_is_real_int = (is_real<T>::yes) && arma_isfinite(val_r) && (val_r > T_int_lowest) && (val_r < T_int_max) && (T(int(val_r)) == val_r);
const bool val_i_is_real_int = (is_real<T>::yes) && arma_isfinite(val_i) && (val_i > T_int_lowest) && (val_i < T_int_max) && (T(int(val_i)) == val_i);
const bool val_r_is_real_int = (is_real<T>::yes) && arma_isfinite(val_r) && (val_r > T_int_lower) && (val_r < T_int_upper) && (T(int(val_r)) == val_r);
const bool val_i_is_real_int = (is_real<T>::yes) && arma_isfinite(val_i) && (val_i > T_int_lower) && (val_i < T_int_upper) && (T(int(val_i)) == val_i);

(val_r_is_real_int) ? arma_ostream::raw_print_elem(f, int(val_r)) : arma_ostream::raw_print_elem(f, val_r);

Expand Down Expand Up @@ -2966,9 +2991,9 @@ diskio::save_csv_ascii(const SpMat<eT>& x, std::ostream& f, const char separator
uword x_n_rows = x.n_rows;
uword x_n_cols = x.n_cols;

const eT eT_zero = eT(0);
const eT eT_int_lowest = eT(std::numeric_limits<int>::lowest());
const eT eT_int_max = eT(std::numeric_limits<int>::max());
constexpr eT eT_zero = eT(0);
constexpr eT eT_int_lower = diskio::real_as_int_lower_limit<eT>();
constexpr eT eT_int_upper = diskio::real_as_int_upper_limit<eT>();

for(uword row=0; row < x_n_rows; ++row)
{
Expand All @@ -2982,7 +3007,7 @@ diskio::save_csv_ascii(const SpMat<eT>& x, std::ostream& f, const char separator
}
else
{
const bool is_real_int = (is_real<eT>::yes) && arma_isfinite(val) && (val > eT_int_lowest) && (val < eT_int_max) && (eT(int(val)) == val);
const bool is_real_int = (is_real<eT>::yes) && arma_isfinite(val) && (val > eT_int_lower) && (val < eT_int_upper) && (eT(int(val)) == val);

(is_real_int) ? arma_ostream::raw_print_elem(f, int(val)) : arma_ostream::raw_print_elem(f, val);
}
Expand Down Expand Up @@ -3064,8 +3089,8 @@ diskio::save_coord_ascii(const SpMat<eT>& x, std::ostream& f)

diskio::prepare_stream<eT>(f);

const eT eT_int_lowest = eT(std::numeric_limits<int>::lowest());
const eT eT_int_max = eT(std::numeric_limits<int>::max());
constexpr eT eT_int_lower = diskio::real_as_int_lower_limit<eT>();
constexpr eT eT_int_upper = diskio::real_as_int_upper_limit<eT>();

typename SpMat<eT>::const_iterator iter = x.begin();
typename SpMat<eT>::const_iterator iter_end = x.end();
Expand All @@ -3077,7 +3102,7 @@ diskio::save_coord_ascii(const SpMat<eT>& x, std::ostream& f)

const eT val = (*iter);

const bool is_real_int = (is_real<eT>::yes) && arma_isfinite(val) && (val > eT_int_lowest) && (val < eT_int_max) && (eT(int(val)) == val);
const bool is_real_int = (is_real<eT>::yes) && arma_isfinite(val) && (val > eT_int_lower) && (val < eT_int_upper) && (eT(int(val)) == val);

(is_real_int) ? arma_ostream::raw_print_elem(f, int(val)) : arma_ostream::raw_print_elem(f, val);

Expand Down Expand Up @@ -3120,8 +3145,8 @@ diskio::save_coord_ascii(const SpMat< std::complex<T> >& x, std::ostream& f)

diskio::prepare_stream<eT>(f);

const T T_int_lowest = T(std::numeric_limits<int>::lowest());
const T T_int_max = T(std::numeric_limits<int>::max());
constexpr T T_int_lower = diskio::real_as_int_lower_limit<T>();
constexpr T T_int_upper = diskio::real_as_int_upper_limit<T>();

typename SpMat<eT>::const_iterator iter = x.begin();
typename SpMat<eT>::const_iterator iter_end = x.end();
Expand All @@ -3136,8 +3161,8 @@ diskio::save_coord_ascii(const SpMat< std::complex<T> >& x, std::ostream& f)
const T val_r = std::real(val);
const T val_i = std::imag(val);

const bool val_r_is_real_int = (is_real<T>::yes) && arma_isfinite(val_r) && (val_r > T_int_lowest) && (val_r < T_int_max) && (T(int(val_r)) == val_r);
const bool val_i_is_real_int = (is_real<T>::yes) && arma_isfinite(val_i) && (val_i > T_int_lowest) && (val_i < T_int_max) && (T(int(val_i)) == val_i);
const bool val_r_is_real_int = (is_real<T>::yes) && arma_isfinite(val_r) && (val_r > T_int_lower) && (val_r < T_int_upper) && (T(int(val_r)) == val_r);
const bool val_i_is_real_int = (is_real<T>::yes) && arma_isfinite(val_i) && (val_i > T_int_lower) && (val_i < T_int_upper) && (T(int(val_i)) == val_i);

(val_r_is_real_int) ? arma_ostream::raw_print_elem(f, int(val_r)) : arma_ostream::raw_print_elem(f, val_r);

Expand Down
2 changes: 1 addition & 1 deletion inst/include/current/armadillo_bits/glue_hist_meat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ glue_hist::apply_noalias(Mat<uword>& out, const Mat<eT>& X, const Mat<eT>& C, co
{
const eT val = X_mem[i];

if(is_finite(val))
if(arma_isfinite(val))
{
eT opt_dist = (val >= center_0) ? (val - center_0) : (center_0 - val);
uword opt_index = 0;
Expand Down