diff --git a/recipes/numojo/README.md b/recipes/numojo/README.md index e9aad48..ce54540 100644 --- a/recipes/numojo/README.md +++ b/recipes/numojo/README.md @@ -1,122 +1,66 @@ - - - - -
- - Logo - - -

NuMojo

- -

- NuMojo is a library for numerical computing in Mojo 🔥 similar to NumPy, SciPy in Python. -
- -

- Explore the docs»     - Changelog»     - Check out our Discord» -
-
-
- 中文·简»   - 中文·繁»   - 日本語» -
- - - - -

-
- -
- Table of Contents -
    -
  1. - About The Project - -
  2. -
  3. Goals
  4. -
  5. Usage
  6. -
  7. How to install
  8. -
  9. Contributing
  10. -
  11. Warnings
  12. -
  13. License
  14. -
  15. Acknowledgments
  16. -
  17. Contributors
  18. -
-
+# NuMojo + +![logo](./image.jpeg) + +NuMojo is a library for numerical computing in Mojo 🔥 similar to NumPy, SciPy in Python. + +**[Explore the docs»](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo-Examples-and-Benchmarks/blob/main/docs/README.md)** | **[Changelog»](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/blob/main/docs/changelog.md)** | **[Check out our Discord»](https://discord.gg/NcnSH5n26F)** + +**Table of Contents** + +1. [About The Project](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/blob/main/README.MD#about-the-project) +2. [Goals](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/blob/main/README.MD#goals) +3. [Usage](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/blob/main/README.MD#usage) +4. [How to install](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/blob/main/README.MD#how-to-install) +5. [Contributing](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/blob/main/README.MD#contributing) +6. [Warnings](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/blob/main/README.MD#warnings) +7. [License](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/blob/main/README.MD#license) +8. [Acknowledgements](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/blob/main/README.MD#acknowledgments) +9. [Contributors](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/blob/main/README.MD#Contributors) ## About the project -### What NuMojo is +NuMojo aims to encompass the extensive numerics capabilities found in Python packages such as NumPy, SciPy, and Scikit-learn. -NuMojo intends to capture a wide swath of numerics capability present in the Python packages NumPy, SciPy, and Scikit. +======= -NuMojo intends to try and get the most out of the capabilities of Mojo including vectorization, parallelization, and GPU acceleration (once available). Currently, NuMojo extends (most of) the standard library math functions to work on array inputs. +***What NuMojo is*** -We intend NuMojo to be a building block for other Mojo packages that need fast math under the hood without the added weight of a ML back and forward propagation system +We seek to harness the full potential of Mojo, including vectorization, parallelization, and GPU acceleration (when available). Currently, NuMojo extends most (if not all) standard library math functions to support array inputs. -### What NuMojo is not +Our vision for NuMojo is to serve as an essential building block for other Mojo packages needing fast math operations, without the additional weight of a machine learning back-propagation system. -NuMojo is not a machine learning library, it will never include back-propagation in the base library. +***What NuMojo is not*** -## Goals and features +NuMojo is not a machine learning library and will never include back-propagation as part of the base library. -Our main goal is to implement a fast, comprehensive numerics library in Mojo. +## Features and goals -Following are some brief long-term goals. Some of them have already been implemented or partially implemented. +Our primary objective is to develop a fast, comprehensive numerics library in Mojo. Below are some features and long-term goals. Some have already been implemented, either fully or partially. Core data types: - Native n-dimensional array (`numojo.core.ndarray.NDArray`). -- Native 2-dimensional array, i.e., matrix (`numojo.mat.matrix.Matrix`). +- Native 2-dimensional array, i.e., matrix (`numojo.core.matrix.Matrix`). +- Native n-dimensional complex array (`numojo.core.complex_ndarray.ComplexNDArray`) - Native fixed-dimension array (to be implemented when trait parameterization is available). Routines and objects: - Array creation routines (`numojo.routines.creation`) - Array manipulation routines (`numojo.routines.manipulation`) -- Bit-wise operations (`numojo.routines.bitwise`) -- Constants (`numojo.routines.constants`) - Input and output (`numojo.routines.io`) -- Text files (`numojo.routines.files`) -- Text formatting options (`numojo.routines.formatting`) - Linear algebra (`numojo.routines.linalg`) -- Decompositions (`numojo.routines.decompositions`) -- Products of matrices and vectors (`numojo.routines.products`) -- Solving (`numojo.routines.solving`) - Logic functions (`numojo.routines.logic`) -- Comparison (`numojo.routines.comparison`) -- Array contents (`numojo.routines.contents`) -- Truth value testing (`numojo.routines.truth`) - Mathematical functions (`numojo.routines.math`) -- Arithmetic operations (`numojo.routines.arithmetic`) - Exponents and logarithms (`numojo.routines.exponents`) - Extrema finding (`numojo.routines.extrema`) -- Floating point routines (`numojo.routines.floating`) -- Hyperbolic functions (`numojo.routines.hyper`) -- Indexing (`numojo.routines.indexing`) -- Miscellaneous (`numojo.routines.misc`) - Rounding (`numojo.routines.rounding`) -- Sums, products, differences (`numojo.routines.sums`, `numojo.routines.products`, `numojo.routines.differences`) - Trigonometric functions (`numojo.routines.trig`) - Random sampling (`numojo.routines.random`) - Sorting, searching, and counting (`numojo.routines.sorting`, `numojo.routines.searching`) - Statistics (`numojo.routines.statistics`) -- Averages and variances (`numojo.routines.averages`) -- Calculus, Integration & Derivatives etc -- Optimizers -- Function approximators +- etc... Please find all the available functions and objects [here](docs/features.md). @@ -133,8 +77,8 @@ from numojo.prelude import * fn main() raises: # Generate two 1000x1000 matrices with random float64 values - var A = nm.random.randn(shape=Shape(1000, 1000)) - var B = nm.random.randn(shape=Shape(1000, 1000)) + var A = nm.random.randn(Shape(1000, 1000)) + var B = nm.random.randn(Shape(1000, 1000)) # Generate a 3x2 matrix from string representation var X = nm.fromstring[f32]("[[1.1, -0.32, 1], [0.1, -3, 2.124]]") @@ -152,26 +96,27 @@ fn main() raises: var A_slice = A[1:3, 4:19] # Get scalar from array - var A_item = A[Idx(291, 141)] + var A_item = A[item(291, 141)] + var A_item_2 = A.item(291, 141) ``` An example of matrix (`Matrix` type) goes as follows. ```mojo -from numojo import mat +from numojo import Matrix from numojo.prelude import * fn main() raises: # Generate two 1000x1000 matrices with random float64 values - var A = mat.rand(shape=(1000, 1000)) - var B = mat.rand(shape=(1000, 1000)) + var A = Matrix.rand(shape=(1000, 1000)) + var B = Matrix.rand(shape=(1000, 1000)) # Generate 1000x1 matrix (column vector) with random float64 values - var C = mat.rand(shape=(1000, 1)) + var C = Matrix.rand(shape=(1000, 1)) # Generate a 4x3 matrix from string representation - var F = mat.fromstring[i8]( + var F = Matrix.fromstring[i8]( "[[12,11,10],[9,8,7],[6,5,4],[3,2,1]]", shape=(4, 3) ) @@ -186,12 +131,12 @@ fn main() raises: print(C[::-1, :]) # Sort and argsort along axis - print(mat.sort(A, axis=1)) - print(mat.argsort(A, axis=0)) + print(nm.sort(A, axis=1)) + print(nm.argsort(A, axis=0)) # Sum the matrix - print(mat.sum(B)) - print(mat.sum(B, axis=1)) + print(nm.sum(B)) + print(nm.sum(B, axis=1)) # Matrix multiplication print(A @ B) @@ -200,27 +145,74 @@ fn main() raises: print(A.inv()) # Solve linear algebra - print(mat.solve(A, B)) + print(nm.solve(A, B)) # Least square - print(mat.lstsq(A, C)) + print(nm.lstsq(A, C)) +``` + +An example of ComplexNDArray is as follows, + +```mojo +import numojo as nm +from numojo.prelude import * + + +fn main() raises: + # Create a complexscalar 5 + 5j + var complexscalar = ComplexSIMD[cf32](re=5, im=5) + # Create complex array filled with (5 + 5j) + var A = nm.full[cf32](Shape(1000, 1000), fill_value=complexscalar) + # Create complex array filled with (1 + 1j) + var B = nm.ones[cf32](Shape(1000, 1000)) + + # Print array + print(A) + + # Array slicing + var A_slice = A[1:3, 4:19] + + # Array multiplication + var C = A * B + + # Get scalar from array + var A_item = A[item(291, 141)] + # Set an element of the array + A[item(291, 141)] = complexscalar ``` ## How to install -There are two approach to install and use the Numojo package. +There are three approach to install and use the Numojo package. + +### Use magic CLI + +You can use the following command in the terminal to install `numojo`. + +```console +magic add numojo +``` + +### Add in toml file + +You can add `numojo` in the dependencies section of your toml file. + +```toml +[dependencies] +numojo = "==0.5" +``` ### Build package -This approach invovles building a standalone package file `mojopkg`. +This approach involves building a standalone package file `mojopkg`. 1. Clone the repository. -2. Build the package using `mojo package numojo` -3. Move the numojo.mojopkg into the directory containing the your code. +2. Build the package using `magic run package`. +3. Move the `numojo.mojopkg` into the directory containing the your code. ### Include NuMojo's path for compiler and LSP -This approach does not require buiding a package file. Instead, when you compile your code, you can include the path of NuMojo reporsitory with the following command: +This approach does not require building a package file. Instead, when you compile your code, you can include the path of NuMojo repository with the following command: ```console mojo run -I "../NuMojo" example.mojo @@ -249,6 +241,8 @@ This library is still very much a work in progress and may change at any time. Distributed under the Apache 2.0 License with LLVM Exceptions. See [LICENSE](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/blob/main/LICENSE) and the LLVM [License](https://llvm.org/LICENSE.txt) for more information. +This project includes code from [Mojo Standard Library](https://github.com/modularml/mojo), licensed under the Apache License v2.0 with LLVM Exceptions (see the LLVM [License](https://llvm.org/LICENSE.txt)). MAX and Mojo usage and distribution are licensed under the [MAX & Mojo Community License](https://www.modular.com/legal/max-mojo-license). + ## Acknowledgements Built in native [Mojo](https://github.com/modularml/mojo) which was created by [Modular](https://github.com/modularml). diff --git a/recipes/numojo/recipe.yaml b/recipes/numojo/recipe.yaml index af09c14..f9ce448 100644 --- a/recipes/numojo/recipe.yaml +++ b/recipes/numojo/recipe.yaml @@ -1,5 +1,5 @@ context: - version: "0.4.0" + version: "0.5.0" package: name: "numojo" @@ -7,7 +7,7 @@ package: source: - git: https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo.git - rev: 13bc54b65a47ba31306dae510e61787284469332 + rev: 4229b768d87b63896f527a7d52527ac1aec22fa2 build: number: 0 diff --git a/recipes/numojo/tests.mojo b/recipes/numojo/tests.mojo index e81c757..694a1f9 100644 --- a/recipes/numojo/tests.mojo +++ b/recipes/numojo/tests.mojo @@ -1,8 +1,12 @@ import numojo as nm from numojo.prelude import * -from numojo import mat from python import Python, PythonObject -from testing.testing import assert_raises, assert_equal, assert_true, assert_almost_equal +from testing.testing import ( + assert_raises, + assert_equal, + assert_true, + assert_almost_equal, +) fn check[ @@ -39,6 +43,7 @@ def test_arange(): "Arange is broken", ) + def test_linspace(): var np = Python.import_module("numpy") check( @@ -47,7 +52,7 @@ def test_linspace(): "Linspace is broken", ) + def main(): test_arange() test_linspace() -