Skip to content

Commit 23f316c

Browse files
authored
[release] NuMojo v0.6 for MAX and mojo 25.1 (#223)
NuMojo v0.6 for MAX and mojo 25.1
2 parents 98ced2c + a07e867 commit 23f316c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+8148
-10487
lines changed

.github/workflows/run_tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131

3232
- name: Install magic
3333
run: |
34-
curl -ssL https://magic.modular.com/ff414efd-16ac-4bf3-8efc-50b059272ab6 | bash
34+
curl -ssL https://magic.modular.com/deb181c4-455c-4abe-a263-afcff49ccf67 | bash
3535
3636
- name: Add path
3737
run: |

.github/workflows/test_pre_commit.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626

2727
- name: Install magic
2828
run: |
29-
curl -ssL https://magic.modular.com/ff414efd-16ac-4bf3-8efc-50b059272ab6 | bash
29+
curl -ssL https://magic.modular.com/deb181c4-455c-4abe-a263-afcff49ccf67 | bash
3030
3131
- name: Add path
3232
run: |

.gitignore

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
# magic environments
1414
.magic
15+
magic.lock
1516

1617
# pixi environments
1718
.pixi
@@ -26,11 +27,12 @@
2627

2728
# Miscellaneous files
2829
mojo
29-
numojo.mojopkg
30-
bench.mojo
31-
test_ndarray.ipynb
32-
test.mojo
33-
tempCodeRunnerFile.mojo
30+
/numojo.mojopkg
31+
/bench.mojo
32+
/test*.mojo
33+
/test*.ipynb
34+
/tempCodeRunnerFile.mojo
3435

3536
# Auto docs
36-
docs/readthedocs/docs.json
37+
docs/readthedocs/docs.json
38+
docs.json

.readthedocs.yaml

Lines changed: 0 additions & 26 deletions
This file was deleted.

README.MD

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ NuMojo is a library for numerical computing in Mojo 🔥 similar to NumPy, SciPy
66

77
**[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)**
88

9+
**[中文·简»](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/blob/main/docs/readme_zhs.md)** | **[中文·繁»](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/blob/main/docs/readme_zht.md)** | **[日本語»](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/blob/main/docs/readme_jp.md)**
10+
911
**Table of Contents**
1012

1113
1. [About The Project](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/blob/main/README.MD#about-the-project)
@@ -40,26 +42,26 @@ Our primary objective is to develop a fast, comprehensive numerics library in Mo
4042

4143
Core data types:
4244

43-
- Native n-dimensional array (`numojo.core.ndarray.NDArray`).
44-
- Native 2-dimensional array, i.e., matrix (`numojo.core.matrix.Matrix`).
45-
- Native n-dimensional complex array (`numojo.core.complex_ndarray.ComplexNDArray`)
45+
- Native n-dimensional array (`numojo.NDArray`).
46+
- Native 2-dimensional array, i.e., matrix (`numojo.Matrix`).
47+
- Native n-dimensional complex array (`numojo.ComplexNDArray`)
4648
- Native fixed-dimension array (to be implemented when trait parameterization is available).
4749

4850
Routines and objects:
4951

50-
- Array creation routines (`numojo.routines.creation`)
51-
- Array manipulation routines (`numojo.routines.manipulation`)
52-
- Input and output (`numojo.routines.io`)
53-
- Linear algebra (`numojo.routines.linalg`)
54-
- Logic functions (`numojo.routines.logic`)
55-
- Mathematical functions (`numojo.routines.math`)
56-
- Exponents and logarithms (`numojo.routines.exponents`)
57-
- Extrema finding (`numojo.routines.extrema`)
58-
- Rounding (`numojo.routines.rounding`)
59-
- Trigonometric functions (`numojo.routines.trig`)
60-
- Random sampling (`numojo.routines.random`)
61-
- Sorting, searching, and counting (`numojo.routines.sorting`, `numojo.routines.searching`)
62-
- Statistics (`numojo.routines.statistics`)
52+
- Array creation routines (`numojo.creation`)
53+
- Array manipulation routines (`numojo.manipulation`)
54+
- Input and output (`numojo.io`)
55+
- Linear algebra (`numojo.linalg`)
56+
- Logic functions (`numojo.logic`)
57+
- Mathematical functions (`numojo.math`)
58+
- Exponents and logarithms (`numojo.exponents`)
59+
- Extrema finding (`numojo.extrema`)
60+
- Rounding (`numojo.rounding`)
61+
- Trigonometric functions (`numojo.trig`)
62+
- Random sampling (`numojo.random`)
63+
- Sorting and searching (`numojo.sorting`, `numojo.searching`)
64+
- Statistics (`numojo.statistics`)
6365
- etc...
6466

6567
Please find all the available functions and objects [here](docs/features.md).
@@ -199,7 +201,7 @@ You can add `numojo` in the dependencies section of your toml file.
199201

200202
```toml
201203
[dependencies]
202-
numojo = "==0.5"
204+
numojo = "=0.6"
203205
```
204206

205207
### Build package

docs/changelog.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,61 @@
22

33
This is a list of RELEASED changes for the NuMojo Package.
44

5+
## 28/02/2025 (v0.6)
6+
7+
### ⭐️ New
8+
9+
- Implement the `broadcast_to()` method for `NDArray`. This function broadcasts an array to any compatible shape ([PR #202](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/202)).
10+
- Add the `apply_along_axis()` function that executes a function working on 1-d arrays on n-d arrays along the given axis ([PR #213](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/213), [PR #218](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/218)).
11+
- Implement the `diagonal()` function and the `NDArray.diagonal()` method ([PR #217](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/217)).
12+
- Implement the `compress()` function and the `NDArray.compress()` method ([PR #219](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/219)).
13+
- Implement the `clip()` function and the `NDArray.clip()` method ([PR #220](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/220)).
14+
- Add the `_NDAxisIter` type as a iterator that returns, in each iteration, a 1-d array along that axis. The iterator traverse the array either by C-order or F-order ([PR #212](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/212), [PR #214](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/214)).
15+
- Add the `ith()` method to the `_NDArrayIter` type and to the `_NDIter` type to get the i-th item ([PR #219](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/219), [PR #221](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/221)).
16+
- Add the `Flags` type for storing information on memory layout of arrays. The `Flags` type replaces the current `Dict[String, Bool]` type ([PR #210](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/210), [PR #214](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/214)).
17+
- Add the `swapaxes()` methods for the `NDArrayShape` type and the `NDArrayStrides` type ([PR #221](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/221)).
18+
- Add the `offset()` methods for the `Item` type to get the offset of an index in the underlying buffer. Allow the `Item` object to be constructed from index and shape ([PR #221](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/221)).
19+
20+
### 🦋 Changed
21+
22+
- Update the syntax to accommodate to Mojo 25.1 ([PR #211](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/211)).
23+
- Change constructors, e.g., `str()` to `String()`.
24+
- Change `index()` function to `Int()`.
25+
- Change the function `isdigit()` to method.
26+
- Stop using `NDArray.__init__()` to construct arrays but `NDArray()`.
27+
- Update functions in the `random` module:
28+
- Add `randint()`, and accept `Shape` as the first argument ([PR #199](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/199)).
29+
- Update functions in the `statistics` module:
30+
- Add the parameter `returned_dtype` to functions which defaults to `f64` ([PR #200](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/200)).
31+
- Add `variance()` and `std()` ([PR #200](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/200)). Allow calculating variance and std of an array by axis ([PR #207](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/207)).
32+
- Allow `median()` and `mode()` functions to work on any axis.
33+
- Update functions in the `sorting` module:
34+
- Considerably improve the performance of `sort()` function ([PR #213](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/213), [PR #214](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/214)).
35+
- Allow `argsort` by any axis for both C-order and F-order arrays ([PR #214](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/214)).
36+
- Update function in the `math.extrema` module ([PR #216](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/216)):
37+
- Allow the `max()` and `min()` functions to work on any axis.
38+
- Update the `max()` and `min()` methods for the `NDArray` type.
39+
- Update the behaviors of 0-d array (numojo scalar). Although the syntax `a.item(0)` or `a[Item(0)]` is always preferred, we also allow some basic operations on 0-d array. 0-d array can now be unpacked to get the corresponding mojo scalar either by `[]` or by `item()` ([PR #209](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/209)).
40+
- Add boundary checks for `NDArrayShape` and `NDArrayStrides` to ensure safe use. Improve the docstring ([PR #205](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/205), [PR #206](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/206)).
41+
- Significantly increase the speed of printing large arrays ([PR #215](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/215)).
42+
- Replace the `NDArray.num_elements()` method by the `NDArray.size` attribute for all modules ([PR #216](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/216)).
43+
44+
### ❌ Removed
45+
46+
- Remove the `cumvariance`, `cumstd`, `cumpvariance`, `cumpstd` functions ([PR #200](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/200)).
47+
- Remove the `maxT()` and `minT()` functions ([PR #216](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/216)).
48+
49+
### 🛠️ Fixed
50+
51+
- Re-write the `ravel()` function so that it will not break for F-order arrays ([PR #214](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/214)).
52+
- Fix the `NDArray.sort()` method (in-place sort). The default axis is changed to `-1` ([PR #217](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/217)).
53+
- Fix the `NDArray.__bool__()` method which may returns incorrect results ([PR #219](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/219)).
54+
55+
### 📚 Documentatory and testing
56+
57+
- Update the docstring of all methods belonging to the `NDArray` type, following the Mojo Docstring Style Guide. Provide more detailed error messages in the internal functions of `NDArray` to enhance clarity and traceability of errors ([PR #222](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/222)).
58+
- Updates the roadmap document according to our current progress ([PR #208](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/208)).
59+
560
## 26/01/2025 (v0.5)
661

762
### ⭐️ New

docs/features.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Available functions and objects by topics (also see imports within `__init__` fi
88
- Array manipulation routines (`numojo.routines.manipulation`)
99
- Bit-wise operations (`numojo.routines.bitwise`)
1010
- Constants (`numojo.routines.constants`)
11+
- Indexing routines (`numojo.routines.indexing`)
1112
- Input and output (`numojo.routines.io`)
1213
- Text files (`numojo.routines.files`)
1314
- Text formatting options (`numojo.routines.formatting`)
@@ -20,7 +21,13 @@ Available functions and objects by topics (also see imports within `__init__` fi
2021
- Array contents (`numojo.routines.contents`)
2122
- Truth value testing (`numojo.routines.truth`)
2223
- Mathematical functions (`numojo.routines.math`)
23-
- Extrema: maxT, minT
24+
- Sums (`numojo.routines.sums`)
25+
- `sum()`
26+
- Products (`numojo.routines.products`)
27+
- `prod()`
28+
- Differences (`numojo.routines.differences`)
29+
- Extrema (`numojo.routines.math.extrema`)
30+
- `max()`, `min()`
2431
- Trigonometry: acos, asin, atan, cos, sin, tan, atan2, hypot
2532
- Hyperbolic: acosh, asinh, atanh, cosh, sinh, tanh
2633
- Floating: copysign
@@ -35,17 +42,14 @@ Available functions and objects by topics (also see imports within `__init__` fi
3542
- Indexing (`numojo.routines.indexing`)
3643
- Miscellaneous (`numojo.routines.misc`)
3744
- Rounding (`numojo.routines.rounding`)
38-
- Sums, products, differences (`numojo.routines.sums`, `numojo.routines.products`, `numojo.routines.differences`)
39-
- sum, prod
4045
- Trigonometric functions (`numojo.routines.trig`)
4146
- Random sampling (`numojo.routines.random`)
4247
- Sorting, searching, and counting (`numojo.routines.sorting`, `numojo.routines.searching`)
4348
- Statistics (`numojo.routines.statistics`)
44-
- mean, mode, median
45-
- variance
46-
- Averages and variances (`numojo.routines.averages`)
49+
- Averages and variances (`numojo.routines.averages`)
50+
- `mean()`, `mode()`, `median()`
51+
- `variance()`, `std()`
4752

4853
To-be-implemented functions and objects by topics:
4954

5055
- Mathematical functions: abs, floor, ceil, trunc, round, roundeven, round_half_down, round_half_up, reciprocal, nextafter, remainder
51-
- Statistical functions: pvariance, pstdev, std

docs/roadmap.md

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,68 @@
1-
# ROADMAP
1+
# Roadmap
22

3-
Overall the goal is to make a powerful and broad featured library for numerical and scientific computing. In order to make a transition from python easy we should largely follow the conventions of numpy and scipy, but we should allow for the flexibility to do things differently where it improves user experience or greatly effects performance.
3+
Our primary objective is to develop a robust and comprehensive library for numerical and scientific computing. To facilitate a smooth transition from Python, we will primarily adhere to the conventions of `numpy` and `scipy`, while allowing deviations when they:
44

5-
With that in mind NuMojo as a project is in an early stage of development. If you notice a missing feature either build it and make a pull request or make a feature request.
5+
- Align with the design philosophy of the Mojo programming language.
6+
- Significantly enhance performance, such as through the use of generics.
7+
- Improve consistency in conventions, such as naming parameters and arguments.
68

7-
## TASKS
9+
NuMojo is currently in its early development stages. At this point, our focus is to ***stabilize the API*** and ***implement the majority of functionalities***. If you notice any missing features, please consider developing them and submitting a pull request or creating a feature request.
810

9-
* Implement array version all SIMDable standard library math functions (mostly done waiting on std lib [issue 2492](https://github.com/modularml/mojo/issues/2492))
10-
* Build statistics functions
11-
* Build optimizers (newton raphson, bisection,etc)
12-
* Build function approximators
11+
## Core Tasks
1312

14-
## N-dimensional Arrays
13+
- Implement the n-dimensional array type and support SIMD-compatible standard library math functions[^stdlib].
14+
- Develop `numpy`-like functions for mathematical, statistical, linear algebra, searching, sorting, etc.
15+
- Create `scipy`-like functions for scientific purposes, such as optimizers, function approximators, and FFT.
1516

16-
Now that Modular has decided to no longer support array and to open source and deprecate it NuMojo intends to take array and Make it our own Once they do.
17+
### N-dimensional Arrays
1718

18-
Which means that we will be trying to add many of the features from numpy.array that array currently lacks, while not sacrificing performance.
19+
We have implemented basic functions and methods for the N-dimensional array `NDArray` (and also `ComplexNDArray` and `Matrix`). We are working on incorporating additional essential features similar to those in `numpy`.
1920

20-
## Notional organization of functions and features
21+
Currently, operations on an array return a copy. When the Mojo programming language supports parameterized traits, some operations (e.g., slicing and transpose) will return a view of the array. This will avoid excessive copying of data, increase memory reuse, and potentially enhance performance.
2122

22-
* Most common functions at top level like in numpy (trig, basic stats, masking, querying, and mapping)
23-
* Other features should be organized either by type of math or intended utilization
24-
* Statistics probably merits its own sub module
25-
* Regression could either be a submodule of statistics or its own module
26-
* kernel density estimators almost certainly should be part of the statistics sub module
27-
* It is tempting to make a algebra, calculus and trig submodules however that may end up being confusing as those topics include so many things, it may be better to organize what would be there into functional applications instead
28-
* An Ordinary differential equations submodule would include solvers and utilities
29-
* The optimizer sub module could mirror scipy.optimize but minimally should include all of those functions
30-
* There will need to be discussions and bike shedding about both organization of the library and what does and doesn't belong.
23+
In the future, when the Mojo programming language supports GPU functionality as it currently does with SIMD, NuMojo will also provide an option to use the GPU for calculations.
24+
25+
### Implement Basic Numeric Functions
26+
27+
We are currently working on implementing basic numeric functions into NuMojo. The scope is similar to `numpy`. Functions on [this page](https://numpy.org/doc/stable/reference/routines.html) will be considered for gradual implementation in NuMojo.
28+
29+
### Implement Advanced Functions
30+
31+
We also aim to implement advanced functions into NuMojo. The scope is similar to `scipy`.
32+
33+
## Internal Organization of Objects and Functions
34+
35+
NuMojo organizes modules internally according to the following structure[^numpy]:
36+
37+
1. A `routines` folder is created under `/numojo`. Functions covered by [this page](https://numpy.org/doc/stable/reference/routines.html) will be considered for implementation in this folder.
38+
2. Sub-folders[^single] will be created under `/routines` for each topic [on this page](https://numpy.org/doc/stable/reference/routines.html). Examples include:
39+
- `/creation` (Array creation routines)
40+
- `/logic` (Logic functions)
41+
- `/mathematics` (Mathematical functions)
42+
- ...
43+
3. In each sub-folder, functions are grouped by topics into single Mojo files. For example, in the `/mathematics` folder, the following files will be created [(as classified by NumPy on this page)](https://numpy.org/doc/stable/reference/routines.math.html):
44+
- `trig.mojo` (Trigonometric functions)
45+
- `hyperbolic.mojo` (Hyperbolic functions)
46+
- `exp_log.mojo` (Exponents and logarithms)
47+
- `other.mojo` (Other special functions)
48+
- `arithmetic.mojo` (Arithmetic operations)
49+
- ...
50+
4. In each file, functions are sorted alphabetically.
51+
5. The `__init__.mojo` files of parent folders import functions from their child modules explicitly, avoiding `import *` to prevent polluting the namespace.
52+
53+
Additionally, a `science` folder is created under `/numojo`. It is similar to the `routines` folder but contains sub-packages for features present in `scipy`[^science]. For example:
54+
55+
Users can access the functions either directly at the top level or via sub-packages.
56+
57+
1. Most common functions can be called from the top level, e.g., `numojo.sort()`.
58+
2. Advanced features (e.g., those listed as sub-packages in `numpy` or `scipy`) need to be called via their own namespaces. For example:
59+
- Random array generators, e.g., `numojo.random.randint()`.
60+
- Linear algebra, e.g., `numojo.linalg.solve()`.
61+
- FFT, e.g., `numojo.fft()`.
62+
- Ordinary differential equations.
63+
- Optimizers, e.g., `numojo.optimize`.
64+
65+
[^stdlib]: Standard library functions that are SIMD-compatible.
66+
[^numpy]: The structure is inspired by the organization of functions in NumPy.
67+
[^single]: If a topic has only a few functions, they can be grouped into a single Mojo file instead of creating a separate folder.
68+
[^science]: This folder can be further integrated into the `routines` folder if necessary.

0 commit comments

Comments
 (0)