"ListVector" (Compiled Type)
"ListVector" (Compiled Type)
"ListVector"::[type]
represents a uniform list with the specified element type.
Details
- "ListVector" can be used in Typed and related constructs to specify a type.
- "ListVector" objects are automatically memory managed.
- The elements of a "ListVector" can have any compiled type.
- The elements of a "ListVector" all have the same type.
- For numerical tensors with rank greater than 1, "PackedArray" or "NumericArray" can be used.
Constructors
- "ListVector" objects can be constructed with Typed[{…},"ListVector"::[type]] in compiled code. »
- CreateTypeInstance["ListVector"::[type],carr,len] constructs a "ListVector" from a "CArray" carr with length len. carr can optionally be wrapped in "Managed".
Properties
- Information[list,"ContainedType"] for list of type "ListVector"::[type] gives type.
- Information[list,"ElementType"] for list of type "ListVector"::[type] gives type.
Conversions
- List expressions can be converted to and from "ListVector"::[type] as long as every element of the list can be converted to type.
- "ListVector" objects can be converted to and from "PackedArray" objects.
- "ListVector" objects can be converted to and from "NumericArray" objects.
Expressions
"PackedArray"
"NumericArray"
Examples
open all close allBasic Examples (2)
"ListVector" can be used as input or output for a CompiledCodeFunction:
cf = FunctionCompile[Function[Typed[arg, "ListVector"::["MachineInteger"]], arg]]cf[{1, 2, 3}]Create a "ListVector" in compiled code:
cf = FunctionCompile[Function[Typed[arg, "MachineInteger"],
Typed[{1, 2, arg}, "ListVector"::["MachineInteger"]]
]]cf[12]Scope (3)
"ListVector" objects can contain objects with any compilable type:
cf = FunctionCompile[Function[Typed[rules, "ListVector"::["Rule"::["String", "MachineInteger"]]], First[rules]]]cf[{"hello" -> 1, "world" -> 3}]Higher-rank arrays can be represented with nested "ListVector" instances:
cf = FunctionCompile[Function[Typed[arg, "ListVector"::["ListVector"::["MachineInteger"]]], Catenate[arg]]]cf[{{1, 2, 3}, {4, 5, 6, 7, 8}, {9, 10}}]Get the element type of a "ListVector":
cf = FunctionCompile[Function[Typed[arg, "ListVector"::["Real64"]], Information[arg, "ElementType"]]]cf[{1.2, 4.5, 5.3}]Properties & Relations (1)
The "PackedArray" can be used to represent numerical arrays:
cf = FunctionCompile[Function[Typed[arg, "PackedArray"::["MachineInteger", 1]], First[arg]]]cf[{1, 2, 3, 4, 5}]However, it cannot be used for non-numerical data:
cf = FunctionCompile[Function[Typed[arg, "PackedArray"::["String", 1]], First[arg]]]In contrast, the "ListVector" type can only represent rank-1 lists, but it can have elements with any compilable type:
cf = FunctionCompile[Function[Typed[arg, "ListVector"::["String"]], First[arg]]]cf[{"hello", "to", "the", "world"}]Tech Notes
Related Guides
History
Introduced in 2022 (13.1)