Ejemplo n.º 1
0
 def test_key_with_slash(self):
     s = Schema()
     s["normal/path"] = DataType.float64(1)
     s.add_child("child_with_/_inside").set(DataType.float64(1))
     print(s)
     self.assertTrue(s.has_path("normal/path"))
     self.assertFalse(s.has_child("normal/path"))
     self.assertFalse(s.has_path("child_with_/_inside"))
     self.assertTrue(s.has_child("child_with_/_inside"))
     self.assertEqual(2,s.number_of_children())
     self.assertEqual(s.child(1).dtype().id(),DataType.float64().id())
     self.assertEqual(s.child(name="child_with_/_inside").dtype().id(),DataType.float64().id())
     s["normal"].remove_child("path")
     self.assertFalse(s.has_path("normal/path"))
Ejemplo n.º 2
0
 def test_schema_remove(self):
     s = Schema()
     s['a'] = DataType.float64(1)
     s['b'] = DataType.float64(1)
     s['c'] = DataType.float64(1)
     self.assertEqual(s.number_of_children(), 3)
     s.remove(path='c')
     self.assertEqual(s.number_of_children(), 2)
     paths = s.child_names()
     for v in ['a', 'b']:
         self.assertTrue(v in paths)
     s.remove(index=0)
     paths = s.child_names()
     for v in ['b']:
         self.assertTrue(v in paths)
Ejemplo n.º 3
0
 def test_constructor_helpers(self):
     # objs
     print(DataType.empty())
     print(DataType.object())
     print(DataType.list())
     # signed integers
     print(DataType.int8())
     print(DataType.int16())
     print(DataType.int32())
     print(DataType.int64())
     # unsigned integers
     print(DataType.uint8())
     print(DataType.uint16())
     print(DataType.uint32())
     print(DataType.uint64())
     # floating point
     print(DataType.float32())
     print(DataType.float64())
     # signed integers
     print(DataType.c_char())
     print(DataType.c_short())
     print(DataType.c_int())
     print(DataType.c_long())
     # unsigned integers
     print(DataType.c_unsigned_char())
     print(DataType.c_unsigned_short())
     print(DataType.c_unsigned_int())
     print(DataType.c_unsigned_long())
     # floating point
     print(DataType.c_float())
     print(DataType.c_double())
Ejemplo n.º 4
0
 def test_constructor_helpers(self):
     # objs
     print(DataType.empty());
     print(DataType.object());
     print(DataType.list());
     # signed integers
     print(DataType.int8());
     print(DataType.int16());
     print(DataType.int32());
     print(DataType.int64());
     # unsigned integers
     print(DataType.uint8());
     print(DataType.uint16());
     print(DataType.uint32());
     print(DataType.uint64());
     # floating point
     print(DataType.float32());
     print(DataType.float64());
     # signed integers
     print(DataType.c_char());
     print(DataType.c_short());
     print(DataType.c_int());
     print(DataType.c_long());
     # unsigned integers
     print(DataType.c_unsigned_char());
     print(DataType.c_unsigned_short());
     print(DataType.c_unsigned_int());
     print(DataType.c_unsigned_long());
     # floating point
     print(DataType.c_float());
     print(DataType.c_double());
Ejemplo n.º 5
0
 def test_create_node_using_schema_object(self):
     s = Schema()
     s["a"] = DataType.float64(10)
     s["b"] = DataType.float32(10)
     n = Node()
     n.set(s)
     sr = n.schema()
     self.assertEqual(sr.total_strided_bytes(), 8 * 10 + 4 * 10)
     self.assertEqual(sr["a"].total_strided_bytes(), 8 * 10)
     self.assertEqual(sr["b"].total_strided_bytes(), 4 * 10)
Ejemplo n.º 6
0
 def test_create_node_using_schema_object(self):
     s = Schema()
     s["a"] = DataType.float64(10)
     s["b"] = DataType.float32(10)
     n = Node()
     n.set(s)
     sr = n.schema()
     self.assertEqual(sr.total_strided_bytes(), 8 * 10 + 4 * 10)
     self.assertEqual(sr["a"].total_strided_bytes(),8 * 10)
     self.assertEqual(sr["b"].total_strided_bytes(),4 * 10)
Ejemplo n.º 7
0
    def test_to_string_and_friends(self):
        dtypes = [ DataType.float64(),
                   DataType.object(),
                   DataType.list(),
                   DataType.empty()]

        for d in dtypes:
            print("yaml rep")
            print(d.to_string("yaml"))

            print("json rep")
            print(d.to_string("json"))

            self.assertEqual(d.to_string("yaml"),d.to_yaml())
            self.assertEqual(d.to_string("json"),d.to_json())
Ejemplo n.º 8
0
 def test_enum_ids(self):
     # objs
     self.assertEqual(DataType.empty().id(), DataType.empty_id())
     self.assertEqual(DataType.object().id(), DataType.object_id())
     self.assertEqual(DataType.list().id(), DataType.list_id())
     # signed integers
     self.assertEqual(DataType.int8().id(), DataType.int8_id())
     self.assertEqual(DataType.int16().id(), DataType.int16_id())
     self.assertEqual(DataType.int32().id(), DataType.int32_id())
     self.assertEqual(DataType.int64().id(), DataType.int64_id())
     # unsigned integers
     self.assertEqual(DataType.uint8().id(), DataType.uint8_id())
     self.assertEqual(DataType.uint16().id(), DataType.uint16_id())
     self.assertEqual(DataType.uint32().id(), DataType.uint32_id())
     self.assertEqual(DataType.uint64().id(), DataType.uint64_id())
     # floating point
     self.assertEqual(DataType.float32().id(), DataType.float32_id())
     self.assertEqual(DataType.float64().id(), DataType.float64_id())
Ejemplo n.º 9
0
    def test_schema_child_rename(self):
        s = Schema()
        with self.assertRaises(Exception):
            s.rename_child('a', 'b')
        s["a"] = DataType.float64(10)
        s["b"] = DataType.float32(10)

        with self.assertRaises(Exception):
            s.rename_child('bad', 'good')

        with self.assertRaises(Exception):
            s.rename_child('b', 'a')

        s.rename_child("b", "c")
        n = Node()
        n.set(s)
        sr = n.schema()
        self.assertEqual(sr.total_strided_bytes(), 8 * 10 + 4 * 10)
        self.assertEqual(sr["a"].total_strided_bytes(), 8 * 10)
        self.assertEqual(sr["c"].total_strided_bytes(), 4 * 10)
Ejemplo n.º 10
0
 def test_hdf5_generic_save_opts(self):
     # only run if we have hdf5
     if not relay.about()["io/protocols/hdf5"] == "enabled":
         return
     # 5k float64 zeros, will compress well, but below default
     # thresh
     n = Node()
     opts = Node()
     opts["hdf5/chunking/threshold"] = 2000
     opts["hdf5/chunking/chunk_size"] = 2000
     # hdf5 requires object at top level ...
     n['value'].set(DataType.float64(5000))
     tout_std = "tout_python_relay_io_hdf5_generic_std.hdf5"
     tout_cmp = "tout_python_relay_io_hdf5_generic_cmp.hdf5"
     relay.io.save(n, tout_std)
     relay.io.save(n, tout_cmp, options=opts)
     tout_std_fs = os.path.getsize(tout_std)
     tout_std_cmp = os.path.getsize(tout_cmp)
     self.assertTrue(os.path.isfile(tout_std))
     self.assertTrue(os.path.isfile(tout_cmp))
     print("fs compare: std = ", tout_std_fs, " cmp = ", tout_std_cmp)
     self.assertTrue(tout_std_cmp < tout_std_fs)
Ejemplo n.º 11
0
 def test_is_checks(self):
     # objs
     edt = DataType.empty()
     self.assertEqual(edt.name(), "empty")
     self.assertTrue(edt.is_empty())
     # lots of false checks anchored from empty
     self.assertFalse(edt.is_object())
     self.assertFalse(edt.is_list())
     #
     self.assertFalse(edt.is_number())
     self.assertFalse(edt.is_floating_point())
     self.assertFalse(edt.is_integer())
     self.assertFalse(edt.is_signed_integer())
     self.assertFalse(edt.is_unsigned_integer())
     #
     self.assertFalse(edt.is_int8())
     self.assertFalse(edt.is_int16())
     self.assertFalse(edt.is_int32())
     self.assertFalse(edt.is_int64())
     #
     self.assertFalse(edt.is_uint8())
     self.assertFalse(edt.is_uint16())
     self.assertFalse(edt.is_uint32())
     self.assertFalse(edt.is_uint64())
     #
     self.assertFalse(edt.is_float32())
     self.assertFalse(edt.is_float64())
     #
     self.assertFalse(edt.is_char())
     self.assertFalse(edt.is_short())
     self.assertFalse(edt.is_int())
     self.assertFalse(edt.is_long())
     self.assertFalse(edt.is_long_long())
     #
     self.assertFalse(edt.is_signed_char())
     self.assertFalse(edt.is_signed_short())
     self.assertFalse(edt.is_signed_int())
     self.assertFalse(edt.is_signed_long())
     self.assertFalse(edt.is_signed_long_long())
     #
     self.assertFalse(edt.is_unsigned_char())
     self.assertFalse(edt.is_unsigned_short())
     self.assertFalse(edt.is_unsigned_int())
     self.assertFalse(edt.is_unsigned_long())
     self.assertFalse(edt.is_unsigned_long_long())
     #
     self.assertFalse(edt.is_float())
     self.assertFalse(edt.is_double())
     self.assertFalse(edt.is_long_double())
     #
     self.assertFalse(edt.is_string())
     self.assertFalse(edt.is_char8_str())
     #
     self.assertFalse(edt.is_index_t())
     #
     self.assertFalse(DataType.object().is_empty())
     #############
     #
     self.assertTrue(DataType.object().is_object())
     self.assertTrue(DataType.list().is_list())
     # signed integers
     self.assertTrue(DataType.int8().is_number())
     self.assertTrue(DataType.int8().is_integer())
     self.assertTrue(DataType.int8().is_signed_integer())
     self.assertFalse(DataType.int8().is_unsigned_integer())
     self.assertFalse(DataType.int8().is_floating_point())
     self.assertTrue(DataType.int8().is_int8())
     self.assertTrue(DataType.int16().is_int16())
     self.assertTrue(DataType.int32().is_int32())
     self.assertTrue(DataType.int64().is_int64())
     # unsigned integers
     self.assertTrue(DataType.uint8().is_uint8())
     self.assertTrue(DataType.uint8().is_number())
     self.assertTrue(DataType.uint8().is_integer())
     self.assertFalse(DataType.uint8().is_signed_integer())
     self.assertTrue(DataType.uint8().is_unsigned_integer())
     self.assertFalse(DataType.uint8().is_floating_point())
     #
     self.assertTrue(DataType.uint16().is_uint16())
     self.assertTrue(DataType.uint32().is_uint32())
     self.assertTrue(DataType.uint64().is_uint64())
     # floating point
     self.assertTrue(DataType.float32().is_number())
     self.assertTrue(DataType.float32().is_floating_point())
     self.assertTrue(DataType.float32().is_float32())
     self.assertTrue(DataType.float64().is_float64())
     # c style integers
     self.assertTrue(DataType.c_char().is_char())
     self.assertTrue(DataType.c_short().is_short())
     self.assertTrue(DataType.c_int().is_int())
     self.assertTrue(DataType.c_long().is_long())
     self.assertFalse(DataType.c_char().is_long_long())
     # c style unsigned integers
     self.assertTrue(DataType.c_unsigned_char().is_unsigned_char())
     self.assertTrue(DataType.c_unsigned_short().is_unsigned_short())
     self.assertTrue(DataType.c_unsigned_int().is_unsigned_int())
     self.assertTrue(DataType.c_unsigned_long().is_unsigned_long())
     # floating point
     self.assertTrue(DataType.c_float().is_float())
     self.assertTrue(DataType.c_double().is_double())
     # string
     self.assertTrue(DataType.char8_str().is_string())
     self.assertTrue(DataType.char8_str().is_char8_str())
     # index_t
     self.assertTrue(DataType.index_t().is_index_t())