diff options
author | Przemyslaw Szczepaniak <pszczepaniak@google.com> | 2018-12-19 12:07:03 +0000 |
---|---|---|
committer | Slava Shklyaev <slavash@google.com> | 2019-01-08 18:21:31 +0000 |
commit | b03e63de9095e58b74210818564cb415e6429ba4 (patch) | |
tree | 9ccd6e5788cfe546b005c73057e566e773ea65ea /nn/runtime/test/TestValidation.cpp | |
parent | 591884569b2774ac06eab0593a463c2a3512b77e (diff) | |
download | ml-b03e63de9095e58b74210818564cb415e6429ba4.tar.gz |
Replace ANNOperandType::ExtraParams with a function call.
Exending ANeuralNetworkOperandType struct with new fields may be problematic
and difficult to maintain in longer term. This change turns recently introduced
ANNOperandType.extraParams field into a function call:
ANeuralNetworksModel_setOperandSymmPerChannelQuant(...)
that associates ANeuralNetworksSymmPerChannelQuant struct with an operand.
+ added to NeuralNetworks.h an ANDROID_Q ifdef for operand types added in Q.
Bug: 119249581
Test: NeuralNetworksTest_static
Change-Id: Idebe86ce1ca8f3a31dbfe7b21de4dd45df380a38
Diffstat (limited to 'nn/runtime/test/TestValidation.cpp')
-rw-r--r-- | nn/runtime/test/TestValidation.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/nn/runtime/test/TestValidation.cpp b/nn/runtime/test/TestValidation.cpp index f3f557e91..5273725e5 100644 --- a/nn/runtime/test/TestValidation.cpp +++ b/nn/runtime/test/TestValidation.cpp @@ -177,6 +177,34 @@ TEST_F(ValidationTestModel, AddOperand) { ANEURALNETWORKS_BAD_STATE); } +TEST_F(ValidationTestModel, SetOperandSymmPerChannelQuantParams) { + uint32_t dim = 2; + + ANeuralNetworksOperandType quant8SymmPerChannel{ + .type = ANEURALNETWORKS_TENSOR_QUANT8_SYMM_PER_CHANNEL, + .dimensionCount = 1, + .dimensions = &dim, + .scale = 0.0f, + .zeroPoint = 0, + }; + EXPECT_EQ(ANeuralNetworksModel_addOperand(mModel, &quant8SymmPerChannel), + ANEURALNETWORKS_NO_ERROR); + + float scale = 1.0f; + ANeuralNetworksSymmPerChannelQuantParams channelQuant{ + .channelDim = 0, + .scaleCount = 1, + .scales = &scale, + }; + + EXPECT_EQ(ANeuralNetworksModel_setOperandSymmPerChannelQuantParams(nullptr, 0, &channelQuant), + ANEURALNETWORKS_UNEXPECTED_NULL); + EXPECT_EQ(ANeuralNetworksModel_setOperandSymmPerChannelQuantParams(mModel, 0, nullptr), + ANEURALNETWORKS_UNEXPECTED_NULL); + EXPECT_EQ(ANeuralNetworksModel_setOperandSymmPerChannelQuantParams(mModel, 100, &channelQuant), + ANEURALNETWORKS_BAD_DATA); +} + TEST_F(ValidationTestModel, SetOptionalOperand) { ANeuralNetworksOperandType floatType{ .type = ANEURALNETWORKS_FLOAT32, .dimensionCount = 0, .dimensions = nullptr}; |