constant<T extends SizedNativeType> function
VARP
constant<T extends SizedNativeType>(
- Iterable<
num> data, - Iterable<
int> shape, { - DimensionFormat format = DimensionFormat.NHWC,
create a constant variable.
Args:
- data: Indicates the values.
- shape: A vector, the shape of the variable.
- format: A enum, NCHW/NHWC/NC4HW4 is allowed.
- type: The type of the elements of the resulting variable.
Returns:
- output: A constant variable.
Implementation
VARP constant<T extends ffi.SizedNativeType>(
Iterable<num> data,
Iterable<int> shape, {
DimensionFormat format = DimensionFormat.NHWC,
}) {
final nElem = shape.reduce((a, b) => a * b);
MnnAssert(
data.length == nElem,
'data.length=${data.length} must be equal to the dot product of shape=$nElem',
);
final pdata = HalideType.of<T>().pointerOf(data);
final pshape = HalideType.of<int32>().pointerOf(shape);
final pvar = C.mnn_expr_Const(
pdata.cast(),
pshape.cast(),
shape.length,
format.value,
HalideType.of<T>().native.ref,
);
// memories of pdata will be copied internally, so here we need to free them
calloc.free(pdata);
calloc.free(pshape);
return VARP.fromPointer(pvar);
}