Use custom data types for code replacement library
조회 수: 2 (최근 30일)
이전 댓글 표시
I want to use a custom data type for a code replacement entry.
I have a C function whose arguments are expected to be in a custom data type defined previously in the same header file.
C Function:
my_func(const my_type_def* matA_in, const my_type_def* matB_in, my_type_def* mat_out)
Type definition (in the same .h):
typedef struct
{
uint16_t numRows;
uint16_t numCols;
double* mdata;
} my_type_def;
As you may notice, I want to replace all matrix multiplications (in the form A*B) with my custom C code. I configure the entry for the Code Replacement Library (CRL) for the conceptual implementation and the specification implementation, respectively, in the following way:
'my_type_def* y1 = mtimes( const my_type_def* u1, const my_type_def* u2 )', ...
'my_func( const my_type_def* u1, const my_type_def* u2, my_type_def* y1 )');
The error I get with this is:
Missing data type for argument 'my_type_def'
I tried desperately to look online for documentation or a way around to do this but unfortunately I was not able to find a solution, it seems the only accepted data types for CRL entries are double, single, int, etc, etc. Any help at all is very welcome ! (I'm not an expert in this topic) Thank you very much in advance.
댓글 수: 0
답변 (1개)
Hugoz
2024년 2월 20일
I was trying to solve the exact same problem few days ago. Basically you are trying to replace a function taking {pointers to array of double} as arguments with a function taking {pointers to structure} as arguments, Matlab matrix multiplication (*) don't know what numRows and numCols are.
Explicitely, the matrix multiplication (A*B) would be equivalent in your situation to something similar to that :
&y1->mdata[0][0] = mtimes( const &u1->mdata[0][0], const &u2->mdata[0][0] )
Notice that the only manipulated element of my_type_def is mdata.
If you want to pass the size of u1, u2 and y1 as arguments, you are not just doing a matrix multiplication anymore. I don't think there is any direct way to solve your problem, but then I'm not working at MathWorks, maybe adding structures and custom named structures as accepted Data Type would be feasible.
If you have flexibility with your generated code, maybe you could try to map the matrix multiplication to a function taking explicitely (double)mdata, as well as (uint16)numRows and (uint16)numCols as arguments and setting upper range of mdata to something you know you will not go over. I have no clue if you can add extra arguments to the mapping of matrix multiplication without replacing it with a custom function, but at least you are passing valid built-in Data Types as arguments.
Or, if you need this exact syntax, you could modify your function to take only mdata as argument, and once the code is generated, you could modify your function and manually switch the function's arguments each times it is called.
I hope you can manage to find a solution, let me know, good luck.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!