Skip to main content

Crate apple_accelerate

Crate apple_accelerate 

Source
Expand description

§accelerate-rs

Safe Rust bindings for Apple’s Accelerate framework on macOS using a Swift bridge over the C APIs.

The GitHub repository is accelerate-rs; the published crates.io package is apple-accelerate.

§Install

cargo add apple-accelerate

Enable the raw-ffi feature if you also want the underlying C declarations:

cargo add apple-accelerate --features raw-ffi

§Quick start

use apple_accelerate::{
    add_f32, integrate, solve_linear_system_f32, sdot, QuadratureOptions,
};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let added = add_f32(&[1.0, 2.0, 3.0], &[4.0, 5.0, 6.0])?;
    assert_eq!(added, vec![5.0, 7.0, 9.0]);

    let dot = sdot(&[1.0, 2.0, 3.0], &[4.0, 5.0, 6.0])?;
    assert_eq!(dot, 32.0);

    // LAPACK matrices are column-major.
    let solution = solve_linear_system_f32(&[3.0, 1.0, 1.0, 2.0], 2, &[9.0, 8.0])?;
    assert!((solution[0] - 2.0).abs() < 1.0e-5);
    assert!((solution[1] - 3.0).abs() < 1.0e-5);

    let integral = integrate(|x| x * x, 0.0, 1.0, QuadratureOptions::default())?;
    assert!((integral.integral - (1.0 / 3.0)).abs() < 1.0e-9);
    Ok(())
}

§v0.2 surface

  • vDSP: FFT setup, biquad setup, vector arithmetic, reductions, and window generation
  • vForce: element-wise transcendental and root functions over f32 slices
  • BLAS: sdot, row-major sgemv, and row-major sgemm
  • LAPACK: LU factorization and linear solves for column-major single-precision matrices
  • BNNS: safe ReLU/sigmoid vector activations plus the existing thin unsafe filter owner
  • Sparse: sparse-vector dot products and sparse-to-dense accumulation
  • vImage: ARGB8888 rotate / box-convolve / scale and Planar8 contrast stretch
  • simd: SIMD4 add / dot / length / normalize helpers
  • Quadrature: one-dimensional adaptive numerical integration with Rust closures
  • raw-ffi feature: re-exports the underlying C declarations for all wrapped areas

§Smoke examples

for ex in examples/*.rs; do
  cargo run --example "$(basename "$ex" .rs)"
done

The numbered examples cover every logical area of the crate.

Re-exports§

pub use crate::blas::blas_order;
pub use crate::blas::blas_transpose;
pub use crate::blas::sdot;
pub use crate::blas::sgemm_row_major;
pub use crate::blas::sgemv_row_major;
pub use crate::bnns::graph_optimization_preference as bnns_graph_optimization_preference;
pub use crate::bnns::relu_f32 as bnns_relu_f32;
pub use crate::bnns::sigmoid_f32 as bnns_sigmoid_f32;
pub use crate::bnns::Filter as BnnsFilter;
pub use crate::bnns::GraphCompileOptions as BnnsGraphCompileOptions;
pub use crate::error::Error;
pub use crate::error::Result;
pub use crate::lapack::lu_decompose_f32;
pub use crate::lapack::solve_linear_system_f32;
pub use crate::lapack::LuDecompositionF32;
pub use crate::quadrature::integrate;
pub use crate::quadrature::Integrator as QuadratureIntegrator;
pub use crate::quadrature::Options as QuadratureOptions;
pub use crate::quadrature::QuadratureOutput;
pub use crate::simd::add_f32x4;
pub use crate::simd::dot_f32x4;
pub use crate::simd::length_f32x4;
pub use crate::simd::normalize_f32x4;
pub use crate::simd::Float4;
pub use crate::sparse::add_to_dense_f32 as sparse_add_to_dense_f32;
pub use crate::sparse::dot_dense_f32 as sparse_dot_dense_f32;
pub use crate::sparse::dot_sparse_f32 as sparse_dot_sparse_f32;
pub use crate::sparse::sparse_matrix_property;
pub use crate::sparse::sparse_status;
pub use crate::sparse::SparseIndex;
pub use crate::sparse::SparseMatrixF32;
pub use crate::vdsp::add_f32;
pub use crate::vdsp::add_f64;
pub use crate::vdsp::blackman_window;
pub use crate::vdsp::blackman_window_f64;
pub use crate::vdsp::dot_f32;
pub use crate::vdsp::dot_f64;
pub use crate::vdsp::fft_direction;
pub use crate::vdsp::fft_radix;
pub use crate::vdsp::hamming_window;
pub use crate::vdsp::hamming_window_f64;
pub use crate::vdsp::max_f32;
pub use crate::vdsp::max_f64;
pub use crate::vdsp::mean_f32;
pub use crate::vdsp::mean_f64;
pub use crate::vdsp::min_f32;
pub use crate::vdsp::min_f64;
pub use crate::vdsp::sub_f32;
pub use crate::vdsp::sub_f64;
pub use crate::vdsp::sum_f32;
pub use crate::vdsp::sum_f64;
pub use crate::vdsp::window_flags;
pub use crate::vdsp::BiquadSetup;
pub use crate::vdsp::FftSetup;
pub use crate::vforce::cos_f32;
pub use crate::vforce::exp_f32;
pub use crate::vforce::log_f32;
pub use crate::vforce::sin_f32;
pub use crate::vforce::sqrt_f32;
pub use crate::vimage::alpha_blend_argb8888;
pub use crate::vimage::box_convolve_argb8888;
pub use crate::vimage::clip_to_alpha_argb8888;
pub use crate::vimage::contrast_stretch_planar8;
pub use crate::vimage::convert_argb8888_to_planar8;
pub use crate::vimage::convert_planar8_to_argb8888;
pub use crate::vimage::premultiply_argb8888;
pub use crate::vimage::rotate_argb8888;
pub use crate::vimage::scale_argb8888;
pub use crate::vimage::unpremultiply_argb8888;
pub use crate::vimage::vimage_flags;
pub use crate::vimage::ImageBuffer;

Modules§

blas
bnns
error
lapack
quadrature
simd
sparse
vdsp
vforce
vimage