graphos
MModular
•Created by graphos on 2/11/2024 in #questions
Char[X] equivalent in Mojo
I always find it odd that c called char what factually represent a single byte. Sementicaly it just feel wrong
11 replies
MModular
•Created by graphos on 2/11/2024 in #questions
Char[X] equivalent in Mojo
If you consider a char as an alias for byte then its easy, but if you consider a char representing a character then it become a mess. How do you enforce safety with nullbyte e.g a Tensor[char, 4] is supposed to contain 4 char, but then you miss the nullbyte so its size is 5...
Then if you think about utf there is utf8,16,32 so whats the size of a char?
11 replies
MModular
•Created by graphos on 2/11/2024 in #questions
Char[X] equivalent in Mojo
Just read https://www.modular.com/blog/mojo-vs-rust-is-mojo-faster-than-rust
Mojo's primitives are natively designed to be SIMD-first: UInt8 is actually a SIMD[DType.uint8, 1] which is a SIMD of 1 element. There is no performance overhead to represent it this way, but it allows the programmer to easily use it for SIMD optimizations. For example, you can split up text into 64 byte blocks and represent it as SIMD[DType.uint8, 64] then compare it to a single newline character, in order to find the index for every newline. Because the SIMD registers on your machine can calculate operations on 512bits of data at the same time, this will improve the performance for those operations by 64x!
So I think it make sense and its a matter of time before we get an alias. On top of that if you consider all char type, it can become quickly messy
11 replies
MModular
•Created by sora on 2/10/2024 in #questions
Why is the dtype of `String`'s underlying storage `int8` and not `uint8`?
https://mojodojo.dev/mojo-team-answers.html#string-uint8-implementation
https://mojodojo.dev/mojo-team-answers.html#string-supporting-utf-8
https://mzaks.medium.com/counting-chars-with-simd-in-mojo-140ee730bd4d
So;e links on the topic
5 replies
MModular
•Created by benny on 2/5/2024 in #questions
Function Decorators
https://docs.modular.com/mojo/roadmap.html#full-mlir-decorator-reflection planned for the future but at the moment its hardcoded in the parser
2 replies