Manuel Saelices
Manuel Saelices
MModular
Created by Manuel Saelices on 12/17/2024 in #questions
Tried the new Max custom_ops examples with my RTX 3050 and using CPU
No description
17 replies
MModular
Created by Manuel Saelices on 12/16/2024 in #questions
cannot return reference iwth incompatible origin
No description
4 replies
MModular
Created by Manuel Saelices on 11/28/2024 in #questions
Passing method references to high-order functions
I would like to pass a reference to a method once the object has been instanciated to a high-order function as an argument, but it seems not supported, right? Example:
@value
struct Foo:
fn func(self) -> Int:
return 42

# None of these declarations work:
fn high_order_func(f: fn (Foo) -> Int) -> Int:
# fn high_order_func(f: fn () -> Int) -> Int:
return f()

fn main() -> Int:
foo = Foo()
print(high_order_func(foo.func))
@value
struct Foo:
fn func(self) -> Int:
return 42

# None of these declarations work:
fn high_order_func(f: fn (Foo) -> Int) -> Int:
# fn high_order_func(f: fn () -> Int) -> Int:
return f()

fn main() -> Int:
foo = Foo()
print(high_order_func(foo.func))
8 replies
MModular
Created by Manuel Saelices on 10/24/2024 in #community-showcase
Mojo LibC bingings
Forked repo with the Mojo libc bindings from @crisadamo , adapted to the latest Mojo nightly package, and released on the mojo-community channel: https://github.com/msaelices/mojo-libc Making the libc bindings a Mojo package hopefully could help avoid copying and pasting the code from the original repo all over the place. Note: I'm still trying to contact @crisadamo, as his original repo had no explicit license.
1 replies
MModular
Created by Manuel Saelices on 10/13/2024 in #questions
Does Mojo implements the Debug Adapter Protocol?
Could we understand that Mojo implements the Debug Adapter Protocol? Meaning, it's created by Microsoft and we can debug Mojo in vscode, so I guess then we could use it for debugging Mojo in other IDEs like nvim (using nvim-dap). Am I right?
3 replies
MModular
Created by Manuel Saelices on 5/5/2024 in #questions
convert error: 'Int' to 'IntLiteral' trying to implement the FloatLiteral.__round__(ndigits) method
I'm trying to contribute implementing the FloatLiteral.round() method with the current implementation:
@always_inline("nodebug")
fn __round__(self, ndigits: IntLiteral = 0) -> Self:
"""Return the rounded value of the FloatLiteral.

Args:
ndigits: The number of digits to round to. Defaults to 0.
Returns:
The rounded value.
"""
# Handle special values first.
if not self._is_normal():
return self

var pow: IntLiteral = 10 ** ndigits
var to_round: Self = self * Self(pow)
var truncated: IntLiteral = to_round.__int_literal__()
var result: Self
if self.__abs__() - Self(truncated).__abs__() < 0.5:
result = Self(truncated)
elif self > 0:
result = Self(truncated + 1)
else:
result = Self(truncated - 1)
if ndigits > 0:
result = result / (Self(10.0) ** ndigits)
return result
@always_inline("nodebug")
fn __round__(self, ndigits: IntLiteral = 0) -> Self:
"""Return the rounded value of the FloatLiteral.

Args:
ndigits: The number of digits to round to. Defaults to 0.
Returns:
The rounded value.
"""
# Handle special values first.
if not self._is_normal():
return self

var pow: IntLiteral = 10 ** ndigits
var to_round: Self = self * Self(pow)
var truncated: IntLiteral = to_round.__int_literal__()
var result: Self
if self.__abs__() - Self(truncated).__abs__() < 0.5:
result = Self(truncated)
elif self > 0:
result = Self(truncated + 1)
else:
result = Self(truncated - 1)
if ndigits > 0:
result = result / (Self(10.0) ** ndigits)
return result
But I'm receiving the error: cannot implicitly convert 'Int' value to 'IntLiteral' in 'var' initializer in the var pow: IntLiteral = 10 ** ndigits line If I change the type to from IntLiteral to Int this will move the error to the following line, the to_round declaration .
2 replies