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

Method test_get_key

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

Source from the content-addressed store, hash-verified

2389 )
2390
2391 def test_get_key(self):
2392 def _is_id_list(input_record):
2393 return almost_equal_schemas(input_record, IdList)
2394
2395
2396 def _is_id_score_list(input_record):
2397 return almost_equal_schemas(input_record,
2398 IdScoreList,
2399 check_field_types=False)
2400
2401 def old_get_sparse_key_logic(input_record):
2402 if _is_id_list(input_record):
2403 sparse_key = input_record.items()
2404 elif _is_id_score_list(input_record):
2405 sparse_key = input_record.keys()
2406 else:
2407 raise NotImplementedError()
2408 return sparse_key
2409
2410 id_score_list_record = schema.NewRecord(
2411 self.model.net,
2412 schema.Map(
2413 schema.Scalar(
2414 np.int64,
2415 metadata=schema.Metadata(
2416 categorical_limit=1000
2417 ),
2418 ),
2419 np.float32
2420 )
2421 )
2422
2423 self.assertEqual(
2424 get_key(id_score_list_record)(),
2425 old_get_sparse_key_logic(id_score_list_record)
2426 )
2427
2428 id_list_record = schema.NewRecord(
2429 self.model.net,
2430 schema.List(
2431 schema.Scalar(
2432 np.int64,
2433 metadata=schema.Metadata(categorical_limit=1000)
2434 )
2435 )
2436 )
2437
2438 self.assertEqual(
2439 get_key(id_list_record)(),
2440 old_get_sparse_key_logic(id_list_record)
2441 )
2442
2443 def testSparseLookupWithAttentionWeightOnIdScoreList(self):
2444 record = schema.NewRecord(

Callers

nothing calls this directly

Calls 2

get_keyFunction · 0.90
assertEqualMethod · 0.45

Tested by

no test coverage detected