Modular

M

Modular

This server is the home of the MAX and Mojo community. Join us to chat about all things Modular.

Join

questions

community-showcase

State of Mojo on WASM?

What are the plans for porting Mojo to WASM? When can we expect it? Wanna make a Mojo based Framework for making Webapps which targets WASM....

Most efficient way to check for tictactoe board win

I want to write a litle tictactoe game (with arbitrary board size) in Mojo and was thinking how to go the hardest on optimizing it (just for fun). I was thinking of using a SIMD to hold the board where 0 is empty, 1 is player X and 2 is player O. Then i can check for a full board like: ```...

Error running https://builds.modular.com/builds/llama3/python example

Hi I am trying out one of the examples per https://builds.modular.com/builds/llama3/python. I followed all the instructions on the page and in addition after CD ing into the pipelines/python folder I ran the "magic shell" to activate the environment. However I am stuck with the following error: None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used. ... ValueError: cannot reshape array of size 12679776 into shape (4096,11760)...

TorchInputSpec

@kapa.ai where can i find TorchInputSpec

anyone know why I might be this error about TorchInputSpec:

use of unknown declaration 'TorchInputSpec'mojo from: var session = engine.InferenceSession() var model = session.load( model_path, input_specs = [...

Posix compliant Mojo Shell?

Will Mojo have a shell like Python? If yes will it be Posix compliant? I was wondering if I can replace Bash or Zsh or Powershell on my computer with Mojo's speedy shell? It would be amazing if that's the case....

Compiling a dynamic/static library

Hi! Is there a way to compile a mojo file into a static or dynamic library to be linked to a c++ project? I see this thread from a while ago https://github.com/modularml/mojo/discussions/303, but still couldn’t find any information on how to actually compile one....

How Unsafe/Safe is this code?

I needed a way to store lists of data of different types in a list, so I have created a list like type that can store any type that conforms to CollectionElement. It works well and doesn't have any memory errors, but I wanted to get a second opinion on if it seems safe enough to use. One issue it has is that I can't check the type when you append or get from it since it does not store type info. Currently I just store the types size and compare to that. ```python simple example:...

How can I see the peak memory usage of a datastructure like alist in mojo?

I want to compare the memory usage of python and mojo. For python I use the memory profiler pip package. How can I get the accurate memory consumption of a list or other structure in mojo?...

Mojo documentation says "The Mojo compiler uses lifetime values to track the validity of references.

Specifically, a lifetime value answers two questions:What logical storage location "owns" this value?Can the value be mutated using this reference? If so, why call it as lifetime? Rather call it as 'refscope' or 'reftype' or something like that. the term 'lifetime' i think confusing when used to describe a reference. Or is there any reason which I'm missing. May be my understanding is limited, I'm pretty new to this. Thanks....

Using Mojo For Back-end Web Development

Hi, I am trying to build something like hacker rank online. Is it possible to do this using mojo? Is it possible to build the back-end of a website using mojo? Apologies if this is a naive question - I’m just starting out as a developer in my free time

What pointer lifetime to use when iterating through a tree?

I've created a tree data structure: ``` struct BKTree: var root: Optional[BKTreeNode] ...

Error when running Mojo when path contains # (hash)

Since the introduction of Magic I have noticed that previous mojo scripts would give me an error when running "magic run mojo hello.mojo". Even using "magic shell" and then "mojo hello.mojo" does not solve the problem. The files are contained in a path where one of the folders starts with a #. When running mojo I get the following error: /home/user/Documents/#MojoProjects/hello-world/.magic/envs/default/bin/mojo: error: cannot map file that is not an actual file or block device ...

Canonical way to add NuMojo to a Mojo project?

Looking at the NuMojo documentation there are directions for building a Mojo packages and making it visible to a Mojo project. Is there a "canonical" way of adding multiple packages like NuMojo to an existing Mojo project? I'm thinking of having a project/vendor or project/lib directory to host these external packages.

Preserving mutability when passing to function

How to make pointer passed to a function preserve/transmit its mutability? ``` var a_instance = A(12) var ref_a = Pointer.address_of(a_instance) ...

Python integration: address not mapped to object

I wrote the below simple python code at jupyter notebook for stamping my pdf documents: ```python import fitz # PyMuPDF def add_signature(input_pdf, output_pdf, signature_image, x, y, stamp_width, stamp_height): doc = fitz.open(input_pdf)...

Creating files from code

Is there a way to create a file from code? I've tried using a python script: ```python def create_proj(path: str): with open(path + "/main.mojo", "x") as f: f.write("text goes here")...

Pyserial-like communication in Mojo

Hi) Trying to port a FFT realtime audio signal visualiser in Mojo. Decided to reimplement most of my imports that were used in the python. However! I do not see any stdlib support for serial communication. no class, etc. So I decided to import it from a foreighn language: saw an example of C++ header import in the roadmap. Instructions unclear, can i use c++ based compiled *.so, or not?...

dict containing sets?

I'm having issuesto have a dict whose values are sets first, Set doesn't implement copyinit so I had to wrap it but now I get that rag[current_label] is a "function that might raise in a context that cannot" what's the simplest way to build a dict whose values are sets? can I operate on the sets? ...

Could Mojo be the first all purpose language?

All languages have their own strengths and weaknesses, which is why we have so many — to cover all our bases. I'm wondering if Mojo could realistically become an "all-purpose" language — not as the default for every use case, but as a strong contender in every domain. In my mind, there are 3 core requirements for a language to be truly all-purpose: Speed — to ensure performance-critical cases don't default to C/C++/Rust. Safety — to prevent Rust from being the go-to in security-sensitive environments....