### 4 releases

0.2.0 | Nov 21, 2021 |
---|---|

0.1.3 | Jun 11, 2020 |

0.1.1 | Oct 18, 2019 |

0.1.0 | Oct 18, 2019 |

#**602** in Math

**36** downloads per month

Used in **2** crates
(via coaster-blas)

**MIT**license

140KB

4K
SLoC

# rust-blas

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`

, and `Complex32`

.`Complex64`

For example the functions

, `cblas_saxpy`

, `cblas_daxpy`

, and
`cblas_caxypy`

are called with the function `cblas_zaxpy`

.`Axpy ::`axpy

Additionally, RBLAS introduces a few traits to shorten calls to these BLAS
functions:

for types that implement vector-like characteristics and
`Vector`

for types that implement matrix-like characteristics. The `Matrix`

trait is already implemented by `Vector`

and `Vec`

types.`[``]`

## Installation

By default, the library links with

dynamically. To link to an alternate
implementation, like OpenBLAS, use the environment variable `blas`

. If
you've already built the bindings, you may need to clean and build again.`CARGO_BLAS`

`export` `CARGO_BLAS``=``openblas`

## Example

`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``)``;`
`}`

## Sugared Example (Soon to be Deprecated)

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

#### Dependencies

~515KB

~11K SLoC