Main Content

coder.rowMajor

Specify row-major array layout for a function or class

Description

example

coder.rowMajorspecifies row-major array layout for the data used by the current function in generated code. When placed in a class constructor,coder.rowMajorspecifies row-major layout for data used by the class.

Note

By default, code generation uses column-major array layout.

Examples

collapse all

Specify row-major array layout for a function by insertingcoder.rowMajorinto the function body.

Suppose thatmyFunctionis the top-level function of your code. Your application requires you to perform matrix addition with row-major array layout and matrix multiplication with column-major layout.

functionS = myFunction(A,B)%#codegen% check to make sure inputs are validifsize(A,1) ~= size(B,1) || size(A,2) ~= size(B,2) disp('Matrices must be same size.');return;end% make both matrices symmetricB = B*B'; A = A*A';% add matricesS = addMatrix(A,B);end

Write a function for matrix addition calledaddMatrix. Specify row-major layout foraddMatrixby usingcoder.rowMajor.

functionS = addMatrix(A,B)%#codegenS = zeros(size(A)); coder.rowMajor;% specify row-major array layoutS = A + B;end

Generate code formyFunction. Use thecodegencommand.

codegenmyFunction-args{ones(10,20),ones(10,20)}-config:lib-launchreport

The code generator produces code foraddMatrix使用行数组out. However, the matrix multiplication from the top-level function uses the default layout, column-major.

Tips

  • To specify row-major array layout for all the functions in your generated code, use thecodegen -rowmajoroption.

  • Other functions called from within a row-major function inherit the row-major specification. However, if one of the called functions has its own distinctcoder.columnMajorcall, the code generator changes the array layout accordingly. If a row-major function and a column-major function call the same function, which does not have its own array layout specification, the code generator produces a row-major version and column-major version of the function.

  • coder.rowMajoris ignored outside of code generation and simulation.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Version History

Introduced in R2018a