42 questions
0
votes
0
answers
44
views
Why does SIMD[DType.bool, 4](True, False, True) give unexpected reduce_bit_count() results in Mojo?
I'm investigating the method reduce_bit_count() from Mojo's SIMD API.
According to the documentation:
Returns the total number of bits set in the SIMD vector.
I expected the following behavior:
3 ...
2
votes
1
answer
96
views
Magic fails to install Mojo dependencies
I cannot use the Mojo dependency called lightbug_http in a fresh Mojo project.
magic init hello_web --format mojoproject
cd hello_web
magic shell
Printing «Hello world» works fine.
Then I add https://...
1
vote
1
answer
524
views
How can I write asynchronous code in mojo? ("Coroutine not copyable")
How can I implement asynchroneous code in mojo (using async etc.)?
In the Changelog, I find the following example (slightly adjusted):
async fn add_three(a: Int, b: Int, c: Int) -> Int:
return ...
1
vote
0
answers
31
views
Is there a way to load a memory-only pointer type
I'm trying to write a solution to a problem I found online using Mojo. The problem is a graph theory related so I wanted to implement the data structure by hand to get more familiar with the language.
...
0
votes
1
answer
73
views
Cannot return a struct implementing a trait in a function
I have this code :
trait State:
fn to_string(self) -> String:
...
struct StateTtt(State):
fn __init__(inout self):
pass
fn to_string(self) -> String:
...
0
votes
1
answer
498
views
Issue using Python.import_module to import python numpy package in Mojo
I've just started learning Mojo, following the documentation to get started. I've run into a problem with importing the Python module numpy. Below is the code I am using which is taken from the ...
0
votes
1
answer
181
views
Pass arguments to a Python module in Mojo?
I have a python module : myScript.py.
Normally, I run it like this
python3 myScript.py -i example.jpg
I want to pass this argument to this python modules's main function
from python import Python
fn ...
1
vote
1
answer
206
views
Mojo (Mac) using wrong python lib
As most Mac users, I have two separate versions of python on my machine: The one installed by Apple (version 3.9 in /usr/bin) and one installed via Homebrew (version 3.11 in /opt/homebrew/bin).
I've ...
2
votes
1
answer
351
views
pressing the run button to run a mojo file does nothing
I'm trying to run mojo in VScode, however pressing the run button does absolutely nothing. No errors, no nothing.
I can run the file from terminal and it works fine but I would love to use running and ...
1
vote
1
answer
1k
views
Mojo build for windows
I have some sample Mojo code:
fn main():
print("Hello, world!")
for i in range(10000):
print_no_newline(i)
print_no_newline(' ')
And I run mojo build test.🔥
And it ...
0
votes
1
answer
84
views
'object' does not refer to a package or module
I tried the below in Jupiter, and it is working fine,
But one I tried to use at at file.mojo as:
from python import Python
# The Python way: `import requests as http`
let http = Python.import_module(...
0
votes
2
answers
508
views
Running falcon ai model on mojo lang
How can we run https://huggingface.co/tiiuae/falcon-180B the one of the current best models on mojo lang which is faster than python 35k? When we just copy this:
`from transformers import ...
7
votes
1
answer
423
views
How to statically declare a Tensor?
I started exploring the mojo programming language and now I am trying to figure out how to properly use the Tensor module. I can't find how to statically declare the values inside a tensor.
For the ...
1
vote
1
answer
252
views
How to add an instance of a struct to a DynamicVector
A total newbie question.
struct Item:
var name: StringLiteral
fn __init__(inout self):
self.name = "Unnamed"
fn main():
var dv = DynamicVector[Item]()
var it = Item(...
5
votes
0
answers
458
views
How to parametrically check if a variable is of a type in Mojo?
I am trying to create a function that takes in any object and prints it if it is _Printable, and prints "object" otherwise.
To do this I am trying to use @paramter if to check the type at ...
16
votes
1
answer
11k
views
Performance Comparison - Mojo vs Python [closed]
Mojo, a programming language, claims to be 65000x faster than python. I am eager to understand if is there any concrete benchmark data that supports this claim? Also, how does it differ in real world ...
0
votes
1
answer
2k
views
Create Pandas Dataframe in Mojo
I am trying to declare a Pandas DataFrame in mojo using a list of data. I have followed the examples seen for importing and using Numpy but declaring a DataFrame is only giving errors. How do I fix ...
0
votes
0
answers
161
views
failure to complete the download of Mojo SDK
when I switched to WSL(from windows) and ran:
curl https://get.modular.com | \ MODULAR_AUTH=###################### \ sh -
multiple times the download process stopped within seconds:
% Total % ...
3
votes
2
answers
2k
views
vectorize vs parallelize in Mojo
According to the docs:
vectorize
vectorize[simd_width: Int, func: fn[Int](Int) capturing -> None](size: Int)
Maps a function which is parametrized over a simd_width over a range from 0 to size in ...
2
votes
1
answer
81
views
How can I store compound data in a struct without copying?
The following program tries to store a Thing in a Holder:
struct Holder:
var thing: Thing
fn __init__(inout self, owned thing: Thing):
self.thing = thing
pass
struct Thing:
...
1
vote
1
answer
284
views
Mojo compile time programming - specifying a type
I run the following in the Mojo Plyaground (https://playground.modular.com/) and get an error, what am I doing wrong?
struct MyPair[type:AnyType]:
var first: type
var second: type
# We ...