Skip to content

Commit 2cca3f1

Browse files
authored
Merge pull request #125 from Mojo-Numerics-and-Algorithms-group/experimental
V0.3 Update
2 parents 4ecaf8b + 655d03a commit 2cca3f1

Some content is hidden

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

57 files changed

+7756
-2684
lines changed

.github/workflows/run_tests.yaml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
os: ["ubuntu-latest", "macos-14"]
16+
os: ["ubuntu-22.04", "macos-14"]
1717

1818
runs-on: ${{ matrix.os }}
1919
timeout-minutes: 30
@@ -28,26 +28,27 @@ jobs:
2828
- name: Checkout repo
2929
uses: actions/checkout@v4
3030

31-
- name: Download Modular installer
31+
- name: Install magic
3232
run: |
33-
curl -s https://get.modular.com | sh -
33+
curl -ssL https://magic.modular.com/ff414efd-16ac-4bf3-8efc-50b059272ab6 | bash
34+
35+
- name: Add path
36+
run: |
37+
echo "MODULAR_HOME=$HOME/.modular" >> $GITHUB_ENV
38+
echo "$HOME/.modular/bin" >> $GITHUB_PATH
39+
echo "$HOME/.modular/pkg/packages.modular.com_mojo/bin" >> $GITHUB_PATH
3440
3541
- name: Activate virtualenv
3642
run: |
3743
python3 -m venv $HOME/venv/
3844
. $HOME/venv/bin/activate
3945
echo PATH=$PATH >> $GITHUB_ENV
4046
41-
- name: Install Mojo
47+
- name: Install packages
4248
run: |
43-
modular install mojo
44-
45-
- name: Set path Mojo
46-
run: |
47-
echo "MODULAR_HOME=$HOME/.modular" >> $GITHUB_ENV
48-
echo "$HOME/.modular/pkg/packages.modular.com_mojo/bin" >> $GITHUB_PATH
49+
pip install "numpy"
4950
5051
- name: Run tests
5152
run: |
52-
pip install "numpy<2.0"
53-
mojo test tests -I .
53+
magic install
54+
magic run mojo test tests -I .

.github/workflows/test_pre_commit.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ permissions:
1111

1212
jobs:
1313
lint:
14-
runs-on: "ubuntu-latest"
14+
runs-on: "ubuntu-22.04"
1515
timeout-minutes: 30
1616

1717
defaults:

.gitignore

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@
99
*.py
1010
mojo
1111
numojo.mojopkg
12-
.gitignore
1312
bench.mojo
1413
test_ndarray.ipynb
15-
/venv
14+
/venv# pixi environments
15+
.pixi
16+
*.egg-info
17+
*.pyc
18+
19+
# magic environments
20+
.magic
21+
22+
.gitattributes
23+
.gitignore

CONTRIBUTING.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Please follow the Mojo standard library style guide for all contributions. Consi
1010
- Write concise, well-documented code.
1111
- Adhere to formatting conventions for indentation, spacing, and line breaks.
1212

13-
Additionally refer to `style guide.md` for docstring and nameing conventions.
13+
Additionally refer to `style guide.md` for docstring and naming conventions.
1414

1515
## Pull Requests
1616

@@ -50,16 +50,20 @@ Following this structure ensures that similar functionalities are grouped togeth
5050
```
5151

5252
4. **Make Your Changes**: Implement your changes in your branch.
53-
5. **Commit Your Changes**: Commit your changes with a clear and descriptive commit message.
53+
5. **Run Tests**: NuMojo now uses the `Magic` package manager by Modular. To ensure that all unit tests pass, the NuMojo module packages correctly, and the .mojo files are properly formatted, run the following command:
54+
```sh
55+
magic run final
56+
```
57+
6. **Commit Your Changes**: Commit your changes with a clear and descriptive commit message.
5458

5559
```sh
5660
git commit -m "Add feature XYZ"
5761
```
5862

59-
6. **Push Your Changes**: Push your branch to your fork on GitHub.
63+
7. **Push Your Changes**: Push your branch to your fork on GitHub.
6064

6165
```sh
6266
git push origin feature-name
6367
```
6468

65-
7. **Submit a Pull Request**: Open a pull request to the `main` branch of the original repository.
69+
8. **Submit a Pull Request**: Open a pull request to the `main` branch of the original repository.

README.MD

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,19 @@
1313
NuMojo is a library for numerical computing in Mojo 🔥 similar to NumPy, SciPy in Python.
1414
<br />
1515
<!-- when we create docs -->
16-
<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>
17-
<br>
18-
<a href="https://discord.com/channels/1149778565756366939/1149778566603620455"><strong>Check out our Discord» </strong></a>
16+
<div style="font-family: 'Arial'; border: 1px solid black; padding: 5px;">
17+
<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;
18+
<a href="./docs/changelog.md"><strong>Changelog» </strong></a> &nbsp; &nbsp;
19+
<a href="https://discord.com/channels/1149778565756366939/1149778566603620455" ><strong>Check out our Discord» </strong></a>
20+
</div>
1921
<br />
22+
<div style="font-family: 'Arial'; border: 1px solid black; padding: 5px;">
23+
<a href="./docs/readme_zhs.md"><strong>中文·简» </strong></a> &nbsp;
24+
<a href="./docs/readme_zht.md"><strong>中文·繁» </strong></a> &nbsp;
25+
<a href="./docs/readme_jp.md"><strong>日本語» </strong></a>
26+
</div>
27+
<!-- <a href="./docs/readme_kr.md"><strong>한국어 문서» </strong></a> -->
28+
<!-- <br /> -->
2029
<!-- <br /> -->
2130
<!-- <a href="">View Demo</a>
2231
·
@@ -55,10 +64,9 @@
5564

5665
NuMojo intends to capture a wide swath of numerics capability present in the Python packages NumPy, SciPy and Scikit.
5766

58-
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.
5967
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.
6068

61-
NuMojo intends 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
69+
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
6270

6371
### What NuMojo is not
6472

@@ -88,14 +96,30 @@ An example goes as follows.
8896

8997
```mojo
9098
import numojo as nm
99+
from numojo.prelude import *
91100
92101
fn main() raises:
93102
# Generate two 1000x1000 matrices with random float64 values
94-
var A = nm.NDArray[nm.f64](shape=List[Int](1000,1000), random=True)
95-
var B = nm.NDArray[nm.f64](1000,1000, random=True)
103+
var A = nm.random.randn[f64](shape=List[Int](1000, 1000))
104+
var B = nm.random.randn[f64](shape=List[Int](1000, 1000))
105+
106+
# Generate a 3x2 matrix from string representation
107+
var X = nm.fromstring[f32]("[[1.1, -0.32, 1], [0.1, -3, 2.124]]")
108+
109+
# Print array
110+
print(A)
111+
112+
# Array multiplication
113+
var C = A @ B
114+
115+
# Array inversion
116+
var I = nm.inv(A)
117+
118+
# Array slicing
119+
var A_slice = A[1:3, 4:19]
96120
97-
# Print AB
98-
print(nm.linalg.matmul_parallelized(A, B))
121+
# Get scalar from array
122+
var A_item = A.item(291, 141)
99123
```
100124

101125
Please find all the available functions [here](features.md)
@@ -109,10 +133,10 @@ There are two approach to install and use the Numojo package.
109133
This approach invovles building a standalone package file `mojopkg`.
110134

111135
1. Clone the repository.
112-
1. Build the package using `mojo pacakge numojo`
113-
1. Move the numojo.mojopkg into the directory containing the your code.
136+
2. Build the package using `mojo package numojo`
137+
3. Move the numojo.mojopkg into the directory containing the your code.
114138

115-
### Inlcude NuMojo's path for compiler and LSP
139+
### Include NuMojo's path for compiler and LSP
116140

117141
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:
118142

@@ -125,11 +149,11 @@ This is more flexible as you are able to edit the NuMojo source files when testi
125149
In order to allow VSCode LSP to resolve the imported `numojo` package, you can:
126150

127151
1. Go to preference page of VSCode.
128-
1. Got to `Mojo › Lsp: Include Dirs`
129-
1. Click `add item` and write the path where the Numojo repository is located, e.g. `/Users/Name/Programs/NuMojo`.
130-
1. Restart the Mojo LSP server.
152+
2. Go to `Mojo › Lsp: Include Dirs`
153+
3. Click `add item` and write the path where the Numojo repository is located, e.g. `/Users/Name/Programs/NuMojo`.
154+
4. Restart the Mojo LSP server.
131155

132-
Now VSCode can show function hints for the Numojo pakcage!
156+
Now VSCode can show function hints for the Numojo package!
133157

134158
## Contributing
135159

docs/changelog.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# NuMojo released changelog
2+
3+
This is a list of RELEASED changes for the NuMojo Package.
4+
5+
## 14/10/2024 (v0.3)
6+
7+
### ⭐️ New
8+
9+
- Add support for `magic` system and MAX 24.5 (PR #91 #109 by @shivasankarka).
10+
- Add some basic functions, e.g., `diagflat`, `tri`, `trace`, `T` (PR #91 by @shivasankarka).
11+
- Add a constructor which reads arrays from numpy arrays (PR #91 by @shivasankarka).
12+
- Add functions `solve` and `inv` for solving linear algebra `AX = Y` for `X`, finding inverse of a matrix, and conducting LU decomposition (PR #101 #104 #105 by @forFudan).
13+
- Add `itemset` method to fill a scalar into an `NDArray` (PR #102 by @forFudan).
14+
- Add `Idx` struct to represent the index of an `NDArray` (PR #118 by @shivasankarka).
15+
- Add NDArray initialization from numpy arrays (PR #118 by @shivasankarka).
16+
- Created a new `io` module with some basic functions, e.g., `format_float_scientific`, `loadtxt`, `savetxt` (PR #118 by @shivasankarka).
17+
18+
### 🦋 Changed
19+
20+
- Make some methods, e.g., `sort`, `flatten`, `inplace` (Issue #87 by @mmenendezg, PR #91 by @shivasankarka).
21+
- Modify initialization of NDArray (PR #97 by @MadAlex1997)
22+
- Added `Formattable` trait and fixed the `print` function (PR #108 by @shivasankarka)
23+
- Refine the `NDArray` initializers and array creation routines (Discussion #90, Issue #110).
24+
- Remove `random` argument from `NDArray` constructors. Make random initializer a standalone functions (Issue #96 by @MadAlex1997, PR #97 by @MadAlex1997, PR #98 by @shivasankarka).
25+
- Remove initializers from `String`. Make `fromstring` a standalone function (#113 by @forFudan).
26+
- Add several `array` overloads for initializing `NDArray` (PR #118 by @shivasankarka).
27+
- Modify the behavior of `__get__` and `__set__`. Passing in a sequence of `Int` or `Slice` returns an `NDArray`. Passing in an `Idx` returns a scalar. Allow users to set a multiple items in one `NDArray` with another `NDArray`, using `__set__` (PR #118 by @shivasankarka, Discussion #70).
28+
29+
### ❌ Removed
30+
31+
- Removed all instances of getters and setters with `List[Int]`, `VariadicList[Int]` (PR #118 by @shivasankarka).
32+
33+
### 🛠️ Fixed
34+
35+
- Fix the issues in parallelization (due to Max 24.5) for some linear algebra functions, e.g, `matmul`, `solve`, `inv`, etc (PR #115 #117 by @forFudan).
36+
37+
### 📚 Documentary and testing
38+
39+
- Add workflows with unit tests and linting (PR #95 by @sandstromviktor).
40+
- Add multi-lingual support (Chinese, Japanese) for the readme file (PR #99 #120 by @forFudan, PR #100 by @shivasankarka).
41+
- Update the test flow file to accommodate MAX 24.5 and the `magic` system (PR #116 by @forFudan).
42+
43+
## 17/08/2024 (V0.2)
44+
45+
### ⭐️ New
46+
47+
Array operations:
48+
49+
- Introduced `diagflat()` method for creating diagonal arrays
50+
- Implemented most basic array creation routines
51+
- Implemented initializer from string `numojo.NDArray("[[1,2,3],[4,5,6]]")`
52+
- Enhanced `NDArray` constructor methods
53+
- Added boolean masking for NDArrays
54+
- Introduced new mathematical methods: `floordiv`, `mod`, and more
55+
- `__getitem__` and `__setitem__` now fully compatible with NumPy behavior
56+
57+
Others:
58+
59+
- Introduced Rust-like data type aliases (e.g., `DType.float64``f64`)
60+
- Implemented function overloading for core mathematical operations (add, sub, etc.)
61+
- Added a new differentiation module
62+
63+
### 🦋 Changed
64+
65+
- Improved slicing functionality to match NumPy behavior
66+
67+
### ❌ Removed
68+
69+
- Removed `in_dtype` and `out_dtype` parameters for simplified type handling
70+
71+
### 📚 Documentatory and testing
72+
73+
Documentation updates:
74+
75+
- Expanded and updated README
76+
- Improved docstrings for functions
77+
- Added style guide and examples
78+
79+
Testing updates:
80+
81+
- Introduced new test files that are compatible with `mojo test`.

docs/changelog_unreleased.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# NuMojo UNRELEASED changelog
2+
3+
This is a list of UNRELEASED changes (not yet merged to the nightly branch) for the NuMojo Package.
4+
5+
When a PR is merged to the nightly branch, the items in this file will be moved to `changelog.md`.
6+
7+
## dd/mm/yyyy (v0.3)
8+
9+
### ⭐️ New
10+
11+
### 🦋 Changed
12+
13+
### ❌ Removed
14+
15+
### 🛠️ Fixed
16+
17+
### 📚 Documentary and testing

0 commit comments

Comments
 (0)