Open mullerhai opened 1 year ago
I also found "class org.bytedeco.javacpp.Pointer cannot be cast to class org.bytedeco.javacpp.FloatPointer " why?
val floatTensor= tensor.data_ptr.asInstanceOf[FloatPointer]
how to convert it
only tensor.toType(torch.ScalarType.Byte) , but I need to compare the datatype will BytePointer or CPUByteType
Have you tried Tensor.createBuffer() and found something missing? If so, please explain more clearly what you need to do exactly that you are not able to do with that method: http://bytedeco.org/javacpp-presets/pytorch/apidocs/org/bytedeco/pytorch/AbstractTensor.html#createBuffer--
http://bytedeco.org/javacpp-presets/pytorch/apidocs/org/bytedeco/pytorch/AbstractTensor.html#createBuffer-- when I use Tensor.createBuffer() ,also crash, If you success use Tensor.createBuffer() ,please give me Tensor.createBuffer() a code example to do, thanks
var tensor2 = torch.randn(34,34)
val buffer2 = tensor2.createBuffer[FloatBuffer]()
val array = buffer2.array() // here will crash
Those buffers don't have an array, so don't call array() on them.
Those buffers don't have an array, so don't call array() on them.
how to convert the buffer2 to java arrayList or Array?
Those buffers don't have an array, so don't call array() on them.
how to see and get the real float data num from those buffers
Everything you need to know about Buffer is documented in the JDK: https://docs.oracle.com/javase/8/docs/api/java/nio/Buffer.html
I found the tensor.createBuffer is DirectBuffer ,is out jvm buffer. But I need to read the buffer inner data to array, I can not get the suitable method .
We can copy the data with one of the get() methods
HI , In scala ,I want to match the tensor datatype to operate something, when I debug ,I find the Tensor type is [CPUFloatType ], But I can not find it ? how to security compare the tensor datatype with declare ,is instance of something? and If the tensor is FloatType ,after I invoke the tensor.data_ptr_byte() or tensor.data_ptr_double() or tensor.data_ptr_int(), the process will crash !!! ,how to security invoke it??
val tensor = torch.randn(34,34) val arr = tensor.data_ptr_float().asInstanceOf[FloatPointer].asBuffer().array() //will crash array is null
val flat = tensor.data_ptr_float() val buffer = DataBuffers.of(flat.asBuffer()) // buffer is null