void test_bspline(gsl_bspline_workspace * bw, gsl_bspline_deriv_workspace * dbw) { gsl_vector *B; gsl_matrix *dB; size_t i, j; size_t n = 100; size_t ncoeffs = gsl_bspline_ncoeffs(bw); size_t order = gsl_bspline_order(bw); size_t nbreak = gsl_bspline_nbreak(bw); double a = gsl_bspline_breakpoint(0, bw); double b = gsl_bspline_breakpoint(nbreak - 1, bw); B = gsl_vector_alloc(ncoeffs); dB = gsl_matrix_alloc(ncoeffs, 1); /* Ensure B-splines form a partition of unity */ for (i = 0; i < n; i++) { double xi = a + (b - a) * (i / (n - 1.0)); double sum = 0; gsl_bspline_eval(xi, B, bw); for (j = 0; j < ncoeffs; j++) { double Bj = gsl_vector_get(B, j); int s = (Bj < 0 || Bj > 1); gsl_test(s, "basis-spline coefficient %u is in range [0,1] for x=%g", j, xi); sum += Bj; } gsl_test_rel(sum, 1.0, order * GSL_DBL_EPSILON, "basis-spline order %u is normalized for x=%g", order, xi); } /* Ensure B-splines 0th derivatives agree with regular evaluation */ for (i = 0; i < n; i++) { double xi = a + (b - a) * (i / (n - 1.0)); gsl_bspline_eval(xi, B, bw); gsl_bspline_deriv_eval(xi, 0, dB, bw, dbw); for (j = 0; j < ncoeffs; j++) { gsl_test_abs(gsl_matrix_get(dB, j, 0), gsl_vector_get(B, j), GSL_DBL_EPSILON, "b-spline order %d basis #%d evaluation and 0th derivative consistent for x=%g", order, j, xi); } } gsl_vector_free(B); gsl_matrix_free(dB); }
/** * Copy break points from GSL internal objects * @param bp :: A vector to accept the break points. */ void BSpline::getGSLBreakPoints(std::vector<double> &bp) const { size_t n = gsl_bspline_nbreak(m_bsplineWorkspace.get()); bp.resize(n); for (size_t i = 0; i < n; ++i) { bp[i] = gsl_bspline_breakpoint(i, m_bsplineWorkspace.get()); } }
void test_bspline (gsl_bspline_workspace * bw) { gsl_vector *B; size_t i, j; size_t n = 100; size_t ncoeffs = gsl_bspline_ncoeffs (bw); size_t order = gsl_bspline_order (bw); size_t nbreak = gsl_bspline_nbreak (bw); double a = gsl_bspline_breakpoint (0, bw); double b = gsl_bspline_breakpoint (nbreak - 1, bw); B = gsl_vector_alloc (ncoeffs); for (i = 0; i < n; i++) { double xi = a + (b - a) * (i / (n - 1.0)); double sum = 0; gsl_bspline_eval (xi, B, bw); for (j = 0; j < ncoeffs; j++) { double Bj = gsl_vector_get (B, j); int s = (Bj < 0 || Bj > 1); gsl_test (s, "basis-spline coefficient %u is in range [0,1] for x=%g", j, xi); sum += Bj; } gsl_test_rel (sum, 1.0, order * GSL_DBL_EPSILON, "basis-spline order %u is normalized for x=%g", order, xi); } gsl_vector_free (B); }
static VALUE rb_gsl_bspline_breakpoint(VALUE obj, VALUE i) { gsl_bspline_workspace *w; Data_Get_Struct(obj, gsl_bspline_workspace, w); return rb_float_new(gsl_bspline_breakpoint(FIX2INT(i), w)); }