coder.screener - Determine if function is suitable for code generation - MATLAB (original) (raw)

Determine if function is suitable for code generation

Syntax

Description

coder.screener([fcn](#mw%5F46b95dbf-f6d0-411d-8283-a0eb9ffa6aad)) analyzes the entry-point MATLAB® function fcn to identify unsupported functions and language features as code generation compliance issues. The code generation compliance issues are displayed in the readiness report.

If fcn calls other functions directly or indirectly that are not MathWorks® functions (MATLAB built-in functions and toolbox functions), coder.screener analyzes these functions. It does not analyze the MathWorks functions.

It is possible that coder.screener does not detect all code generation issues. Under certain circumstances, it is possible that coder.screener reports false errors.

To avoid undetected code generation issues and false errors, before generating code, verify that your MATLAB code is suitable for code generation by performing these additional checks:

The coder.screener function does not report functions that the code generator treats as extrinsic. Examples of such functions are plot,disp, and figure. See Use MATLAB Engine to Execute a Function Call in Generated Code.

example

coder.screener([fcn](#mw%5F46b95dbf-f6d0-411d-8283-a0eb9ffa6aad),'-gpu') analyzes the entry-point MATLAB function fcn to identify unsupported functions and language features for GPU code generation.

coder.screener([fcn_1,...,fcn_n](#mw%5Fc8717a43-99ce-4db3-a1ba-5e2465994434)) analyzes multiple entry-point MATLAB functions.

example

`info` = coder.screener(___) returns a coder.ScreenerInfo object. The properties of this object contain the code generation readiness analysis results. Use info to access the code generation readiness results programmatically. For a list of properties, see coder.ScreenerInfo Properties.

example

Examples

collapse all

Identify Unsupported Functions

The coder.screener function identifies calls to functions that are not supported for code generation. It checks the entry-point function,foo1, and the function, foo2, thatfoo1 calls.

Write the function foo2 and save it in the filefoo2.m.

function [tf1,tf2] = foo2(source,target) G = digraph(source,target); tf1 = hascycles(G); tf2 = isdag(G); end

Write the function foo1 that calls foo2. Save foo1 in the filefoo1.m.

function [tf1,tf2] = foo1(source,target) assert(numel(source)==numel(target)) [tf1,tf2] = foo2(source,target); end

Analyze foo1.

The Code Generation Readiness report displays a summary of the unsupported MATLAB function calls. The report Issues tab indicates thatfoo2.m contains one call to the isdag function and one call to the hascycles, which are not supported for code generation.

Screenshot of the code generation readiness tool with sample code and analysis results.

The function foo2 calls two unsupported MATLAB functions. To generate a MEX function, modify the code to make the calls to hascycles and isdag extrinsic by using thecoder.extrinsic directive, and then rerun the code generation readiness tool.

function [tf1,tf2] = foo2(source,target) coder.extrinsic('hascycles','isdag'); G = digraph(source,target); tf1 = hascycles(G); tf2 = isdag(G); end

Rerun coder.screener on the entry-point functionfoo1.

The report no longer flags that code generation does not support the hascycles and isdag functions. When you generate a MEX function for foo1, the code generator dispatches these two functions to MATLAB for execution.

Access Code Generation Readiness Results Programmatically

You can call the coder.screener function with an optional output argument. If you use this syntax, the coder.screener function returns a coder.ScreenerInfo object that contains the results of the code generation readiness analysis for your MATLAB code base. See coder.ScreenerInfo Properties.

This example uses the files foo1.m and foo2.m defined in the previous example. Call the coder.screener function:

info = coder.screener('foo1.m')

info =

ScreenerInfo with properties:

           Files: [2×1 coder.CodeFile]
        Messages: [2×1 coder.Message]
UnsupportedCalls: [2×1 coder.CallSite]

View Screener Report

To access information about the first unsupported call, index into theUnsupportedCalls property,

firstCall = info.UnsupportedCalls(1)

firstCall =

CallSite with properties:

CalleeName: 'hascycles'
      File: [1×1 coder.CodeFile]
StartIndex: 78
  EndIndex: 86

View the text of the file that contains this unsupported call tohascycles.

ans =

'function [tf1,tf2] = foo2(source,target)
 G = digraph(source,target);
 tf1 = hascycles(G);
 tf2 = isdag(G);
 end
 '

To export the entire code generation readiness report to a MATLAB string, use the textReport function.

reportString = textReport(info)

reportString =

'Code Generation Readiness (Text Report)
 =======================================
 
 2 Code generation readiness issues
 2 Unsupported functions
 2 Files analyzed
 
 Configuration
 =============
 
 Language: C/C++ (MATLAB Coder)
 
 Code Generation Issues
 ======================
 
 Unsupported function: digraph (2)
     - foo2.m (Line 3)
     - foo2.m (Line 4)
 
 '

Identify Unsupported Data Types

The coder.screener function identifies MATLAB data types that code generation does not support.

Write the function myfun1 that contains a MATLAB calendar duration array data type.

function out = myfun1(A) out = calyears(A); end

Analyze myfun1.

coder.screener('myfun1');

The code generation readiness report indicates that the calyears data type is not supported for code generation. Before generating code, fix the reported issue.

Input Arguments

collapse all

fcn — Name of entry-point function

character vector | string scalar

Name of entry-point MATLAB function for analysis. Specify as a character vector or a string scalar.

Example: coder.screener('myfun');

Data Types: char | string

fcn_1,...,fcn_n — List of entry-point function names

character vector | string scalar

Comma-separated list of entry-point MATLAB function names for analysis. Specify as character vectors or string scalars.

Example: coder.screener('myfun1','myfun2');

Data Types: char | string

Alternatives

Version History

Introduced in R2012b