本文整理汇总了Python中gauged.structures.FloatArray类的典型用法代码示例。如果您正苦于以下问题:Python FloatArray类的具体用法?Python FloatArray怎么用?Python FloatArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FloatArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_map_append
def test_map_append(self):
v = SparseMap()
s = FloatArray([1, 2, 3])
v.append(1, s)
s.free()
self.assertDictEqual(dict(v.items()), {1: [1, 2, 3]})
v.free()
示例2: test_double_free
def test_double_free(self):
s = FloatArray()
s.free()
s.free()
v = SparseMap()
v.free()
v.free()
示例3: test_array_getitem
def test_array_getitem(self):
s = FloatArray([1, 2, 3])
self.assertEqual(s[0], 1)
self.assertEqual(s[1], 2)
self.assertEqual(s[2], 3)
with self.assertRaises(IndexError):
self.assertEqual(s[3], 0)
s.free()
示例4: test_array_append
def test_array_append(self):
s = FloatArray([1, 2, 3])
s.append(4)
s.append(10)
self.assertEqual(s.byte_length(), 20)
self.assertListEqual(s.values(), [1, 2, 3, 4, 10])
s.free()
示例5: test_array_repr
def test_array_repr(self):
s = FloatArray()
self.assertEqual(str(s), '[]')
s.free()
s = FloatArray([1])
self.assertEqual(str(s), '[1.0]')
s.free()
s = FloatArray([1, 2, 3])
self.assertEqual(str(s), '[1.0, 2.0, 3.0]')
s.free()
示例6: test_array_buffer_offset
def test_array_buffer_offset(self):
s = FloatArray([1, 2, 3])
buf = s.buffer(byte_offset=4)
s.free()
self.assertEqual(len(buf), 8)
copy = FloatArray(buf, 8)
self.assertListEqual(copy.values(), [2, 3])
copy.free()
示例7: test_map_map_from_dict
def test_map_map_from_dict(self):
a = FloatArray([ 1, 2, 3, 4 ])
b = FloatArray([ 2, 4, 6, 8 ])
v = SparseMap({ 1: a, 3: b })
self.assertDictEqual(dict(v.items()), { 1: [1, 2, 3, 4], 3: [2, 4, 6, 8] })
v.free()
a.free()
b.free()
示例8: test_map_clear
def test_map_clear(self):
a = FloatArray([1, 2, 3, 4])
b = FloatArray([2, 4, 6, 8])
v = SparseMap({1: a, 3: b})
a.free()
b.free()
v.clear()
self.assertEqual(v.byte_length(), 0)
v.free()
示例9: test_map_buffer_offset
def test_map_buffer_offset(self):
a = FloatArray([1])
b = FloatArray([1, 2, 3])
v = SparseMap({1: a, 3: b})
buf = v.buffer(byte_offset=8)
a.free()
b.free()
v.free()
copy = SparseMap(buf, len(buf))
self.assertDictEqual(dict(copy.items()), {3: [1, 2, 3]})
copy.free()
示例10: test_map_repr
def test_map_repr(self):
map = SparseMap()
self.assertEqual(str(map), '')
a = FloatArray([1, 2, 3])
map.append(1, a)
b = FloatArray([4])
map.append(2, b)
self.assertEqual(str(map), '[ 1 ] = [1.0, 2.0, 3.0]\n[ 2 ] = [4.0]')
a.free()
b.free()
map.free()
示例11: test_map_import_export
def test_map_import_export(self):
a = FloatArray([ 1, 2, 3, 4 ])
b = FloatArray([ 2, 4, 6, 8 ])
v = SparseMap({ 1: a, 3: b })
buf = v.buffer()
a.free()
b.free()
v.free()
self.assertEqual(len(buf), 40)
copy = SparseMap(buf, len(buf))
self.assertDictEqual(dict(copy.items()), { 1: [1, 2, 3, 4], 3: [2, 4, 6, 8] })
copy.free()
v = SparseMap()
self.assertEqual(v.buffer(), None)
v.free()
示例12: test_use_map_after_free_error
def test_use_map_after_free_error(self):
s = SparseMap()
s.free()
freed_array = FloatArray()
freed_array.free()
tmp_array = FloatArray()
tmp = SparseMap()
with self.assertRaises(GaugedUseAfterFreeError):
s.append(1, tmp_array)
with self.assertRaises(GaugedUseAfterFreeError):
tmp.append(1, freed_array)
with self.assertRaises(GaugedUseAfterFreeError):
s.slice()
with self.assertRaises(GaugedUseAfterFreeError):
s.concat(tmp)
with self.assertRaises(GaugedUseAfterFreeError):
tmp.concat(s)
with self.assertRaises(GaugedUseAfterFreeError):
s.byte_length()
with self.assertRaises(GaugedUseAfterFreeError):
s.buffer()
with self.assertRaises(GaugedUseAfterFreeError):
s.clear()
with self.assertRaises(GaugedUseAfterFreeError):
s.first()
with self.assertRaises(GaugedUseAfterFreeError):
s.last()
with self.assertRaises(GaugedUseAfterFreeError):
s.sum()
with self.assertRaises(GaugedUseAfterFreeError):
s.min()
with self.assertRaises(GaugedUseAfterFreeError):
s.max()
with self.assertRaises(GaugedUseAfterFreeError):
s.mean()
with self.assertRaises(GaugedUseAfterFreeError):
s.stddev()
with self.assertRaises(GaugedUseAfterFreeError):
s.count()
with self.assertRaises(GaugedUseAfterFreeError):
s.percentile(50)
with self.assertRaises(GaugedUseAfterFreeError):
list(s.iteritems())
tmp_array.free()
tmp.free()
示例13: test_array_import_export
def test_array_import_export(self):
s = FloatArray([1, 2, 3])
buf = str(s.buffer())
s.free()
self.assertEqual(len(buf), 12)
copy = FloatArray(buf, 12)
self.assertEqual(copy.values(), [1, 2, 3])
copy.free()
s = FloatArray()
self.assertIsNone(s.buffer())
s.free()
示例14: test_array_import_export_using_buffer
def test_array_import_export_using_buffer(self):
s = FloatArray([1, 2, 3])
buf = buffer(s.buffer())
s.free()
self.assertEqual(len(buf), 12)
copy = FloatArray(buf, 12)
self.assertListEqual(copy.values(), [1, 2, 3])
copy.free()
s = FloatArray()
self.assertEqual(s.buffer(), None)
s.free()
示例15: test_use_array_after_free_error
def test_use_array_after_free_error(self):
s = FloatArray()
s.free()
with self.assertRaises(GaugedUseAfterFreeError):
len(s)
with self.assertRaises(GaugedUseAfterFreeError):
s.values()
with self.assertRaises(GaugedUseAfterFreeError):
s.values()
with self.assertRaises(GaugedUseAfterFreeError):
s.append(1)
with self.assertRaises(GaugedUseAfterFreeError):
s.byte_length()
with self.assertRaises(GaugedUseAfterFreeError):
s.buffer()
with self.assertRaises(GaugedUseAfterFreeError):
s.clear()