how to read and write half precision arrays via mexFunction

1 visualización (últimos 30 días)
Seongjin Lim
Seongjin Lim el 22 de En. de 2022
Editada: James Tursa el 25 de En. de 2022
#include "mex.h"
#include "rtwhalf.h"
#define IN_X prhs[0]
#define IN_Y prhs[1]
#define OUT_Z plhs[0]
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) {
real16_T *X, *Y, *Z;
size_t ndim=3;
size_t *dims;
dims[0] = 128; dims[1] = 128; dims[2] = 128;
X = (real16_T*)(mxGetPr(IN_X));
Y = (real16_T*)(mxGetPr(IN_Y));
OUT_Z = mxCreateNumericArray(ndim, dims, mxSINGLE_CLASS, mxREAL);
Z = (real16_T*)(mxGetPr(OUT_Z));
}
https://www.mathworks.com/help/coder/ug/edge-detection-with-sobel-method-in-half-precision.html
By referring the link, I wanted to use half-precision float arrays in a MEX file. However, it failed, though the code worked for single/double precision float arrays. Is there any way to use half-precision float arrays in the MEX file? Thank you.

Respuestas (1)

James Tursa
James Tursa el 25 de En. de 2022
Editada: James Tursa el 25 de En. de 2022
Very unfortunately, MATLAB has implemented the half precision data type as an opaque classdef type instead of a simple numeric type. The half precision data is hidden and cannot be accessed directly in a mex routine. You would have to use helper routines at the m-file level to get at the data and then pass that into the mex routine. See these related discussions:

Categorías

Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by