#numeric #array #ndarray #multidimensional #numpy

numas

numas library is implementation of multidimensional array for efficient computing

17 releases

0.2.7 Jul 24, 2019
0.2.5 May 1, 2019
0.2.4 Apr 22, 2019
0.1.9 Apr 17, 2019
0.1.0 Mar 28, 2019

#145 in Data structures

Download history 88/week @ 2019-04-09 55/week @ 2019-04-16 48/week @ 2019-04-23 15/week @ 2019-04-30 18/week @ 2019-05-07 18/week @ 2019-05-14 66/week @ 2019-05-21 32/week @ 2019-05-28 16/week @ 2019-06-04 48/week @ 2019-06-11 48/week @ 2019-06-18 203/week @ 2019-06-25 142/week @ 2019-07-02 33/week @ 2019-07-09 32/week @ 2019-07-16

232 downloads per month

MIT license

52KB
844 lines

numas

Build Status License: MIT

numas is Rust library implementing n-dimensional array for generic types.

Content

  • Multidimensional array support
  • Multidimensional view support
  • Random factories, fillers and other factories
  • Hyperbolic, trigonometric, arithmetic, logarithmic, exponential and rounding functions for arrays

Usage

Initializing array

Array can be initialized in many ways, for example factories, or calling new method.

let array = Array::new(vec![1,2,3,4,5,6], vec![2, 3]);
// Creates array with elements from 1 to 6 and shape of two dimensions with 2 and 3 length

Reshaping

Sometimes is needed to change shape of an array. Actually there are two ways of doing that.

  • reshape Using reshape returns array which method is called on. This behavior enables fluent/builder pattern interface resulting in method chaining posibility.
  • set_shape Method set_shape only sets shape and has no return value.

Functions

The majority of functions are accessible via an array instance.


let array = Array::new(vec![1,2,3,4,5], vec![5]);
array.sin(); // Returns new array with elements equal to sin(1), sin(2)...
array.cos();
array.sqrt();
//etc.

Operators

Currently there are supported basic mathematical operators on array - add, sub, mul, div and negation, all element wise. Also theirs assign equivalents are implemented (+=, -= ...)

View

numas implements views the same way as array, so views act as arrays and it's possible to perform all operations as on array, but modifying elements affects the origin array as well.

// Create new linear array with elements from 1 to 9
let array = Array::new(vec![1,2,3,4,5,6,7,8,9], vec![9]);

// Create view into array of index from 3 to 6 (elements 4,5,6,7)
let mut view = array.get(s![3 => 7]);

// Multiply view by 10, also possible to pass whole array with same shape as view
view *= u![10];

// Now elements in view are 40, 50, 60, 70
// Modifying elements in view also affects origin array
// origin array now contains elements 1, 2, 3, 40, 50, 60, 70, 8, 9

Macros

Currently there are following macros:

s

Macro s! is for convenient indexing of an array. Example of usage is following

let view = array.get(s![0; 1 => 3]);
// Array view now contains first row of array columns from index 1 to 3 (excluded) and its shape is onedimensional of length 2

u

Macro u! is for creating "unit arrays". Unit arrays are arrays of exactly one element with shape of one dimension of length one.

let array = u![7];
// Creates array of element 7
// Equivalent would be Array::new(vec![7], vec![1]);

tuple

Macro tuple! is an internal macro used inside of u!. It is not supposed to be used by user. It pushes value with 0 to provided vector if only one value is provided. If two values are provided, it pushes both of them.

let mut vec: Vec<i32> = Vec::new();
tuple![vec; 1, 5];
// vec now contains [1, 5]

tuple![vec; 6]
// vec now contains [1, 5, 6, 0]

Dependencies

~505KB