Create coder.Type
object to represent the type
of an entry-point function input
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
.
For sparse matrices, coder.typeof
drops upper bounds for
variable-size dimensions.
For representing GPU arrays, only bounded numeric and logical base types are supported. 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'
.
coder.typeof
fixes the size of a singleton dimension
unless the variable_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.
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 of
coder.typeof(single(0))
, use the syntax
single(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.CellType
makeHomogeneous
or
makeHeterogeneous
methods to make a type with the
classification that you want. The makeHomogeneous
method
makes a homogeneous copy of a type. The makeHeterogeneous
method makes a heterogeneous copy of a type.
The makeHomogeneous
and
makeHeterogeneous
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.
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 because struct
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.
codegen
| coder.ArrayType
| coder.CellType
| coder.ClassType
| coder.EnumType
| coder.FiType
| coder.newtype
| coder.PrimitiveType
| coder.resize
| coder.StructType
| coder.Type