12个版本
使用旧的Rust 2015
0.0.13 | 2015年12月19日 |
---|---|
0.0.12 | 2015年12月18日 |
0.0.10 | 2015年9月29日 |
0.0.8 | 2015年7月22日 |
0.0.1 | 2015年1月9日 |
2142 in 算法
92 每月下载量
在 5 个crate中使用 (3直接使用)
100KB
2.5K SLoC
RBLAS
Rust对BLAS(基本线性代数子程序)的绑定和包装器。
概述
RBLAS将每个外部调用封装在与名称相同的特质中(但首字母大写)。这个特质包含一个同名的单个静态方法。这些特质是针对BLAS支持的四种主要数值类型泛型的:f32
、f64
、Complex32
和 Complex64
。
例如,函数 cblas_saxpy
、cblas_daxpy
、cblas_caxypy
和 cblas_zaxpy
使用函数 Axpy::axpy
调用。
此外,RBLAS引入了一些特质来缩短对这些BLAS函数的调用:用于实现类似向量特性的类型的 Vector
和用于实现类似矩阵特性的类型的 Matrix
。特质 Vector
已经由 Vec
和 []
类型实现。
安装
默认情况下,库以动态方式链接到 blas
。要链接到其他实现,如OpenBLAS,请使用环境变量 CARGO_BLAS
。如果您已经构建了绑定,可能需要清理并重新构建。
export CARGO_BLAS=openblas
示例
extern crate rblas;
use rblas::Dot;
fn main() {
let x = vec![1.0, -2.0, 3.0, 4.0];
let y = [1.0, 1.0, 1.0, 1.0, 7.0];
let d = Dot::dot(&x, &y[..x.len()]);
assert_eq!(d, 6.0);
}
糖化示例
#[macro_use]
extern crate rblas as blas;
use blas::math::Mat;
use blas::{Matrix, Vector};
use blas::math::Marker::T;
fn main() {
let x = vec![1.0, 2.0];
let xr = &x as &Vector<_>;
let i = mat![1.0, 0.0; 0.0, 1.0];
let ir = &i as &Matrix<_>;
assert!(xr + &x == 2.0 * xr);
assert!(ir * xr == x);
let dot = (xr ^ T) * xr;
assert!(dot == 5.0);
}
依赖项
~630KB
~13K SLoC