Unverified Commit 6486d6d8 authored by Justin Carpentier's avatar Justin Carpentier Committed by GitHub
Browse files

Merge pull request #284 from ManifoldFR/devel

Fix for Refs to dynamic (1, N) blocks
parents 1ae74c73 71a329d1
Pipeline #18580 passed with stage
in 6 minutes and 7 seconds
......@@ -70,11 +70,11 @@ 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 bool reverse_strides = MatType::IsRowMajor || (mat.rows() == 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};
......@@ -135,10 +135,11 @@ struct NumpyAllocator<const Eigen::Ref<const 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 bool reverse_strides = MatType::IsRowMajor || (mat.rows() == 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};
......
......@@ -35,17 +35,28 @@ def test(mat):
assert np.all(mat[:2, :3] == np.ones((2, 3)))
mat.fill(0.0)
mat[:, :] = np.arange(rows * cols).reshape(rows, cols)
printMatrix(mat)
mat0 = mat.copy()
mat_as_C_order = np.array(mat, order="F")
getBlock(mat_as_C_order, 0, 0, 3, 2)[:, :] = 1.0
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.reshape(rowsize, colsize))
B[:] = 1.0
rhs = np.ones((rowsize, colsize))
assert np.array_equal(mat_as_C_order[i : rowsize + i, :colsize], rhs)
assert np.all(mat_as_C_order[:3, :2] == np.ones((3, 2)))
mat_as_C_order[:, :] = mat0
mat_as_C_order[:3, :2] = 0.0
mat_copy = mat_as_C_order.copy()
editBlock(mat_as_C_order, 0, 0, 3, 2)
mat_copy[:3, :2] = np.arange(6).reshape(3, 2)
assert np.all(mat_as_C_order == mat_copy)
assert np.array_equal(mat_as_C_order, mat_copy)
class ModifyBlockImpl(modify_block):
def __init__(self):
......
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