ModularM
Modular2y ago
4 replies
mad alex 1997

NuMojo’s got NDArrays! 🥳

NuMojo has just released v0.1 adding many new features the largest of which is an N dimensional array type completely independent of Tensor. Our NDArray has many features including
* Native Vectorization of arithmetic dunder operations +,-.*./ etc.
* Indexing with both integers and Slices (though mixed requires using Slice explicitly due to Mojo parser limitations).
* sum, mean, stdev both on axis and cumulative.
* A few different matmul implementations.
* Basic integration trapz.
* A few of the array creation routines from numpy: arange, ones, zeros, identity.
* Some Sorting functions: bubble_sort, quick_sort,and quick_sort_inplace.


Our math functions were all migrated to NDArray, and a new Backend was added. VectorizedParallelizedNWorkers which allows the number of workers to be set as a parameter. I have found that setting the number of workers to between half, and three-quarters of the total number of cores provides a speed-up where default parallelization caused a slowdown (on WSL).

For those of you who are new to NuMojo Backend is a trait that defines how calculations get carried out for many of the functions in our math module. The default is Vectorized which uses SIMD vectorization. In the future, all numojo functions and data types will implement backends to enable easy switching between computational methods and eventually even hardware accelerators such as GPUs.

Example: The following calculates the square root of an array from 0 to 99, reshaped to 10x10, vectorized, and parallelized with 8 workers.
import numojo as nm
alias backend = nm.VectorizedParallelizedNWorkers[8]
def main():
    var array = nm.arange[nm.f64](0,100)
    array.reshape(10,10)
    var res = nm.sqrt[nm.f64,backend=backend](array)
    print(res)
GitHub
NuMojo is a library for numerical computing in Mojo 🔥 similar to numpy in Python. - Mojo-Numerics-and-Algorithms-group/NuMojo
GitHub - Mojo-Numerics-and-Algorithms-group/NuMojo: NuMojo is a lib...
Was this page helpful?