benny
benny
MModular
Created by benny on 7/6/2024 in #questions
Determine Pointer Location
Hey everyone :) Got stuck on an issue and was wondering if anyone knew how to implement a kind of function to check if a pointer is allocated on the stack or the heap, i.e.
fn is_stack[T: DType](ptr: DTypePointer[T]) -> Bool:
...
fn is_stack[T: DType](ptr: DTypePointer[T]) -> Bool:
...
That returns true for a pointer that was created with stack_allocate[T], but false for DTypePointer[T].alloc
4 replies
MModular
Created by benny on 5/25/2024 in #community-showcase
GLibC.Mojo
https://github.com/Benny-Nottonson/glibc.mojo This is the beginnings of a wrapper for glibc in Mojo, it is written to help with extremely low level coding in Mojo, something I haven't really seen done yet. I would love help converting functions over or improving syntax, all documentation needed is available at https://sourceware.org/glibc/manual/latest/html_mono/libc.html
3 replies
MModular
Created by benny on 5/23/2024 in #community-showcase
MIL: Mojo Imaging Library
https://github.com/Benny-Nottonson/MIL This is EXTREMELY WIP, DO NOT USE THIS FOR PROD ANYTHING.
6 replies
MModular
Created by benny on 3/22/2024 in #questions
Create a SIMD[DType.address] from a DTypePointer[T]
It would seem like DTypePointer[T].address_of(SIMD[T) would be correct, but this returns a DTypePointer aswell, which has type T, not DType.address. A bitcast seems incorrect as this would directly cast the numeric value into a pointer location, which is wrong, and I do not feel that loading the data as an address is the correct answer either. Hoping to use gather and scatter on SIMD vectors from a DTypePointer if possible.
19 replies
MModular
Created by benny on 3/17/2024 in #questions
Compile Time UUID
Dainemo does a good job accomplishing this (https://github.com/StijnWoestenborghs/dainemo/blob/main/dainemo/utils/uuid.mojo) But I wonder if there is a better way using instrinsics or system calls to get the time (Since time.now() doesnt work at compile time) The goal being of course to be able to run the following code
alias UUID_ONE = generate_uuidv4()
alias UUID_TWO = generate_uuidv4()

fn main():
print(UUID_ONE == UUID_TWO)
alias UUID_ONE = generate_uuidv4()
alias UUID_TWO = generate_uuidv4()

fn main():
print(UUID_ONE == UUID_TWO)
Where the output is
1 replies
MModular
Created by benny on 3/15/2024 in #questions
Type independent traits
Any ways to make the example code work? Would be nice to be able to implement custom traits for abstract classes
trait Container:
fn __contains__(self, item: AnyType) -> Bool:
...


@value
struct List(Container):
var data: VariadicList[Int]

fn __contains__(self, item: Int) -> Bool:
for i in self.data:
if i == item:
return True
return False
trait Container:
fn __contains__(self, item: AnyType) -> Bool:
...


@value
struct List(Container):
var data: VariadicList[Int]

fn __contains__(self, item: Int) -> Bool:
for i in self.data:
if i == item:
return True
return False
14 replies
MModular
Created by benny on 3/4/2024 in #questions
partially unbound parameters as return values?
struct Person[Age: UInt8, coder: Bool]:
...

fn example(p: Person) -> Person[p.Age, *_]:
...
struct Person[Age: UInt8, coder: Bool]:
...

fn example(p: Person) -> Person[p.Age, *_]:
...
This code will not compile and instead gives 'Person' missing required parameter 'coder'mojo. Is this intended behavior? I can see how given lambda functions one could represent every possible relationship between compile time constants in a function, but this seems a little excessive, especially once we get into nested parametric types, any ideas?
22 replies
MModular
Created by benny on 2/27/2024 in #questions
AnyFunction type
I asked about decorators a while ago, but in the meantime, some syntax for AnyFunction / Callable would be nice. Could be as simple as a trait for an object that has a special function. I don’t think functions themselves implement call but i could be completely wrong. and this might already be a thing somehow - definitely doable by wrapping in a struct
1 replies
MModular
Created by benny on 2/24/2024 in #questions
Traits from structs
In terms of a feature, would be interesting to reference an existing struct as a trait, maybe with the *operator or something
16 replies
MModular
Created by benny on 2/17/2024 in #questions
SHA256
Any implementations of SHA256 algorithm in Mojo yet, I've seen other work about other hashing algorithms and obviously the builtin, but has anyone implemented this?
35 replies
MModular
Created by benny on 2/10/2024 in #questions
Memset
From the docs -
memset memset[type: DType, address_space: AddressSpace](ptr: DTypePointer[type, address_space], value: SIMD[ui8, 1], count: Int) Fills memory with the given value. Parameters: ​type (DType): The element dtype. ​address_space (AddressSpace): The address space of the pointer. Args: ​ptr (DTypePointer[type, address_space]): Pointer to the beginning of the memory block to fill. ​value (SIMD[ui8, 1]): The value to fill with. ​count (Int): Number of elements to fill (in elements, not bytes).
Shouldn't the type of value be of type rather than SIMD[ui8, 1]? For example
let a = DTypePointer[DType.float32].alloc(10)
memset[DType.float32](a, 1.0, 10)
let a = DTypePointer[DType.float32].alloc(10)
memset[DType.float32](a, 1.0, 10)
The above code gives an error since 1.0 cannot be converted to ui8
2 replies
MModular
Created by benny on 2/5/2024 in #questions
Function Decorators
Are functions decorators and related syntax supported in Mojo right now, if so, has anyone had any luck with custom decorators? I’m aware of the builtin ones like @value and @register_passable
2 replies
MModular
Created by benny on 1/26/2024 in #questions
Set struct coming?
Now that hashable traits and structs based on them have gotten mature enough to have a Dict implementation (0.7), can we expect to see Set’s be implemented soon?
7 replies
MModular
Created by benny on 1/25/2024 in #questions
Will Mojo ever support multi variable tuple unpacking?
let a, b = StaticIntTuple[2](1, 2)
let a, b = StaticIntTuple[2](1, 2)
Will this code ever work?
2 replies
MModular
Created by benny on 1/22/2024 in #questions
Tutorial / Example of targetting GPU with llvm_instrinsic or __mlir_op etc?
Does anyone know of any resources (other than https://docs.modular.com/mojo/notebooks/BoolMLIR.html#adding-functionality-with-mlir), that show examples or methodology behind targetting the GPU for Mojo code?
19 replies
MModular
Created by benny on 12/18/2023 in #questions
Any ideas on implementing linked based structs in mojo?
I’m working on data structures in mojo and hit a roadblock at objects like linked lists and trees, how would I code a pointer to another object of the same type in mojo? and is there a way to use DTypePointers to ensure the result is string able?
5 replies
MModular
Created by benny on 12/16/2023 in #questions
Get Date/Time in Native Mojo
Is there a library for this? The only way I can think to implement is with a python module import.
9 replies