How to initialize a tensor[DType.int8] with random values of either: -1, 0, or 1?
Probably a dumb question, but how can I initialize a Tensor like so with random values of either -1, 0, or 1?
The rand functions I could find either don't let me specify the range, or work for other data types.
Furthermore, is this really only for SIMD compatible sizes? Like what if I wanted it to have 10,000 elements? Is Tensor the wrong data type for this?
I want to perform element-wise vector operations on it later, like xor(vector_a, vector_b) - but in a highly parallel way
9 Replies
are you trying to work with vectors or tensors? if you don’t need n dimensions then a much better option is Buffer or even DTypePointer, what exactly are you trying to do?
@benny Playing with hyperdimensional vectors, requires vectors with dimensions over 10,000 to be useful (this is a rule in Vector Symbolic Architecture).
For example: https://torchhd.readthedocs.io/en/stable/generated/torchhd.random.html#torchhd.random
Except I want to experiment with 3 valued systems rather than two.
But anyway, to create a VSA you need operations like element wise multiplication, addition, and other operations (element wise XOR, etc, for the BSC architecture)
ahhhh I understand
Point being, I need a way to randomly initialize really large vectors (could be a million dimensions for example)
very cool
let me check some stuff
randint is what you are looking for
randint | Modular Docs
randinttype Int, low Int)
get the underlying data pointer from the tensor and give that as an argument to randint, ranged -1, 1
Like this?
err, not 1..
Actually, maybe that's right? It explodes when I try and print a though.
"number of elements to fill", I assume that is 100. so:
randintDType.int8, 100, -1, 1)
then when I try and print:
Ah, got it. a.unsafe_ptr() not a._take_data_ptr(). My intellisense betrayed me!
yep, glad you got it working :)