### 39 releases

0.15.1 | Jan 24, 2023 |
---|---|

0.14.3 | Sep 3, 2022 |

0.14.2 | May 6, 2022 |

0.13.5 | Mar 11, 2022 |

0.1.1 | Jan 18, 2021 |

#**2** in #std-iter-fromiterator

**2,297** downloads per month

Used in **2** crates
(via tc-tensor)

**Apache-2.0**

185KB

4.5K
SLoC

# afarray

Convenience methods for working with ArrayFire arrays in Rust, compatible with number-general.

Usage example:

`use` `std``::``iter``::`FromIterator`;`
`use` `afarray``::`Array`;`
`use` `number_general``::`Number`;`
`let` a `=` `[``1``,` `2``,` `3``]``;`
`let` b `=` `[``5``]``;`
`let` product `=` `&``Array``::`from`(``&`a`[``..``]``)` `*` `&``Array``::`from`(``&`b`[``..``]``)``;`
`assert_eq!``(`product`,` `Array``::`from_iter`(``vec!``[``5``,` `10``,` `15``]``)``)``;`
`assert_eq!``(`product`.``sum``(``)``,` `Number``::`from`(``30``)``)`

Note that you must have ArrayFire installed in order to build this crate. The installation instructions are at http://arrayfire.org/docs/installing.htm.

You can find detailed instructions for building the Rust

crate from crates.io at: https://crates.io/crates/arrayfire.`arrayfire`

###
`lib.rs`

:

Provides a generic one-dimensional

which wraps `Array`

and supports
all `arrayfire ::`Array

`number_general``::`NumberType

variants. `Array`

and `ArrayExt`

support basic math like
`Add`

, `Sub`

, `Mul`

, `Div`

, and `Rem`

, with hardware acceleration on systems which support CUDA
or OpenCL. `ArrayExt``<``bool``>`

supports common logical operations `and`

, `not`

, `or`

, and `xor`

.N-dimensional array functionality can be implemented using

and `Coords`

, which
provide methods for indexing a one-dimensional `Offsets`

or `Array`

as an n-dimensional
tensor.`ArrayExt`

supports (de)serialization without type hinting. `Array`

supports serialization
for `ArrayExt <T>`

`T``:` Serialize

and deserialization for `T``:` Deserialize

.Example usage:

`let` a `=` `[``1``,` `2``,` `3``]``;`
`let` b `=` `[``5``]``;`
`let` product `=` `&``Array``::`from`(``&`a`[``..``]``)` `*` `&``Array``::`from`(``&`b`[``..``]``)``;`
`assert_eq!``(`product`,` `Array``::`from_iter`(``vec!``[``5``,` `10``,` `15``]``)``)``;`
`assert_eq!``(`product`.``sum``(``)``,` `Number``::`from`(``30``)``)`

This crate depends on ArrayFire version 3.8. You will have to install ArrayFire separately by following the instructions at https://arrayfire.org/docs/installing.htm in order to build this crate.

You can find detailed instructions for building the Rust

crate from crates.io at
https://crates.io/crates/arrayfire.`arrayfire`

#### Dependencies

~4.5MB

~92K SLoC