[−][src]Module gulali::builders
Introduction
There are 4 general mechanisms for creating vectors:
- Conversion from other Rust data type (e.g., lists, tuples)
- Using Gulali vector builder routines (e.g., ones, zeros, etc.)
- Reading vectors from disk, either from standard or custom formats (Not available yet)
- Creating vectors from raw bytes through the use of strings or buffers (Not available yet)
This section will not cover means of replicating, joining, or otherwise expanding or mutating existing vectors. Those are covered in their own sections.
Converting Array-like objects to Vector
In general, numerical data arranged in an array-like structure
in Rust can be converted to vector through the use of the to_vec()
function. The most obvious examples are array and slices.
See the documentation for to_vec()
for details for its use.
Examples:
let arr = [4, 4, 1, 6]; assert_eq!(arr.to_vec(), vec![4, 4, 1, 6]); let slice = &[2, 3, 1, 0]; assert_eq!(slice.to_vec(), vec![2, 3, 1, 0])
Vector Builders
Gulali has built-in functions for creating vectors from scratch:
zeros()
will create a vector filled with 0 values with
the specified dimension and shape.
// Create two-dimensional vector with shape [3, 3] // filled with zeros let a: Vec<Vec<i32>> = Vec::two_dim(3, 3).zeros(); assert_eq!(a, [[0, 0, 0], [0, 0, 0], [0, 0, 0]]);
ones()
will create a vector filled with 1 values with
the specified dimension and shape.
// Create three-dimensional vector with shape [1, 2, 1] // filled with ones let a: Vec<Vec<Vec<f64>>> = Vec::three_dim(1, 2, 1).ones(); assert_eq!(a, [[[1.0], [1.0]]]);
Modules
dimensional | |
full | |
ones | |
zeros |