detect NaN in XI
This commit is contained in:
@@ -53,6 +53,11 @@ interp1_helper_nearest(const Mat<eT>& XG, const Mat<eT>& YG, const Mat<eT>& XI,
|
||||
{
|
||||
YI_mem[i] = extrap_val;
|
||||
}
|
||||
else
|
||||
if(arma_isnan(XI_val))
|
||||
{
|
||||
YI_mem[i] = Datum<eT>::nan;
|
||||
}
|
||||
else
|
||||
{
|
||||
// XG and XI are guaranteed to be sorted in ascending manner,
|
||||
@@ -113,6 +118,11 @@ interp1_helper_linear(const Mat<eT>& XG, const Mat<eT>& YG, const Mat<eT>& XI, M
|
||||
{
|
||||
YI_mem[i] = extrap_val;
|
||||
}
|
||||
else
|
||||
if(arma_isnan(XI_val))
|
||||
{
|
||||
YI_mem[i] = Datum<eT>::nan;
|
||||
}
|
||||
else
|
||||
{
|
||||
// XG and XI are guaranteed to be sorted in ascending manner,
|
||||
@@ -223,11 +233,11 @@ interp1_helper(const Mat<eT>& X, const Mat<eT>& Y, const Mat<eT>& XI, Mat<eT>& Y
|
||||
Mat<eT> XI_tmp;
|
||||
uvec XI_indices;
|
||||
|
||||
const bool XI_is_sorted = XI.is_sorted();
|
||||
const bool XI_is_sorted = XI.is_sorted(); // NOTE: .is_sorted() currently doesn't detect NaN
|
||||
|
||||
if(XI_is_sorted == false)
|
||||
{
|
||||
XI_indices = sort_index(XI);
|
||||
XI_indices = sort_index(XI); // NOTE: sort_index() will throw if XI has NaN
|
||||
|
||||
const uword N = XI.n_elem;
|
||||
|
||||
@@ -246,6 +256,8 @@ interp1_helper(const Mat<eT>& X, const Mat<eT>& Y, const Mat<eT>& XI, Mat<eT>& Y
|
||||
|
||||
const Mat<eT>& XI_sorted = (XI_is_sorted) ? XI : XI_tmp;
|
||||
|
||||
// NOTE: XI_sorted may have NaN
|
||||
|
||||
|
||||
if(sig == 10) { interp1_helper_nearest(X_sanitised, Y_sanitised, XI_sorted, YI, extrap_val); }
|
||||
else if(sig == 20) { interp1_helper_linear (X_sanitised, Y_sanitised, XI_sorted, YI, extrap_val); }
|
||||
|
||||
Reference in New Issue
Block a user