Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

NuMojo is a library for numerical computing in Mojo 🔥 similar to numpy in Python.

License

NotificationsYou must be signed in to change notification settings

Mojo-Numerics-and-Algorithms-group/NuMojo

Repository files navigation

logo

NuMojo is a library for numerical computing in Mojo 🔥 similar to NumPy, SciPy in Python.

Explore the docs» |Changelog» |Check out our Discord»

中文·简» |中文·繁» |日本語»

Table of Contents

  1. About The Project
  2. Goals
  3. Usage
  4. How to install
  5. Contributing
  6. Warnings
  7. License
  8. Acknowledgements
  9. Contributors

About the project

NuMojo aims to encompass the extensive numerics capabilities found in Python packages such as NumPy, SciPy, and Scikit-learn.

=======

What NuMojo is

We seek to harness the full potential of Mojo, including vectorization, parallelization, and GPU acceleration (when available). Currently, NuMojo extends most (if not all) standard library math functions to support array inputs.

Our vision for NuMojo is to serve as an essential building block for other Mojo packages needing fast math operations, without the additional weight of a machine learning back-propagation system.

What NuMojo is not

NuMojo is not a machine learning library and will never include back-propagation as part of the base library.

Features and goals

Our primary objective is to develop a fast, comprehensive numerics library in Mojo. Below are some features and long-term goals. Some have already been implemented, either fully or partially.

Core data types:

  • 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.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 objectshere.

For a detailed roadmap, please refer to thedocs/roadmap.md file.

Usage

An example of n-dimensional array (NDArray type) goes as follows.

import numojoas nmfrom numojo.preludeimport*fnmain()raises:# Generate two 1000x1000 matrices with random float64 valuesvarA= nm.random.randn(Shape(1000,1000))varB= nm.random.randn(Shape(1000,1000))# Generate a 3x2 matrix from string representationvarX= nm.fromstring[f32]("[[1.1, -0.32, 1], [0.1, -3, 2.124]]")# Print arrayprint(A)# Array multiplicationvarC= A@ B# Array inversionvarI= nm.inv(A)# Array slicingvarA_slice= A[1:3,4:19]# Get scalar from arrayvarA_item= A[item(291,141)]varA_item_2= A.item(291,141)

An example of matrix (Matrix type) goes as follows.

from numojoimport Matrixfrom numojo.preludeimport*fnmain()raises:# Generate two 1000x1000 matrices with random float64 valuesvarA= Matrix.rand(shape=(1000,1000))varB= Matrix.rand(shape=(1000,1000))# Generate 1000x1 matrix (column vector) with random float64 valuesvarC= Matrix.rand(shape=(1000,1))# Generate a 4x3 matrix from string representationvarF= Matrix.fromstring[i8]("[[12,11,10],[9,8,7],[6,5,4],[3,2,1]]",shape=(4,3)    )# Matrix slicingvarA_slice= A[1:3,4:19]varB_slice= B[255,103:241:2]# Get scalar from matrixvarA_item= A[291,141]# Flip the column vectorprint(C[::-1, :])# Sort and argsort along axisprint(nm.sort(A,axis=1))print(nm.argsort(A,axis=0))# Sum the matrixprint(nm.sum(B))print(nm.sum(B,axis=1))# Matrix multiplicationprint(A@ B)# Matrix inversionprint(A.inv())# Solve linear algebraprint(nm.solve(A, B))# Least squareprint(nm.lstsq(A, C))

An example of ComplexNDArray is as follows,

import numojoas nmfrom numojo.preludeimport*fnmain()raises:# Create a complexscalar 5 + 5jvarcomplexscalar= ComplexSIMD[f32](re=5,im=5)# Create complex array filled with (5 + 5j)varA= nm.full[f32](Shape(1000,1000),fill_value=complexscalar)# Create complex array filled with (1 + 1j)varB= nm.ones[f32](Shape(1000,1000))# Print arrayprint(A)# Array slicingvarA_slice= A[1:3,4:19]# Array multiplicationvarC= A* B# Get scalar from arrayvarA_item= A[item(291,141)]# Set an element of the array    A[item(291,141)]= complexscalar

How to install

There are three approach to install and use the Numojo package.

Addnumojo inpixi.toml

You can add the packagenumojo of a specific version in the dependencies section of your toml file.

[dependencies]numojo ="=0.7.0"

Then, you can runpixi install to install the package.

The following table shows the version ofnumojo and the corresponding version ofmojo that is required.

numojomojo
v0.7.0==25.3
v0.6.1==25.2
v0.6.0==25.2

Build package

This approach involves building a standalone package filemojopkg.

  1. Clone the repository.
  2. Build the package usingpixi run package.
  3. Move thenumojo.mojopkg into the directory containing the your code.

Include NuMojo's path for compiler and LSP

This approach does not require building a package file. Instead, when you compile your code, you can include the path of NuMojo repository with the following command:

mojo run -I "../NuMojo" example.mojo

This is more flexible as you are able to edit the NuMojo source files when testing your code.

In order to allow VSCode LSP to resolve the importednumojo package, you can:

  1. Go to preference page of VSCode.
  2. Go toMojo › Lsp: Include Dirs
  3. Clickadd item and write the path where the Numojo repository is located, e.g./Users/Name/Programs/NuMojo.
  4. Restart the Mojo LSP server.

Now VSCode can show function hints for the Numojo package!

Contributing

Any contributions you make aregreatly appreciated. For more details and guidelines on contributions, please checkhere

Warnings

This library is still very much a work in progress and may change at any time.

License

Distributed under the Apache 2.0 License with LLVM Exceptions. SeeLICENSE and the LLVMLicense for more information.

This project includes code fromMojo Standard Library, licensed under the Apache License v2.0 with LLVM Exceptions (see the LLVMLicense). MAX and Mojo usage and distribution are licensed under theMAX & Mojo Community License.

Acknowledgements

Built in nativeMojo which was created byModular.

Contributors

About

NuMojo is a library for numerical computing in Mojo 🔥 similar to numpy in Python.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp