M
Modular•13mo ago
alvinjrush

Outputting Items in a tensor

I there ant way to print all the items in a tensor at once rather than iterating through the tensor index by index.
3 Replies
Kyle Hassold
Kyle Hassold•13mo ago
From what I have found, there is no default str() method or something similar for Tensors (or honestly most of the data types). If you want, there are some functions online which print tensors in an organized way. I will also send the method that I use to print the data in my custom tensor type which would need to be slightly rewords to be used on a regular tensor.
fn __str__(self) -> String:
var s: String = ""

for i in range(self.num_elements):
if mod[DType.uint8, 1](i, self.shape[self.rank-1]) == 0:
var num = self.num_elements
var j = 0
while mod[DType.uint8, 1](i, num) != 0:
num /= self.shape[j]
j += 1

for k in range(self.rank):
s += ']' if k < self.rank-j else ' '
for _ in range(self.rank-j):
s += '\n'
for k in range(self.rank):
s += '[' if k >= j else ' '

let val = self.data.load(i)
if val >= 0:
s += ' '
s += ' ' + String(val) + ' '

for _ in range(self.rank):
s += ']'
return s[self.rank*2:]
fn __str__(self) -> String:
var s: String = ""

for i in range(self.num_elements):
if mod[DType.uint8, 1](i, self.shape[self.rank-1]) == 0:
var num = self.num_elements
var j = 0
while mod[DType.uint8, 1](i, num) != 0:
num /= self.shape[j]
j += 1

for k in range(self.rank):
s += ']' if k < self.rank-j else ' '
for _ in range(self.rank-j):
s += '\n'
for k in range(self.rank):
s += '[' if k >= j else ' '

let val = self.data.load(i)
if val >= 0:
s += ' '
s += ' ' + String(val) + ' '

for _ in range(self.rank):
s += ']'
return s[self.rank*2:]
alvinjrush
alvinjrushOP•13mo ago
Alright thanks
alvinjrush
alvinjrushOP•13mo ago
@Kyle Hassold looks there was a fix 😃
No description
Want results from more Discord servers?
Add your server