Class

NumCosmoMathFunctionSampleSet

Description [src]

final class NumCosmoMath.FunctionSampleSet : GObject.Object
{
  /* No available fields */
}

Ordered sample set for vector-valued functions $\vec{F}: \mathbb{R} \to \mathbb{R}^n$.

This object stores an ordered set of samples $(x_i, \vec{y}_i)$ where each sample consists of a knot position $x_i$ and a vector value $\vec{y}_i \in \mathbb{R}^n$. Each sample also has an associated “interval_ok” flag that indicates whether the interval between that node and the next node has passed refinement tests.

The primary use case is for iterative refinement algorithms that build splines from vector-valued functions. The typical workflow is: 1. Add initial samples using ncm_function_sample_set_add() or ncm_function_sample_set_add_func() 2. Convert to NcmSplineVec and test interpolation error using ncm_function_sample_set_refine() 3. Insert new samples where error exceeds tolerance using iterator-based insertion 4. Mark samples as interval_ok when bins pass error tests 5. Repeat until ncm_function_sample_set_all_intervals_ok() returns TRUE

Iterator-Based API

This class provides an efficient iterator-based API for traversing and manipulating samples. Iterators provide O(1) access to sample data once positioned, making sequential operations efficient. Example usage:

// Create iterator and traverse all samples (stack-allocated - no free needed)
NcmFunctionSampleSetIter iter_s;
NcmFunctionSampleSetIter *iter = &iter_s;
ncm_function_sample_set_iter_begin (fss, &iter);
while (ncm_function_sample_set_iter_is_valid (iter))
{
  gdouble x = ncm_function_sample_set_iter_get_x (iter);
  NcmVector *y = ncm_function_sample_set_iter_get_y (iter);
  // Process sample...
  ncm_function_sample_set_iter_next (iter);
}

// Iterate over intervals using iter_next_pair (stack-allocated iterators)
NcmFunctionSampleSetIter it_s, next_it_s;
NcmFunctionSampleSetIter *it = &it_s;
NcmFunctionSampleSetIter *next_it = &next_it_s;
ncm_function_sample_set_iter_begin (fss, &it);
ncm_function_sample_set_iter_copy (it, &next_it);
while (ncm_function_sample_set_iter_next_pair (it, next_it))
{
  if (ncm_function_sample_set_iter_get_interval_ok (it) < threshold)
  {
    gdouble x_mid = 0.5 * (ncm_function_sample_set_iter_get_x (it) +
                           ncm_function_sample_set_iter_get_x (next_it));
    NcmFunctionSampleSetIter new_it_s;
    NcmFunctionSampleSetIter *new_it = &new_it_s;
    ncm_function_sample_set_iter_insert_after_func (fss, it, x_mid, func, NULL, &new_it);
  }
  ncm_function_sample_set_iter_next (it);
}

Memory Management and Performance

Samples are maintained in ascending x-order using a GList internally, which provides efficient insertion operations during the building phase.

When converting to NcmSplineVec using ncm_function_sample_set_to_spline_vec() or ncm_function_sample_set_to_spline_vec_old(), the object reuses internal cached arrays for optimal performance. This means: - Each call to these functions invalidates the previously returned NcmSplineVec - If you need to preserve multiple splines, call ncm_spline_vec_dup() before generating a new one - This pattern matches ncm_spline_func behavior and is optimal for iterative refinement workflows

The dimension $n$ of the vector values is fixed at creation time and validated on every insertion.

Ancestors

Constructors

ncm_function_sample_set_new

Creates a new NcmFunctionSampleSet for storing samples of a vector-valued function with output dimension len.

Functions

ncm_function_sample_set_clear

Decreases the reference count of fss and sets the pointer fss to NULL.

Instance methods

ncm_function_sample_set_adaptive_midpoint

Performs an iterative midpoint-based adaptive refinement similar to the Python test harness. On each iteration intervals with interval_ok < min_pass_threshold receive their midpoint inserted (evaluated via f). After insertion, a refinement pass is performed via ncm_function_sample_set_refine(). The process stops when all intervals reach min_pass_threshold or when max_iter is reached.

ncm_function_sample_set_add

Adds a new sample point to fss with position x and vector value y. The sample is inserted in the correct position to maintain ascending x-order. The vector y is copied and must have dimension matching the fss:len property. The interval_ok flag for the new sample is initialized to 0. The sample is marked as a new point.

ncm_function_sample_set_add_func

Evaluates the vector-valued function f at x and adds the result as a new sample point. The sample is inserted in the correct position to maintain ascending x-order. The interval_ok flag for the new sample is initialized to 0. The sample is marked as a new point.

ncm_function_sample_set_add_old

Adds a new sample point to fss with position x and vector value y, marked as OLD. This function is useful for boundary extensions where the added point should be considered part of the base spline rather than a refinement target. The sample is inserted in the correct position to maintain ascending x-order. The vector y is copied and must have dimension matching the fss:len property. The interval_ok flag for the new sample is initialized to 0. The sample is marked as an old point (new_point = FALSE).

ncm_function_sample_set_add_old_func

Evaluates the vector-valued function f at x and adds the result as an old sample point. This function is useful for boundary extensions where the added point should be considered part of the base spline rather than a refinement target. The sample is inserted in the correct position to maintain ascending x-order. The interval_ok flag for the new sample is initialized to 0. The sample is marked as an old point (new_point = FALSE).

ncm_function_sample_set_all_intervals_ok

Checks if all intervals have interval_ok >= threshold. This is useful for determining convergence in refinement algorithms - when all intervals have passed the refinement test enough times.

ncm_function_sample_set_expand_domain

Expands the domain of the function sample set by alternating between left and right boundary expansion until convergence or limits are reached. At each step:.

ncm_function_sample_set_free

Decreases the reference count of fss. If the reference count reaches zero, fss is freed.

ncm_function_sample_set_get_absmaxF

Gets the maximum absolute value observed for component i across all samples. This is useful for determining appropriate tolerances in refinement algorithms.

ncm_function_sample_set_get_absmaxF_l2_norm

Computes the $L_2$ norm (Euclidean norm) of the maximum absolute values across all components: $$|\vec{F}|2 = \sqrt{\sum{i=0}^{n-1} (\max_x |F_i(x)|)^2}$$.

ncm_function_sample_set_get_absmaxF_linf_norm

Computes the $L_\infty$ norm (maximum norm) of the maximum absolute values across all components: $$|\vec{F}|\infty = \max{i=0}^{n-1} (\max_x |F_i(x)|)$$.

ncm_function_sample_set_get_absmaxF_min

Computes the minimum of the maximum absolute values across all components: $$\min_{i=0}^{n-1} (\max_x |F_i(x)|)$$.

ncm_function_sample_set_get_len

Gets the dimension of the vector-valued function output.

ncm_function_sample_set_get_nsamples

Gets the number of samples currently stored in fss.

ncm_function_sample_set_get_x_max

Gets the maximum x value in the sample set.

ncm_function_sample_set_get_x_min

Gets the minimum x value in the sample set.

ncm_function_sample_set_iter_begin

Positions an iterator at the first sample in fss. If fss is empty, the iterator will be invalid. When iter_out points to a NULL pointer the callee allocates a new iterator that must be freed with ncm_function_sample_set_iter_free(). When iter_out points to an already-allocated iterator (e.g. a stack variable) no allocation occurs and no free is required.

ncm_function_sample_set_iter_end

Positions an iterator at the last sample in fss. If fss is empty, the iterator will be invalid. When iter_out points to a NULL pointer the callee allocates a new iterator that must be freed with ncm_function_sample_set_iter_free(). When iter_out points to an already-allocated iterator (e.g. a stack variable) no allocation occurs and no free is required.

ncm_function_sample_set_iter_insert_after

Inserts a new sample after the position of iter. The vector y must have dimension matching fss:len property. The new sample’s interval_ok is initialized to 0 and new_point is set to TRUE. When iter_out points to a NULL pointer the callee allocates a new iterator that must be freed with ncm_function_sample_set_iter_free(). When iter_out points to an already-allocated iterator (e.g. a stack variable) no allocation occurs and no free is required.

ncm_function_sample_set_iter_insert_after_func

Evaluates f at x and inserts the result as a new sample after iter. The new sample’s interval_ok is initialized to 0 and new_point is set to TRUE. When iter_out points to a NULL pointer the callee allocates a new iterator that must be freed with ncm_function_sample_set_iter_free(). When iter_out points to an already-allocated iterator (e.g. a stack variable) no allocation occurs and no free is required.

ncm_function_sample_set_iter_insert_before

Inserts a new sample before the position of iter. The vector y must have dimension matching fss:len property. The new sample’s interval_ok is initialized to 0 and new_point is set to TRUE. When iter_out points to a NULL pointer the callee allocates a new iterator that must be freed with ncm_function_sample_set_iter_free(). When iter_out points to an already-allocated iterator (e.g. a stack variable) no allocation occurs and no free is required.

ncm_function_sample_set_iter_insert_before_func

Evaluates f at x and inserts the result as a new sample before iter. The new sample’s interval_ok is initialized to 0 and new_point is set to TRUE. When iter_out points to a NULL pointer the callee allocates a new iterator that must be freed with ncm_function_sample_set_iter_free(). When iter_out points to an already-allocated iterator (e.g. a stack variable) no allocation occurs and no free is required.

ncm_function_sample_set_log_vals

Logs all sample values in fss for debugging purposes. This prints the x position, vector components, interval_ok flag, and new_point flag for each sample.

ncm_function_sample_set_mark_all_old

Marks all points in fss as old. This is typically called after a refinement pass to indicate that all current points should be used in the next spline construction.

ncm_function_sample_set_ref

Increases the reference count of fss.

ncm_function_sample_set_refine

Performs a refinement pass on all NEW points. For each NEW point, this function: 1. Creates a spline using OLD points only 2. Evaluates the spline at the NEW point position 3. Computes the error: ||f(x) - spline_f(x)||_2 < reltol * ||f(x)||_2 + abstol 4. If the test passes, increments interval_ok for both the NEW point and its left neighbor 5. Marks all NEW points as OLD.

ncm_function_sample_set_reset_interval_ok

Resets all interval_ok flags to 0. This is useful when starting a new refinement pass.

ncm_function_sample_set_to_spline_vec

Converts the sample set to a NcmSplineVec. This reuses cached internal arrays for efficiency, which means that:.

ncm_function_sample_set_to_spline_vec_old

Converts only the OLD sample points to a NcmSplineVec. This reuses cached internal arrays for efficiency, which means that:.

Methods inherited from GObject (43)

Please see GObject for a full list of methods.

Properties

NumCosmoMath.FunctionSampleSet:len

The dimension of the vector-valued function output.

Signals

Signals inherited from GObject (1)
GObject::notify

The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.

Class structure

struct NumCosmoMathFunctionSampleSetClass {
  GObjectClass parent_class;
  
}

No description available.

Class members
parent_class: GObjectClass

No description available.