| 177 | class ModuleWrongInputTest : public MNNTestCase { |
| 178 | public: |
| 179 | virtual bool run(int precision) { |
| 180 | auto executor = cloneCurrentExecutor(); |
| 181 | ExecutorScope scope(executor); |
| 182 | std::vector<int8_t> buffer; |
| 183 | // construct |
| 184 | { |
| 185 | auto x = _Input({1, 3, 5, 7}, NCHW, halide_type_of<int>()); |
| 186 | x->setName("data"); |
| 187 | auto x1 = _Input({1, 3, 5, 7}, NCHW, halide_type_of<int>()); |
| 188 | x1->setName("data1"); |
| 189 | auto y = x + x1; |
| 190 | y->setName("o0"); |
| 191 | auto y1 = x - x1; |
| 192 | y1->setName("o1"); |
| 193 | buffer = Variable::save({y, y1}); |
| 194 | } |
| 195 | // Execute |
| 196 | std::shared_ptr<Module> refModule(Module::load({"data", "data1"}, {"o0", "o1"}, (const uint8_t*)buffer.data(), buffer.size()), Module::destroy); |
| 197 | auto _runModuleTest = [&refModule](int number) { |
| 198 | auto x = _Input({1, 3, 5, 7}, NCHW, halide_type_of<int>()); |
| 199 | auto x1 = _Input({1, 3, 5, 7}, NCHW, halide_type_of<int>()); |
| 200 | auto xPtr = x->writeMap<int>(); |
| 201 | auto x1Ptr = x1->writeMap<int>(); |
| 202 | for (int i=0; i<x->getInfo()->size; ++i) { |
| 203 | xPtr[i] = i; |
| 204 | x1Ptr[i] = i + 1; |
| 205 | } |
| 206 | std::vector<VARP> y; |
| 207 | if (2 == number) { |
| 208 | y = refModule->onForward({x, x1}); |
| 209 | } else { |
| 210 | y = refModule->onForward({x, x1, x1}); |
| 211 | } |
| 212 | auto y0Ptr = y[0]->readMap<int>(); |
| 213 | auto y1Ptr = y[1]->readMap<int>(); |
| 214 | for (int i=0; i<x->getInfo()->size; ++i) { |
| 215 | if (y0Ptr[i] != i * 2 + 1) { |
| 216 | FUNC_PRINT(1); |
| 217 | return false; |
| 218 | } |
| 219 | if (y1Ptr[i] != -1) { |
| 220 | FUNC_PRINT(1); |
| 221 | return false; |
| 222 | } |
| 223 | } |
| 224 | return true; |
| 225 | }; |
| 226 | auto res = _runModuleTest(2); |
| 227 | if (!res) { |
| 228 | FUNC_PRINT(1); |
| 229 | return false; |
| 230 | } |
| 231 | refModule.reset(Module::load({"data", "data1", "data2"}, {"o0", "o1"}, (const uint8_t*)buffer.data(), buffer.size()), Module::destroy); |
| 232 | res = _runModuleTest(3); |
| 233 | if (!res) { |
| 234 | FUNC_PRINT(1); |
| 235 | return false; |
| 236 | } |