Commit 9e0d6e50 authored by Wilson Jallet's avatar Wilson Jallet 🎬
Browse files

Fix for dynamic (1, N) block Refs

* stride reversed also in this case
* add test for (1,n) and (n,1) blocks
parent 6b652d7a
Pipeline #18575 canceled with stage
in 0 seconds
......@@ -70,11 +70,12 @@ struct NumpyAllocator<Eigen::Ref<MatType, Options, Stride> > {
if (NumpyType::sharedMemory()) {
const int Scalar_type_code = Register::getTypeCode<Scalar>();
Eigen::DenseIndex inner_stride = MatType::IsRowMajor ? mat.outerStride()
: mat.innerStride(),
outer_stride = MatType::IsRowMajor ? mat.innerStride()
: mat.outerStride();
const npy_int R = (npy_int)mat.rows();
const bool reverse_strides = MatType::IsRowMajor || (R == 1);
Eigen::DenseIndex inner_stride = reverse_strides ? mat.outerStride()
: mat.innerStride(),
outer_stride = reverse_strides ? mat.innerStride()
: mat.outerStride();
const int elsize = call_PyArray_DescrFromType(Scalar_type_code)->elsize;
npy_intp strides[2] = {elsize * inner_stride, elsize * outer_stride};
......
......@@ -39,16 +39,16 @@ def test(mat):
printMatrix(mat)
mat0 = mat.copy()
mat_as_C_order = np.array(mat, order="F")
for i, rowsize in ([0, 3], [1, 1]):
print("taking block [{}:{}, {}:{}]".format(i, rowsize+i, 0, 2))
B = getBlock(mat_as_C_order, i, 0, rowsize, 2)
lhs = mat_as_C_order[i:rowsize + i, :2]
for i, rowsize, colsize in ([0, 3, 2], [1, 1, 2], [0, 3, 1]):
print("taking block [{}:{}, {}:{}]".format(i, rowsize+i, 0, colsize))
B = getBlock(mat_as_C_order, i, 0, rowsize, colsize)
lhs = mat_as_C_order[i:rowsize + i, :colsize]
print("should be:\n{}\ngot:\n{}".format(lhs, B))
assert np.array_equal(lhs, B)
assert np.array_equal(lhs, B.reshape(rowsize, colsize))
B[:] = 1.0
rhs = np.ones((rowsize, 2))
assert np.array_equal(mat_as_C_order[i:rowsize+i, :2], rhs)
rhs = np.ones((rowsize, colsize))
assert np.array_equal(mat_as_C_order[i:rowsize+i, :colsize], rhs)
mat_as_C_order[:, :] = mat0
......
Supports Markdown
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