Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[PyOV] Transposed packing of `u3` and `u6` types (#33349)

Przemyslaw Wysocki3f8df6989692
diff --git a/src/bindings/python/src/openvino/helpers/packing.py b/src/bindings/python/src/openvino/helpers/packing.py
index 1ad36df061e..f85a84bfd0e 100644
--- a/src/bindings/python/src/openvino/helpers/packing.py
+++ b/src/bindings/python/src/openvino/helpers/packing.py
@@ -9,7 +9,11 @@ from openvino import Type, Shape
def pack_data(array: np.ndarray, type: Type) -> np.ndarray:
- """Represent array values as u1, u2, u4 or i4 openvino element type and pack them into uint8 numpy array.
+ """Represent array values as u1, u2, u3, u4, u6 or i4 openvino element type and pack them into uint8 numpy array.
+
+ For u1, u4, i4: Standard bit packing where 8 % bitwidth == 0
+ For u3: Transposed packing - 8 values in 3 bytes
+ For u6: Transposed packing - 4 values in 3 bytes
If the number of elements in array is odd we pad them with zero value to be able to fit the bit
sequence into the uint8 array.
@@ -20,9 +24,15 @@ def pack_data(array: np.ndarray, type: Type) -> np.ndarray:
:param array: numpy array with values to pack.
:type array: numpy array
- :param type: Type to interpret the array values. Type must be u1, u2, u4, i4, nf4 or f4e2m1.
+ :param type: Type to interpret the array values. Type must be u1, u2, u3, u4, u6, i4, nf4 or f4e2m1.
:type type: openvino.Type
"""
+ # Handle u3 and u6 with special transposed packing
+ if type == Type.u3:
+ return _pack_u3(array)
+ elif type == Type.u6:
+ return _pack_u6(array)
+
assert type in [Type.u1, Type.u2, Type.u4, Type.i4, Type.nf4, Type.f4e2m1], "Packing algorithm for the" "data types stored in 1, 2 or 4 bits"
minimum_regular_dtype = np.int8 if type == Type.i4 else np.uint8
@@ -51,17 +61,27 @@ def pack_data(array: np.ndarray, type: Type) -> np.ndarray:
def unpack_data(array: np.ndarray, type: Type, shape: Union[list, Shape]) -> np.ndarray:
"""Extract openvino element type values from array into new uint8/int8 array given shape.
+ For u1, u4, i4: Standard bit unpacking where 8 % bitwidth == 0
+ For u3: Transposed unpacking - 8 values from 3 bytes
+ For u6: Transposed unpacking - 4 values from 3 bytes
+
Example: uint8 value [120] can be represented as two u4 values and be unpacked into [7, 8]
because [120] bit representation is [01111000] will be viewed as [0111, 1000],
which is bit representation of [7, 8].
:param array: numpy array to unpack.
:type array: numpy array
- :param type: Type to extract from array values. Type must be u1, u2, u4, i4, nf4 or f4e2m1.
+ :param type: Type to extract from array values. Type must be u1, u2, u3, u4, u6, i4, nf4 or f4e2m1.
:type type: openvino.Type
:param shape: the new shape for the unpacked array.
:type shape: Union[list, openvino.Shape]
"""
+ # Handle u3 and u6 with special transposed unpacking
+ if type == Type.u3:
+ return _unpack_u3(array, shape)
+ elif type == Type.u6:
+ return _unpack_u6(array, shape)
+
assert type in [Type.u1, Type.u2, Type.u4, Type.i4, Type.nf4, Type.f4e2m1], "Unpacking algorithm for the" "data types stored in 1, 2 or 4 bits"
unpacked = np.unpackbits(array.view(np.uint8))
shape = list(shape)
@@ -85,3 +105,150 @@ def unpack_data(array: np.ndarray, type: Type, shape: Union[list, Shape]) -> np.
return np.resize(packed, shape).astype(dtype=np.int8)
else:
return np.resize(packed, shape)
+
+
+def _pack_u3(array: np.ndarray) -> np.ndarray:
+ """Pack u3 values using transposed packing scheme.
+
+ 8 values (each 3 bits) are packed into 3 bytes:
+ - Byte 0: bits [1:0] of values 0-3 (4 values * 2 bits = 8 bits)
+ - Byte 1: bits [1:0] of values 4-7 (4 values * 2 bits = 8 bits)
+ - Byte 2: bits [2] of all 8 values (8 values * 1 bit = 8 bits)
+ """
+ array = array.astype(np.uint8, casting="unsafe").flatten()
+ # Pad to multiple of 8
+ pad = (-len(array)) % 8
+ if pad:
+ array = np.concatenate([array, np.zeros(pad, dtype=np.uint8)])
+
+ groups = array.reshape(-1, 8)
+ result = []
+
+ for group in groups:
+ # Extract lower 2 bits and MSB for each value
+ lower_bits = group & 0x03 # bits [1:0]
+ msb = (group >> 2) & 0x01 # bit [2]
+
+ # Pack into 3 bytes
+ byte0 = (lower_bits[0] << 6) | (lower_bits[1] << 4) | (lower_bits[2] << 2) | lower_bits[3]
+ byte1 = (lower_bits[4] << 6) | (lower_bits[5] << 4) | (lower_bits[6] << 2) | lower_bits[7]
+ byte2 = (msb[0] << 7) | (msb[1] << 6) | (msb[2] << 5) | (msb[3] << 4) | \
+ (msb[4] << 3) | (msb[5] << 2) | (msb[6] << 1) | msb[7]
+
+ result.extend([byte0, byte1, byte2])
+
+ return np.array(result, dtype=np.uint8)
+
+
+def _unpack_u3(array: np.ndarray, shape: Union[list, Shape]) -> np.ndarray:
+ """Unpack u3 values using transposed unpacking scheme.
+
+ 3 bytes are unpacked into 8 values (each 3 bits).
+ """
+ array = array.view(np.uint8)
+ shape = list(shape)
+
+ # Process 3 bytes at a time
+ result = []
+ for i in range(0, len(array), 3):
+ if i + 2 >= len(array):
+ break
+ byte0, byte1, byte2 = array[i:i+3]
+
+ # Unpack lower 2 bits from first two bytes
+ val0 = (byte0 >> 6) & 0x03
+ val1 = (byte0 >> 4) & 0x03
+ val2 = (byte0 >> 2) & 0x03
+ val3 = byte0 & 0x03
+ val4 = (byte1 >> 6) & 0x03
+ val5 = (byte1 >> 4) & 0x03
+ val6 = (byte1 >> 2) & 0x03
+ val7 = byte1 & 0x03
+
+ # Unpack MSBs from third byte
+ msb0 = (byte2 >> 7) & 0x01
+ msb1 = (byte2 >> 6) & 0x01
+ msb2 = (byte2 >> 5) & 0x01
+ msb3 = (byte2 >> 4) & 0x01
+ msb4 = (byte2 >> 3) & 0x01
+ msb5 = (byte2 >> 2) & 0x01
+ msb6 = (byte2 >> 1) & 0x01
+ msb7 = byte2 & 0x01
+
+ # Combine to form 3-bit values
+ result.extend([
+ val0 | (msb0 << 2), val1 | (msb1 << 2), val2 | (msb2 << 2), val3 | (msb3 << 2),
+ val4 | (msb4 << 2), val5 | (msb5 << 2), val6 | (msb6 << 2), val7 | (msb7 << 2)
+ ])
+
+ result = np.array(result, dtype=np.uint8)
+ return np.resize(result, shape)
+
+
+def _pack_u6(array: np.ndarray) -> np.ndarray:
+ """Pack u6 values using transposed packing scheme.
+
+ 4 values (each 6 bits) are packed into 3 bytes:
+ - Byte 0: bits [3:0] of values 0-1 (2 values * 4 bits = 8 bits)
+ - Byte 1: bits [3:0] of values 2-3 (2 values * 4 bits = 8 bits)
+ - Byte 2: bits [5:4] of all 4 values (4 values * 2 bits = 8 bits)
+ """
+ array = array.astype(np.uint8, casting="unsafe").flatten()
+ # Pad to multiple of 4
+ pad = (-len(array)) % 4
+ if pad:
+ array = np.concatenate([array, np.zeros(pad, dtype=np.uint8)])
+
+ groups = array.reshape(-1, 4)
+ result = []
+
+ for group in groups:
+ lower_bits = group & 0x0F # bits [3:0]
+ upper_bits = (group >> 4) & 0x03 # bits [5:4]
+
+ # Pack into 3 bytes
+ byte0 = (lower_bits[0] << 4) | lower_bits[1]
+ byte1 = (lower_bits[2] << 4) | lower_bits[3]
+ byte2 = (upper_bits[0] << 6) | (upper_bits[1] << 4) | (upper_bits[2] << 2) | upper_bits[3]
+
+ result.extend([byte0, byte1, byte2])
+
+ return np.array(result, dtype=np.uint8)
+
+
+def _unpack_u6(array: np.ndarray, shape: Union[list, Shape]) -> np.ndarray:
+ """Unpack u6 values using transposed unpacking scheme.
+
+ 3 bytes are unpacked into 4 values (each 6 bits).
+ """
+ array = array.view(np.uint8)
+ shape = list(shape)
+ num_values = int(np.prod(shape))
+
+ # Process 3 bytes at a time
+ result = []
+ for i in range(0, len(array), 3):
+ if i + 2 >= len(array):
+ break
+ byte0, byte1, byte2 = array[i:i+3]
+
+ # Unpack lower 4 bits from first two bytes
+ val0 = (byte0 >> 4) & 0x0F
+ val1 = byte0 & 0x0F
+ val2 = (byte1 >> 4) & 0x0F
+ val3 = byte1 & 0x0F
+
+ # Unpack upper 2 bits from third byte
+ upper0 = (byte2 >> 6) & 0x03
+ upper1 = (byte2 >> 4) & 0x03
+ upper2 = (byte2 >> 2) & 0x03
+ upper3 = byte2 & 0x03
+
+ # Combine to form 6-bit values
+ result.extend([
+ val0 | (upper0 << 4), val1 | (upper1 << 4),
+ val2 | (upper2 << 4), val3 | (upper3 << 4)
+ ])
+
+ result = np.array(result, dtype=np.uint8)
+ return np.resize(result, shape)
diff --git a/src/bindings/python/src/openvino/opset13/ops.py b/src/bindings/python/src/openvino/opset13/ops.py
index b840d76a2f0..42ec8cb0140 100644
--- a/src/bindings/python/src/openvino/opset13/ops.py
+++ b/src/bindings/python/src/openvino/opset13/ops.py
@@ -312,7 +312,7 @@ def constant(
Requires data to be C_CONTIGUOUS if `True`.
Disabled by default if:
- value is a scalar.
- - dtype is one of: Type.u1, Type.u2, Type.i4, Type.u4, Type.nf4, Type.bf16.
+ - dtype is one of: Type.u1, Type.u2, Type.u3, Type.i4, Type.u4, Type.u6, Type.nf4, Type.bf16.
- dtype force conversion of data.
:return: The Constant node initialized with provided data.
"""
@@ -332,7 +332,7 @@ def constant(
# Handle type casting, when dtype is not None:
if dtype:
# Expect packed data, use different constructor to handle it correctly:
- if dtype in [Type.u1, Type.u2, Type.i4, Type.u4, Type.nf4, Type.f4e2m1]:
+ if dtype in [Type.u1, Type.u2, Type.u3, Type.i4, Type.u4, Type.u6, Type.nf4, Type.f4e2m1]:
display_shared_memory_warning(f"Constant initialized with packed type of {dtype}")
return Constant(dtype, Shape(_value.shape), _value.flatten().tolist())
elif dtype in [Type.bf16, Type.f8e8m0, Type.f8e4m3, Type.f8e5m2]:
diff --git a/src/bindings/python/src/pyopenvino/core/common.cpp b/src/bindings/python/src/pyopenvino/core/common.cpp
index e52dc5632e3..5ec19028566 100644
--- a/src/bindings/python/src/pyopenvino/core/common.cpp
+++ b/src/bindings/python/src/pyopenvino/core/common.cpp
@@ -20,18 +20,19 @@ namespace type_helpers {
const std::map<ov::element::Type, py::dtype>& ov_type_to_dtype() {
static const std::map<ov::element::Type, py::dtype> ov_type_to_dtype_mapping = {
- {ov::element::f16, py::dtype("float16")}, {ov::element::bf16, py::dtype("float16")},
- {ov::element::f32, py::dtype("float32")}, {ov::element::f64, py::dtype("float64")},
- {ov::element::i8, py::dtype("int8")}, {ov::element::i16, py::dtype("int16")},
- {ov::element::i32, py::dtype("int32")}, {ov::element::i64, py::dtype("int64")},
- {ov::element::u8, py::dtype("uint8")}, {ov::element::u16, py::dtype("uint16")},
- {ov::element::u32, py::dtype("uint32")}, {ov::element::u64, py::dtype("uint64")},
- {ov::element::boolean, py::dtype("bool")}, {ov::element::u1, py::dtype("uint8")},
- {ov::element::u2, py::dtype("uint8")}, {ov::element::u4, py::dtype("uint8")},
- {ov::element::nf4, py::dtype("uint8")}, {ov::element::i4, py::dtype("int8")},
- {ov::element::f8e4m3, py::dtype("uint8")}, {ov::element::f8e5m2, py::dtype("uint8")},
- {ov::element::string, py::dtype("bytes_")}, {ov::element::f4e2m1, py::dtype("uint8")},
- {ov::element::f8e8m0, py::dtype("uint8")},
+ {ov::element::f16, py::dtype("float16")}, {ov::element::bf16, py::dtype("float16")},
+ {ov::element::f32, py::dtype("float32")}, {ov::element::f64, py::dtype("float64")},
+ {ov::element::i8, py::dtype("int8")}, {ov::element::i16, py::dtype("int16")},
+ {ov::element::i32, py::dtype("int32")}, {ov::element::i64, py::dtype("int64")},
+ {ov::element::u8, py::dtype("uint8")}, {ov::element::u16, py::dtype("uint16")},
+ {ov::element::u32, py::dtype("uint32")}, {ov::element::u64, py::dtype("uint64")},
+ {ov::element::boolean, py::dtype("bool")}, {ov::element::u1, py::dtype("uint8")},
+ {ov::element::u2, py::dtype("uint8")}, {ov::element::u3, py::dtype("uint8")},
+ {ov::element::u4, py::dtype("uint8")}, {ov::element::u6, py::dtype("uint8")},
+ {ov::element::nf4, py::dtype("uint8")}, {ov::element::nf4, py::dtype("uint8")},
+ {ov::element::i4, py::dtype("int8")}, {ov::element::f8e4m3, py::dtype("uint8")},
+ {ov::element::f8e5m2, py::dtype("uint8")}, {ov::element::string, py::dtype("bytes_")},
+ {ov::element::f4e2m1, py::dtype("uint8")}, {ov::element::f8e8m0, py::dtype("uint8")},
};
return ov_type_to_dtype_mapping;
}
@@ -275,6 +276,10 @@ py::array as_contiguous(py::array& array, ov::element::Type type) {
return array.cast<py::array_t<uint8_t, py::array::c_style | py::array::forcecast>>();
case ov::element::u2:
return array.cast<py::array_t<uint8_t, py::array::c_style | py::array::forcecast>>();
+ case ov::element::u3:
+ return array.cast<py::array_t<uint8_t, py::array::c_style | py::array::forcecast>>();
+ case ov::element::u6:
+ return array.cast<py::array_t<uint8_t, py::array::c_style | py::array::forcecast>>();
// need to create a view on array to cast it correctly
case ov::element::f16:
case ov::element::bf16:
@@ -402,7 +407,10 @@ std::vector<size_t> _get_strides(const ov::op::v0::Constant& self) {
switch (self.get_element_type()) {
case i4:
case u1:
+ case u2:
+ case u3:
case u4:
+ case u6:
case nf4:
case f4e2m1:
return _get_byte_strides(self.get_shape(), 8);
diff --git a/src/bindings/python/src/pyopenvino/core/tensor.cpp b/src/bindings/python/src/pyopenvino/core/tensor.cpp
index cdaa8150f11..925c326714f 100644
--- a/src/bindings/python/src/pyopenvino/core/tensor.cpp
+++ b/src/bindings/python/src/pyopenvino/core/tensor.cpp
@@ -315,7 +315,7 @@ void regclass_Tensor(py::module m) {
Returns numpy array with corresponding shape and dtype.
- For tensors with OpenVINO specific element type, such as u1, u2, u4 or i4
+ For tensors with OpenVINO specific element type, such as u1, u2, u3, u4, u6 or i4
it returns linear array, with uint8 / int8 numpy dtype.
For tensors with string element type, returns a numpy array of bytes
diff --git a/src/bindings/python/src/pyopenvino/graph/ops/constant.cpp b/src/bindings/python/src/pyopenvino/graph/ops/constant.cpp
index 999913601e1..9d065081120 100644
--- a/src/bindings/python/src/pyopenvino/graph/ops/constant.cpp
+++ b/src/bindings/python/src/pyopenvino/graph/ops/constant.cpp
@@ -108,8 +108,9 @@ void regclass_graph_op_Constant(py::module m) {
return _cast_vector<int32_t>(self);
} else if (element_type == ov::element::i64) {
return _cast_vector<int64_t>(self);
- } else if (element_type == ov::element::u8 || element_type == ov::element::u1 ||
- element_type == ov::element::u2 || element_type == ov::element::u4) {
+ } else if (element_type == ov::element::u1 || element_type == ov::element::u2 ||
+ element_type == ov::element::u3 || element_type == ov::element::u4 ||
+ element_type == ov::element::u6 || element_type == ov::element::u8) {
return _cast_vector<uint8_t>(self);
} else if (element_type == ov::element::u16) {
return _cast_vector<uint16_t>(self);
@@ -158,8 +159,9 @@ void regclass_graph_op_Constant(py::module m) {
return _get_buffer_info<int32_t>(self);
} else if (element_type == ov::element::i64) {
return _get_buffer_info<int64_t>(self);
- } else if (element_type == ov::element::u8 || element_type == ov::element::u1 ||
- element_type == ov::element::u2 || element_type == ov::element::u4) {
+ } else if (element_type == ov::element::u1 || element_type == ov::element::u2 ||
+ element_type == ov::element::u3 || element_type == ov::element::u4 ||
+ element_type == ov::element::u6 || element_type == ov::element::u8) {
return _get_buffer_info<uint8_t>(self);
} else if (element_type == ov::element::u16) {
return _get_buffer_info<uint16_t>(self);
diff --git a/src/bindings/python/src/pyopenvino/graph/types/element_type.cpp b/src/bindings/python/src/pyopenvino/graph/types/element_type.cpp
index cd2f482f86b..8f88265db13 100644
--- a/src/bindings/python/src/pyopenvino/graph/types/element_type.cpp
+++ b/src/bindings/python/src/pyopenvino/graph/types/element_type.cpp
@@ -43,7 +43,9 @@ void regclass_graph_Type(py::module m) {
type.attr("i64") = ov::element::i64;
type.attr("u1") = ov::element::u1;
type.attr("u2") = ov::element::u2;
+ type.attr("u3") = ov::element::u3;
type.attr("u4") = ov::element::u4;
+ type.attr("u6") = ov::element::u6;
type.attr("u8") = ov::element::u8;
type.attr("u16") = ov::element::u16;
type.attr("u32") = ov::element::u32;
diff --git a/src/bindings/python/tests/test_graph/test_constant.py b/src/bindings/python/tests/test_graph/test_constant.py
index a225b4462df..c2091051b05 100644
--- a/src/bindings/python/tests/test_graph/test_constant.py
+++ b/src/bindings/python/tests/test_graph/test_constant.py
@@ -252,7 +252,9 @@ def test_init_bf16_direct(ov_type, numpy_dtype, shared_flag):
[
(Type.u1, np.uint8),
(Type.u2, np.uint8),
+ (Type.u3, np.uint8),
(Type.u4, np.uint8),
+ (Type.u6, np.uint8),
(Type.i4, np.int8),
(Type.nf4, np.uint8),
],
diff --git a/src/bindings/python/tests/test_runtime/test_tensor.py b/src/bindings/python/tests/test_runtime/test_tensor.py
index 7f0e71e0e58..b083cbefd13 100644
--- a/src/bindings/python/tests/test_runtime/test_tensor.py
+++ b/src/bindings/python/tests/test_runtime/test_tensor.py
@@ -36,7 +36,9 @@ from tests.utils.helpers import generate_image, generate_relu_compiled_model
(ov.Type.boolean, bool),
(ov.Type.u1, np.uint8),
(ov.Type.u2, np.uint8),
+ (ov.Type.u3, np.uint8),
(ov.Type.u4, np.uint8),
+ (ov.Type.u6, np.uint8),
(ov.Type.i4, np.int8),
],
)
@@ -374,7 +376,9 @@ def test_can_set_shape_other_dims():
[
(ov.Type.u1),
(ov.Type.u2),
+ (ov.Type.u3),
(ov.Type.u4),
+ (ov.Type.u6),
(ov.Type.i4),
],
)
@@ -390,7 +394,9 @@ def test_cannot_create_roi_from_packed_tensor(ov_type):
[
(ov.Type.u1),
(ov.Type.u2),
+ (ov.Type.u3),
(ov.Type.u4),
+ (ov.Type.u6),
(ov.Type.i4),
],
)
@@ -443,7 +449,9 @@ def test_init_with_packed_buffer(dtype, ov_type):
[
(0, 2, ov.Type.u1, np.uint8),
(0, 4, ov.Type.u2, np.uint8),
+ (0, 8, ov.Type.u3, np.uint8),
(0, 16, ov.Type.u4, np.uint8),
+ (0, 64, ov.Type.u6, np.uint8),
(-8, 7, ov.Type.i4, np.int8),
(0, 16, ov.Type.nf4, np.uint8),
],
@@ -671,3 +679,92 @@ def test_tensor_from_pillow(numpy_dtype, shape):
assert isinstance(tensor.data, np.ndarray)
assert tensor.data.dtype == numpy_dtype
assert tensor.data.shape == shape
+
+
+def test_pack_unpack_u3_numerical():
+ """Test u3 packing/unpacking with known numerical values."""
+ # 8 values packed into 3 bytes
+ # Decimal values: [0, 1, 2, 3, 4, 5, 6, 7]
+ # In binary: [000, 001, 010, 011, 100, 101, 110, 111]
+ data = np.array([0, 1, 2, 3, 4, 5, 6, 7], dtype=np.uint8)
+
+ packed = pack_data(data, ov.Type.u3)
+
+ # Expected packing:
+ # Byte 0: bits[1:0] of values 0-3 = [00, 01, 10, 11] = 0x1B
+ # Byte 1: bits[1:0] of values 4-7 = [00, 01, 10, 11] = 0x1B
+ # Byte 2: bits[2] of all 8 values = [0,0,0,0,1,1,1,1] = 0x0F
+ expected = np.array([0x1B, 0x1B, 0x0F], dtype=np.uint8)
+
+ assert len(packed) == 3
+ assert np.array_equal(packed, expected), f"Expected {expected.tolist()}, got {packed.tolist()}"
+
+ unpacked = unpack_data(packed, ov.Type.u3, [8])
+ assert np.array_equal(unpacked, data), f"Expected {data.tolist()}, got {unpacked.tolist()}"
+
+
+def test_pack_unpack_u3_edge_cases():
+ data = np.array([0, 0, 0, 0, 0, 0, 0, 0], dtype=np.uint8)
+ packed = pack_data(data, ov.Type.u3)
+ expected = np.array([0x00, 0x00, 0x00], dtype=np.uint8)
+ assert np.array_equal(packed, expected)
+ unpacked = unpack_data(packed, ov.Type.u3, [8])
+ assert np.array_equal(unpacked, data)
+
+ data = np.array([7, 7, 7, 7, 7, 7, 7, 7], dtype=np.uint8)
+ packed = pack_data(data, ov.Type.u3)
+ # All bits[1:0] = 11, all bits[2] = 1
+ expected = np.array([0xFF, 0xFF, 0xFF], dtype=np.uint8)
+ assert np.array_equal(packed, expected)
+ unpacked = unpack_data(packed, ov.Type.u3, [8])
+ assert np.array_equal(unpacked, data)
+
+
+def test_pack_unpack_u6_numerical():
+ # 4 values packed into 3 bytes
+ # Decimal values: [0, 15, 48, 63]
+ # In binary: [000000, 001111, 110000, 111111]
+ data = np.array([0, 15, 48, 63], dtype=np.uint8)
+ packed = pack_data(data, ov.Type.u6)
+
+ # Expected packing:
+ # Byte 0: bits[3:0] of values 0-1 = [0000, 1111] = 0x0F
+ # Byte 1: bits[3:0] of values 2-3 = [0000, 1111] = 0x0F
+ # Byte 2: bits[5:4] of all 4 values = [00, 00, 11, 11] = 0x0F
+ expected = np.array([0x0F, 0x0F, 0x0F], dtype=np.uint8)
+
+ assert len(packed) == 3
+ assert np.array_equal(packed, expected), f"Expected {expected.tolist()}, got {packed.tolist()}"
+
+ unpacked = unpack_data(packed, ov.Type.u6, [4])
+ assert np.array_equal(unpacked, data), f"Expected {data.tolist()}, got {unpacked.tolist()}"
+
+
+def test_pack_unpack_u6_edge_cases():
+ data = np.array([0, 0, 0, 0], dtype=np.uint8)
+ packed = pack_data(data, ov.Type.u6)
+ expected = np.array([0x00, 0x00, 0x00], dtype=np.uint8)
+ assert np.array_equal(packed, expected)
+ unpacked = unpack_data(packed, ov.Type.u6, [4])
+ assert np.array_equal(unpacked, data)
+
+ data = np.array([63, 63, 63, 63], dtype=np.uint8)
+ packed = pack_data(data, ov.Type.u6)
+ expected = np.array([0xFF, 0xFF, 0xFF], dtype=np.uint8)
+ assert np.array_equal(packed, expected)
+ unpacked = unpack_data(packed, ov.Type.u6, [4])
+ assert np.array_equal(unpacked, data)
+
+
+def test_pack_unpack_u3_multidimensional():
+ data = np.array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]], dtype=np.uint8)
+ packed = pack_data(data, ov.Type.u3)
+ unpacked = unpack_data(packed, ov.Type.u3, data.shape)
+ assert np.array_equal(unpacked, data)
+
+
+def test_pack_unpack_u6_multidimensional():
+ data = np.array([[10, 20], [30, 40]], dtype=np.uint8)
+ packed = pack_data(data, ov.Type.u6)
+ unpacked = unpack_data(packed, ov.Type.u6, data.shape)
+ assert np.array_equal(unpacked, data)
diff --git a/src/bindings/python/tests/test_runtime/test_type.py b/src/bindings/python/tests/test_runtime/test_type.py
index faf4a353670..c70d25fce1d 100644
--- a/src/bindings/python/tests/test_runtime/test_type.py
+++ b/src/bindings/python/tests/test_runtime/test_type.py
@@ -63,8 +63,10 @@ def test_dtype_ovtype_conversion(dtype_string, dtype, ovtype):
(Type.boolean, True, False, False, True, True, False, "boolean", 1, 8),
(Type.u1, True, False, False, True, False, False, "u1", 1, 1),
(Type.u2, True, False, False, True, False, False, "u2", 1, 2),
+ (Type.u3, True, False, False, True, False, False, "u3", 1, 3),
(Type.u4, True, False, False, True, False, False, "u4", 1, 4),
(Type.i4, True, False, False, True, True, True, "i4", 1, 4),
+ (Type.u6, True, False, False, True, False, False, "u6", 1, 6),
])
def test_basic_ovtypes(ovtype,
static_flag,