Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: PULL-PUSH-PULL 1D Column vector will convert into 1D Row Vector #221

Closed
yasirroni opened this issue Mar 24, 2022 · 4 comments
Closed

Comments

@yasirroni
Copy link
Contributor

This is working just fine:

m.eval("x = cell(1,4); x(:) = 1.0;")
x = m.pull('x')
x
# (Cell([[1.0, 1.0, 1.0, 1.0]]), (1, 4))
m.push('x', x)
x = m.pull('x')
x
# (Cell([[1.0, 1.0, 1.0, 1.0]]), (1, 4))

But, this will convert into (1,n)

m.eval("x = cell(4,1); x(:) = 1.0;")
x = m.pull('x')
x
# (Cell([1.0, 1.0, 1.0, 1.0]), (4,))
m.push('x', x)
x = m.pull('x')
x
# (Cell([1.0, 1.0, 1.0, 1.0]), (1,4))
@yasirroni
Copy link
Contributor Author

After investigating, the problem located on m.push()

m.eval("x = cell(4,1); x(:) = 1.0;")
m.eval('size(x)')

# ans =

#    4   1

x = m.pull('x')
print(np.shape(x))

# (4,)

m.push('x', x)
m.eval('size(x)')

# ans =

#    1   4

@yasirroni
Copy link
Contributor Author

yasirroni commented Mar 24, 2022

A fix would be force 1D Cell push as 2D Cell push or fix it while octave reading (the latter is better)


Edit:

If we look at how m.eval('size(x)') return (4,1), I think we should also use numpy atleast 2D?

x = m.pull('x')
print(np.shape(x))

# (4,)

@yasirroni
Copy link
Contributor Author

Should we change it to atleast 2D or add special case for Column vector?

oct2py/oct2py/io.py

Lines 224 to 226 in e8ebd99

if (value.shape[value.ndim - 1] == 1):
value = value.squeeze(axis=value.ndim - 1)
value = np.atleast_1d(value)

@blink1073
Copy link
Owner

I think special casing Column vector makes sense.

Adding a few tests that ensure we preserve the shape for (n,1) and (1,n) cells would help as well.

We should be able to round trip these cells without losing the shape, that was an oversight on my part.

This was referenced Mar 24, 2022
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

No branches or pull requests

2 participants