Module basic_dsp_vector::combined_ops [] [src]

This module allows to combine certain operations into one operation. Since one many machines the speed of many DSP operations is limited by the memory bus speed this approach may result in better register and cache usage and thus decrease the pressure on the memory bus. As with all performance hints remember rule number 1: Benchmark your code. This is especially true at this very early state of the library.

With this approach we change how we operate on vectors. If you perform M operations on a vector with the length N you iterate wit hall other methods like this:

// pseudocode:
// for m in M:
//  for n in N:
//    execute m on n

with this method the pattern is changed slightly:

// pseudocode:
// for n in N:
//  for m in M:
//    execute m on n

Both variants have the same complexity however the second one is beneficial since we have increased locality this way. This should help us by making better use of registers and CPU caches.

Only operations can be combined where the result of every element in the vector is independent from any other element in the vector.

Examples

use std::f32::consts::PI;
use basic_dsp_vector::*;
use basic_dsp_vector::combined_ops::*;
let a = vec!(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8).to_real_time_vec();
let b = vec!(0.0; 8).to_real_time_vec();
let ops = multi_ops2(a, b);
let ops = ops.add_ops(|mut a, mut b| {
    a.scale(2.0 * PI);
    b.clone_from(&a);
    a.sin();
    b.cos();
    a.mul(&b);
    a.abs();
    a.log(10.0);
    a.scale(10.0);
    (a, b)
});
let mut buffer = SingleBuffer::new();
let (a, b) = ops.get(&mut buffer).expect("Ignoring error handling in examples");
close(&[0.80902, 0.30902, -0.30902, -0.80902, -1.00000, -0.80902, -0.30902, 0.30902],
          &b[..]);
close(&[-3.2282, -5.3181, -5.3181, -3.2282, -159.1199, -3.2282, -5.3181, -5.3181],
          &a[..]);

Structs

Identifier

An identifier is just a placeholder for a data type used to ensure already at compile time that operations are valid.

MultiOperation1

A multi operation which holds a vector and records all changes which need to be done to the vectors. By calling get on the struct all operations will be executed in one run.

MultiOperation2

A multi operation which holds a vector and records all changes which need to be done to the vectors. By calling get on the struct all operations will be executed in one run.

PreparedOperation1

An operation on one data vector which has been prepared in advance.

PreparedOperation2

An operation on two data vectors which has been prepared in advance.

Enums

Operation

An alternative way to define operations on a vector.

Traits

IdentifierOps

Operations for all kind of vectors which can be used in combination with multi ops or prepared ops.

PreparedOperation1Exec

Executes the prepared operations to convert Sto D.

PreparedOperation2Exec

Executes the prepared operations to convert S1 and S2 to D1 and D2.

Functions

multi_ops1

Creates a new multi operation for one vectors.

multi_ops2

Creates a new multi operation for two vectors.

prepare32_1

Prepares an operation with one input and one output.

prepare32_2

Prepares an operation with one input and one output.

prepare64_1

Prepares an operation with one input and one output.

prepare64_2

Prepares an operation with one input and one output.

Type Definitions

ComplexFreqIdent

A identifier with complex numbers in frequency domain.

ComplexTimeIdent

A identifier with complex numbers in time domain.

GenDspIdent

A identifier with no information about number space or domain at compile time.

RealFreqIdent

A identifier with real numbers in frequency domain.

RealTimeIdent

A identifier with real numbers in time domain.