diff --git a/include/armadillo_bits/fn_interp1.hpp b/include/armadillo_bits/fn_interp1.hpp index b4a89ba4..d1154230 100644 --- a/include/armadillo_bits/fn_interp1.hpp +++ b/include/armadillo_bits/fn_interp1.hpp @@ -53,6 +53,11 @@ interp1_helper_nearest(const Mat& XG, const Mat& YG, const Mat& XI, { YI_mem[i] = extrap_val; } + else + if(arma_isnan(XI_val)) + { + YI_mem[i] = Datum::nan; + } else { // XG and XI are guaranteed to be sorted in ascending manner, @@ -113,6 +118,11 @@ interp1_helper_linear(const Mat& XG, const Mat& YG, const Mat& XI, M { YI_mem[i] = extrap_val; } + else + if(arma_isnan(XI_val)) + { + YI_mem[i] = Datum::nan; + } else { // XG and XI are guaranteed to be sorted in ascending manner, @@ -223,11 +233,11 @@ interp1_helper(const Mat& X, const Mat& Y, const Mat& XI, Mat& Y Mat 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& X, const Mat& Y, const Mat& XI, Mat& Y const Mat& 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); }