Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
539af95
[routine][random] Update the random module + unify behaviors + add `r…
forfudan Jan 28, 2025
75fb2a5
[routine][statistics] Update the `statistics` module + add `returned_…
forfudan Jan 29, 2025
f05de8c
[manipulation routines] Implement` broadcast_to()` for `NDArray` (#202)
forfudan Feb 2, 2025
e73ed6e
[shape][safe] Add boundary checks for values of `NDArrayShape` + bett…
forfudan Feb 2, 2025
509d3c5
[strides][safe] Add boundary checks for values of `NDArrayStrides` + …
forfudan Feb 2, 2025
830d16b
[statistics] Allow calculating variance and std of an array by axis (…
forfudan Feb 4, 2025
15b01cb
[ndarray][doc] Improve behaviors of 0darray + more docstring (#209)
forfudan Feb 8, 2025
c6ad872
[doc] Update the Roadmap document + other cleansing (#208)
forfudan Feb 8, 2025
718d748
[core][flags] Add `Flags` type for storing information on memory layo…
forfudan Feb 13, 2025
756740a
[mojo] Update the code to accommodate to Mojo v25.1 (#211)
forfudan Feb 13, 2025
68b5595
[ndarray] Add `NDAxisIter` struct and `iter_by_axis` method that iter…
forfudan Feb 15, 2025
8b38e67
[routines][generic] Add functionality to allow functions on 1-d array…
forfudan Feb 16, 2025
e40a29f
[sorting][core] Refine `argsort`, `sort`, `ravel`, and `_NDAxisIter` …
forfudan Feb 17, 2025
a1295ea
[core][print] Significantly increase the speed of printing arrays (#215)
forfudan Feb 17, 2025
148db64
[extrema][optimize] Update `max` and `min` functions to allow any ord…
forfudan Feb 17, 2025
811a100
[diagonal][sort] Add `diagonal` function + fix `NDArray.sort()` metho…
forfudan Feb 18, 2025
792a038
[routines] Finalize `apply_along _axis()` and place it in a dedicated…
forfudan Feb 18, 2025
bc007ba
[routine] Add `compress()` function + allow `NDArrayIter` by any axi…
forfudan Feb 18, 2025
f390de3
[routines] Implement `clip()` function (#220)
forfudan Feb 20, 2025
c552c80
[doc][core][ndarray] Update Doctoring format & errors for `NDArray` (…
shivasankarka Feb 20, 2025
f85df10
[core] Improve `NDIter` to allow arbitrary axis to travel (#221)
forfudan Feb 25, 2025
a07e867
[doc][changelog] Change log for the release v0.6 (#201)
forfudan Feb 27, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/run_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

- name: Install magic
run: |
curl -ssL https://magic.modular.com/ff414efd-16ac-4bf3-8efc-50b059272ab6 | bash
curl -ssL https://magic.modular.com/deb181c4-455c-4abe-a263-afcff49ccf67 | bash

- name: Add path
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_pre_commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

- name: Install magic
run: |
curl -ssL https://magic.modular.com/ff414efd-16ac-4bf3-8efc-50b059272ab6 | bash
curl -ssL https://magic.modular.com/deb181c4-455c-4abe-a263-afcff49ccf67 | bash

- name: Add path
run: |
Expand Down
14 changes: 8 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# magic environments
.magic
magic.lock

# pixi environments
.pixi
Expand All @@ -26,11 +27,12 @@

# Miscellaneous files
mojo
numojo.mojopkg
bench.mojo
test_ndarray.ipynb
test.mojo
tempCodeRunnerFile.mojo
/numojo.mojopkg
/bench.mojo
/test*.mojo
/test*.ipynb
/tempCodeRunnerFile.mojo

# Auto docs
docs/readthedocs/docs.json
docs/readthedocs/docs.json
docs.json
26 changes: 0 additions & 26 deletions .readthedocs.yaml

This file was deleted.

36 changes: 19 additions & 17 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ NuMojo is a library for numerical computing in Mojo 🔥 similar to NumPy, SciPy

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

**[中文·简»](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)**

**Table of Contents**

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

Core data types:

- Native n-dimensional array (`numojo.core.ndarray.NDArray`).
- Native 2-dimensional array, i.e., matrix (`numojo.core.matrix.Matrix`).
- Native n-dimensional complex array (`numojo.core.complex_ndarray.ComplexNDArray`)
- Native n-dimensional array (`numojo.NDArray`).
- Native 2-dimensional array, i.e., matrix (`numojo.Matrix`).
- Native n-dimensional complex array (`numojo.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`)
- Input and output (`numojo.routines.io`)
- Linear algebra (`numojo.routines.linalg`)
- Logic functions (`numojo.routines.logic`)
- Mathematical functions (`numojo.routines.math`)
- Exponents and logarithms (`numojo.routines.exponents`)
- Extrema finding (`numojo.routines.extrema`)
- Rounding (`numojo.routines.rounding`)
- Trigonometric functions (`numojo.routines.trig`)
- Random sampling (`numojo.routines.random`)
- Sorting, searching, and counting (`numojo.routines.sorting`, `numojo.routines.searching`)
- Statistics (`numojo.routines.statistics`)
- Array creation routines (`numojo.creation`)
- Array manipulation routines (`numojo.manipulation`)
- Input and output (`numojo.io`)
- Linear algebra (`numojo.linalg`)
- Logic functions (`numojo.logic`)
- Mathematical functions (`numojo.math`)
- Exponents and logarithms (`numojo.exponents`)
- Extrema finding (`numojo.extrema`)
- Rounding (`numojo.rounding`)
- Trigonometric functions (`numojo.trig`)
- Random sampling (`numojo.random`)
- Sorting and searching (`numojo.sorting`, `numojo.searching`)
- Statistics (`numojo.statistics`)
- etc...

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

```toml
[dependencies]
numojo = "==0.5"
numojo = "=0.6"
```

### Build package
Expand Down
55 changes: 55 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,61 @@

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

## 28/02/2025 (v0.6)

### ⭐️ New

- 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)).
- 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)).
- Implement the `diagonal()` function and the `NDArray.diagonal()` method ([PR #217](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/217)).
- Implement the `compress()` function and the `NDArray.compress()` method ([PR #219](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/219)).
- Implement the `clip()` function and the `NDArray.clip()` method ([PR #220](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/220)).
- 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)).
- 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)).
- 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)).
- 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)).
- 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)).

### 🦋 Changed

- Update the syntax to accommodate to Mojo 25.1 ([PR #211](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/211)).
- Change constructors, e.g., `str()` to `String()`.
- Change `index()` function to `Int()`.
- Change the function `isdigit()` to method.
- Stop using `NDArray.__init__()` to construct arrays but `NDArray()`.
- Update functions in the `random` module:
- Add `randint()`, and accept `Shape` as the first argument ([PR #199](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/199)).
- Update functions in the `statistics` module:
- Add the parameter `returned_dtype` to functions which defaults to `f64` ([PR #200](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/200)).
- 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)).
- Allow `median()` and `mode()` functions to work on any axis.
- Update functions in the `sorting` module:
- 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)).
- 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)).
- Update function in the `math.extrema` module ([PR #216](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/216)):
- Allow the `max()` and `min()` functions to work on any axis.
- Update the `max()` and `min()` methods for the `NDArray` type.
- 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)).
- 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)).
- Significantly increase the speed of printing large arrays ([PR #215](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/215)).
- 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)).

### ❌ Removed

- Remove the `cumvariance`, `cumstd`, `cumpvariance`, `cumpstd` functions ([PR #200](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/200)).
- Remove the `maxT()` and `minT()` functions ([PR #216](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/216)).

### 🛠️ Fixed

- 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)).
- 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)).
- Fix the `NDArray.__bool__()` method which may returns incorrect results ([PR #219](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/219)).

### 📚 Documentatory and testing

- 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)).
- Updates the roadmap document according to our current progress ([PR #208](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/208)).

## 26/01/2025 (v0.5)

### ⭐️ New
Expand Down
18 changes: 11 additions & 7 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Available functions and objects by topics (also see imports within `__init__` fi
- Array manipulation routines (`numojo.routines.manipulation`)
- Bit-wise operations (`numojo.routines.bitwise`)
- Constants (`numojo.routines.constants`)
- Indexing routines (`numojo.routines.indexing`)
- Input and output (`numojo.routines.io`)
- Text files (`numojo.routines.files`)
- Text formatting options (`numojo.routines.formatting`)
Expand All @@ -20,7 +21,13 @@ Available functions and objects by topics (also see imports within `__init__` fi
- Array contents (`numojo.routines.contents`)
- Truth value testing (`numojo.routines.truth`)
- Mathematical functions (`numojo.routines.math`)
- Extrema: maxT, minT
- Sums (`numojo.routines.sums`)
- `sum()`
- Products (`numojo.routines.products`)
- `prod()`
- Differences (`numojo.routines.differences`)
- Extrema (`numojo.routines.math.extrema`)
- `max()`, `min()`
- Trigonometry: acos, asin, atan, cos, sin, tan, atan2, hypot
- Hyperbolic: acosh, asinh, atanh, cosh, sinh, tanh
- Floating: copysign
Expand All @@ -35,17 +42,14 @@ Available functions and objects by topics (also see imports within `__init__` fi
- Indexing (`numojo.routines.indexing`)
- Miscellaneous (`numojo.routines.misc`)
- Rounding (`numojo.routines.rounding`)
- Sums, products, differences (`numojo.routines.sums`, `numojo.routines.products`, `numojo.routines.differences`)
- sum, prod
- Trigonometric functions (`numojo.routines.trig`)
- Random sampling (`numojo.routines.random`)
- Sorting, searching, and counting (`numojo.routines.sorting`, `numojo.routines.searching`)
- Statistics (`numojo.routines.statistics`)
- mean, mode, median
- variance
- Averages and variances (`numojo.routines.averages`)
- Averages and variances (`numojo.routines.averages`)
- `mean()`, `mode()`, `median()`
- `variance()`, `std()`

To-be-implemented functions and objects by topics:

- Mathematical functions: abs, floor, ceil, trunc, round, roundeven, round_half_down, round_half_up, reciprocal, nextafter, remainder
- Statistical functions: pvariance, pstdev, std
80 changes: 59 additions & 21 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,68 @@
# ROADMAP
# Roadmap

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.
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:

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.
- Align with the design philosophy of the Mojo programming language.
- Significantly enhance performance, such as through the use of generics.
- Improve consistency in conventions, such as naming parameters and arguments.

## TASKS
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.

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

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

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.
### N-dimensional Arrays

Which means that we will be trying to add many of the features from numpy.array that array currently lacks, while not sacrificing performance.
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`.

## Notional organization of functions and features
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.

* Most common functions at top level like in numpy (trig, basic stats, masking, querying, and mapping)
* Other features should be organized either by type of math or intended utilization
* Statistics probably merits its own sub module
* Regression could either be a submodule of statistics or its own module
* kernel density estimators almost certainly should be part of the statistics sub module
* 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
* An Ordinary differential equations submodule would include solvers and utilities
* The optimizer sub module could mirror scipy.optimize but minimally should include all of those functions
* There will need to be discussions and bike shedding about both organization of the library and what does and doesn't belong.
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.

### Implement Basic Numeric Functions

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.

### Implement Advanced Functions

We also aim to implement advanced functions into NuMojo. The scope is similar to `scipy`.

## Internal Organization of Objects and Functions

NuMojo organizes modules internally according to the following structure[^numpy]:

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.
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:
- `/creation` (Array creation routines)
- `/logic` (Logic functions)
- `/mathematics` (Mathematical functions)
- ...
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):
- `trig.mojo` (Trigonometric functions)
- `hyperbolic.mojo` (Hyperbolic functions)
- `exp_log.mojo` (Exponents and logarithms)
- `other.mojo` (Other special functions)
- `arithmetic.mojo` (Arithmetic operations)
- ...
4. In each file, functions are sorted alphabetically.
5. The `__init__.mojo` files of parent folders import functions from their child modules explicitly, avoiding `import *` to prevent polluting the namespace.

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:

Users can access the functions either directly at the top level or via sub-packages.

1. Most common functions can be called from the top level, e.g., `numojo.sort()`.
2. Advanced features (e.g., those listed as sub-packages in `numpy` or `scipy`) need to be called via their own namespaces. For example:
- Random array generators, e.g., `numojo.random.randint()`.
- Linear algebra, e.g., `numojo.linalg.solve()`.
- FFT, e.g., `numojo.fft()`.
- Ordinary differential equations.
- Optimizers, e.g., `numojo.optimize`.

[^stdlib]: Standard library functions that are SIMD-compatible.
[^numpy]: The structure is inspired by the organization of functions in NumPy.
[^single]: If a topic has only a few functions, they can be grouped into a single Mojo file instead of creating a separate folder.
[^science]: This folder can be further integrated into the `routines` folder if necessary.
Loading