I found a good library called NuMojo , it seems to be a good substitute for numpy in mojo. I install this library via magic add numojo
,and it already shows in my mojoproject.toml.But compiler told me error: failed to materialize top-level module
. Why and how?
Hi @Treagzhao , Thanks for trying out NuMojo. The reason for the error is mismatch in Max/Mojo versions. We haven’t updated NuMojo to v25.2 yet (There’s a lot of bundled updates incoming!). In the meantime, you can use NuMojo by changing the Mojo/Max version in your .toml file, please make sure the Max version is
max = "25.1.1"
Let me know if you face any problems.
I’ve got another problem. I has a NDArray[DType.float64]
variable, I want to subtract this variable from 1.0, just like in NumPy, It said error: 'NDArray[result[::DType,::DType]()]' value has no attribute 'success'
. I really don’t know what result is in mojo. (Maybe I am too fresh in mojo)
Hey @Treagzhao That is indeed one of the foot guns in the v0.6 version NuMojo. The mojo type system is still not mature enough for us to do Type conversions based on the input data type at compile time yet, That’s why you get the error result[::DType, ::DType]()
which just implies that Mojo couldn’t calculate the resulting data types and just returns a generic one instead.. You can definitely work around this, but I would suggest you to use our latest NuMojo version directly from our GitHub as we have patched this in latest pre-0.7 branch. Note that this latest NuMojo versions cannot be added with magic add
yet as we haven’t updated the community channel package, so please follow instructions in the GitHub README to install and use latest NuMojo package! Let me know if you face any difficulties.
I`ll try,thanks.
I found edge_items
in set_printoptions
does not work.
fn main():
try:
print("Hello, world!")
numojo.set_printoptions(precision=20, edge_items=10)
var list: List[Float64] = List[Float64]()
for i in range(2000):
list.append(i)
var array: numojo.NDArray[DType.float64] = numojo.array(list)
array = array.reshape(numojo.Shape(40, 50))
print(array)
except e:
print(e)
And the print still remains 3 edge items;
fn numojo_exp() raises -> numojo.NDArray[DType.float64]:
var inner_list: List[Float64] = List[Float64]()
for _i in range(200):
inner_list.append(1.0e-5)
var l = numojo.array(inner_list).reshape(numojo.Shape(200, 1))
var z = numojo.exp(-l) + 1.0
var r: numojo.NDArray[DType.float64] = 1.0 / (numojo.exp(-l) + 1.0)
return r
In the above code snippet,I generated an array which only contains a group of 1e-5
, the result of numojo.exp(-l)
should be 0.9999999. The result of adding 1.0 to this array should be 1.999999. Then, when you divide 1.0 by this array,the result should be almose 0.5. But actually the result is 2.000 . I am confused·······
Hey @Treagzhao Thanks for reporting the errors! The formatting options is still being worked on right now, so not all options are available for customisations yet. Regarding the division error, thanks for reporting it, I looked into it and found that there was an error that reversed the division of 1 / array to array / 1 which results in 2.0 in your case. I have fixed this in the latest PR which you can find here.