Git Product home page Git Product logo

rust-blas's Introduction

RBLAS

Rust bindings and wrappers for BLAS (Basic Linear Algebra Subprograms).

Overview

RBLAS wraps each external call in a trait with the same name (but capitalized). This trait contains a single static method, of the same name. These traits are generic over the four main types of numbers BLAS supports: f32, f64, Complex32, and Complex64.

For example the functions cblas_saxpy, cblas_daxpy, cblas_caxypy, and cblas_zaxpy are called with the function Axpy::axpy.

Additionally, RBLAS introduces a few traits to shorten calls to these BLAS functions: Vector for types that implement vector-like characteristics and Matrix for types that implement matrix-like characteristics. The Vector trait is already implemented by Vec and [] types.

Documentation

Installation

Add this to your Cargo.toml:

[dependencies]
rblas = "0.0.8"

and this to your crate root:

extern crate rblas;

By default, the library links with blas dynamically. To link to an alternate implementation, like OpenBLAS, use the environment variable CARGO_BLAS. If you've already built the bindings, you may need to clean and build again.

export CARGO_BLAS=openblas

Example

extern crate rblas;

use rblas::Dot;

fn main() {
    let x = vec![1.0f32, -2.0, 3.0, 4.0];
    let y = vec![1.0f32, 1.0, 1.0, 1.0];

    let d: f32 = Dot::dot(&x, &y);
    assert_eq!(d, 6.0);
}

Sugared Example

#[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);
}

rust-blas's People

Contributors

bovee avatar mikkyang avatar raineszm avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.