-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ivy: better formatting for vectors containing multiline elements
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
- Loading branch information
Showing
3 changed files
with
287 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# Copyright 2023 The Go Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style | ||
# license that can be found in the LICENSE file. | ||
|
||
# Test printing, particularly when the output is multline. | ||
|
||
# First, the easy stuff. | ||
|
||
1 | ||
1 | ||
|
||
float(1.01) | ||
1.01 | ||
|
||
1/3 | ||
1/3 | ||
|
||
10000000000+1 | ||
10000000001 | ||
|
||
sqrt 2 | ||
1.41421356237 | ||
|
||
3j4 | ||
3j4 | ||
|
||
iota 5 | ||
1 2 3 4 5 | ||
|
||
3 4 rho iota 12 | ||
1 2 3 4 | ||
5 6 7 8 | ||
9 10 11 12 | ||
|
||
'a' 'b' 2 'c' | ||
a b 2 c | ||
|
||
'abc' | ||
abc | ||
|
||
# Vector with vector elements | ||
1 (1 2) (1 2 3) | ||
1 (1 2) (1 2 3) | ||
|
||
(1 2) (3 4) (5 6) | ||
(1 2) (3 4) (5 6) | ||
|
||
1 'ab' (1 2 3) | ||
1 (ab) (1 2 3) | ||
|
||
1 2 3 (10 11 12) 5 6 7 | ||
1 2 3 (10 11 12) 5 6 7 | ||
|
||
# Vector with matrix elements. Various versions to test | ||
# alignment and indenting | ||
|
||
1 2 3 (3 3 rho iota 10) 5 6 7 | ||
1 2 3 (1 2 3| 5 6 7 | ||
|4 5 6| | ||
|7 8 9) | ||
|
||
1 2 3 (3 3 rho iota 10) 5 6 (2 2 rho iota 10) 7 | ||
1 2 3 (1 2 3| 5 6 (1 2| 7 | ||
|4 5 6| |3 4) | ||
|7 8 9) | ||
|
||
1 2 3 5 6 (4 4 rho iota 10) 7 5 6 (4 4 rho iota 10) 7 | ||
1 2 3 5 6 ( 1 2 3 4| 7 5 6 ( 1 2 3 4| 7 | ||
| 5 6 7 8| | 5 6 7 8| | ||
| 9 10 1 2| | 9 10 1 2| | ||
| 3 4 5 6) | 3 4 5 6) | ||
|
||
1 2 3 (2 2 rho iota 10) 5 6 (4 4 rho iota 10) 7 5 6 (4 4 rho iota 10) 7 | ||
1 2 3 (1 2| 5 6 ( 1 2 3 4| 7 5 6 ( 1 2 3 4| 7 | ||
|3 4) | 5 6 7 8| | 5 6 7 8| | ||
| 9 10 1 2| | 9 10 1 2| | ||
| 3 4 5 6) | 3 4 5 6) | ||
|
||
1 2 3 (2 2 rho iota 10) 5 6 (4 4 rho iota 10) 7 5 6 (4 4 rho iota 10) 7 8 (5 5 rho iota 10) 9 | ||
1 2 3 (1 2| 5 6 ( 1 2 3 4| 7 5 6 ( 1 2 3 4| 7 8 ( 1 2 3 4 5| 9 | ||
|3 4) | 5 6 7 8| | 5 6 7 8| | 6 7 8 9 10| | ||
| 9 10 1 2| | 9 10 1 2| | 1 2 3 4 5| | ||
| 3 4 5 6) | 3 4 5 6) | 6 7 8 9 10| | ||
| 1 2 3 4 5) | ||
|
||
x=1 2 3; x[2]=3 4 5 rho iota 100; x | ||
1 ( 1 2 3 4 5| 3 | ||
| 6 7 8 9 10| | ||
|11 12 13 14 15| | ||
|16 17 18 19 20| | ||
|
||
|21 22 23 24 25| | ||
|26 27 28 29 30| | ||
|31 32 33 34 35| | ||
|36 37 38 39 40| | ||
|
||
|41 42 43 44 45| | ||
|46 47 48 49 50| | ||
|51 52 53 54 55| | ||
|56 57 58 59 60) | ||
|
||
|
||
# Matrix with vector elements | ||
3 4 rho (1 2) (3 4) | ||
(1 2) (3 4) (1 2) (3 4) | ||
(1 2) (3 4) (1 2) (3 4) | ||
(1 2) (3 4) (1 2) (3 4) | ||
|
||
x = 3 4 rho iota 12; x[2;2] = 1 2 3; x | ||
1 2 3 4 | ||
5 (1 2 3) 7 8 | ||
9 10 11 12 | ||
|
||
x = 3 4 5 rho iota 60; x[2;2;2] = 1 2 3; x | ||
1 2 3 4 5 | ||
6 7 8 9 10 | ||
11 12 13 14 15 | ||
16 17 18 19 20 | ||
|
||
21 22 23 24 25 | ||
26 (1 2 3) 28 29 30 | ||
31 32 33 34 35 | ||
36 37 38 39 40 | ||
|
||
41 42 43 44 45 | ||
46 47 48 49 50 | ||
51 52 53 54 55 | ||
56 57 58 59 60 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters