how to read and write half precision arrays via mexFunction
Afficher commentaires plus anciens
#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.
Réponses (1)
James Tursa
le 25 Jan 2022
Modifié(e) : James Tursa
le 25 Jan 2022
0 votes
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:
Catégories
En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!