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

a way to construct multidimensional array without rho? #117

Closed
smasher164 opened this issue Dec 1, 2022 · 5 comments
Closed

a way to construct multidimensional array without rho? #117

smasher164 opened this issue Dec 1, 2022 · 5 comments

Comments

@smasher164
Copy link

Is there a way to construct a multidimensional array with regular data entry?
In Dyalog, you can just write

> (1 2 3)(4 5)
┌─────┬───┐
│1 2 3│4 5│
└─────┴───┘

Thanks

@robpike
Copy link
Owner

robpike commented Dec 1, 2022

No, there is not. It was a deliberate decision for simplicity. It could be changed but would be a fair bit of work.

@smasher164
Copy link
Author

smasher164 commented Dec 2, 2022

I see. Is there a recommendation or hack for constructing such arrays if such syntax doesn't exist? I was trying to do simple processing over an array like

[1000 2000 3000]

[4000]

[5000 6000]

[7000 8000 9000]

yesterday for Advent of Code, but gave up since I couldn't get the input into ivy.

@robpike
Copy link
Owner

robpike commented Dec 2, 2022

The engine doesn't support them, so there is no way to inject them.

@mykhal
Copy link

mykhal commented Dec 16, 2022

Sometimes, vectors inside vector is obtained, looking flat at first sight:

x = ,\iota 3

x
result: 1 1 2 1 2 3

rho x
result: 3

x[1]
result: 1

x[2]
result: 1 2

x[3]
result: 1 2 3

.. So if these cannot be constructed literally, shouldn't the result be flat and/or "Everything in ivy can be placed into a vector" statement from the demo be corrected?

UPDATE: the same result here considered an error

robpike added a commit that referenced this issue Jul 2, 2023
In #117, @smasher164 observed that
	,\1 2 3
generates
	1 (1 2) (1 2 3)
despite the claim that ivy does not support non-scalar elements.
I looked into preventing them from ever appearing, but that was
messy and slow as it requires a lot of post-construction checking
of things.

So I tried the other direction, and made them legal. That turned
out to be much more straightforward than I thought, although there
were a number of associated changes to make it work. Whenever the
existing barriers were removed, the code must actually work.
Significant changes and bug fixes:

- Fixed a trivial bug in parse that did not allow indexed expressions
in vectors, for example
  	1 2 x[3] 4
- Can now input compound elements of vectors: 1 (1 2) 3
- They must also be printable clearly, and for simplicity I made
  the output model the input, at least for these simple vector
  cases.
- Indexed assignment needed some tweaks, including fixing an
  existing bug: The rhs was not copied, so aliasing could happen
  and it was easy to demostrate bad behavior. Added a Copy method
  to Value to clean this up.
- Support matrices and vectors in OrderedCompare.
- Update and extend the tests. Some failure tests now worked!

I didn't touch the docs. Not clear a change is needed, although
this might be worth a phrase somewhere, perhaps in the demo.

Also simplify the method for printing matrices, which will make it
easier to fix a layout issue: A multiline matrix as an element of
an array or matrix results in ugly output. Relatively easy to fix,
but to be a separate change.

Update #117
@robpike
Copy link
Owner

robpike commented Jul 2, 2023

As you can see from the commit above, you got what you wanted.

I suspect there remain rough edges. I know that printing still needs work, but have a handle on that. I'll leave this issue open at least until that is resolved.

Thanks for the prod.

robpike added a commit that referenced this issue Jul 4, 2023
Make the columns and rows line up in a meaningful way when there
is, for example, a 2d matrix in the middle of a vector.  There are
surely many cases this won't handle well, but they should be quite
rare, such as a 5d matrix inside a vector. And for the common cases
that might actually arise, the output is reasonable.

Also add testdata/print.ivy to have a single place to write
tests for this. There may be many as things evolve.

The same treatment for matrices will come next, or soon at least.

Update #117
@robpike robpike closed this as completed in 07efe1f Jul 5, 2023
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

3 participants