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

GH-33854: [MATLAB] Add basic libmexclass integration code to MATLAB interface #34563

Merged
merged 57 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
c90fbd7
Add basic libmexclass integration code to MATLAB interface
kevingurney Jan 12, 2023
5e0a794
Set SOURCE_SUBDIR in the call to ExternalProject_Add to point to the …
kevingurney Jan 13, 2023
8cf062f
Implement basic DoubleArrayProxy using libmexclass.
kevingurney Jan 13, 2023
00568c0
Fix Windows build error for the libmexclass integration.
sreeharihegden Jan 20, 2023
e5c40f2
Use dynamic values in DoubleArray.m, currently making a copy of all v…
lafiona Feb 3, 2023
32c2819
Add UInt64 array type, currently attempting no copy, but there is a bug.
lafiona Feb 3, 2023
826b386
Edit arrays to perform no-copy
lafiona Feb 15, 2023
44dd06c
Remove printing in C++ layer
lafiona Feb 16, 2023
77cb963
Install libmexclass binaries in +libmexclass packaged folder to arrow…
sreeharihegden Mar 9, 2023
61ae888
Specify CUSTOM_PROXY_FACTORY_HEADER_FILENAME and CUSTOM_PROXY_FACTORY…
kevingurney Mar 13, 2023
80805b9
Remove Proxy subclasses.
kevingurney Mar 13, 2023
1e4db94
Add basic custom display to arrow.array.DoubleArray which calls Print…
kevingurney Mar 13, 2023
e000ee1
Remove unused CustomDisplay subclass.
kevingurney Mar 13, 2023
6ed4274
Remove UInt64Array and UInt8Array.
kevingurney Mar 13, 2023
25fec16
Remove uint64 and uint8 C++ Proxy source code.
kevingurney Mar 13, 2023
d9afe91
Remove comment about 'No copy version'.
kevingurney Mar 13, 2023
cd7b7dc
Rearrange header order.
kevingurney Mar 13, 2023
718ee4b
Rename CustomProxyFactory to ArrowProxyFactory.
kevingurney Mar 13, 2023
64b2d04
Change namespace from proxy::array to arrow::matlab::proxy::array.
kevingurney Mar 13, 2023
84acd9d
Remove calls to REGISTER_PROXY for UInt64Array and UInt8Array.
kevingurney Mar 13, 2023
03b8132
Update #include for arrow_proxy_factory.h.
kevingurney Mar 13, 2023
cc3abaa
Remove references to UInt64 and UInt8 source files in CMakeLists.txt.
kevingurney Mar 13, 2023
433cf35
Use scope resolution operator to resolve MDA symbol look-up issues.
kevingurney Mar 13, 2023
5f3e5b4
Fix STRING typo in CMakeLists.txt.
kevingurney Mar 13, 2023
ac591ad
Change registered Proxy name from arrow.proxy.array.DoubleArrayProxy …
kevingurney Mar 13, 2023
e294427
Move double_array_proxy source code to array/proxy folder structure.
kevingurney Mar 13, 2023
6dfba28
Rename DoubleArrayProxy to DoubleArray.
kevingurney Mar 13, 2023
8b86eaa
Update CMakeLists.txt.
kevingurney Mar 13, 2023
64f054f
Update MATLAB Proxy constructor call for arrow.array.DoubleArray to u…
kevingurney Mar 13, 2023
b69b598
Rename ArrowProxyFactory to Factory.
kevingurney Mar 13, 2023
cff7364
Update value of CUSTOM_PROXY_SOURCES to reflect new directory structure.
kevingurney Mar 13, 2023
c89d0fb
Fix CMAKE_SOURCE_DIR typo.
kevingurney Mar 13, 2023
f704e19
Add using namespace declaration for libmexclass::proxy to arrow::matl…
kevingurney Mar 13, 2023
2ff931c
Disable warning output from find_package(Arrow) call by adding the QU…
kevingurney Mar 13, 2023
0d800a2
Add tools/cmake to CMAKE_MODULE_PATH.
kevingurney Mar 13, 2023
dbc5881
Create tools/cmake directory. Add MATLAB_ARROW_INTERFACE flag.
kevingurney Mar 13, 2023
8e7a3e7
Move libmexclass code into tools/cmake directory.
kevingurney Mar 13, 2023
884d2b1
Fixed build error for MATLAB_ARROW_INTERFACE with include.
sreeharihegden Mar 14, 2023
0ea2eb3
Inherit from matlab.mixin.CustomDisplay.
kevingurney Mar 14, 2023
cb85f7b
Remove comments referring to libmexclass in CMakeLists.txt.
kevingurney Mar 14, 2023
d845a92
Remove debug messages.
kevingurney Mar 14, 2023
383afdc
Modify comments. Add success message for libmexclass build.
kevingurney Mar 14, 2023
6b1bad9
Add MATLAB_ARROW_INTERFACE=ON to matlab_build.sh CI script.
kevingurney Mar 14, 2023
807f743
Add arrow_ep as a dependency of libmexclass target.
kevingurney Mar 14, 2023
95dbd12
Add basic MATLAB test for arrow.array.DoubleArray.
kevingurney Mar 14, 2023
239ceaa
Add missing license headers.
kevingurney Mar 14, 2023
4bf1153
Fix linting isssues in CMakeLists.txt.
kevingurney Mar 14, 2023
5451d76
Rename arrow.array.DoubleArray to arrow.array.Float64Array.
kevingurney Mar 14, 2023
6f00627
Use refactored libmexclass functionality via FetchContent.
kevingurney Apr 3, 2023
0a22524
Use list(PREPEND ...) to modify CMAKE_MODULE_PATH.
kevingurney Apr 18, 2023
2ddf128
Set Arrow_ROOT instead of modifying CMAKE_PREFIX_PATH to configure fi…
kevingurney Apr 18, 2023
38f967a
Refactor logic for building Arrow from source in order to build Googl…
kevingurney Apr 19, 2023
2e59596
Error when building in Debug mode on Windows by default.
kevingurney Apr 19, 2023
37470dd
Revert changes related to erroring for Debug builds.
kevingurney Apr 19, 2023
66f3548
Fix linting issues with matlab/CMakeLists.txt.
kevingurney Apr 19, 2023
737950a
Add newlines for readability in ci/scripts/matlab_build.sh.
kevingurney Apr 21, 2023
28721d7
Remove $ARROW_INCLUDE_DIRS from $MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROX…
kevingurney Apr 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ci/scripts/matlab_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ source_dir=${base_dir}/matlab
build_dir=${base_dir}/matlab/build
install_dir=${base_dir}/matlab/install

cmake -S ${source_dir} -B ${build_dir} -G Ninja -D MATLAB_BUILD_TESTS=ON -D CMAKE_INSTALL_PREFIX=${install_dir} -D MATLAB_ADD_INSTALL_DIR_TO_SEARCH_PATH=OFF
cmake \
-S ${source_dir} \
-B ${build_dir} \
-G Ninja \
-D MATLAB_ARROW_INTERFACE=ON \
-D MATLAB_BUILD_TESTS=ON \
-D CMAKE_INSTALL_PREFIX=${install_dir} \
-D MATLAB_ADD_INSTALL_DIR_TO_SEARCH_PATH=OFF
cmake --build ${build_dir} --config Release --target install
ctest --test-dir ${build_dir}
183 changes: 116 additions & 67 deletions matlab/CMakeLists.txt
kevingurney marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,66 @@ function(build_arrow)
message(SEND_ERROR "Error: unrecognized arguments: ${ARG_UNPARSED_ARGUMENTS}")
endif()

# If Arrow needs to be built, the default location will be within the build tree.
set(ARROW_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/arrow_ep-prefix")

if(WIN32)
# The shared library is located in the "bin" directory.
set(ARROW_SHARED_LIBRARY_DIR "${ARROW_PREFIX}/bin")

# Imported libraries are used
set(ARROW_IMPORT_LIB_FILENAME
"${CMAKE_IMPORT_LIBRARY_PREFIX}arrow${CMAKE_IMPORT_LIBRARY_SUFFIX}")
set(ARROW_IMPORT_LIB "${ARROW_PREFIX}/lib/${ARROW_IMPORT_LIB_FILENAME}")
else()
# The shared library is located in the "lib" directory.
set(ARROW_SHARED_LIBRARY_DIR "${ARROW_PREFIX}/lib")
endif()

set(ARROW_SHARED_LIB_FILENAME
"${CMAKE_SHARED_LIBRARY_PREFIX}arrow${CMAKE_SHARED_LIBRARY_SUFFIX}")
set(ARROW_SHARED_LIB "${ARROW_SHARED_LIBRARY_DIR}/${ARROW_SHARED_LIB_FILENAME}")

set(ARROW_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/arrow_ep-build")
set(ARROW_CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${ARROW_PREFIX}"
"-DCMAKE_INSTALL_LIBDIR=lib" "-DARROW_BUILD_STATIC=OFF")
set(ARROW_INCLUDE_DIR "${ARROW_PREFIX}/include")

# The output libraries need to be guaranteed to be available for linking the test
# executables.
if(WIN32)
# On Windows, add the Arrow link library as a BUILD_BYPRODUCTS for arrow_ep.
set(ARROW_BUILD_BYPRODUCTS "${ARROW_IMPORT_LIB}")
if(Arrow_FOUND
AND NOT GTest_FOUND
AND ARG_BUILD_GTEST)
# If find_package has already found a valid Arrow installation, then
# we don't want to link against the Arrow libraries that will be built
# from source.
#
# However, we still need to create a library target to trigger building
# of the arrow_ep target, which will ultimately build the bundled
# GoogleTest binaries.
add_library(arrow_shared_for_gtest SHARED IMPORTED)
set(ARROW_LIBRARY_TARGET arrow_shared_for_gtest)
else()
# On Linux and macOS, add the Arrow shared library as a BUILD_BYPRODUCTS for arrow_ep.
set(ARROW_BUILD_BYPRODUCTS "${ARROW_SHARED_LIB}")
add_library(arrow_shared SHARED IMPORTED)
set(ARROW_LIBRARY_TARGET arrow_shared)

# Set the runtime shared library (.dll, .so, or .dylib)
if(WIN32)
# The shared library (i.e. .dll) is located in the "bin" directory.
set(ARROW_SHARED_LIBRARY_DIR "${ARROW_PREFIX}/bin")
else()
# The shared library (i.e. .so or .dylib) is located in the "lib" directory.
set(ARROW_SHARED_LIBRARY_DIR "${ARROW_PREFIX}/lib")
endif()

set(ARROW_SHARED_LIB_FILENAME
"${CMAKE_SHARED_LIBRARY_PREFIX}arrow${CMAKE_SHARED_LIBRARY_SUFFIX}")
set(ARROW_SHARED_LIB "${ARROW_SHARED_LIBRARY_DIR}/${ARROW_SHARED_LIB_FILENAME}")

set_target_properties(arrow_shared PROPERTIES IMPORTED_LOCATION ${ARROW_SHARED_LIB})

# Set the link-time import library (.lib)
if(WIN32)
# The import library (i.e. .lib) is located in the "lib" directory.
set(ARROW_IMPORT_LIB_FILENAME
"${CMAKE_IMPORT_LIBRARY_PREFIX}arrow${CMAKE_IMPORT_LIBRARY_SUFFIX}")
set(ARROW_IMPORT_LIB "${ARROW_PREFIX}/lib/${ARROW_IMPORT_LIB_FILENAME}")

set_target_properties(arrow_shared PROPERTIES IMPORTED_IMPLIB ${ARROW_IMPORT_LIB})
endif()

# Set the include directories
set(ARROW_INCLUDE_DIR "${ARROW_PREFIX}/include")
file(MAKE_DIRECTORY "${ARROW_INCLUDE_DIR}")
set_target_properties(arrow_shared PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
${ARROW_INCLUDE_DIR})

# Set the build byproducts for the ExternalProject build
# The appropriate libraries need to be guaranteed to be available when linking the test
# executables.
if(WIN32)
set(ARROW_BUILD_BYPRODUCTS "${ARROW_IMPORT_LIB}")
else()
set(ARROW_BUILD_BYPRODUCTS "${ARROW_SHARED_LIB}")
endif()
endif()

# Building the Arrow C++ libraries and bundled GoogleTest binaries requires ExternalProject.
Expand All @@ -80,29 +107,6 @@ function(build_arrow)
CMAKE_ARGS "${ARROW_CMAKE_ARGS}"
BUILD_BYPRODUCTS "${ARROW_BUILD_BYPRODUCTS}")

set(ARROW_LIBRARY_TARGET arrow_shared)

# If find_package has already found a valid Arrow installation, then
# we don't want to link against the newly built arrow_shared library.
# However, we still need to create a library target to trigger building
# of the arrow_ep target, which will ultimately build the bundled
# GoogleTest binaries.
if(Arrow_FOUND)
set(ARROW_LIBRARY_TARGET arrow_shared_for_gtest)
endif()

file(MAKE_DIRECTORY "${ARROW_INCLUDE_DIR}")
add_library(${ARROW_LIBRARY_TARGET} SHARED IMPORTED)
set_target_properties(${ARROW_LIBRARY_TARGET}
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${ARROW_INCLUDE_DIR}
IMPORTED_LOCATION ${ARROW_SHARED_LIB})
if(WIN32)
# On Windows, IMPORTED_IMPLIB is set to the location of arrow.lib, which is
# for linking arrow_matlab against the Arrow C++ library.
set_target_properties(${ARROW_LIBRARY_TARGET} PROPERTIES IMPORTED_IMPLIB
${ARROW_IMPORT_LIB})
endif()

add_dependencies(${ARROW_LIBRARY_TARGET} arrow_ep)

if(ARG_BUILD_GTEST)
Expand Down Expand Up @@ -202,13 +206,16 @@ endif()

option(MATLAB_BUILD_TESTS "Build the C++ tests for the MATLAB interface" OFF)

# Grab CMAKE Modules from the CPP interface.
set(CPP_CMAKE_MODULES "${CMAKE_SOURCE_DIR}/../cpp/cmake_modules")
if(EXISTS "${CPP_CMAKE_MODULES}")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CPP_CMAKE_MODULES})
endif()
# Add tools/cmake directory to the CMAKE_MODULE_PATH.
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/tools/cmake)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake_modules)
# Configure find_package to look for arrow-config.cmake in Config mode
# underneath the Arrow installation directory hierarchy specified
# by ARROW_HOME or Arrow_ROOT.
# NOTE: ARROW_HOME is supported for backwards compatibility.
if(ARROW_HOME AND NOT Arrow_ROOT)
set(Arrow_ROOT "${ARROW_HOME}")
endif()

# Multi-Configuration generators (e.g. Visual Studio or XCode) place their build artifacts
# in a subdirectory named ${CMAKE_BUILD_TYPE} by default, where ${CMAKE_BUILD_TYPE} varies
Expand All @@ -228,7 +235,7 @@ if(MATLAB_BUILD_TESTS)
if(NOT GTest_FOUND)
# find_package(Arrow) supports custom ARROW_HOME as well as package
# managers.
find_package(Arrow)
find_package(Arrow QUIET)
# Trigger an automatic build of the Arrow C++ libraries and bundled
# GoogleTest binaries. If a valid Arrow installation was not already
# found by find_package, then build_arrow will use the Arrow
Expand Down Expand Up @@ -258,15 +265,15 @@ if(MATLAB_BUILD_TESTS)
"${GTEST_MAIN_SHARED_LIBRARY_LIB}")
endif()

find_package(Arrow)
find_package(Arrow QUIET)
if(NOT Arrow_FOUND)
# Trigger an automatic build of the Arrow C++ libraries.
build_arrow()
endif()
endif()

else()
find_package(Arrow)
find_package(Arrow QUIET)
if(NOT Arrow_FOUND)
build_arrow()
endif()
Expand Down Expand Up @@ -317,6 +324,51 @@ matlab_add_mex(R2018a

target_include_directories(mexcall PRIVATE ${CPP_SOURCE_DIR})

# ARROW_SHARED_LIB
# On Windows, this will be ARROW_HOME/bin/arrow.dll and on Linux and macOS, it is the arrow.so/dylib in the newly built arrow_shared library.
if(NOT Arrow_FOUND)
message(STATUS "ARROW_SHARED_LIB will be set using IMPORTED_LOCATION value when building."
)
get_target_property(ARROW_SHARED_LIB arrow_shared IMPORTED_LOCATION)
else()
# If not building Arrow, ARROW_SHARED_LIB derived from ARROW_PREFIX set to the ARROW_HOME specified with cmake would be non-empty.
message(STATUS "ARROW_SHARED_LIB: ${ARROW_SHARED_LIB}")
endif()

# ARROW_LINK_LIB
# On Windows, we use the arrow.lib for linking arrow_matlab against the Arrow C++ library.
# The location of arrow.lib is previously saved in IMPORTED_IMPLIB.
if(WIN32)
# If not building Arrow, IMPORTED_IMPLIB will be empty.
# Then set ARROW_LINK_LIB to ARROW_IMPORT_LIB which would have been derived from ARROW_PREFIX set to the ARROW_HOME specified with cmake. This will avoid the ARROW_LINK_LIB set to NOTFOUND error.
# The ARROW_IMPORT_LIB should be ARROW_HOME/lib/arrow.lib on Windows.
if(NOT Arrow_FOUND)
message(STATUS "ARROW_LINK_LIB will be set using IMPORTED_IMPLIB value when building."
)
get_target_property(ARROW_LINK_LIB arrow_shared IMPORTED_IMPLIB)
else()
set(ARROW_LINK_LIB "${ARROW_IMPORT_LIB}")
message(STATUS "Setting ARROW_LINK_LIB to ARROW_IMPORT_LIB: ${ARROW_IMPORT_LIB}, which is derived from the ARROW_HOME provided."
)
endif()
else()
# On Linux and macOS, it is the arrow.so/dylib in the newly built arrow_shared library used for linking.
# On Unix, this is the same as ARROW_SHARED_LIB.
message(STATUS "Setting ARROW_LINK_LIB to ARROW_SHARED_LIB as they are same on Unix.")
set(ARROW_LINK_LIB "${ARROW_SHARED_LIB}")
endif()

# ARROW_INCLUDE_DIR should be set so that header files in the include directory can be found correctly.
# The value of ARROW_INCLUDE_DIR should be ARROW_HOME/include on all platforms.
if(NOT Arrow_FOUND)
message(STATUS "ARROW_INCLUDE_DIR will be set using INTERFACE_INCLUDE_DIRECTORIES value when building."
)
get_target_property(ARROW_INCLUDE_DIR arrow_shared INTERFACE_INCLUDE_DIRECTORIES)
else()
# If not building Arrow, ARROW_INCLUDE_DIR derived from ARROW_PREFIX set to the ARROW_HOME specified with cmake would be non-empty.
message(STATUS "ARROW_INCLUDE_DIR: ${ARROW_INCLUDE_DIR}")
endif()

kevingurney marked this conversation as resolved.
Show resolved Hide resolved
# ##############################################################################
# C++ Tests
# ##############################################################################
Expand Down Expand Up @@ -396,9 +448,13 @@ endif()
# Create a subdirectory at CMAKE_INSTALL_PREFIX to install the interface.
set(CMAKE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/arrow_matlab")

if(MATLAB_ARROW_INTERFACE)
include(BuildMatlabArrowInterface)
endif()

# Create a package hierarchy at CMAKE_INSTALL_PREFIX to install the mex function
# and dependencies.
set(CMAKE_PACKAGED_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/arrow_matlab/+arrow/+cpp")
set(CMAKE_PACKAGED_INSTALL_DIR "${CMAKE_INSTALL_DIR}/+arrow/+cpp")

# Install MATLAB source files.
# On macOS, exclude '.DS_Store' files in the source tree from installation.
Expand All @@ -413,16 +469,9 @@ install(TARGETS arrow_matlab mexcall
RUNTIME DESTINATION ${CMAKE_PACKAGED_INSTALL_DIR}
LIBRARY DESTINATION ${CMAKE_PACKAGED_INSTALL_DIR})

get_target_property(ARROW_SHARED_LIB arrow_shared IMPORTED_LOCATION)
get_filename_component(ARROW_SHARED_LIB_DIR ${ARROW_SHARED_LIB} DIRECTORY)
get_filename_component(ARROW_SHARED_LIB_FILENAME ${ARROW_SHARED_LIB} NAME_WE)

if(WIN32)
# On Windows, arrow.dll must be installed to to CMAKE_PACKAGED_INSTALL_DIR regardless of whether
# Arrow_FOUND is true or false.
install(FILES ${ARROW_SHARED_LIB} DESTINATION "${CMAKE_PACKAGED_INSTALL_DIR}")
endif()

# On macOS, use the RPATH values below for runtime dependency resolution. This enables
# relocation of the installation directory.
if(APPLE)
Expand Down
25 changes: 25 additions & 0 deletions matlab/src/cpp/arrow/matlab/array/proxy/float64_array.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#include "float64_array.h"

namespace arrow::matlab::array::proxy {
void Float64Array::Print(libmexclass::proxy::method::Context& context) {
// TODO: Return an MDA string representation of the Arrow array.
std::cout << array->ToString() << std::endl;
}
} // namespace arrow::matlab::array::proxy
60 changes: 60 additions & 0 deletions matlab/src/cpp/arrow/matlab/array/proxy/float64_array.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#pragma once

#include "arrow/array.h"
#include "arrow/builder.h"

#include "libmexclass/proxy/Proxy.h"

namespace arrow::matlab::array::proxy {
class Float64Array : public libmexclass::proxy::Proxy {
public:
Float64Array(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
// Get the mxArray from constructor arguments
const ::matlab::data::TypedArray<double> double_mda = constructor_arguments[0];

// Get raw pointer of mxArray
auto it(double_mda.cbegin());
auto dt = it.operator->();

// Pass pointer to Arrow array constructor that takes a buffer
// Do not make a copy when creating arrow::Buffer
std::shared_ptr<arrow::Buffer> buffer(
new arrow::Buffer(reinterpret_cast<const uint8_t*>(dt),
sizeof(double) * double_mda.getNumberOfElements()));

// Construct arrow::NumericArray specialization using arrow::Buffer.
// pass in nulls information...we could compute and provide the number of nulls here too
std::shared_ptr<arrow::Array> array_wrapper(
new arrow::NumericArray<arrow::DoubleType>(double_mda.getNumberOfElements(), buffer,
nullptr, // TODO: fill validity bitmap with data
-1));

array = array_wrapper;

// Register Proxy methods.
REGISTER_METHOD(Float64Array, Print);
}
private:
void Print(libmexclass::proxy::method::Context& context);

// "Raw" arrow::Array
std::shared_ptr<arrow::Array> array;
};
} // namespace arrow::matlab::array::proxy
30 changes: 30 additions & 0 deletions matlab/src/cpp/arrow/matlab/mex/gateway.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#include "mex.hpp"
#include "mexAdapter.hpp"

#include "libmexclass/mex/gateway.h"

#include "arrow/matlab/proxy/factory.h"

class MexFunction : public matlab::mex::Function {
public:
void operator()(matlab::mex::ArgumentList outputs, matlab::mex::ArgumentList inputs) {
libmexclass::mex::gateway<arrow::matlab::proxy::Factory>(inputs, outputs, getEngine());
}
};
Loading