def test_flatten(): 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) dims = get_shape(l) assert [2, 3, 4] == dims assert l != l2 l3 = _reshape(l2, (2, 3, 4)) assert l == l3 l = [[[], [], []], [[], [], []]] l2 = flatten(l) dims = get_shape(l) assert dims == [2, 3, 0] l = [1, 2, 3, 4] l2 = flatten(l) dims = get_shape(l) assert dims == [4] assert l == l2
def variant_to_binary(var): encoding = var.VariantType.value & 0b0011_1111 if var.is_array or isinstance(var.Value, (list, tuple)): body = pack_uatype_array(var.VariantType, ua.flatten(var.Value)) if var.Dimensions is None: encoding |= 0b1000_0000 else: encoding |= 0b1100_0000 body += pack_uatype_array(ua.VariantType.Int32, var.Dimensions) else: body = pack_uatype(var.VariantType, var.Value) return Primitives.Byte.pack(encoding) + body
def variant_to_binary(var): b = [] encoding = var.VariantType.value & 0b111111 if var.is_array or isinstance(var.Value, (list, tuple)): encoding = set_bit(encoding, 7) if var.Dimensions is not None: encoding = set_bit(encoding, 6) b.append(Primitives.Byte.pack(encoding)) b.append(pack_uatype_array(var.VariantType, ua.flatten(var.Value))) if var.Dimensions is not None: b.append(pack_uatype_array(ua.VariantType.Int32, var.Dimensions)) else: b.append(Primitives.Byte.pack(encoding)) b.append(pack_uatype(var.VariantType, var.Value)) return b"".join(b)