coder.typeof
Create coder.Type
object to represent the type
of an entry-point function input
Syntax
Description
Note
You can also create and edit coder.Type
objects
interactively by using the Coder Type Editor. See Create and Edit Input Types by Using the Coder Type Editor.
creates an object that is derived from type_obj
= coder.typeof(v
)coder.Type
to represent the type of v
for code generation. Use
coder.typeof
to specify only input parameter types. Use it with the codegen
function
-args
option or in a MATLAB®
Coder™ project when you are defining an input type by providing a sample
code. Do not use it in MATLAB code from which you intend to generate code.
returns a modified copy of type_obj
= coder.typeof(v
,sz
,variable_dims
)type_obj
=
coder.typeof(v
) with upper bound size specified by
sz
and variable dimensions specified by
variable_dims
.
Examples
Input Arguments
Output Arguments
Limitations
For sparse matrices,
coder.typeof
drops upper bounds for variable-size dimensions.Scalar GPU arrays, structures, cell-arrays, classes, enumerated types, character, half-precision and fixed-point data types are not supported.
When using
coder.typeof
to represent GPU arrays, the memory allocation (malloc) mode property of the GPU code configuration object must be set to be'discrete'
.You cannot pass an unconfigured dictionary to
coder.typeof
.
Tips
coder.typeof
fixes the size of a singleton dimension unless thevariable_dims
argument explicitly specifies that the singleton dimension has a variable size.For example, the following code specifies a 1-by-:10 double. The first dimension (the singleton dimension) has a fixed size. The second dimension has a variable size.
By contrast, this code specifies a :1-by-:10 double. Both dimensions have a variable size.t = coder.typeof(5,[1 10],1)
t = coder.typeof(5,[1 10],[1 1])
Note
For a MATLAB Function block, singleton dimensions of input or output signals cannot have a variable size.
If you are already specifying the type of an input variable by using a type function, do not use
coder.typeof
unless you also want to specify the size. For instance, instead ofcoder.typeof(single(0))
, use the syntaxsingle(0)
.For cell array types,
coder.typeof
determines whether the cell array type is homogeneous or heterogeneous.If the cell array elements have the same class and size,
coder.typeof
returns a homogeneous cell array type.If the elements have different classes,
coder.typeof
returns a heterogeneous cell array type.For some cell arrays, classification as homogeneous or heterogeneous is ambiguous. For example, the type for {1 [2 3]} can be a 1x2 heterogeneous type where the first element is double and the second element is 1x2 double. The type can also be a 1x3 homogeneous type in which the elements have class double and size 1x:2. For these ambiguous cases,
coder.typeof
uses heuristics to classify the type as homogeneous or heterogeneous. If you want a different classification, use the coder.CellTypemakeHomogeneous
ormakeHeterogeneous
methods to make a type with the classification that you want. ThemakeHomogeneous
method makes a homogeneous copy of a type. ThemakeHeterogeneous
method makes a heterogeneous copy of a type.The
makeHomogeneous
andmakeHeterogeneous
methods permanently assign the classification as heterogeneous and homogeneous. You cannot later use one of these methods to create a copy that has a different classification.You can use
coder.typeof
to create an unbounded GPU array input and pass it to the entry-point functions. For example, create a GPU input usingcoder.typeof(int32(1),[inf,1],'Gpu',true)
.During code generation with GPU array types, if one input to the entry-point function is of the GPU array type, then the output variables are all GPU array types, provided they are supported for GPU code generation. For example. if the entry-point function returns a
struct
and becausestruct
is not supported, the generated code returns a CPU output. However, if a supported matrix type is returned, then the generated code returns a GPU output.
Version History
Introduced in R2011aSee Also
coder.newtype
| coder.resize
| coder.Type
| coder.ArrayType
| coder.EnumType
| coder.FiType
| coder.PrimitiveType
| coder.StructType
| coder.CellType
| coder.ClassType
| codegen
| coder.OutputType