Commit 8f9bd20e authored by olivier R-D's avatar olivier R-D

get_dimensions => get_shape

parent a7a4acb1
...@@ -736,7 +736,7 @@ class Variant(FrozenClass): ...@@ -736,7 +736,7 @@ class Variant(FrozenClass):
if self.VariantType is None: if self.VariantType is None:
self.VariantType = self._guess_type(self.Value) self.VariantType = self._guess_type(self.Value)
if self.Dimensions is None and type(self.Value) in (list, tuple): if self.Dimensions is None and type(self.Value) in (list, tuple):
dims = get_dimensions(self.Value) dims = get_shape(self.Value)
if len(dims) > 1: if len(dims) > 1:
self.Dimensions = dims self.Dimensions = dims
...@@ -832,7 +832,7 @@ def _split_list(l, n): ...@@ -832,7 +832,7 @@ def _split_list(l, n):
return [l[i:i + n] for i in range(0, len(l), n)] return [l[i:i + n] for i in range(0, len(l), n)]
def flatten_and_get_dimensions(mylist): def flatten_and_get_shape(mylist):
dims = [] dims = []
dims.append(len(mylist)) dims.append(len(mylist))
while isinstance(mylist[0], (list, tuple)): while isinstance(mylist[0], (list, tuple)):
...@@ -853,7 +853,7 @@ def flatten(mylist): ...@@ -853,7 +853,7 @@ def flatten(mylist):
return mylist return mylist
def get_dimensions(mylist): def get_shape(mylist):
dims = [] dims = []
while isinstance(mylist, (list, tuple)): while isinstance(mylist, (list, tuple)):
dims.append(len(mylist)) dims.append(len(mylist))
......
...@@ -22,7 +22,7 @@ from opcua.ua import ObjectIds ...@@ -22,7 +22,7 @@ from opcua.ua import ObjectIds
from opcua.ua import AttributeIds from opcua.ua import AttributeIds
from opcua.ua import extensionobject_from_binary from opcua.ua import extensionobject_from_binary
from opcua.ua import extensionobject_to_binary from opcua.ua import extensionobject_to_binary
from opcua.ua.uatypes import flatten, get_dimensions, reshape from opcua.ua.uatypes import flatten, get_shape, reshape
port_num1 = 48510 port_num1 = 48510
port_num2 = 48530 port_num2 = 48530
...@@ -115,7 +115,7 @@ class Unit(unittest.TestCase): ...@@ -115,7 +115,7 @@ class Unit(unittest.TestCase):
def test_flatten(self): def test_flatten(self):
l = [[[1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0]],[[1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0]]] l = [[[1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0]],[[1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0]]]
l2 = flatten(l) l2 = flatten(l)
dims = get_dimensions(l) dims = get_shape(l)
self.assertEqual(dims, [2, 3, 4]) self.assertEqual(dims, [2, 3, 4])
self.assertNotEqual(l, l2) self.assertNotEqual(l, l2)
...@@ -125,12 +125,12 @@ class Unit(unittest.TestCase): ...@@ -125,12 +125,12 @@ class Unit(unittest.TestCase):
l = [[[], [], []], [[], [], []]] l = [[[], [], []], [[], [], []]]
l2 = flatten(l) l2 = flatten(l)
dims = get_dimensions(l) dims = get_shape(l)
self.assertEqual(dims, [2, 3, 0]) self.assertEqual(dims, [2, 3, 0])
l = [1, 2, 3, 4] l = [1, 2, 3, 4]
l2 = flatten(l) l2 = flatten(l)
dims = get_dimensions(l) dims = get_shape(l)
self.assertEqual(dims, [4]) self.assertEqual(dims, [4])
self.assertEqual(l, l2) self.assertEqual(l, l2)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment