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

Pretty printing of matrices (and multidimensional arrays) #40

Open
certik opened this issue Dec 22, 2019 · 7 comments · May be fixed by #520
Open

Pretty printing of matrices (and multidimensional arrays) #40

certik opened this issue Dec 22, 2019 · 7 comments · May be fixed by #520
Labels
easy Difficulty level is easy and good for starting into this project good first issue Good for newcomers in progress This proposal is being worked on topic: utilities containers, strings, files, OS/environment integration, unit testing, assertions, logging, ...

Comments

@certik
Copy link
Member

certik commented Dec 22, 2019

Currently the standard Fortran's print *, A prints a 2D array A as a 1D list of numbers. Rather, I would like stdlib to have a function print_array (we can discuss a better name) that would print the array as NumPy:

>>> numpy.arange(10000).reshape(250,40)
array([[   0,    1,    2, ...,   37,   38,   39],
       [  40,   41,   42, ...,   77,   78,   79],
       [  80,   81,   82, ...,  117,  118,  119],
       ..., 
       [9880, 9881, 9882, ..., 9917, 9918, 9919],
       [9920, 9921, 9922, ..., 9957, 9958, 9959],
       [9960, 9961, 9962, ..., 9997, 9998, 9999]])

or Julia:

julia> B = [1 2; 3 4; 5 6; 7 8; 9 10]
5×2 Array{Int64,2}:
 1   2
 3   4
 5   6
 7   8
 9  10

Julia can also use nice unicode characters for ... and vertical ... if the array is too large.

Then we should use this function at

subroutine print_array(a)
and other places.

Then compilers can perhaps optionally use such print_array as default in the Fortran's language print statement.

@jvdp1
Copy link
Member

jvdp1 commented Dec 22, 2019

My preference is for a format like Julia 's one. It would be also a similar format as savetxt.

@ivan-pi
Copy link
Member

ivan-pi commented Dec 24, 2019

One prior art - Algorithm 892: DISPMODULE, a Fortran 95 module for pretty-printing matrices
https://dl.acm.org/citation.cfm?id=1486531

The code can be downloaded from netlib: http://netlib.org/toms/892.zip

@jvdp1
Copy link
Member

jvdp1 commented Dec 24, 2019

One prior art - Algorithm 892: DISPMODULE, a Fortran 95 module for pretty-printing matrices
https://dl.acm.org/citation.cfm?id=1486531

The code can be downloaded from netlib: http://netlib.org/toms/892.zip

Thank you for mentioning this librabry. It seems to be quite complete and flexible. Could we use it (with some modernisations) in stdlib (license?)?

@ivan-pi
Copy link
Member

ivan-pi commented Dec 25, 2019

Code published in TOMS is under the ACM Software License Agreement which allows usage for non-commercial purposes. I think that it is not compatible with what we want to achieve here.

I know Scipy contains the TOMS 748 algorithm. I checked and it looks like they wrote their own implementation.

@certik
Copy link
Member Author

certik commented Dec 25, 2019 via email

@ivan-pi
Copy link
Member

ivan-pi commented Dec 25, 2019

I had a look at the DISPMODULE API and it is indeed very nice and flexible supporting different formats (e.g. with a title, numbered rows and columns, precision, separators) and even printing several matrices adjacent to one another.

Taking a peak inside I can say that it would be beneficial to first start work on our own string module to handle conversion of reals/integers/logicals to character strings and some tools to parse format strings.

@jvdp1
Copy link
Member

jvdp1 commented Dec 25, 2019

Taking a peak inside I can say that it would be beneficial to first start work on our own string module to handle conversion of reals/integers/logicals to character strings and some tools to parse format strings.

I agree with that. I would also add that I think it would be goood to first take a discussion on the issue #35 , because it will be the same problem for this issue #40 (i.e., printing matrices of different kinds).
Also, since we not use DISPMODULE, we could base this API on those of savetxt. Afterall, savetxt write a matrix to a file instead to the standard output.

@jvdp1 jvdp1 added the topic: utilities containers, strings, files, OS/environment integration, unit testing, assertions, logging, ... label Jan 18, 2020
@milancurcic milancurcic added easy Difficulty level is easy and good for starting into this project good first issue Good for newcomers labels Mar 11, 2021
@awvwgk awvwgk linked a pull request Sep 18, 2021 that will close this issue
1 task
@zoziha zoziha linked a pull request Nov 9, 2021 that will close this issue
1 task
@14NGiestas 14NGiestas added the in progress This proposal is being worked on label May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy Difficulty level is easy and good for starting into this project good first issue Good for newcomers in progress This proposal is being worked on topic: utilities containers, strings, files, OS/environment integration, unit testing, assertions, logging, ...
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants