return ANEURALNETWORKS_BAD_DATA;
}
}
+
+ // TODO-NNRT : add 'type.type == ANEURALNETWORKS_OEM_SCALAR' later.
+ // OEM operaters are not supported now.
+ if (type.type == ANEURALNETWORKS_FLOAT32 ||
+ type.type == ANEURALNETWORKS_INT32 ||
+ type.type == ANEURALNETWORKS_UINT32) {
+ if (type.dimensionCount != 0 || type.dimensions != nullptr) {
+ LOG(ERROR) << tag << " Invalid dimensions for scalar type";
+ return ANEURALNETWORKS_BAD_DATA;
+ }
+ }
+
return ANEURALNETWORKS_NO_ERROR;
}
int ModelArgumentInfo::setFromPointer(const Operand& operand,
const ANeuralNetworksOperandType* type, void* data,
uint32_t length) {
- int n = updateDimensionInfo(operand, type);
- if (n != ANEURALNETWORKS_NO_ERROR) {
- return n;
+ if ((data == nullptr) != (length == 0)) {
+ LOG(ERROR) << "Data pointer must be nullptr if and only if length is zero (data = "
+ << data << ", length = " << length << ")";
+ return ANEURALNETWORKS_BAD_DATA;
}
if (data == nullptr) {
- if (length) {
- LOG(ERROR) << "Setting argument as having no value but non-zero length passed.";
- return ANEURALNETWORKS_BAD_DATA;
- }
state = ModelArgumentInfo::HAS_NO_VALUE;
} else {
+ int n = updateDimensionInfo(operand, type);
+ if (n != ANEURALNETWORKS_NO_ERROR) {
+ return n;
+ }
+ uint32_t neededLength = sizeOfData(operand.type, dimensions);
+ if (operand.type != OperandType::OEM && neededLength != length) {
+ LOG(ERROR) << "Setting argument with invalid length: " << length
+ << ", expected length: " << neededLength;
+ return ANEURALNETWORKS_BAD_DATA;
+ }
state = ModelArgumentInfo::POINTER;
}
buffer = data;