Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is float16 supported in matlab?

Does MATLAB support float16 operations? If so, how to convert a double matrix to float16? I am doing an arithmetic operation on a large matrix where 16-bit floating representation is sufficient for my representation. Representing by a double datatype takes 4 times more memory.

like image 299
ssk Avatar asked Dec 16 '22 20:12

ssk


2 Answers

Is your matrix full? Otherwise, try sparse -- saves a lot of memory if there's lots of zero-valued elements.

AFAIK, float16 is not supported. Lowest you can go in float-datatype is with single, which is a 32-bit datatype:

A = single( rand(50) );

You could multiply by a constant and cast to int16, but you'd lose precision.

like image 76
Rody Oldenhuis Avatar answered Dec 26 '22 15:12

Rody Oldenhuis


The numeric classes, which Matlab supports out of the box are the following:

int8
int16
int32
int64
uint8
uint16
uint32
uint64
single (32-bit float)
double (64-bit float)

plus the complex data type. So no 16-bit floats, unfortunately.

On Mathworks file exchange, there seems to be a half-precision float library. It requires MEX, however.

like image 24
Mehrwolf Avatar answered Dec 26 '22 17:12

Mehrwolf