Class: Numo::GSL::Wavelet

Inherits:
Object
  • Object
show all
Defined in:
ext/numo/gsl/wavelet/gsl_wavelet.c

Defined Under Namespace

Classes: Bspline, BsplineCentered, Daubechies, DaubechiesCentered, Haar, HaarCentered

Instance Method Summary collapse

Instance Method Details

#nameString

This function returns a pointer to the name of the wavelet family for w.

Returns:

  • (String)


321
322
323
324
325
326
327
328
329
# File 'ext/numo/gsl/wavelet/gsl_wavelet.c', line 321

static VALUE
wavelet_name(VALUE self)
{
    gsl_wavelet *w;

    TypedData_Get_Struct(self, gsl_wavelet, &wavelet_data_type, w);

    return rb_str_new_cstr(gsl_wavelet_name(w));
}

#transform(data, dir) ⇒ DFloat

These functions compute in-place forward and inverse discrete wavelet transforms of length n with stride stride on the array data. The length of the transform n is restricted to powers of two. For the transform version of the function the argument dir can be either forward (+1) or backward (-1). A workspace work of length n must be provided.

For the forward transform, the elements of the original array are replaced by the discrete wavelet transform $f_i \rightarrow w_j,k$ f_i -> w_[j,k] in a packed triangular storage layout, where j is the index of the level $j = 0 \dots J-1$ j = 0 … J-1 and k is the index of the coefficient within each level, $k = 0 \dots 2^j - 1$ k = 0 … (2^j)-1. The total number of levels is J = \log_2(n). The output data has the following form,

(s_[-1,0], d_[0,0], d_[1,0], d_[1,1], d_[2,0], …, d_[j,k], …, d_[J-1,2^[J-1]-1])

where the first element is the smoothing coefficient $s_-1,0$ s_[-1,0], followed by the detail coefficients $d_j,k$ d_[j,k] for each level j. The backward transform inverts these coefficients to obtain the original data.

These functions return a status of GSL_SUCCESS upon successful completion. GSL_EINVAL is returned if n is not an integer power of 2 or if insufficient workspace is provided.

Parameters:

  • data (DFloat)
  • dir (Integer)

Returns:

  • (DFloat)

    result



395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'ext/numo/gsl/wavelet/gsl_wavelet.c', line 395

static VALUE
wavelet_transform(VALUE self, VALUE v1, VALUE v2)
{
    ndfunc_arg_in_t ain[1] = {{OVERWRITE,1}};
    ndfunc_t ndf = {iter_wavelet_transform, NO_LOOP, 1,0, ain,0};
    gsl_wavelet *w;
    gsl_wavelet_workspace *ws;
    size_t    n;
    int       dir;
    void     *opts[3];
    VALUE     vws;

    TypedData_Get_Struct(self, gsl_wavelet, &wavelet_data_type, w);
    opts[0] = w;

    v1 = wavelet_array_check(v1, 1, &n);

    vws = wavelet_workspace_s_new(cWaveletWorkspace, SIZET2NUM(n));
    TypedData_Get_Struct(vws, gsl_wavelet_workspace, &wavelet_workspace_data_type, ws);
    opts[1] = ws;
    dir = NUM2INT(v2);
    opts[2] = &dir;

    na_ndloop3(&ndf, opts, 1, v1);
    RB_GC_GUARD(vws);
    return v1;
}

#transform_forward(data) ⇒ DFloat

These functions compute in-place forward and inverse discrete wavelet transforms of length n with stride stride on the array data. The length of the transform n is restricted to powers of two. For the transform version of the function the argument dir can be either forward (+1) or backward (-1). A workspace work of length n must be provided.

For the forward transform, the elements of the original array are replaced by the discrete wavelet transform $f_i \rightarrow w_j,k$ f_i -> w_[j,k] in a packed triangular storage layout, where j is the index of the level $j = 0 \dots J-1$ j = 0 … J-1 and k is the index of the coefficient within each level, $k = 0 \dots 2^j - 1$ k = 0 … (2^j)-1. The total number of levels is J = \log_2(n). The output data has the following form,

(s_[-1,0], d_[0,0], d_[1,0], d_[1,1], d_[2,0], …, d_[j,k], …, d_[J-1,2^[J-1]-1])

where the first element is the smoothing coefficient $s_-1,0$ s_[-1,0], followed by the detail coefficients $d_j,k$ d_[j,k] for each level j. The backward transform inverts these coefficients to obtain the original data.

These functions return a status of GSL_SUCCESS upon successful completion. GSL_EINVAL is returned if n is not an integer power of 2 or if insufficient workspace is provided.

Parameters:

  • data (DFloat)

Returns:

  • (DFloat)

    result



466
467
468
469
470
471
472
473
474
475
476
477
478
# File 'ext/numo/gsl/wavelet/gsl_wavelet.c', line 466

static VALUE
wavelet_transform_forward(VALUE self, VALUE v1)
{
    int dir;
    VALUE v2;

    
    dir = gsl_wavelet_forward;
    
    v2 = INT2FIX(dir);

    return wavelet_transform(self, v1, v2);
}

#transform_inverse(data) ⇒ DFloat

These functions compute in-place forward and inverse discrete wavelet transforms of length n with stride stride on the array data. The length of the transform n is restricted to powers of two. For the transform version of the function the argument dir can be either forward (+1) or backward (-1). A workspace work of length n must be provided.

For the forward transform, the elements of the original array are replaced by the discrete wavelet transform $f_i \rightarrow w_j,k$ f_i -> w_[j,k] in a packed triangular storage layout, where j is the index of the level $j = 0 \dots J-1$ j = 0 … J-1 and k is the index of the coefficient within each level, $k = 0 \dots 2^j - 1$ k = 0 … (2^j)-1. The total number of levels is J = \log_2(n). The output data has the following form,

(s_[-1,0], d_[0,0], d_[1,0], d_[1,1], d_[2,0], …, d_[j,k], …, d_[J-1,2^[J-1]-1])

where the first element is the smoothing coefficient $s_-1,0$ s_[-1,0], followed by the detail coefficients $d_j,k$ d_[j,k] for each level j. The backward transform inverts these coefficients to obtain the original data.

These functions return a status of GSL_SUCCESS upon successful completion. GSL_EINVAL is returned if n is not an integer power of 2 or if insufficient workspace is provided.

Parameters:

  • data (DFloat)

Returns:

  • (DFloat)

    result



523
524
525
526
527
528
529
530
531
532
533
534
535
# File 'ext/numo/gsl/wavelet/gsl_wavelet.c', line 523

static VALUE
wavelet_transform_inverse(VALUE self, VALUE v1)
{
    int dir;
    VALUE v2;

    
    dir = gsl_wavelet_backward;
    
    v2 = INT2FIX(dir);

    return wavelet_transform(self, v1, v2);
}