MCPcopy Create free account
hub / github.com/apple/coremltools / testInvalidDefaultOptionalValue

Function testInvalidDefaultOptionalValue

mlmodel/tests/NNValidatorTests.cpp:195–246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

193}
194
195int testInvalidDefaultOptionalValue() {
196
197 Specification::Model m;
198
199 auto *in1 = m.mutable_description()->add_input();
200 in1->set_name("input1");
201 auto *inShape1 = in1->mutable_type()->mutable_multiarraytype();
202 inShape1->set_datatype(Specification::ArrayFeatureType::ArrayDataType::ArrayFeatureType_ArrayDataType_FLOAT32);
203
204 inShape1->add_shape(3);
205 inShape1->add_shape(5);
206 inShape1->add_shape(2);
207
208 auto *in2 = m.mutable_description()->add_input();
209 in2->set_name("input2");
210 auto type = in2->mutable_type();
211 type->set_isoptional(true);
212 auto arr = type->mutable_multiarraytype();
213 arr->set_datatype(Specification::ArrayFeatureType::ArrayDataType::ArrayFeatureType_ArrayDataType_INT32);
214 arr->set_floatdefaultvalue(2.0);
215 arr->add_shape(3);
216 arr->add_shape(5);
217 arr->add_shape(2);
218
219 auto *out = m.mutable_description()->add_output();
220 out->set_name("output");
221 auto *outShape = out->mutable_type()->mutable_multiarraytype();
222 outShape->add_shape(3);
223 outShape->add_shape(5);
224 outShape->add_shape(1);
225
226 const auto nn = m.mutable_neuralnetwork();
227 nn->set_arrayinputshapemapping(Specification::NeuralNetworkMultiArrayShapeMapping::EXACT_ARRAY_MAPPING);
228
229 auto *layers = nn->add_layers();
230 layers->add_input("input1");
231 layers->add_input("input2");
232 layers->add_output("output");
233 layers->add_inputtensor()->set_rank(3);
234 layers->add_inputtensor()->set_rank(3);
235
236 auto *params = layers->mutable_stack();
237 params->set_axis(2);
238
239 m.set_specificationversion(4);
240 // axis should be in range [-(rank + 1), rank + 1)
241 Result res = Model::validate(m);
242 ML_ASSERT_BAD(res);
243 ML_ASSERT(res.message().find("mistmatch between dataType and the type") != std::string::npos);
244
245 return 0;
246}
247
248int testDefaultOptionalValueZeroIfNotSet() {
249

Callers

nothing calls this directly

Calls 3

validateFunction · 0.85
set_nameMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected