def test_set_shape(ov_type, numpy_dtype): shape = ng.impl.Shape([1, 3, 32, 32]) ref_shape = ng.impl.Shape([1, 3, 48, 48]) ref_shape_np = [1, 3, 28, 28] ov_tensor = Tensor(ov_type, shape) ov_tensor.shape = ref_shape assert list(ov_tensor.shape) == list(ref_shape) ones_arr = np.ones(list(ov_tensor.shape), numpy_dtype) ov_tensor.data[:] = ones_arr assert np.array_equal(ov_tensor.data, ones_arr) ov_tensor.shape = ref_shape_np assert list(ov_tensor.shape) == ref_shape_np zeros = np.zeros(ref_shape_np, numpy_dtype) ov_tensor.data[:] = zeros assert np.array_equal(ov_tensor.data, zeros)
def test_cannot_set_shape_on_preallocated_memory(ref_shape): ones_arr = np.ones(shape=(1, 3, 32, 32), dtype=np.float32) ov_tensor = Tensor(ones_arr) with pytest.raises(RuntimeError) as e: ov_tensor.shape = ref_shape assert "Cannot call setShape for Blobs created on top of preallocated memory" in str( e.value)
def test_cannot_set_shape_incorrect_dims(): ov_tensor = Tensor(np.float32, [1, 3, 48, 48]) with pytest.raises(RuntimeError) as e: ov_tensor.shape = [3, 28, 28] assert "Dims and format are inconsistent" in str(e.value)