Main Content

coder.isColumnMajor

Determine whether the current function or variable uses column-major layout

Description

example

coder.isColumnMajorresolves as true in the generated code if the current function uses column-major array layout. Use the function as the expression in control flow (if,else,switch) statements.

example

coder.isColumnMajor(arg)resolves as true if the current variable uses column-major array layout.

Examples

collapse all

To query the array layout of a function at compile time, usecoder.isColumnMajororcoder.isRowMajor. This query can be useful for specializing your generated code when it involves row-major and column-major functions. For example, consider this function:

functionS = addMatrixRouted(A,B)ifcoder.isRowMajor%执行此代码,如果行专业S = addMatrix_OptimizedForRowMajor(A,B);elseifcoder.isColumnMajor%execute this code if column majorS = addMatrix_OptimizedForColumnMajor(A,B);end

The functionaddMatrixRoutedbehaves differently depending on whether it uses row-major layout or column-major layout. The layout that the function uses, for example, can depend on whether it is called from a function that containscoder.rowMajororcoder.columnMajor. WhenaddMatrixRouteduses row-major layout, it calls theaddMatrix_OptimizedForRowMajorfunction, which has efficient memory access for row-major data. When the function uses column-major layout, it calls a version of theaddMatrixfunction optimized for column-major data.

By using the query functions, the generated code foraddMatrixRoutedprovides efficient memory access for either choice of array layout.

Consider the functionbar:

functionbar coder.columnMajor; x = magic(3);ifcoder.isColumnMajor(x) fprintf('This will always be displayed in generated code.\n');elsefprintf('这将永远不会以生成的代码显示。\ n');endend

Generate code:

codegenbar

To run the MEX function, enter:

bar_mex

Input Arguments

collapse all

Variable to query for array layout.

Example:coder.isColumnMajor(x);

Limitations

  • You cannot query the array layout of a structure field or property.

Tips

  • The code generator uses column-major layout by default.

  • Outside of code generation and simulation,coder.isColumnMajoris always true.

  • Ifcoder.isColumnMajoralways resolves to true for your code, other branches in theifstatement are ignored by the code generator. Otherwise, one instance of the current function is created for each array layout.

Extended Capabilities

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

GPU Code Generation
使用GPU CODER™为NVIDIA®GPU生成CUDA®代码。

版本历史

Introduced in R2018a