1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
//
// A rust binding for the GSL library by Guillaume Gomez (guillaume1.gomez@gmail.com)
//

/*!
## Transform Functions

This sections describes the actual functions performing the discrete wavelet transform. Note that the transforms use periodic boundary
conditions. If the signal is not periodic in the sample length then spurious coefficients will appear at the beginning and end of each
level of the transform.
!*/

/// 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 -> w_{j,k} in a
/// packed triangular storage layout, where j is the index of the level j = 0 ... J-1 and k is the index of the coefficient within each
/// level, 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}, followed by the detail coefficients d_{j,k} for each level j. The
/// backward transform inverts these coefficients to obtain the original data.
///
/// These functions return a status of ::Value::Success upon successful completion. ::Inval is returned if n is not an integer power of
/// 2 or if insufficient workspace is provided.
pub mod one_dimension {
    use crate::Value;
    use ffi::FFI;

    #[doc(alias = "gsl_wavelet_transform")]
    pub fn transform(
        w: &::Wavelet,
        data: &mut [f64],
        stride: usize,
        n: usize,
        dir: ::WaveletDirection,
        work: &mut ::WaveletWorkspace,
    ) -> Value {
        Value::from(unsafe {
            sys::gsl_wavelet_transform(
                w.unwrap_shared(),
                data.as_mut_ptr(),
                stride,
                n,
                dir.into(),
                work.unwrap_unique(),
            )
        })
    }

    #[doc(alias = "gsl_wavelet_transform_forward")]
    pub fn transform_forward(
        w: &::Wavelet,
        data: &mut [f64],
        stride: usize,
        n: usize,
        work: &mut ::WaveletWorkspace,
    ) -> Value {
        Value::from(unsafe {
            sys::gsl_wavelet_transform_forward(
                w.unwrap_shared(),
                data.as_mut_ptr(),
                stride,
                n,
                work.unwrap_unique(),
            )
        })
    }

    #[doc(alias = "gsl_wavelet_transform_inverse")]
    pub fn transform_inverse(
        w: &::Wavelet,
        data: &mut [f64],
        stride: usize,
        n: usize,
        work: &mut ::WaveletWorkspace,
    ) -> Value {
        Value::from(unsafe {
            sys::gsl_wavelet_transform_inverse(
                w.unwrap_shared(),
                data.as_mut_ptr(),
                stride,
                n,
                work.unwrap_unique(),
            )
        })
    }
}

/// The library provides functions to perform two-dimensional discrete wavelet transforms on square matrices. The matrix dimensions must
/// be an integer power of two. There are two possible orderings of the rows and columns in the two-dimensional wavelet transform,
/// referred to as the “standard” and “non-standard” forms.
///
/// The “standard” transform performs a complete discrete wavelet transform on the rows of the matrix, followed by a separate complete
/// discrete wavelet transform on the columns of the resulting row-transformed matrix. This procedure uses the same ordering as a
/// two-dimensional Fourier transform.
///
/// The “non-standard” transform is performed in interleaved passes on the rows and columns of the matrix for each level of the transform.
/// The first level of the transform is applied to the matrix rows, and then to the matrix columns. This procedure is then repeated across
/// the rows and columns of the data for the subsequent levels of the transform, until the full discrete wavelet transform is complete.
/// The non-standard form of the discrete wavelet transform is typically used in image analysis.
pub mod two_dimension {
    use crate::Value;
    use ffi::FFI;

    /// These functions compute two-dimensional in-place forward and inverse discrete wavelet transforms in standard form on the array
    /// data stored in row-major form with dimensions size1 and size2 and physical row length tda. The dimensions must be equal
    /// (square matrix) and are 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 the appropriate size must be provided. On exit, the appropriate elements of
    /// the array data are replaced by their two-dimensional wavelet transform.
    ///
    /// The functions return a status of ::Value::Success upon successful completion. ::Inval is returned if size1 and size2 are not
    /// equal and integer powers of 2, or if insufficient workspace is provided.
    #[doc(alias = "gsl_wavelet2d_transform")]
    pub fn transform(
        w: &::Wavelet,
        data: &mut [f64],
        tda: usize,
        size1: usize,
        size2: usize,
        dir: ::WaveletDirection,
        work: &mut ::WaveletWorkspace,
    ) -> Value {
        Value::from(unsafe {
            sys::gsl_wavelet2d_transform(
                w.unwrap_shared(),
                data.as_mut_ptr(),
                tda,
                size1,
                size2,
                dir.into(),
                work.unwrap_unique(),
            )
        })
    }

    /// These functions compute two-dimensional in-place forward and inverse discrete wavelet transforms in standard form on the array
    /// data stored in row-major form with dimensions size1 and size2 and physical row length tda. The dimensions must be equal
    /// (square matrix) and are 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 the appropriate size must be provided. On exit, the appropriate elements of
    /// the array data are replaced by their two-dimensional wavelet transform.
    ///
    /// The functions return a status of ::Value::Success upon successful completion. ::Inval is returned if size1 and size2 are not
    /// equal and integer powers of 2, or if insufficient workspace is provided.
    #[doc(alias = "gsl_wavelet2d_transform_forward")]
    pub fn transform_forward(
        w: &::Wavelet,
        data: &mut [f64],
        tda: usize,
        size1: usize,
        size2: usize,
        work: &mut ::WaveletWorkspace,
    ) -> Value {
        Value::from(unsafe {
            sys::gsl_wavelet2d_transform_forward(
                w.unwrap_shared(),
                data.as_mut_ptr(),
                tda,
                size1,
                size2,
                work.unwrap_unique(),
            )
        })
    }

    /// These functions compute two-dimensional in-place forward and inverse discrete wavelet transforms in standard form on the array
    /// data stored in row-major form with dimensions size1 and size2 and physical row length tda. The dimensions must be equal
    /// (square matrix) and are 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 the appropriate size must be provided. On exit, the appropriate elements of
    /// the array data are replaced by their two-dimensional wavelet transform.
    ///
    /// The functions return a status of ::Value::Success upon successful completion. ::Inval is returned if size1 and size2 are not
    /// equal and integer powers of 2, or if insufficient workspace is provided.
    #[doc(alias = "gsl_wavelet2d_transform_inverse")]
    pub fn transform_inverse(
        w: &::Wavelet,
        data: &mut [f64],
        tda: usize,
        size1: usize,
        size2: usize,
        work: &mut ::WaveletWorkspace,
    ) -> Value {
        Value::from(unsafe {
            sys::gsl_wavelet2d_transform_inverse(
                w.unwrap_shared(),
                data.as_mut_ptr(),
                tda,
                size1,
                size2,
                work.unwrap_unique(),
            )
        })
    }

    /// These functions compute the two-dimensional in-place wavelet transform on a matrix a.
    #[doc(alias = "gsl_wavelet2d_transform_matrix")]
    pub fn transform_matrix(
        w: &::Wavelet,
        m: &mut ::MatrixF64,
        dir: ::WaveletDirection,
        work: &mut ::WaveletWorkspace,
    ) -> Value {
        Value::from(unsafe {
            sys::gsl_wavelet2d_transform_matrix(
                w.unwrap_shared(),
                m.unwrap_unique(),
                dir.into(),
                work.unwrap_unique(),
            )
        })
    }

    /// These functions compute the two-dimensional in-place wavelet transform on a matrix a.
    #[doc(alias = "gsl_wavelet2d_transform_matrix_forward")]
    pub fn transform_matrix_forward(
        w: &::Wavelet,
        m: &mut ::MatrixF64,
        work: &mut ::WaveletWorkspace,
    ) -> Value {
        Value::from(unsafe {
            sys::gsl_wavelet2d_transform_matrix_forward(
                w.unwrap_shared(),
                m.unwrap_unique(),
                work.unwrap_unique(),
            )
        })
    }

    /// These functions compute the two-dimensional in-place wavelet transform on a matrix a.
    #[doc(alias = "gsl_wavelet2d_transform_matrix_inverse")]
    pub fn transform_matrix_inverse(
        w: &::Wavelet,
        m: &mut ::MatrixF64,
        work: &mut ::WaveletWorkspace,
    ) -> Value {
        Value::from(unsafe {
            sys::gsl_wavelet2d_transform_matrix_inverse(
                w.unwrap_shared(),
                m.unwrap_unique(),
                work.unwrap_unique(),
            )
        })
    }

    /// These functions compute the two-dimensional wavelet transform in non-standard form.
    #[doc(alias = "gsl_wavelet2d_nstransform")]
    pub fn nstransform(
        w: &::Wavelet,
        data: &mut [f64],
        tda: usize,
        size1: usize,
        size2: usize,
        dir: ::WaveletDirection,
        work: &mut ::WaveletWorkspace,
    ) -> Value {
        Value::from(unsafe {
            sys::gsl_wavelet2d_nstransform(
                w.unwrap_shared(),
                data.as_mut_ptr(),
                tda,
                size1,
                size2,
                dir.into(),
                work.unwrap_unique(),
            )
        })
    }

    /// These functions compute the two-dimensional wavelet transform in non-standard form.
    #[doc(alias = "gsl_wavelet2d_nstransform_forward")]
    pub fn nstransform_forward(
        w: &::Wavelet,
        data: &mut [f64],
        tda: usize,
        size1: usize,
        size2: usize,
        work: &mut ::WaveletWorkspace,
    ) -> Value {
        Value::from(unsafe {
            sys::gsl_wavelet2d_nstransform_forward(
                w.unwrap_shared(),
                data.as_mut_ptr(),
                tda,
                size1,
                size2,
                work.unwrap_unique(),
            )
        })
    }

    /// These functions compute the two-dimensional wavelet transform in non-standard form.
    #[doc(alias = "gsl_wavelet2d_nstransform_inverse")]
    pub fn nstransform_inverse(
        w: &::Wavelet,
        data: &mut [f64],
        tda: usize,
        size1: usize,
        size2: usize,
        work: &mut ::WaveletWorkspace,
    ) -> Value {
        Value::from(unsafe {
            sys::gsl_wavelet2d_nstransform_inverse(
                w.unwrap_shared(),
                data.as_mut_ptr(),
                tda,
                size1,
                size2,
                work.unwrap_unique(),
            )
        })
    }

    /// These functions compute the non-standard form of the two-dimensional in-place wavelet transform on a matrix a.
    #[doc(alias = "gsl_wavelet2d_nstransform_matrix")]
    pub fn nstransform_matrix(
        w: &::Wavelet,
        m: &mut ::MatrixF64,
        dir: ::WaveletDirection,
        work: &mut ::WaveletWorkspace,
    ) -> Value {
        Value::from(unsafe {
            sys::gsl_wavelet2d_nstransform_matrix(
                w.unwrap_shared(),
                m.unwrap_unique(),
                dir.into(),
                work.unwrap_unique(),
            )
        })
    }

    /// These functions compute the non-standard form of the two-dimensional in-place wavelet transform on a matrix a.
    #[doc(alias = "gsl_wavelet2d_nstransform_matrix_forward")]
    pub fn nstransform_matrix_forward(
        w: &::Wavelet,
        m: &mut ::MatrixF64,
        work: &mut ::WaveletWorkspace,
    ) -> Value {
        Value::from(unsafe {
            sys::gsl_wavelet2d_nstransform_matrix_forward(
                w.unwrap_shared(),
                m.unwrap_unique(),
                work.unwrap_unique(),
            )
        })
    }

    /// These functions compute the non-standard form of the two-dimensional in-place wavelet transform on a matrix a.
    #[doc(alias = "gsl_wavelet2d_nstransform_matrix_inverse")]
    pub fn nstransform_matrix_inverse(
        w: &::Wavelet,
        m: &mut ::MatrixF64,
        work: &mut ::WaveletWorkspace,
    ) -> Value {
        Value::from(unsafe {
            sys::gsl_wavelet2d_nstransform_matrix_inverse(
                w.unwrap_shared(),
                m.unwrap_unique(),
                work.unwrap_unique(),
            )
        })
    }
}