Skip to content

Commit 13bc54b

Browse files
Merge pull request #155 from Mojo-Numerics-and-Algorithms-group/pre-0.4
NuMojo V0.4 Update
2 parents 2814cbe + 18d999a commit 13bc54b

File tree

101 files changed

+14975
-5536
lines changed

Some content is hidden

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

101 files changed

+14975
-5536
lines changed

.github/workflows/run_tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ jobs:
5151
- name: Run tests
5252
run: |
5353
magic install
54-
magic run mojo test tests -I .
54+
magic run mojo test tests -I .

.github/workflows/test_pre_commit.yaml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,28 @@ jobs:
2424
- name: Checkout repo
2525
uses: actions/checkout@v4
2626

27-
- name: Download Modular installer
27+
- name: Install magic
2828
run: |
29-
curl -s https://get.modular.com | sh -
29+
curl -ssL https://magic.modular.com/ff414efd-16ac-4bf3-8efc-50b059272ab6 | bash
30+
31+
- name: Add path
32+
run: |
33+
echo "MODULAR_HOME=$HOME/.modular" >> $GITHUB_ENV
34+
echo "$HOME/.modular/bin" >> $GITHUB_PATH
35+
echo "$HOME/.modular/pkg/packages.modular.com_mojo/bin" >> $GITHUB_PATH
3036
31-
- name: Set path Mojo
37+
- name: Activate virtualenv
3238
run: |
33-
modular install mojo
34-
echo "MODULAR_HOME=/home/runner/.modular" >> $GITHUB_ENV
35-
echo "/home/runner/.modular/pkg/packages.modular.com_mojo/bin" >> $GITHUB_PATH
39+
python3 -m venv $HOME/venv/
40+
. $HOME/venv/bin/activate
41+
echo PATH=$PATH >> $GITHUB_ENV
3642
3743
- name: Install pre-commit
3844
run: |
3945
pip install pre-commit
4046
pre-commit install
4147
4248
- name: Run pre-commit
43-
run: pre-commit run --all-files
49+
run: |
50+
magic install
51+
pre-commit run --all-files

.gitignore

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@
77
*.html
88
*.css
99
*.py
10-
mojo
11-
numojo.mojopkg
12-
bench.mojo
13-
test_ndarray.ipynb
14-
/venv# pixi environments
15-
.pixi
1610
*.egg-info
1711
*.pyc
1812

1913
# magic environments
2014
.magic
2115

22-
.gitattributes
23-
.gitignore
16+
# pixi environments
17+
.pixi
18+
/venv
19+
20+
# Miscellaneous files
21+
mojo
22+
numojo.mojopkg
23+
bench.mojo
24+
test_ndarray.ipynb
25+
test.mojo
26+
tempCodeRunnerFile.mojo

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ repos:
33
hooks:
44
- id: mojo-format
55
name: mojo-format
6-
entry: mojo format
6+
entry: magic run mojo format
77
language: system
88
files: '\.(mojo|🔥|py)$'
9-
stages: [commit]
9+
stages: [pre-commit]

README.MD

Lines changed: 117 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,63 +45,96 @@
4545
<li><a href="#what-numojo-is-not">What NuMojo is not</a></li>
4646
</ul>
4747
</li>
48-
<a href="#goals-roadmap">Goals/Roadmap</a>
49-
<ul>
50-
<li><a href="#long-term-goals">Long term goals</a></li>
51-
</ul>
48+
<li><a href="#goals">Goals</a></li>
5249
<li><a href="#usage">Usage</a></li>
5350
<li><a href="#how-to-install">How to install</a></li>
5451
<li><a href="#contributing">Contributing</a></li>
5552
<li><a href="#warnings">Warnings</a></li>
5653
<li><a href="#license">License</a></li>
5754
<li><a href="#acknowledgments">Acknowledgments</a></li>
55+
<li><a href="#Contributors">Contributors</a></li>
5856
</ol>
5957
</details>
6058

6159
## About the project
6260

6361
### What NuMojo is
6462

65-
NuMojo intends to capture a wide swath of numerics capability present in the Python packages NumPy, SciPy and Scikit.
63+
NuMojo intends to capture a wide swath of numerics capability present in the Python packages NumPy, SciPy, and Scikit.
6664

67-
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.
65+
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.
6866

6967
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
7068

7169
### What NuMojo is not
7270

7371
NuMojo is not a machine learning library, it will never include back-propagation in the base library.
7472

75-
## Goals / Roadmap
76-
77-
For a detailed roadmap, please refer to the [Roadmap.md](Roadmap.md) file.
78-
79-
Our main goal is to implement a fast, comprehensive numerics library in Mojo. Following are some brief long-term goals,
80-
81-
### Long term goals
82-
83-
* Linear Algebra
84-
* Native n-dimensional array types
85-
* Vectorized, Parallelized math operations
86-
* Array manipulation - vstack, slicing, concat etc.
87-
* Calculus
88-
* Integration & Derivatives etc
89-
* Optimizers
90-
* Function approximators
91-
* Sorting
73+
## Goals and features
74+
75+
Our main goal is to implement a fast, comprehensive numerics library in Mojo.
76+
77+
Following are some brief long-term goals. Some of them have already been implemented or partially implemented.
78+
79+
Core data types:
80+
81+
- Native n-dimensional array (`numojo.core.ndarray.NDArray`).
82+
- Native 2-dimensional array, i.e., matrix (`numojo.mat.matrix.Matrix`).
83+
- Native fixed-dimension array (to be implemented when trait parameterization is available).
84+
85+
Routines and objects:
86+
87+
- Array creation routines (`numojo.routines.creation`)
88+
- Array manipulation routines (`numojo.routines.manipulation`)
89+
- Bit-wise operations (`numojo.routines.bitwise`)
90+
- Constants (`numojo.routines.constants`)
91+
- Input and output (`numojo.routines.io`)
92+
- Text files (`numojo.routines.files`)
93+
- Text formatting options (`numojo.routines.formatting`)
94+
- Linear algebra (`numojo.routines.linalg`)
95+
- Decompositions (`numojo.routines.decompositions`)
96+
- Products of matrices and vectors (`numojo.routines.products`)
97+
- Solving (`numojo.routines.solving`)
98+
- Logic functions (`numojo.routines.logic`)
99+
- Comparison (`numojo.routines.comparison`)
100+
- Array contents (`numojo.routines.contents`)
101+
- Truth value testing (`numojo.routines.truth`)
102+
- Mathematical functions (`numojo.routines.math`)
103+
- Arithmetic operations (`numojo.routines.arithmetic`)
104+
- Exponents and logarithms (`numojo.routines.exponents`)
105+
- Extrema finding (`numojo.routines.extrema`)
106+
- Floating point routines (`numojo.routines.floating`)
107+
- Hyperbolic functions (`numojo.routines.hyper`)
108+
- Indexing (`numojo.routines.indexing`)
109+
- Miscellaneous (`numojo.routines.misc`)
110+
- Rounding (`numojo.routines.rounding`)
111+
- Sums, products, differences (`numojo.routines.sums`, `numojo.routines.products`, `numojo.routines.differences`)
112+
- Trigonometric functions (`numojo.routines.trig`)
113+
- Random sampling (`numojo.routines.random`)
114+
- Sorting, searching, and counting (`numojo.routines.sorting`, `numojo.routines.searching`)
115+
- Statistics (`numojo.routines.statistics`)
116+
- Averages and variances (`numojo.routines.averages`)
117+
- Calculus, Integration & Derivatives etc
118+
- Optimizers
119+
- Function approximators
120+
121+
Please find all the available functions and objects [here](docs/features.md).
122+
123+
For a detailed roadmap, please refer to the [docs/roadmap.md](docs/roadmap.md) file.
92124

93125
## Usage
94126

95-
An example goes as follows.
127+
An example of n-dimensional array (`NDArray` type) goes as follows.
96128

97129
```mojo
98130
import numojo as nm
99131
from numojo.prelude import *
100132
133+
101134
fn main() raises:
102135
# Generate two 1000x1000 matrices with random float64 values
103-
var A = nm.random.randn[f64](shape=List[Int](1000, 1000))
104-
var B = nm.random.randn[f64](shape=List[Int](1000, 1000))
136+
var A = nm.random.randn(shape=Shape(1000, 1000))
137+
var B = nm.random.randn(shape=Shape(1000, 1000))
105138
106139
# Generate a 3x2 matrix from string representation
107140
var X = nm.fromstring[f32]("[[1.1, -0.32, 1], [0.1, -3, 2.124]]")
@@ -119,10 +152,59 @@ fn main() raises:
119152
var A_slice = A[1:3, 4:19]
120153
121154
# Get scalar from array
122-
var A_item = A.item(291, 141)
155+
var A_item = A[Idx(291, 141)]
123156
```
124157

125-
Please find all the available functions [here](features.md)
158+
An example of matrix (`Matrix` type) goes as follows.
159+
160+
```mojo
161+
from numojo import mat
162+
from numojo.prelude import *
163+
164+
165+
fn main() raises:
166+
# Generate two 1000x1000 matrices with random float64 values
167+
var A = mat.rand(shape=(1000, 1000))
168+
var B = mat.rand(shape=(1000, 1000))
169+
170+
# Generate 1000x1 matrix (column vector) with random float64 values
171+
var C = mat.rand(shape=(1000, 1))
172+
173+
# Generate a 4x3 matrix from string representation
174+
var F = mat.fromstring[i8](
175+
"[[12,11,10],[9,8,7],[6,5,4],[3,2,1]]", shape=(4, 3)
176+
)
177+
178+
# Matrix slicing
179+
var A_slice = A[1:3, 4:19]
180+
var B_slice = B[255, 103:241:2]
181+
182+
# Get scalar from matrix
183+
var A_item = A[291, 141]
184+
185+
# Flip the column vector
186+
print(C[::-1, :])
187+
188+
# Sort and argsort along axis
189+
print(mat.sort(A, axis=1))
190+
print(mat.argsort(A, axis=0))
191+
192+
# Sum the matrix
193+
print(mat.sum(B))
194+
print(mat.sum(B, axis=1))
195+
196+
# Matrix multiplication
197+
print(A @ B)
198+
199+
# Matrix inversion
200+
print(A.inv())
201+
202+
# Solve linear algebra
203+
print(mat.solve(A, B))
204+
205+
# Least square
206+
print(mat.lstsq(A, C))
207+
```
126208

127209
## How to install
128210

@@ -169,4 +251,10 @@ Distributed under the Apache 2.0 License with LLVM Exceptions. See [LICENSE](htt
169251

170252
## Acknowledgements
171253

172-
* Built in native [Mojo](https://github.com/modularml/mojo) which was created by [Modular](https://github.com/modularml)
254+
Built in native [Mojo](https://github.com/modularml/mojo) which was created by [Modular](https://github.com/modularml).
255+
256+
## Contributors
257+
258+
<a href="https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/graphs/contributors">
259+
<img src="https://contrib.rocks/image?repo=Mojo-Numerics-and-Algorithms-group/NuMojo" />
260+
</a>

docs/changelog.md

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

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

5+
## 22/12/2024 (v0.4)
6+
7+
### ⭐️ New
8+
9+
- Implement a static-sized 2D Array type (`Matrix` type) in `numojo.mat` sub-package. `Matrix` is a special case of `NDArray` but has been optimized since the number of dimensions is known at the compile time. It is useful when users only want to work with 2-dimensional arrays. The indexing and slicing is also more consistent with `numpy` ([PR #138](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/138), [PR #141](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/142), [PR #141](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/142)). It provides:
10+
- `Matrix` type (2D array) with basic dunder methods and core methods.
11+
- Function to construct `Matrix` from other data objects, e.g., `List`, `NDArray`, `String`, and `numpy` array.
12+
- Arithmetic functions for item-wise calculation and broadcasting.
13+
- Linear algebra: matrix mutiplication, decomposition, inverse of matrix, solve of linear system, Ordinary Least Square, etc.
14+
- Auxilliary types, e.g., `_MatrixIter`.
15+
- Implement more the array creation routines from numpy and expand the NuMojo array creation functionality ([PR #137](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/137)).
16+
- Add `convolve2d` and in the `science.signal` module ([PR #135](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/135)).
17+
- Add more detailed error messages for `NDArray` type ([PR #140](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/140)).
18+
19+
### 🦋 Changed
20+
21+
- Adapt the code to [the latest update of Mojo to V24.6](https://docs.modular.com/mojo/changelog/) ([PR #148](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/148)).
22+
- `Slice.step` is now returning `Optional[int]`. Thus, it is fixed by using `Slice.step.else_to(1)`.
23+
- `Formattable` is now renamed to `Writable` (same applies to `write_to` and `string.write`).
24+
- `width` is now inferred from the SIMD's width. So this parameter must be removed when we call `UnSafePointer`'s `load` and `store` methods. Due to this, the function `fill_pointer`, which fill in a width of array with a scale, no longer work. It is replaced by copying with loop.
25+
- `Lifetime` is renamed as `Origin` (same applies to the function `__origin_of`).
26+
- `inout` is renamed as `mut`.
27+
- Rename the data buffer from `data` to `_buf` ([PR #136](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/136), [PR #137](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/137))
28+
- To make `matmul` flexible for different shapes of input arrays ([PR #137](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/137)).
29+
- Change the way to get the shape of the array: `array.shape` returns the shape of array as `NDArrayShape` ([PR #137](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/137)).
30+
- The array creation functions are unified in such a way ([PR #139](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/139)).
31+
- `NDAarray.__init__()` reads in shape information and initializes an empty ndarray.
32+
- All other creation routines are implemented by the functions in the `array_creation_routine` module. For example, to create an array with filled value, the function `full` should be used. To create an array from a list, the function `array` should be used.
33+
- Re-organize the functions and modules by topic, so that it is more consistent with `numpy` ([Issue 144](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/issues/144), [PR #146](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/146)).
34+
- Rename some attributes of `NDArray` and make `size` an attribute instead of a method ([PR #145](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/145)).
35+
- Completely remove `import *` in __init__ files to fix namespace leak ([PR #151](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/151)).
36+
- Update function `sum` ([PR #149](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/149)).
37+
- `transpose` now allows arbitrary dimensions and permutations of axes ([PR #152](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/152)).
38+
- Change buffer type of `NDArrayShape` and `NDArrayStrides` to `Int` ([PR #153](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/153)).
39+
- `sort` now allows sorting by any axis for high dimensional arrays ([PR #154](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/154)).
40+
41+
### ❌ Removed
42+
43+
- Temporarily removed negative indexing support in slices since it causes error. Will add just feature in later updates ([PR #133](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/133)).
44+
- Remove `inout` before `self` for `NDArray.__getitem__` ([PR #137](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/137)).
45+
46+
### 🛠️ Fixed
47+
48+
- Fixed and rewrote the `adjust_slice` function that was causing errors ([PR #133](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/133)).
49+
- There is an error in fromstring that the negative signs are not read. It is fixed. Now a valid numeric should start with a digit, a dot, or a hyhen ([PR #134](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/134)).
50+
51+
### 📚 Documentary and testing
52+
53+
- Added test for slicing in getters. Complete tests for setters will be added later. This is due to python interop limitation ([PR #133](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/133)).
54+
- Move documents from root docs. Delete unused files ([PR #147](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/147)).
55+
- Update the readme.md and features.md to reflect current progress ([PR #150](https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/pull/150)).
56+
557
## 19/10/2024 (v0.3.1)
658

759
### 🛠️ Fixed

docs/changelog_unreleased.md

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

0 commit comments

Comments
 (0)