return ANEURALNETWORKS_BAD_STATE;
}
- // ASSUME A tensor operand always consists of fp32 values
- // NOTE We do not care about scala operands.
- assert(!(type->dimensionCount > 1) || (type->type == 3 /* ANEURALNETWORKS_TENSOR_FLOAT32 */));
+ // ASSUME A tensor operand should consists of fp32 or int32 values.
+ // NOTE We do not care about scalar operands.
+ assert((type->dimensionCount == 0) || (type->type == ANEURALNETWORKS_TENSOR_FLOAT32 ||
+ type->type == ANEURALNETWORKS_TENSOR_INT32 ||
+ type->type == ANEURALNETWORKS_TENSOR_QUANT8_ASYMM));
+
+ // scale and zeroPoint should be zero for scalars and non-fixed point tensors
+ // Quantized:
+ // scale: a 32 bit floating point value greater than zero
+ // zeroPoint: a 32 bit integer, in range [0, 255]
+ if (type->type == ANEURALNETWORKS_TENSOR_QUANT8_ASYMM)
+ {
+ if (!(type->scale > 0.0f))
+ {
+ return ANEURALNETWORKS_BAD_DATA;
+ }
+
+ if ((type->zeroPoint < 0) || (type->zeroPoint > 255))
+ {
+ return ANEURALNETWORKS_BAD_DATA;
+ }
+ }
+ else if ((type->scale != 0.0f) || (type->zeroPoint != 0))
+ {
+ return ANEURALNETWORKS_BAD_DATA;
+ }
+
+ // dimensionCount should be zero for scalars
+ if ((type->dimensionCount != 0) &&
+ ((type->type == ANEURALNETWORKS_FLOAT32) | (type->type == ANEURALNETWORKS_INT32) ||
+ (type->type == ANEURALNETWORKS_UINT32)))
+ {
+ return ANEURALNETWORKS_BAD_DATA;
+ }
internal::tflite::operand::Shape shape(type->dimensionCount);