Skip to content

fix(base): accept a list of rows in getmatrix and a range in getvector - #278

Open
MrNK2107 wants to merge 1 commit into
rai-opensource:masterfrom
MrNK2107:fix/getmatrix-nested-lists-255
Open

MrNK2107 wants to merge 1 commit into
rai-opensource:masterfrom
MrNK2107:fix/getmatrix-nested-lists-255

Conversation

@MrNK2107

Copy link
Copy Markdown

Part of #255.

getmatrix() raised TypeError for a nested list or tuple, such as a 2xN path written as [[0, 1, 2], [0, 1, 0]], and getvector() raised TypeError for a range.

  • getmatrix: a list or tuple that isn't a vector is converted with np.array and then goes through the existing 2D branch, so its shape is checked against shape (a mismatch raises ValueError; it isn't reshaped). A range is treated as a 1D sequence.
  • getvector: a range is converted to a list first, so every out format works.

Not changed: a flat list is still reshaped (getmatrix([0, 1, 2, 3], (2, None)) is still (2, 2)), and Points2/Points3 are untouched. Both change public behaviour, so I've left them for a separate decision.

Behaviour change: inputs that used to raise TypeError are now accepted; nothing that previously worked returns a different result.

Tests: new cases in tests/base/test_argcheck.py for nested lists/tuples (including shape mismatch) and range in getvector. Both fail on master and pass with the fix. Full suite: 475 passed, 3 skipped (master: 473 passed, 3 skipped). black and flake8 are clean on the changed files.

AI disclosure: I used an AI assistant while working on this; I've read the diff and run the tests myself.

getmatrix() raised TypeError for a nested list or tuple, such as a 2xN
path written as [[0, 1, 2], [0, 1, 0]], and getvector() raised TypeError
for a range. Convert a nested sequence to an array and check its shape
like any 2D array, and treat a range like a list.

A flat list is still reshaped as before.

Refs rai-opensource#255

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant