Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[recipes] Update NuMojo to v0.5 #66

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
206 changes: 100 additions & 106 deletions recipes/numojo/README.md
Original file line number Diff line number Diff line change
@@ -1,122 +1,66 @@
<a name="readme-top"></a>
<!-- add these later -->
<!-- [![MIT License][license-shield]][] -->

<div align="center">
<a href="">
<img src="./numojo_logo.png" alt="Logo" width="350" height="350">
</a>

<h1 align="center" style="font-size: 3em; color: white; font-family: 'Avenir'; text-shadow: 1px 1px orange;">NuMojo</h1>

<p align="center">
NuMojo is a library for numerical computing in Mojo 🔥 similar to NumPy, SciPy in Python.
<br />
<!-- when we create docs -->
<div style="font-family: 'Arial'; border: 1px solid black; padding: 5px;">
<a href="https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo-Examples-and-Benchmarks/blob/main/docs/README.md"><strong>Explore the docs» </strong></a> &nbsp; &nbsp;
<a href="./docs/changelog.md"><strong>Changelog» </strong></a> &nbsp; &nbsp;
<a href="https://discord.com/channels/1149778565756366939/1149778566603620455" ><strong>Check out our Discord» </strong></a>
</div>
<br />
<div style="font-family: 'Arial'; border: 1px solid black; padding: 5px;">
<a href="./docs/readme_zhs.md"><strong>中文·简» </strong></a> &nbsp;
<a href="./docs/readme_zht.md"><strong>中文·繁» </strong></a> &nbsp;
<a href="./docs/readme_jp.md"><strong>日本語» </strong></a>
</div>
<!-- <a href="./docs/readme_kr.md"><strong>한국어 문서» </strong></a> -->
<!-- <br /> -->
<!-- <br /> -->
<!-- <a href="">View Demo</a>
·
<a href="">Report Bug</a>
·
<a href="">Request Feature</a> -->
</p>
</div>

<details>
<summary>Table of Contents</summary>
<ol>
<li>
<a href="#about-the-project">About The Project</a>
<ul>
<li><a href="#what-numojo-is"> What NuMojo is </a></li>
<li><a href="#what-numojo-is-not">What NuMojo is not</a></li>
</ul>
</li>
<li><a href="#goals">Goals</a></li>
<li><a href="#usage">Usage</a></li>
<li><a href="#how-to-install">How to install</a></li>
<li><a href="#contributing">Contributing</a></li>
<li><a href="#warnings">Warnings</a></li>
<li><a href="#license">License</a></li>
<li><a href="#acknowledgments">Acknowledgments</a></li>
<li><a href="#Contributors">Contributors</a></li>
</ol>
</details>
# 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).

Expand All @@ -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]]")
Expand All @@ -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)
)

Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions recipes/numojo/recipe.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
context:
version: "0.4.0"
version: "0.5.0"

package:
name: "numojo"
version: ${{ version }}

source:
- git: https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo.git
rev: 13bc54b65a47ba31306dae510e61787284469332
rev: 4229b768d87b63896f527a7d52527ac1aec22fa2

build:
number: 0
Expand Down