Creating an array and attaching it to a pointer to a type

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Creating an array and attaching it to a pointer to a type

Douglas Bates
I'm still trying to come up with a way to read a feather (https://github.com/wesm/feather) file in Julia.  The available library that essentially defines the format is written in C++ and, while I can imitate existing code, I quickly tie myself in knots trying to access the heavily templated C++ code in a C function that can be called through ccall.

The file contains the binary representations of a number of columns, all the same length but not necessarily the same type. We want to return copies of the contents of the columns and their names and possibly other metadata.  Before I open the file I don't know the number of rows, number of columns or types of columns.  This information is all embedded in the binary file, the format of which is really only accessible through the C++ functions and methods.

I want to somehow create a C function that will take the path name, and possibly a pointer to a struct, open the file, determine the number of rows and the number and types of the columns, allocate storage that belongs to Julia and populate it.  If I have a pointer to an array of n Float64 values, say, how would I create a Julia Vector{Float64} of length n so that I can copy the contents into it?  And once I have created and populated the vector, how to I return it?  I'm sort-of thinking of passing a Ref{<immutable type>} and assigning a field in there but that is just a guess.

Reply | Threaded
Open this post in threaded view
|

Re: Creating an array and attaching it to a pointer to a type

Scott Jones
I was told on Twitter by the great Hadley Wickham 🤓 himself a couple of days ago:
@GandalfSoftware @wesmckinn  if it was blocking you, I think we could add a C API fairly quickly

You should also comment on these issues (about Julia support and C99 support):

It might be easier to wait until they produce a C API as part of their library, before trying to get a Julia wrapper for it.

On Friday, April 1, 2016 at 6:11:02 PM UTC-4, Douglas Bates wrote:
I'm still trying to come up with a way to read a feather (<a href="https://github.com/wesm/feather" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Fwesm%2Ffeather\46sa\75D\46sntz\0751\46usg\75AFQjCNEpvZ9gX4KIQ_YtCjqvq8vU3HundA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Fwesm%2Ffeather\46sa\75D\46sntz\0751\46usg\75AFQjCNEpvZ9gX4KIQ_YtCjqvq8vU3HundA&#39;;return true;">https://github.com/wesm/feather) file in Julia.  The available library that essentially defines the format is written in C++ and, while I can imitate existing code, I quickly tie myself in knots trying to access the heavily templated C++ code in a C function that can be called through ccall.

The file contains the binary representations of a number of columns, all the same length but not necessarily the same type. We want to return copies of the contents of the columns and their names and possibly other metadata.  Before I open the file I don't know the number of rows, number of columns or types of columns.  This information is all embedded in the binary file, the format of which is really only accessible through the C++ functions and methods.

I want to somehow create a C function that will take the path name, and possibly a pointer to a struct, open the file, determine the number of rows and the number and types of the columns, allocate storage that belongs to Julia and populate it.  If I have a pointer to an array of n Float64 values, say, how would I create a Julia Vector{Float64} of length n so that I can copy the contents into it?  And once I have created and populated the vector, how to I return it?  I'm sort-of thinking of passing a Ref{<immutable type>} and assigning a field in there but that is just a guess.