Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

hydra_resolvers_test.py 1.8 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  1. import unittest
  2. from omegaconf import OmegaConf
  3. from super_gradients.common.environment.omegaconf_utils import register_hydra_resolvers
  4. class HydraResolversTest(unittest.TestCase):
  5. def setUp(self) -> None:
  6. register_hydra_resolvers()
  7. def test_add(self):
  8. conf = OmegaConf.create({"a": 1, "b": 2, "c": 3, "a_plus_b": "${add: ${a},${b}}", "a_plus_b_plus_c": "${add: ${a}, ${b}, ${c}}"})
  9. self.assertEqual(conf["a_plus_b"], 3)
  10. self.assertEqual(conf["a_plus_b_plus_c"], 6)
  11. def test_div(self):
  12. conf = OmegaConf.create({"a": 1, "b": 2, "a_div_b": "${div: ${a},${b}}"})
  13. self.assertAlmostEqual(conf["a_div_b"], 0.5)
  14. def test_mul(self):
  15. conf = OmegaConf.create({"a": 1, "b": 2, "c": 4, "a_mul_b": "${mul: ${a},${b}}", "a_mul_b_mul_c": "${mul: ${a}, ${b}, ${c}}"})
  16. self.assertEqual(conf["a_mul_b"], 2)
  17. self.assertEqual(conf["a_mul_b_mul_c"], 8)
  18. def test_list(self):
  19. conf = OmegaConf.create(
  20. {
  21. "my_list": [10, 20, 30, 40, 50],
  22. "third_of_list": "${getitem: ${my_list}, 2}",
  23. "first_of_list": "${first: ${my_list}}",
  24. "last_of_list": "${last: ${my_list}}",
  25. "len_of_list": "${len: ${my_list}}",
  26. }
  27. )
  28. self.assertEqual(conf["third_of_list"], 30)
  29. self.assertEqual(conf["first_of_list"], 10)
  30. self.assertEqual(conf["last_of_list"], 50)
  31. self.assertEqual(conf["len_of_list"], 5)
  32. def test_cond(self):
  33. conf = OmegaConf.create(
  34. {
  35. "boolean": True,
  36. "a": "red_pill",
  37. "b": "blue_pill",
  38. "result": "${cond:${boolean}, ${a}, ${b}}",
  39. }
  40. )
  41. assert conf["result"] == "red_pill"
  42. conf["boolean"] = False
  43. assert conf["result"] == "blue_pill"
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...