tch-rs icon indicating copy to clipboard operation
tch-rs copied to clipboard

Is it possible to impl Element for usize?

Open jafioti opened this issue 3 years ago • 1 comments

I do a lot of NLP, and after tokenizing and converting to indexes, my tokens are of type usize. Is it possible to impl Element for usize so a type conversion of every element in a potentially large array doesn't need to be converted? I've seen the types supported, so I was wondering if maybe usize can be seen as like a u32.

jafioti avatar Jan 20 '22 02:01 jafioti

The issue with usize is that it may contain values that are too large for u32 on a 64 bit platform. As there is no straightforward equivalent on the C++ libtorch side I would prefer letting the user in control of what happens by handling the conversion on their side.

LaurentMazare avatar May 14 '23 11:05 LaurentMazare