Skip to content

Conversation

alexvong243f
Copy link
Collaborator

@alexvong243f alexvong243f commented Aug 30, 2022

This PR makes @sym/vertcat, @sym/horzcat and @sym/transpose Array-compatible.

In @sym/horzcat, we make use of the property that

[A_1; A_2; ...; A_n).' == [A_1.' A_2.' ... A_n.']

for all A_k with compatible sizes.

' return x.T'
'elif isinstance(x, NDimArray):'
' xx = x.tolist()'
' return Array(list(zip(*xx)))'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should these go through your new helper function? (not saying they should, just asking)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it alright if I do

If isinstance(x, (MatrixBase, NDimArray)):
    xx = x.tolist()
    return make_matrix_or_array(list(zip(*xx)))

directly instead of splitting the case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually doesn't work because of issues with empty matrices. We have to split it into 2 cases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replying to your original Q:

I thought about this but don't have a clear ans. Using make_matrix_or_array means sticking to a more consistent interface, while using Array is better for performance because no Expr checks are performed. I guess sticking to a more consistent interface is more important (?)

Copy link
Collaborator Author

@alexvong243f alexvong243f Aug 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per my latest comment in #1124, we may want to use is_2d_sym and is_non_matrix_2d_sym for generality sake. WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that sounds reasonable. A new PR perhaps

Alex Vong added 4 commits August 30, 2022 16:30
* inst/@sym/{horzcat,vertcat}.m: Fix them.
* inst/@sym/vertcat.m: Implement it.
This is a prerequisite for making @sym/horzcat Array-compatible.

Partially fixes <gnu-octave#1215>.

* inst/@sym/transpose.m: Implement it.
@alexvong243f alexvong243f force-pushed the make-cats-array-compat branch from d104b60 to 0d93602 Compare August 31, 2022 13:07
@alexvong243f
Copy link
Collaborator Author

PR updated to fix issues raised, I think we can worry about generalizing to non-Array (e.g. TableForm) in another PR

@cbm755
Copy link
Collaborator

cbm755 commented Aug 31, 2022

I agree for TableForm. One thing at a time

@alexvong243f alexvong243f merged commit 9a3b3f0 into gnu-octave:Array_not_Matrix Aug 31, 2022
@alexvong243f alexvong243f deleted the make-cats-array-compat branch August 31, 2022 20:13
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.

2 participants