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-accelerateEnable 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 generationvForce: element-wise transcendental and root functions overf32slicesBLAS:sdot, row-majorsgemv, and row-majorsgemmLAPACK: LU factorization and linear solves for column-major single-precision matricesBNNS: safe ReLU/sigmoid vector activations plus the existing thin unsafe filter ownerSparse: sparse-vector dot products and sparse-to-dense accumulationvImage: ARGB8888 rotate / box-convolve / scale and Planar8 contrast stretchsimd: SIMD4 add / dot / length / normalize helpersQuadrature: one-dimensional adaptive numerical integration with Rust closuresraw-ffifeature: re-exports the underlying C declarations for all wrapped areas
§Smoke examples
for ex in examples/*.rs; do
cargo run --example "$(basename "$ex" .rs)"
doneThe 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;