MCPcopy Create free account
hub / github.com/pytorch/pytorch / testMapToRange

Method testMapToRange

caffe2/python/layers_test.py:1300–1366  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1298 )
1299
1300 def testMapToRange(self):
1301 input_record = self.new_record(schema.Scalar(np.int32))
1302 indices_blob = self.model.MapToRange(input_record,
1303 max_index=100).indices
1304 self.model.output_schema = schema.Struct()
1305
1306 train_init_net, train_net = self.get_training_nets()
1307
1308 schema.FeedRecord(
1309 input_record,
1310 [np.array([10, 3, 20, 99, 15, 11, 3, 11], dtype=np.int32)]
1311 )
1312 workspace.RunNetOnce(train_init_net)
1313 workspace.RunNetOnce(train_net)
1314 indices = workspace.FetchBlob(indices_blob())
1315 np.testing.assert_array_equal(
1316 np.array([1, 2, 3, 4, 5, 6, 2, 6], dtype=np.int32),
1317 indices
1318 )
1319
1320 schema.FeedRecord(
1321 input_record,
1322 [np.array([10, 3, 23, 35, 60, 15, 10, 15], dtype=np.int32)]
1323 )
1324 workspace.RunNetOnce(train_net)
1325 indices = workspace.FetchBlob(indices_blob())
1326 np.testing.assert_array_equal(
1327 np.array([1, 2, 7, 8, 9, 5, 1, 5], dtype=np.int32),
1328 indices
1329 )
1330
1331 eval_net = self.get_eval_net()
1332
1333 schema.FeedRecord(
1334 input_record,
1335 [np.array([10, 3, 23, 35, 60, 15, 200], dtype=np.int32)]
1336 )
1337 workspace.RunNetOnce(eval_net)
1338 indices = workspace.FetchBlob(indices_blob())
1339 np.testing.assert_array_equal(
1340 np.array([1, 2, 7, 8, 9, 5, 0], dtype=np.int32),
1341 indices
1342 )
1343
1344 schema.FeedRecord(
1345 input_record,
1346 [np.array([10, 3, 23, 15, 101, 115], dtype=np.int32)]
1347 )
1348 workspace.RunNetOnce(eval_net)
1349 indices = workspace.FetchBlob(indices_blob())
1350 np.testing.assert_array_equal(
1351 np.array([1, 2, 7, 5, 0, 0], dtype=np.int32),
1352 indices
1353 )
1354
1355 predict_net = self.get_predict_net()
1356
1357 schema.FeedRecord(

Callers

nothing calls this directly

Calls 4

new_recordMethod · 0.80
get_training_netsMethod · 0.80
get_eval_netMethod · 0.80
get_predict_netMethod · 0.80

Tested by

no test coverage detected