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

Collaborate with Fortran Standard Library to support npy format I/O #5

Open
milancurcic opened this issue Aug 27, 2021 · 10 comments
Open

Comments

@milancurcic
Copy link

milancurcic commented Aug 27, 2021

Hi Matthias, thank you for making this useful package.

I'm one of the maintainers of Fortran stdlib. We discussed supporting some common array storage file formats in fortran-lang/stdlib#486.

Are you interested in collaborating there on adding support for npy+npz file formats to stdlib?

@certik
Copy link

certik commented Aug 27, 2021

I second what Milan wrote. @MRedies your implementation is short and simple, I think it would be a perfect fit.

@milancurcic I think you might have tagged a wrong person.

@milancurcic
Copy link
Author

@milancurcic I think you might have tagged a wrong person.

Indeed, an @ snuck in :).

@MRedies
Copy link
Owner

MRedies commented Aug 28, 2021

Hello,

I am glad you like it and I'd be very happy if it can be part of stdlib. What do you need and how do you want me to help?

Maybe the library could cover all datatypes and dimensions more systematically, because currently I added them kind of on personal needs.

@MRedies
Copy link
Owner

MRedies commented Aug 28, 2021

I am not sure how stdlib is built, but it think it would ne nice if the library can still be build without any other files. (Kind of like Boost where you can also build some modules seperately)

@certik
Copy link

certik commented Aug 28, 2021

Thank you @MRedies.

We can definitely keep it separate, as well as include it in stdlib. Given how simple it is, I think there is a way to probably have exactly the same source code, so that there is no duplication of effort.

The next step is to discuss the API. The process is described here: https://github.com/fortran-lang/stdlib/blob/master/WORKFLOW.md

We can probably do it at the issue fortran-lang/stdlib#486, or open a new one.

@TejasAvinashShetty
Copy link

Is this going anywhere? @certik @MRedies @milancurcic

@certik
Copy link

certik commented Nov 24, 2021

I think I was waiting for @MRedies or @milancurcic to drive the effort :), but we got all busy.

@TejasAvinashShetty
Copy link

Thanks @certik for replying back so soon. I somehow have the feeling that the code could be compressed by using the

KIND 

PARAMETER to prevent the duplication of code.

@TejasAvinashShetty
Copy link

libnpy seems to be a library that provides simple routines for saving a C or Fortran array to a data file using NumPy's own binary format.
Please see https://scipy-cookbook.readthedocs.io/items/InputOutput.html

Not my idea See first CAZT's comment on CAZT's stackoverflow answer

@certik @milancurcic

@TejasAvinashShetty
Copy link

TejasAvinashShetty commented Dec 2, 2021

The following is an excerpt from https://scipy-cookbook.readthedocs.io/items/InputOutput.html

program fex
    use fnpy
    use iso_c_binding
    implicit none

    integer  :: i
    real(C_DOUBLE) :: a(2,4) = reshape([(i, i=1,8)], [2,4])

    call save_double("fa.npy", shape(a), a)
end program fe

The program creates a file fa.npy that you can load into python in the usual way.

But the entries of the NumPy array now follow the Fortran (column-major) ordering.

>>> fa = np.load('fa.npy')
>>> print fa
[[ 1.  3.  5.  7.]
 [ 2.  4.  6.  8.]] 

You can build the executable fex with npy.mod and libnpy.a in the same directory as fex.f95, with the command.

gfortran -o fex fex.f95 libnpy.a

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

4 participants