Skip to content

Commit

Permalink
Merge branch 'experimental' into inverse
Browse files Browse the repository at this point in the history
  • Loading branch information
forFudan authored Sep 9, 2024
2 parents 6ccc532 + 504b9dd commit 1e6b598
Show file tree
Hide file tree
Showing 28 changed files with 2,400 additions and 557 deletions.
11 changes: 9 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
*.py
mojo
numojo.mojopkg
.gitignore
bench.mojo
test_ndarray.ipynb
/venv
/venv# pixi environments
.pixi
*.egg-info

# magic environments
.magic

.gitattributes
.gitignore
12 changes: 8 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Please follow the Mojo standard library style guide for all contributions. Consi
- Write concise, well-documented code.
- Adhere to formatting conventions for indentation, spacing, and line breaks.

Additionally refer to `style guide.md` for docstring and nameing conventions.
Additionally refer to `style guide.md` for docstring and naming conventions.

## Pull Requests

Expand Down Expand Up @@ -50,16 +50,20 @@ Following this structure ensures that similar functionalities are grouped togeth
```

4. **Make Your Changes**: Implement your changes in your branch.
5. **Commit Your Changes**: Commit your changes with a clear and descriptive commit message.
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:
```sh
magic run final
```
6. **Commit Your Changes**: Commit your changes with a clear and descriptive commit message.

```sh
git commit -m "Add feature XYZ"
```

6. **Push Your Changes**: Push your branch to your fork on GitHub.
7. **Push Your Changes**: Push your branch to your fork on GitHub.

```sh
git push origin feature-name
```

7. **Submit a Pull Request**: Open a pull request to the `main` branch of the original repository.
8. **Submit a Pull Request**: Open a pull request to the `main` branch of the original repository.
1,583 changes: 1,583 additions & 0 deletions magic.lock

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions mojoproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[project]
name = "NuMojo"
version = "0.2.0"
description = "NuMojo is a library for numerical computing written in Mojo 🔥"
authors = [
"Shivasankar <shivasankar.ka@gmail.com>",
"MadAlex1997 <>",
"Yuhao Zhu <>",
"mmenendezg <>",
"sandstromviktor <>",
]
channels = ["conda-forge", "https://conda.modular.com/max"]
platforms = ["osx-arm64", "linux-64"]
license = "Apache-2.0"
readme = "README.md"

[tasks]
# test whether tests pass and the package can be built
test = " magic run mojo test tests -I ./ && magic run mojo package numojo"
# runs all final checks before a commit
final = "magic run mojo test tests -I ./ && magic run mojo format ./ && magic run mojo package numojo"
# defaults tasks
package = "magic run mojo package numojo"
format = "magic run mojo format ./"

[dependencies]
max = ">=24.4.0,<25"
39 changes: 20 additions & 19 deletions numojo/core/_array_funcs.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ fn math_func_1_array_in_one_array_out[
A new NDArray that is the result of applying the function to the NDArray.
"""
var result_array: NDArray[dtype] = NDArray[dtype](array.shape())
alias opt_nelts = simdwidthof[dtype]()
alias width = simdwidthof[dtype]()

@parameter
fn closure[simdwidth: Int](i: Int):
var simd_data = array.load[width=opt_nelts](i)
result_array.store[width=opt_nelts](
i, func[dtype, opt_nelts](simd_data)
fn closure[simd_width: Int](i: Int):
var simd_data = array.load[width=simd_width](i)
result_array.store[width=simd_width](
i, func[dtype, simd_width](simd_data)
)

vectorize[closure, opt_nelts](array.num_elements())
vectorize[closure, width](array.num_elements())

return result_array

Expand Down Expand Up @@ -69,17 +69,18 @@ fn math_func_2_array_in_one_array_out[
raise Error("Shape Mismatch error shapes must match for this function")

var result_array: NDArray[dtype] = NDArray[dtype](array1.shape())
alias opt_nelts = simdwidthof[dtype]()
alias width = simdwidthof[dtype]()

@parameter
fn closure[simdwidth: Int](i: Int):
var simd_data1 = array1.load[width=opt_nelts](i)
var simd_data2 = array2.load[width=opt_nelts](i)
result_array.store[width=opt_nelts](
i, func[dtype, opt_nelts](simd_data1, simd_data2)
fn closure[simd_width: Int](i: Int):
var simd_data1 = array1.load[width=simd_width](i)
var simd_data2 = array2.load[width=simd_width](i)
result_array.store[width=simd_width](
i, func[dtype, simd_width](simd_data1, simd_data2)
)

vectorize[closure, opt_nelts](result_array.num_elements())
vectorize[closure, width](result_array.num_elements())

return result_array


Expand All @@ -105,14 +106,14 @@ fn math_func_one_array_one_SIMD_in_one_array_out[
"""

var result_array: NDArray[dtype] = NDArray[dtype](array.shape())
alias opt_nelts = simdwidthof[dtype]()
alias width = simdwidthof[dtype]()

@parameter
fn closure[simdwidth: Int](i: Int):
var simd_data1 = array.load[width=opt_nelts](i)
result_array.store[width=opt_nelts](
i, func[dtype, opt_nelts](simd_data1, scalar)
fn closure[simd_width: Int](i: Int):
var simd_data1 = array.load[width=simd_width](i)
result_array.store[width=simd_width](
i, func[dtype, simd_width](simd_data1, scalar)
)

vectorize[closure, opt_nelts](result_array.num_elements())
vectorize[closure, width](result_array.num_elements())
return result_array
Loading

0 comments on commit 1e6b598

Please sign in to comment.