how to read and write half precision arrays via mexFunction
이전 댓글 표시
#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.
답변 (1개)
James Tursa
2022년 1월 25일
편집: James Tursa
2022년 1월 25일
0 개 추천
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:
카테고리
도움말 센터 및 File Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!