Skip to content

Commit

Permalink
Add exportToC method on Array proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
sgilmore10 committed May 10, 2024
1 parent f56c10c commit c3e6119
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions matlab/src/cpp/arrow/matlab/array/proxy/array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include "arrow/util/utf8.h"

#include "arrow/c/bridge.h"

#include "arrow/matlab/array/proxy/array.h"
#include "arrow/matlab/array/proxy/wrap.h"
#include "arrow/matlab/bit/unpack.h"
Expand Down Expand Up @@ -178,4 +180,19 @@ void Array::slice(libmexclass::proxy::method::Context& context) {
output[0]["TypeID"] = factory.createScalar(type_id);
context.outputs[0] = output;
}

void Array::exportToC(libmexclass::proxy::method::Context& context) {
namespace mda = ::matlab::data;
mda::StructArray opts = context.inputs[0];
const mda::TypedArray<uint64_t> array_address_mda = opts[0]["ArrowArrayAddress"];
const mda::TypedArray<uint64_t> schema_address_mda = opts[0]["ArrowSchemaAddress"];

struct ArrowArray* arrow_array = reinterpret_cast<struct ArrowArray*>(uint64_t(array_address_mda[0]));
struct ArrowSchema* arrow_schema = reinterpret_cast<struct ArrowSchema*>(uint64_t(schema_address_mda[0]));

MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(arrow::ExportArray(*array, arrow_array, arrow_schema), context, "arrow:c:export:Failed");

}


} // namespace arrow::matlab::array::proxy
2 changes: 2 additions & 0 deletions matlab/src/cpp/arrow/matlab/array/proxy/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class Array : public libmexclass::proxy::Proxy {

void slice(libmexclass::proxy::method::Context& context);

void exportToC(libmexclass::proxy::method::Context& context);

std::shared_ptr<arrow::Array> array;
};

Expand Down

0 comments on commit c3e6119

Please sign in to comment.