Mojo-Numerics-and-Algorithms-group / NuMojo

NuMojo is a library for numerical computing in Mojo 🔥 similar to numpy in Python.
Apache License 2.0
112 stars 15 forks source link

[new] Add `prelude` module for better importing #119

Closed forFudan closed 1 month ago

forFudan commented 1 month ago

This idea comes from the Rust.

NuMojo comes a wide range of functions, types, and constants. If you manually import everything, it will make the header of the file too long. On the other hand, using from numojo import * would import a lot of functions that you never use and would pollute the naming space.

This module tries to find out a balance by providing a list of things that can be imported at one time. The list contains the functions or types that are the most essential for a user.

You can use the following code to import them:

from numojo.prelude import *

fn main() raises:
    var array = NDArray[i32](shape=List[Int](2, 3))
    print(array)

In this case NDArray and dtypes are automatically imported.