From c90fbd742ed47058427ce75ec0aaeb5cadaf69f6 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Thu, 12 Jan 2023 13:58:22 -0500 Subject: [PATCH 01/57] Add basic libmexclass integration code to MATLAB interface CMakeLists.txt. Co-authored-by: Sreehari Hegden --- matlab/CMakeLists.txt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index fbfd13edf3d..17bb4a7cdbc 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -317,6 +317,30 @@ matlab_add_mex(R2018a target_include_directories(mexcall PRIVATE ${CPP_SOURCE_DIR}) +############# libmexclass ################################# +# TODO: Define CUSTOM_PROXY variables. +set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "") +set(CUSTOM_PROXY_FACTORY_SOURCES "") +set(CUSTOM_PROXY_SOURCES "") +set(CUSTOM_PROXY_INCLUDE_DIR "") +set(CUSTOM_PROXY_LINK_LIBRARIES "") + +# Build libmexclass as an external project. +include(ExternalProject) +ExternalProject_Add( + libmexclass + GIT_REPOSITORY git@github.com:mathworks/libmexclass.git + GIT_TAG main + CMAKE_CACHE_ARGS "-D CUSTOM_PROXY_FACTORY_INCLUDE_DIR:STRING=${CUSTOM_PROXY_FACTORY_INCLUDE_DIR}" + "-D CUSTOM_PROXY_FACTORY_SOURCES:STRING=${CUSTOM_PROXY_FACTORY_SOURCES}" + "-D CUSTOM_PROXY_SOURCES:STRING=${CUSTOM_PROXY_SOURCES}" + "-D CUSTOM_PROXY_INCLUDE_DIR:STRING=${CUSTOM_PROXY_INCLUDE_DIR}" + "-D CUSTOM_PROXY_LINK_LIBRARIES:STRING=${CUSTOM_PROXY_LINK_LIBRARIES}" +) + +# TODO: Install libmexclass binaries. +############# libmexclass ################################# + # ############################################################################## # C++ Tests # ############################################################################## From 5e0a7944d7f88648b4f292f18f2ad327222f97b7 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Fri, 13 Jan 2023 15:08:55 -0500 Subject: [PATCH 02/57] Set SOURCE_SUBDIR in the call to ExternalProject_Add to point to the libmexclass CMakeLists.txt in the libmexclass/cpp directory. Co-authored-by: Sreehari Hegden --- matlab/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index 17bb4a7cdbc..44134c5987b 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -331,6 +331,7 @@ ExternalProject_Add( libmexclass GIT_REPOSITORY git@github.com:mathworks/libmexclass.git GIT_TAG main + SOURCE_SUBDIR libmexclass/cpp CMAKE_CACHE_ARGS "-D CUSTOM_PROXY_FACTORY_INCLUDE_DIR:STRING=${CUSTOM_PROXY_FACTORY_INCLUDE_DIR}" "-D CUSTOM_PROXY_FACTORY_SOURCES:STRING=${CUSTOM_PROXY_FACTORY_SOURCES}" "-D CUSTOM_PROXY_SOURCES:STRING=${CUSTOM_PROXY_SOURCES}" From 8cf062fdbb74f8cc33d07556b8086a1ba563786f Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Fri, 13 Jan 2023 17:48:29 -0500 Subject: [PATCH 03/57] Implement basic DoubleArrayProxy using libmexclass. Co-authored-by: Sreehari Hegden Co-authored-by: Fiona la --- matlab/CMakeLists.txt | 16 +++--- .../arrow/matlab/proxy/CustomProxyFactory.cc | 25 +++++++++ .../arrow/matlab/proxy/CustomProxyFactory.h | 28 ++++++++++ .../matlab/proxy/array/double_array_proxy.cc | 25 +++++++++ .../matlab/proxy/array/double_array_proxy.h | 52 +++++++++++++++++++ matlab/src/matlab/+arrow/+array/DoubleArray.m | 22 ++++++++ .../+arrow/+proxy/+array/DoubleArrayProxy.m | 2 + 7 files changed, 164 insertions(+), 6 deletions(-) create mode 100644 matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc create mode 100644 matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.h create mode 100644 matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.cc create mode 100644 matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h create mode 100644 matlab/src/matlab/+arrow/+array/DoubleArray.m create mode 100644 matlab/src/matlab/+arrow/+proxy/+array/DoubleArrayProxy.m diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index 44134c5987b..d17f28e391d 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -318,12 +318,15 @@ matlab_add_mex(R2018a target_include_directories(mexcall PRIVATE ${CPP_SOURCE_DIR}) ############# libmexclass ################################# -# TODO: Define CUSTOM_PROXY variables. -set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "") -set(CUSTOM_PROXY_FACTORY_SOURCES "") -set(CUSTOM_PROXY_SOURCES "") -set(CUSTOM_PROXY_INCLUDE_DIR "") -set(CUSTOM_PROXY_LINK_LIBRARIES "") +get_target_property(ARROW_SHARED_LIB arrow_shared IMPORTED_LOCATION) +get_target_property(ARROW_INCLUDE_DIR arrow_shared INTERFACE_INCLUDE_DIRECTORIES) + +set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy;${CMAKE_SOURCE_DIR}/src/cpp") +set(CUSTOM_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc") +set(CUSTOM_PROXY_SOURCES_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy") +set(CUSTOM_PROXY_SOURCES "${CUSTOM_PROXY_SOURCES_DIR}/array/double_array_proxy.cc") +set(CUSTOM_PROXY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp;${ARROW_INCLUDE_DIR}") +set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_SHARED_LIB}) # Build libmexclass as an external project. include(ExternalProject) @@ -337,6 +340,7 @@ ExternalProject_Add( "-D CUSTOM_PROXY_SOURCES:STRING=${CUSTOM_PROXY_SOURCES}" "-D CUSTOM_PROXY_INCLUDE_DIR:STRING=${CUSTOM_PROXY_INCLUDE_DIR}" "-D CUSTOM_PROXY_LINK_LIBRARIES:STRING=${CUSTOM_PROXY_LINK_LIBRARIES}" + INSTALL_COMMAND "" ) # TODO: Install libmexclass binaries. diff --git a/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc b/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc new file mode 100644 index 00000000000..96711a264d4 --- /dev/null +++ b/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc @@ -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 "arrow/matlab/proxy/array/double_array_proxy.h" + +#include "CustomProxyFactory.h" + +std::shared_ptr CustomProxyFactory::make_proxy(const ClassName& class_name, const FunctionArguments& constructor_arguments) { + registerProxy(DoubleArrayProxy); + return nullptr; +}; diff --git a/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.h b/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.h new file mode 100644 index 00000000000..428c73669bc --- /dev/null +++ b/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.h @@ -0,0 +1,28 @@ +// 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 "libmexclass/proxy/Factory.h" + +using namespace libmexclass::proxy; + +class CustomProxyFactory : public libmexclass::proxy::Factory { + public: + CustomProxyFactory() { } + virtual std::shared_ptr make_proxy(const ClassName& class_name, const FunctionArguments& constructor_arguments); +}; diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.cc b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.cc new file mode 100644 index 00000000000..cf7bec4a4f3 --- /dev/null +++ b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.cc @@ -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 "double_array_proxy.h" + +using namespace libmexclass::proxy; + +void DoubleArrayProxy::Print(method::Context& context) { + // TODO: Return an MDA string representation of the Arrow array. + std::cout << array->ToString() << std::endl; +} diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h new file mode 100644 index 00000000000..aeb57dc2f1a --- /dev/null +++ b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h @@ -0,0 +1,52 @@ +// 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 "libmexclass/proxy/Proxy.h" + +#include "arrow/array.h" +#include "arrow/builder.h" + +using namespace libmexclass::proxy; + +class DoubleArrayProxy : public libmexclass::proxy::Proxy { + public: + DoubleArrayProxy(const FunctionArguments& constructor_arguments) { + // TODO: Implement initialization of Array from the MATLAB mxArray passed to the constructor. + arrow::DoubleBuilder builder; + + auto status = builder.Append(1.0); + status = builder.Append(2.0); + status = builder.Append(3.0); + + auto maybe_array = builder.Finish(); + if (!maybe_array.ok()) { + // TODO: Handle possible errors. + } + + array = *maybe_array; + + // Register Proxy methods. + registerMethod(DoubleArrayProxy, Print); + } + private: + void Print(method::Context& context); + + // "Raw" arrow::Array + std::shared_ptr array; +}; diff --git a/matlab/src/matlab/+arrow/+array/DoubleArray.m b/matlab/src/matlab/+arrow/+array/DoubleArray.m new file mode 100644 index 00000000000..03b5ba1bbca --- /dev/null +++ b/matlab/src/matlab/+arrow/+array/DoubleArray.m @@ -0,0 +1,22 @@ +classdef DoubleArray + + properties (Access=private) + Proxy + end + + properties (Access=private) + MatlabArray + end + + methods + function obj = DoubleArray(matlabArray) + obj.Proxy = arrow.proxy.array.DoubleArrayProxy(); + obj.MatlabArray = matlabArray; + end + + function Print(obj) + obj.Proxy.Print(); + end + end + +end diff --git a/matlab/src/matlab/+arrow/+proxy/+array/DoubleArrayProxy.m b/matlab/src/matlab/+arrow/+proxy/+array/DoubleArrayProxy.m new file mode 100644 index 00000000000..1ebe6bb583a --- /dev/null +++ b/matlab/src/matlab/+arrow/+proxy/+array/DoubleArrayProxy.m @@ -0,0 +1,2 @@ +classdef DoubleArrayProxy < libmexclass.proxy.Proxy +end From 00568c0578dbc41d66441c8ae7d1be915e4be64c Mon Sep 17 00:00:00 2001 From: shegden Date: Fri, 20 Jan 2023 16:52:54 -0500 Subject: [PATCH 04/57] Fix Windows build error for the libmexclass integration. Also, update the register proxy macro used to reflect the libmexclass changes for mathworks/libmexclass#20. Co-authored-by: Fiona la --- matlab/CMakeLists.txt | 12 ++++++++++-- .../src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index d17f28e391d..a1e7eb092ef 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -318,7 +318,15 @@ matlab_add_mex(R2018a target_include_directories(mexcall PRIVATE ${CPP_SOURCE_DIR}) ############# libmexclass ################################# -get_target_property(ARROW_SHARED_LIB arrow_shared IMPORTED_LOCATION) +# 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) + get_target_property(ARROW_LINK_LIB arrow_shared IMPORTED_IMPLIB) +else() + # On Linux and macOS, it is the arrow.dll in the newly built arrow_shared library used for linking. + # This is available in IMPORTED_LOCATION. + get_target_property(ARROW_LINK_LIB arrow_shared IMPORTED_LOCATION) +endif() get_target_property(ARROW_INCLUDE_DIR arrow_shared INTERFACE_INCLUDE_DIRECTORIES) set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy;${CMAKE_SOURCE_DIR}/src/cpp") @@ -326,7 +334,7 @@ set(CUSTOM_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy set(CUSTOM_PROXY_SOURCES_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy") set(CUSTOM_PROXY_SOURCES "${CUSTOM_PROXY_SOURCES_DIR}/array/double_array_proxy.cc") set(CUSTOM_PROXY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp;${ARROW_INCLUDE_DIR}") -set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_SHARED_LIB}) +set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_LINK_LIB}) # Build libmexclass as an external project. include(ExternalProject) diff --git a/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc b/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc index 96711a264d4..72d8a028d68 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc +++ b/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc @@ -20,6 +20,6 @@ #include "CustomProxyFactory.h" std::shared_ptr CustomProxyFactory::make_proxy(const ClassName& class_name, const FunctionArguments& constructor_arguments) { - registerProxy(DoubleArrayProxy); + REGISTER_PROXY_SAME_NAME(DoubleArrayProxy); return nullptr; }; From e5c40f250077147de9ab914100208e6de5710ea3 Mon Sep 17 00:00:00 2001 From: Fiona La Date: Fri, 3 Feb 2023 16:48:36 -0500 Subject: [PATCH 05/57] Use dynamic values in DoubleArray.m, currently making a copy of all values. --- matlab/CMakeLists.txt | 28 +++++--- .../arrow/matlab/proxy/CustomProxyFactory.cc | 11 +++- .../matlab/proxy/array/double_array_proxy.cc | 6 +- .../matlab/proxy/array/double_array_proxy.h | 64 ++++++++++++++++--- matlab/src/matlab/+arrow/+array/DoubleArray.m | 4 +- 5 files changed, 90 insertions(+), 23 deletions(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index a1e7eb092ef..83c068f6879 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -202,13 +202,17 @@ 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() +# # 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() + +# set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake_modules) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake_modules) +# Get find_package(Arrow) by setting Arrow_DIR to CPP interface ArrowConfig.cmake +# TODO: Make sure this works on all platforms submitting +set(CMAKE_PREFIX_PATH "${ARROW_HOME}/lib/cmake/Arrow") # 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 @@ -323,16 +327,22 @@ target_include_directories(mexcall PRIVATE ${CPP_SOURCE_DIR}) if(WIN32) get_target_property(ARROW_LINK_LIB arrow_shared IMPORTED_IMPLIB) else() - # On Linux and macOS, it is the arrow.dll in the newly built arrow_shared library used for linking. + # On Linux and macOS, it is the arrow.so/dylib in the newly built arrow_shared library used for linking. # This is available in IMPORTED_LOCATION. - get_target_property(ARROW_LINK_LIB arrow_shared IMPORTED_LOCATION) + # TODO: Why does this not return a value? Returns NOT-FOUND + # get_target_property(ARROW_LINK_LIB arrow_shared IMPORTED_LOCATION) + # message(STATUS "**************** ARROW_SHARED_LIB: ${ARROW_SHARED_LIB}") + + set(ARROW_LINK_LIB "${ARROW_SHARED_LIB}") endif() get_target_property(ARROW_INCLUDE_DIR arrow_shared INTERFACE_INCLUDE_DIRECTORIES) + + set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy;${CMAKE_SOURCE_DIR}/src/cpp") set(CUSTOM_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc") set(CUSTOM_PROXY_SOURCES_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy") -set(CUSTOM_PROXY_SOURCES "${CUSTOM_PROXY_SOURCES_DIR}/array/double_array_proxy.cc") +set(CUSTOM_PROXY_SOURCES "${CUSTOM_PROXY_SOURCES_DIR}/array/double_array_proxy.cc" "${CUSTOM_PROXY_SOURCES_DIR}/array/uint64_array_proxy.cc") set(CUSTOM_PROXY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp;${ARROW_INCLUDE_DIR}") set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_LINK_LIB}) diff --git a/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc b/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc index 72d8a028d68..508babab1f1 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc +++ b/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc @@ -16,10 +16,19 @@ // under the License. #include "arrow/matlab/proxy/array/double_array_proxy.h" +#include "arrow/matlab/proxy/array/uint64_array_proxy.h" #include "CustomProxyFactory.h" +#include + std::shared_ptr CustomProxyFactory::make_proxy(const ClassName& class_name, const FunctionArguments& constructor_arguments) { - REGISTER_PROXY_SAME_NAME(DoubleArrayProxy); + + // Link MATLAB proxy classes with corresponding C++ proxy classes + REGISTER_PROXY(arrow.proxy.array.DoubleArrayProxy, proxy::array::DoubleArrayProxy); + REGISTER_PROXY(arrow.proxy.array.UInt64ArrayProxy, proxy::array::UInt64ArrayProxy); + + // TODO: Decide what to do in the case that there isn't a Proxy match. + std::cout << "Did not find a matching C++ proxy for: " + class_name << std::endl; return nullptr; }; diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.cc b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.cc index cf7bec4a4f3..74a21a881a6 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.cc +++ b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.cc @@ -17,9 +17,9 @@ #include "double_array_proxy.h" -using namespace libmexclass::proxy; - -void DoubleArrayProxy::Print(method::Context& context) { +namespace proxy::array { +void DoubleArrayProxy::Print(libmexclass::proxy::method::Context& context) { // TODO: Return an MDA string representation of the Arrow array. std::cout << array->ToString() << std::endl; } +} // namespace proxy::array \ No newline at end of file diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h index aeb57dc2f1a..107ea39858f 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h +++ b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h @@ -22,17 +22,50 @@ #include "arrow/array.h" #include "arrow/builder.h" -using namespace libmexclass::proxy; - +namespace proxy::array { class DoubleArrayProxy : public libmexclass::proxy::Proxy { public: - DoubleArrayProxy(const FunctionArguments& constructor_arguments) { - // TODO: Implement initialization of Array from the MATLAB mxArray passed to the constructor. + DoubleArrayProxy(const libmexclass::proxy::FunctionArguments& constructor_arguments) { + // // No copy version + // std::cout << "DoubleArrayProxy constructor: " << std::endl; + + // // Get the mxArray from constructor arguments + // matlab::data::TypedArray double_mda = constructor_arguments[0]; + + // for (auto& elem : double_mda) { + // std::cout << elem << std::endl; + // } + + // std::cout << "1. Get raw pointer of mxArray" << std::endl; + // // Get raw pointer of mxArray + // matlab::data::TypedIterator it(double_mda.begin()); + // auto dt = it.operator->(); + + // std::cout << "Pass raw pointer to construct array" << std::endl; + // // Pass pointer to Arrow array constructor that takes a buffer + // // Do not make a copy when creating arrow::Buffer + // std::shared_ptr buffer( + // new arrow::Buffer(reinterpret_cast(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 array_wrapper( + // new arrow::NumericArray(double_mda.getNumberOfElements(), buffer, + // nullptr, // TODO: fill validity bitmap with data + // -1)); + + // array = array_wrapper; + + // With copy version arrow::DoubleBuilder builder; + + // Get the mxArray from constructor arguments + matlab::data::TypedArray double_mda = constructor_arguments[0]; - auto status = builder.Append(1.0); - status = builder.Append(2.0); - status = builder.Append(3.0); + for (auto& elem : double_mda) { + auto status = builder.Append(elem); + } auto maybe_array = builder.Finish(); if (!maybe_array.ok()) { @@ -41,12 +74,27 @@ class DoubleArrayProxy : public libmexclass::proxy::Proxy { array = *maybe_array; + // // Hard coded values version + // arrow::DoubleBuilder builder; + + // auto status = builder.Append(1.0); + // status = builder.Append(2.0); + // status = builder.Append(3.0); + + // auto maybe_array = builder.Finish(); + // if (!maybe_array.ok()) { + // // TODO: Handle possible errors. + // } + + // array = *maybe_array; + // Register Proxy methods. registerMethod(DoubleArrayProxy, Print); } private: - void Print(method::Context& context); + void Print(libmexclass::proxy::method::Context& context); // "Raw" arrow::Array std::shared_ptr array; }; +} // namespace proxy::array \ No newline at end of file diff --git a/matlab/src/matlab/+arrow/+array/DoubleArray.m b/matlab/src/matlab/+arrow/+array/DoubleArray.m index 03b5ba1bbca..1466e6abd9b 100644 --- a/matlab/src/matlab/+arrow/+array/DoubleArray.m +++ b/matlab/src/matlab/+arrow/+array/DoubleArray.m @@ -1,4 +1,4 @@ -classdef DoubleArray +classdef DoubleArray < arrow.array.internal.CustomDisplay properties (Access=private) Proxy @@ -10,7 +10,7 @@ methods function obj = DoubleArray(matlabArray) - obj.Proxy = arrow.proxy.array.DoubleArrayProxy(); + obj.Proxy = arrow.proxy.array.DoubleArrayProxy(matlabArray); obj.MatlabArray = matlabArray; end From 32c28191273d38143c2cb5df36d572ecf4e8de7b Mon Sep 17 00:00:00 2001 From: Fiona La Date: Fri, 3 Feb 2023 16:53:24 -0500 Subject: [PATCH 06/57] Add UInt64 array type, currently attempting no copy, but there is a bug. --- .../matlab/proxy/array/uint64_array_proxy.cc | 25 +++++++ .../matlab/proxy/array/uint64_array_proxy.h | 67 +++++++++++++++++++ .../+arrow/+array/+internal/CustomDisplay.m | 7 ++ matlab/src/matlab/+arrow/+array/UInt64Array.m | 22 ++++++ .../+arrow/+proxy/+array/UInt64ArrayProxy.m | 2 + 5 files changed, 123 insertions(+) create mode 100644 matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.cc create mode 100644 matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.h create mode 100644 matlab/src/matlab/+arrow/+array/+internal/CustomDisplay.m create mode 100644 matlab/src/matlab/+arrow/+array/UInt64Array.m create mode 100644 matlab/src/matlab/+arrow/+proxy/+array/UInt64ArrayProxy.m diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.cc b/matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.cc new file mode 100644 index 00000000000..fffcf39d0e2 --- /dev/null +++ b/matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.cc @@ -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 "uint64_array_proxy.h" + +namespace proxy::array { +void UInt64ArrayProxy::Print(libmexclass::proxy::method::Context& context) { + // TODO: Return an MDA string representation of the Arrow array. + std::cout << array->ToString() << std::endl; +} +} // namespace proxy::array \ No newline at end of file diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.h b/matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.h new file mode 100644 index 00000000000..cd3bf902ae2 --- /dev/null +++ b/matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.h @@ -0,0 +1,67 @@ +// 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 <_types/_uint64_t.h> +#include "libmexclass/proxy/Proxy.h" + +#include "arrow/array.h" +#include "arrow/builder.h" + +namespace proxy::array { +class UInt64ArrayProxy : public libmexclass::proxy::Proxy { + public: + UInt64ArrayProxy(const libmexclass::proxy::FunctionArguments& constructor_arguments) { + // TODO: Implement initialization of Array from the MATLAB mxArray passed to the constructor. + std::cout << "UInt64ArrayProxy constructor: " << std::endl; + + // Get the mxArray from constructor arguments + matlab::data::TypedArray uint64_mda = constructor_arguments[0]; + + std::cout << "1. Get raw pointer of mxArray" << std::endl; + // Get raw pointer of mxArray + matlab::data::TypedIterator it(uint64_mda.begin()); + auto dt = it.operator->(); + + std::cout << "2. Pass raw pointer to construct array" << std::endl; + // Pass pointer to Arrow array constructor that takes a buffer + // Do not make a copy when creating arrow::Buffer + std::shared_ptr buffer( + new arrow::Buffer(reinterpret_cast(dt), + sizeof(uint64_t) * uint64_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 array_wrapper( + new arrow::NumericArray(uint64_mda.getNumberOfElements(), buffer, + nullptr, // TODO: fill validity bitmap with data + -1)); + + std::cout << "3. Return array to be stored in LifetimeManager" << std::endl; + array = array_wrapper; + + // Register Proxy methods. + registerMethod(UInt64ArrayProxy, Print); + } + private: + void Print(libmexclass::proxy::method::Context& context); + + // "Raw" arrow::Array + std::shared_ptr array; +}; +} // namespace proxy::array \ No newline at end of file diff --git a/matlab/src/matlab/+arrow/+array/+internal/CustomDisplay.m b/matlab/src/matlab/+arrow/+array/+internal/CustomDisplay.m new file mode 100644 index 00000000000..fad319a28c3 --- /dev/null +++ b/matlab/src/matlab/+arrow/+array/+internal/CustomDisplay.m @@ -0,0 +1,7 @@ +classdef CustomDisplay < matlab.mixin.CustomDisplay + methods (Access = protected) + function s = getFooter(~) + s = 'Here is my custom footer'; + end + end +end \ No newline at end of file diff --git a/matlab/src/matlab/+arrow/+array/UInt64Array.m b/matlab/src/matlab/+arrow/+array/UInt64Array.m new file mode 100644 index 00000000000..e3b63336cb2 --- /dev/null +++ b/matlab/src/matlab/+arrow/+array/UInt64Array.m @@ -0,0 +1,22 @@ +classdef UInt64Array + + properties (Access=private) + Proxy + end + + properties (Access=private) + MatlabArray + end + + methods + function obj = UInt64Array(matlabArray) + obj.Proxy = arrow.proxy.array.UInt64ArrayProxy(uint64(matlabArray)); + obj.MatlabArray = matlabArray; + end + + function Print(obj) + obj.Proxy.Print(); + end + end + +end diff --git a/matlab/src/matlab/+arrow/+proxy/+array/UInt64ArrayProxy.m b/matlab/src/matlab/+arrow/+proxy/+array/UInt64ArrayProxy.m new file mode 100644 index 00000000000..8444045c2af --- /dev/null +++ b/matlab/src/matlab/+arrow/+proxy/+array/UInt64ArrayProxy.m @@ -0,0 +1,2 @@ +classdef UInt64ArrayProxy < libmexclass.proxy.Proxy +end From 826b3862b9f25ce599ff8d395046868c10ff8882 Mon Sep 17 00:00:00 2001 From: Fiona La Date: Wed, 15 Feb 2023 16:45:26 -0500 Subject: [PATCH 07/57] Edit arrays to perform no-copy --- matlab/CMakeLists.txt | 2 +- .../arrow/matlab/proxy/CustomProxyFactory.cc | 2 + .../matlab/proxy/array/double_array_proxy.h | 74 +++++-------------- .../matlab/proxy/array/uint64_array_proxy.h | 9 +-- .../matlab/proxy/array/uint8_array_proxy.cc | 25 +++++++ .../matlab/proxy/array/uint8_array_proxy.h | 70 ++++++++++++++++++ .../+arrow/+array/+internal/CustomDisplay.m | 8 +- matlab/src/matlab/+arrow/+array/DoubleArray.m | 2 +- matlab/src/matlab/+arrow/+array/UInt64Array.m | 4 +- matlab/src/matlab/+arrow/+array/UInt8Array.m | 22 ++++++ .../+arrow/+proxy/+array/UInt8ArrayProxy.m | 2 + 11 files changed, 153 insertions(+), 67 deletions(-) create mode 100644 matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.cc create mode 100644 matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.h create mode 100644 matlab/src/matlab/+arrow/+array/UInt8Array.m create mode 100644 matlab/src/matlab/+arrow/+proxy/+array/UInt8ArrayProxy.m diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index 83c068f6879..585543f6886 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -342,7 +342,7 @@ get_target_property(ARROW_INCLUDE_DIR arrow_shared INTERFACE_INCLUDE_DIRECTORIES set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy;${CMAKE_SOURCE_DIR}/src/cpp") set(CUSTOM_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc") set(CUSTOM_PROXY_SOURCES_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy") -set(CUSTOM_PROXY_SOURCES "${CUSTOM_PROXY_SOURCES_DIR}/array/double_array_proxy.cc" "${CUSTOM_PROXY_SOURCES_DIR}/array/uint64_array_proxy.cc") +set(CUSTOM_PROXY_SOURCES "${CUSTOM_PROXY_SOURCES_DIR}/array/double_array_proxy.cc" "${CUSTOM_PROXY_SOURCES_DIR}/array/uint64_array_proxy.cc" "${CUSTOM_PROXY_SOURCES_DIR}/array/uint8_array_proxy.cc" ) set(CUSTOM_PROXY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp;${ARROW_INCLUDE_DIR}") set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_LINK_LIB}) diff --git a/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc b/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc index 508babab1f1..91c0cff2851 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc +++ b/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc @@ -17,6 +17,7 @@ #include "arrow/matlab/proxy/array/double_array_proxy.h" #include "arrow/matlab/proxy/array/uint64_array_proxy.h" +#include "arrow/matlab/proxy/array/uint8_array_proxy.h" #include "CustomProxyFactory.h" @@ -27,6 +28,7 @@ std::shared_ptr CustomProxyFactory::make_proxy(const ClassName& class_nam // Link MATLAB proxy classes with corresponding C++ proxy classes REGISTER_PROXY(arrow.proxy.array.DoubleArrayProxy, proxy::array::DoubleArrayProxy); REGISTER_PROXY(arrow.proxy.array.UInt64ArrayProxy, proxy::array::UInt64ArrayProxy); + REGISTER_PROXY(arrow.proxy.array.UInt8ArrayProxy, proxy::array::UInt8ArrayProxy); // TODO: Decide what to do in the case that there isn't a Proxy match. std::cout << "Did not find a matching C++ proxy for: " + class_name << std::endl; diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h index 107ea39858f..2fc85ba1e9c 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h +++ b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h @@ -26,67 +26,33 @@ namespace proxy::array { class DoubleArrayProxy : public libmexclass::proxy::Proxy { public: DoubleArrayProxy(const libmexclass::proxy::FunctionArguments& constructor_arguments) { - // // No copy version - // std::cout << "DoubleArrayProxy constructor: " << std::endl; + // No copy version - // // Get the mxArray from constructor arguments - // matlab::data::TypedArray double_mda = constructor_arguments[0]; - - // for (auto& elem : double_mda) { - // std::cout << elem << std::endl; - // } - - // std::cout << "1. Get raw pointer of mxArray" << std::endl; - // // Get raw pointer of mxArray - // matlab::data::TypedIterator it(double_mda.begin()); - // auto dt = it.operator->(); - - // std::cout << "Pass raw pointer to construct array" << std::endl; - // // Pass pointer to Arrow array constructor that takes a buffer - // // Do not make a copy when creating arrow::Buffer - // std::shared_ptr buffer( - // new arrow::Buffer(reinterpret_cast(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 array_wrapper( - // new arrow::NumericArray(double_mda.getNumberOfElements(), buffer, - // nullptr, // TODO: fill validity bitmap with data - // -1)); - - // array = array_wrapper; - - // With copy version - arrow::DoubleBuilder builder; - // Get the mxArray from constructor arguments - matlab::data::TypedArray double_mda = constructor_arguments[0]; + const matlab::data::TypedArray double_mda = constructor_arguments[0]; for (auto& elem : double_mda) { - auto status = builder.Append(elem); + std::cout << elem << std::endl; } - auto maybe_array = builder.Finish(); - if (!maybe_array.ok()) { - // TODO: Handle possible errors. - } - - array = *maybe_array; - - // // Hard coded values version - // arrow::DoubleBuilder builder; + // Get raw pointer of mxArray + auto it(double_mda.cbegin()); + auto dt = it.operator->(); - // auto status = builder.Append(1.0); - // status = builder.Append(2.0); - // status = builder.Append(3.0); - - // auto maybe_array = builder.Finish(); - // if (!maybe_array.ok()) { - // // TODO: Handle possible errors. - // } - - // array = *maybe_array; + // Pass pointer to Arrow array constructor that takes a buffer + // Do not make a copy when creating arrow::Buffer + std::shared_ptr buffer( + new arrow::Buffer(reinterpret_cast(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 array_wrapper( + new arrow::NumericArray(double_mda.getNumberOfElements(), buffer, + nullptr, // TODO: fill validity bitmap with data + -1)); + + array = array_wrapper; // Register Proxy methods. registerMethod(DoubleArrayProxy, Print); diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.h b/matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.h index cd3bf902ae2..9098eac9a59 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.h +++ b/matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.h @@ -27,18 +27,14 @@ namespace proxy::array { class UInt64ArrayProxy : public libmexclass::proxy::Proxy { public: UInt64ArrayProxy(const libmexclass::proxy::FunctionArguments& constructor_arguments) { - // TODO: Implement initialization of Array from the MATLAB mxArray passed to the constructor. - std::cout << "UInt64ArrayProxy constructor: " << std::endl; // Get the mxArray from constructor arguments - matlab::data::TypedArray uint64_mda = constructor_arguments[0]; + const matlab::data::TypedArray uint64_mda = constructor_arguments[0]; - std::cout << "1. Get raw pointer of mxArray" << std::endl; // Get raw pointer of mxArray - matlab::data::TypedIterator it(uint64_mda.begin()); + auto it(uint64_mda.cbegin()); auto dt = it.operator->(); - std::cout << "2. Pass raw pointer to construct array" << std::endl; // Pass pointer to Arrow array constructor that takes a buffer // Do not make a copy when creating arrow::Buffer std::shared_ptr buffer( @@ -52,7 +48,6 @@ class UInt64ArrayProxy : public libmexclass::proxy::Proxy { nullptr, // TODO: fill validity bitmap with data -1)); - std::cout << "3. Return array to be stored in LifetimeManager" << std::endl; array = array_wrapper; // Register Proxy methods. diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.cc b/matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.cc new file mode 100644 index 00000000000..431892657ea --- /dev/null +++ b/matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.cc @@ -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 "uint8_array_proxy.h" + +namespace proxy::array { +void UInt8ArrayProxy::Print(libmexclass::proxy::method::Context& context) { + // TODO: Return an MDA string representation of the Arrow array. + std::cout << array->ToString() << std::endl; +} +} // namespace proxy::array \ No newline at end of file diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.h b/matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.h new file mode 100644 index 00000000000..8b1e4092b42 --- /dev/null +++ b/matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.h @@ -0,0 +1,70 @@ +// 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 "libmexclass/proxy/Proxy.h" + +#include "arrow/array.h" +#include "arrow/builder.h" + +namespace proxy::array { +class UInt8ArrayProxy : public libmexclass::proxy::Proxy { + private: + // const matlab::data::TypedArray uint8_mda; + + public: + UInt8ArrayProxy(const libmexclass::proxy::FunctionArguments& constructor_arguments) { + // Fewer copy version + + // Get the mxArray from constructor arguments + const matlab::data::TypedArray uint8_mda = constructor_arguments[0]; + + for (auto& elem : uint8_mda) { + std::cout << elem << std::endl; + } + + // Create a shared data copy of uint8_mda and store it as a property of proxy class + // Get raw pointer of mxArray + auto it = uint8_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 buffer( + new arrow::Buffer(reinterpret_cast(dt), + sizeof(uint8_t) * uint8_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 array_wrapper( + new arrow::NumericArray(uint8_mda.getNumberOfElements(), buffer, + nullptr, // TODO: fill validity bitmap with data + -1)); + + array = array_wrapper; + + // Register Proxy methods. + registerMethod(UInt8ArrayProxy, Print); + } + private: + void Print(libmexclass::proxy::method::Context& context); + + // "Raw" arrow::Array + std::shared_ptr array; +}; +} // namespace proxy::array \ No newline at end of file diff --git a/matlab/src/matlab/+arrow/+array/+internal/CustomDisplay.m b/matlab/src/matlab/+arrow/+array/+internal/CustomDisplay.m index fad319a28c3..a95338d4051 100644 --- a/matlab/src/matlab/+arrow/+array/+internal/CustomDisplay.m +++ b/matlab/src/matlab/+arrow/+array/+internal/CustomDisplay.m @@ -1,7 +1,11 @@ classdef CustomDisplay < matlab.mixin.CustomDisplay methods (Access = protected) - function s = getFooter(~) - s = 'Here is my custom footer'; + function [pg] = getPropertyGroups(obj) + pg = []; + end + + function displayNonScalarObject(obj) + obj.Print(); end end end \ No newline at end of file diff --git a/matlab/src/matlab/+arrow/+array/DoubleArray.m b/matlab/src/matlab/+arrow/+array/DoubleArray.m index 1466e6abd9b..10bc8c3c4a8 100644 --- a/matlab/src/matlab/+arrow/+array/DoubleArray.m +++ b/matlab/src/matlab/+arrow/+array/DoubleArray.m @@ -10,8 +10,8 @@ methods function obj = DoubleArray(matlabArray) - obj.Proxy = arrow.proxy.array.DoubleArrayProxy(matlabArray); obj.MatlabArray = matlabArray; + obj.Proxy = arrow.proxy.array.DoubleArrayProxy(obj.MatlabArray); end function Print(obj) diff --git a/matlab/src/matlab/+arrow/+array/UInt64Array.m b/matlab/src/matlab/+arrow/+array/UInt64Array.m index e3b63336cb2..8db6ef11b13 100644 --- a/matlab/src/matlab/+arrow/+array/UInt64Array.m +++ b/matlab/src/matlab/+arrow/+array/UInt64Array.m @@ -10,8 +10,8 @@ methods function obj = UInt64Array(matlabArray) - obj.Proxy = arrow.proxy.array.UInt64ArrayProxy(uint64(matlabArray)); - obj.MatlabArray = matlabArray; + obj.MatlabArray = uint64(matlabArray); + obj.Proxy = arrow.proxy.array.UInt64ArrayProxy(obj.MatlabArray); end function Print(obj) diff --git a/matlab/src/matlab/+arrow/+array/UInt8Array.m b/matlab/src/matlab/+arrow/+array/UInt8Array.m new file mode 100644 index 00000000000..94cf5711684 --- /dev/null +++ b/matlab/src/matlab/+arrow/+array/UInt8Array.m @@ -0,0 +1,22 @@ +classdef UInt8Array + + properties (Access=private) + Proxy + end + + properties (Access=private) + MatlabArray + end + + methods + function obj = UInt8Array(matlabArray) + obj.MatlabArray = uint8(matlabArray); + obj.Proxy = arrow.proxy.array.UInt8ArrayProxy(obj.MatlabArray); + end + + function Print(obj) + obj.Proxy.Print(); + end + end + +end diff --git a/matlab/src/matlab/+arrow/+proxy/+array/UInt8ArrayProxy.m b/matlab/src/matlab/+arrow/+proxy/+array/UInt8ArrayProxy.m new file mode 100644 index 00000000000..0735dbbb87d --- /dev/null +++ b/matlab/src/matlab/+arrow/+proxy/+array/UInt8ArrayProxy.m @@ -0,0 +1,2 @@ +classdef UInt8ArrayProxy < libmexclass.proxy.Proxy +end From 44dd06cb1f7bdcbb1ef0f980456ee6d0dfcce88d Mon Sep 17 00:00:00 2001 From: Fiona La Date: Thu, 16 Feb 2023 12:00:08 -0500 Subject: [PATCH 08/57] Remove printing in C++ layer --- .../src/cpp/arrow/matlab/proxy/array/double_array_proxy.h | 4 ---- matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.h | 6 +----- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h index 2fc85ba1e9c..c6f2d336eae 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h +++ b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h @@ -31,10 +31,6 @@ class DoubleArrayProxy : public libmexclass::proxy::Proxy { // Get the mxArray from constructor arguments const matlab::data::TypedArray double_mda = constructor_arguments[0]; - for (auto& elem : double_mda) { - std::cout << elem << std::endl; - } - // Get raw pointer of mxArray auto it(double_mda.cbegin()); auto dt = it.operator->(); diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.h b/matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.h index 8b1e4092b42..a3159de727c 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.h +++ b/matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.h @@ -34,10 +34,6 @@ class UInt8ArrayProxy : public libmexclass::proxy::Proxy { // Get the mxArray from constructor arguments const matlab::data::TypedArray uint8_mda = constructor_arguments[0]; - for (auto& elem : uint8_mda) { - std::cout << elem << std::endl; - } - // Create a shared data copy of uint8_mda and store it as a property of proxy class // Get raw pointer of mxArray auto it = uint8_mda.cbegin(); @@ -57,7 +53,7 @@ class UInt8ArrayProxy : public libmexclass::proxy::Proxy { -1)); array = array_wrapper; - + // Register Proxy methods. registerMethod(UInt8ArrayProxy, Print); } From 77cb963c6fa7b50c90d09425fff3c427449de315 Mon Sep 17 00:00:00 2001 From: shegden Date: Wed, 8 Mar 2023 19:56:34 -0500 Subject: [PATCH 09/57] Install libmexclass binaries in +libmexclass packaged folder to arrow_matlab. Also, updates to reflect latest libmexclass. --- matlab/CMakeLists.txt | 86 +++++++++++++------ .../matlab/proxy/array/double_array_proxy.h | 2 +- .../matlab/proxy/array/uint64_array_proxy.h | 3 +- .../matlab/proxy/array/uint8_array_proxy.h | 2 +- matlab/src/matlab/+arrow/+array/DoubleArray.m | 2 +- matlab/src/matlab/+arrow/+array/UInt64Array.m | 2 +- matlab/src/matlab/+arrow/+array/UInt8Array.m | 2 +- 7 files changed, 68 insertions(+), 31 deletions(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index 585543f6886..9cbb694132b 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -32,8 +32,13 @@ 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 Arrow build available, set ARROW_PREFIX to the ARROW_HOME specified with cmake. + if(Arrow_FOUND) + set(ARROW_PREFIX "${ARROW_HOME}") + else() + # 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") + endif() if(WIN32) # The shared library is located in the "bin" directory. @@ -322,35 +327,68 @@ matlab_add_mex(R2018a target_include_directories(mexcall PRIVATE ${CPP_SOURCE_DIR}) ############# libmexclass ################################# +message(STATUS "Start configure libmexclass") + +message(STATUS "Arrow_FOUND is ${Arrow_FOUND}.") + +# 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) - get_target_property(ARROW_LINK_LIB arrow_shared IMPORTED_IMPLIB) + # 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. - # This is available in IMPORTED_LOCATION. - # TODO: Why does this not return a value? Returns NOT-FOUND - # get_target_property(ARROW_LINK_LIB arrow_shared IMPORTED_LOCATION) - # message(STATUS "**************** ARROW_SHARED_LIB: ${ARROW_SHARED_LIB}") - - set(ARROW_LINK_LIB "${ARROW_SHARED_LIB}") + # 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() -get_target_property(ARROW_INCLUDE_DIR arrow_shared INTERFACE_INCLUDE_DIRECTORIES) - +# 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() +# Arguments to build libmexclass. set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy;${CMAKE_SOURCE_DIR}/src/cpp") set(CUSTOM_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc") set(CUSTOM_PROXY_SOURCES_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy") set(CUSTOM_PROXY_SOURCES "${CUSTOM_PROXY_SOURCES_DIR}/array/double_array_proxy.cc" "${CUSTOM_PROXY_SOURCES_DIR}/array/uint64_array_proxy.cc" "${CUSTOM_PROXY_SOURCES_DIR}/array/uint8_array_proxy.cc" ) set(CUSTOM_PROXY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp;${ARROW_INCLUDE_DIR}") set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_LINK_LIB}) +# On Windows, arrow.dll must be installed regardless of whether Arrow_FOUND is true or false. +# Pass this to libmexclass to copy over to the packaged install folder +libmexclass during install. +set(CUSTOM_PROXY_RUNTIME_LIBRARIES ${ARROW_SHARED_LIB}) # Build libmexclass as an external project. include(ExternalProject) ExternalProject_Add( libmexclass - GIT_REPOSITORY git@github.com:mathworks/libmexclass.git + # TODO: Consider using SSH URL for the Git Repository when libmexclass is accessible for CI without permission issues. + GIT_REPOSITORY https://github.com/mathworks/libmexclass.git GIT_TAG main SOURCE_SUBDIR libmexclass/cpp CMAKE_CACHE_ARGS "-D CUSTOM_PROXY_FACTORY_INCLUDE_DIR:STRING=${CUSTOM_PROXY_FACTORY_INCLUDE_DIR}" @@ -358,10 +396,11 @@ ExternalProject_Add( "-D CUSTOM_PROXY_SOURCES:STRING=${CUSTOM_PROXY_SOURCES}" "-D CUSTOM_PROXY_INCLUDE_DIR:STRING=${CUSTOM_PROXY_INCLUDE_DIR}" "-D CUSTOM_PROXY_LINK_LIBRARIES:STRING=${CUSTOM_PROXY_LINK_LIBRARIES}" - INSTALL_COMMAND "" + "-D CUSTOM_PROXY_RUNTIME_LIBRARIES:STRING=${CUSTOM_PROXY_RUNTIME_LIBRARIES}" + INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install ) -# TODO: Install libmexclass binaries. +message(STATUS "End configure libmexclass") ############# libmexclass ################################# # ############################################################################## @@ -443,9 +482,15 @@ endif() # Create a subdirectory at CMAKE_INSTALL_PREFIX to install the interface. set(CMAKE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/arrow_matlab") +# Install libmexclass. +# Get the installation directory for libmexclass. +ExternalProject_Get_Property(libmexclass BINARY_DIR) +# Copy only the packaged folder +libmexclass from the libmexclass installation directory. +install(DIRECTORY ${BINARY_DIR}/+libmexclass DESTINATION ${CMAKE_INSTALL_DIR}) + # 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. @@ -460,16 +505,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) @@ -577,4 +615,4 @@ if(MATLAB_ADD_INSTALL_DIR_TO_SEARCH_PATH OR MATLAB_ADD_INSTALL_DIR_TO_STARTUP_FI # to the MATLAB Search Path or add a command to the MATLAB startup file to add the # install directory to the MATLAB Search Path. install(SCRIPT "${TOOLS_DIR}/UpdateMatlabSearchPath.cmake") -endif() +endif() \ No newline at end of file diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h index c6f2d336eae..33f8defa7b3 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h +++ b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h @@ -51,7 +51,7 @@ class DoubleArrayProxy : public libmexclass::proxy::Proxy { array = array_wrapper; // Register Proxy methods. - registerMethod(DoubleArrayProxy, Print); + REGISTER_METHOD(DoubleArrayProxy, Print); } private: void Print(libmexclass::proxy::method::Context& context); diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.h b/matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.h index 9098eac9a59..cd12d5522f0 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.h +++ b/matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.h @@ -17,7 +17,6 @@ #pragma once -#include <_types/_uint64_t.h> #include "libmexclass/proxy/Proxy.h" #include "arrow/array.h" @@ -51,7 +50,7 @@ class UInt64ArrayProxy : public libmexclass::proxy::Proxy { array = array_wrapper; // Register Proxy methods. - registerMethod(UInt64ArrayProxy, Print); + REGISTER_METHOD(UInt64ArrayProxy, Print); } private: void Print(libmexclass::proxy::method::Context& context); diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.h b/matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.h index a3159de727c..5a57a85c1fc 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.h +++ b/matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.h @@ -55,7 +55,7 @@ class UInt8ArrayProxy : public libmexclass::proxy::Proxy { array = array_wrapper; // Register Proxy methods. - registerMethod(UInt8ArrayProxy, Print); + REGISTER_METHOD(UInt8ArrayProxy, Print); } private: void Print(libmexclass::proxy::method::Context& context); diff --git a/matlab/src/matlab/+arrow/+array/DoubleArray.m b/matlab/src/matlab/+arrow/+array/DoubleArray.m index 10bc8c3c4a8..e9df6ab1ab9 100644 --- a/matlab/src/matlab/+arrow/+array/DoubleArray.m +++ b/matlab/src/matlab/+arrow/+array/DoubleArray.m @@ -11,7 +11,7 @@ methods function obj = DoubleArray(matlabArray) obj.MatlabArray = matlabArray; - obj.Proxy = arrow.proxy.array.DoubleArrayProxy(obj.MatlabArray); + obj.Proxy = libmexclass.proxy.Proxy("Name", "arrow.proxy.array.DoubleArrayProxy", "ConstructorArguments", {obj.MatlabArray}); end function Print(obj) diff --git a/matlab/src/matlab/+arrow/+array/UInt64Array.m b/matlab/src/matlab/+arrow/+array/UInt64Array.m index 8db6ef11b13..08ed1224d35 100644 --- a/matlab/src/matlab/+arrow/+array/UInt64Array.m +++ b/matlab/src/matlab/+arrow/+array/UInt64Array.m @@ -11,7 +11,7 @@ methods function obj = UInt64Array(matlabArray) obj.MatlabArray = uint64(matlabArray); - obj.Proxy = arrow.proxy.array.UInt64ArrayProxy(obj.MatlabArray); + obj.Proxy = libmexclass.proxy.Proxy("Name", "arrow.proxy.array.UInt64ArrayProxy", "ConstructorArguments", {obj.MatlabArray}); end function Print(obj) diff --git a/matlab/src/matlab/+arrow/+array/UInt8Array.m b/matlab/src/matlab/+arrow/+array/UInt8Array.m index 94cf5711684..8f95b32a744 100644 --- a/matlab/src/matlab/+arrow/+array/UInt8Array.m +++ b/matlab/src/matlab/+arrow/+array/UInt8Array.m @@ -11,7 +11,7 @@ methods function obj = UInt8Array(matlabArray) obj.MatlabArray = uint8(matlabArray); - obj.Proxy = arrow.proxy.array.UInt8ArrayProxy(obj.MatlabArray); + obj.Proxy = libmexclass.proxy.Proxy("Name", "arrow.proxy.array.UInt8ArrayProxy", "ConstructorArguments", {obj.MatlabArray}); end function Print(obj) From 61ae8883c139131e1a4b3b761291db502f83665c Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 07:24:33 -0400 Subject: [PATCH 10/57] Specify CUSTOM_PROXY_FACTORY_HEADER_FILENAME and CUSTOM_PROXY_FACTORY_CLASS_NAME. --- matlab/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index 9cbb694132b..ccaac03bdad 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -382,6 +382,8 @@ set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_LINK_LIB}) # On Windows, arrow.dll must be installed regardless of whether Arrow_FOUND is true or false. # Pass this to libmexclass to copy over to the packaged install folder +libmexclass during install. set(CUSTOM_PROXY_RUNTIME_LIBRARIES ${ARROW_SHARED_LIB}) +set(CUSTOM_PROXY_FACTORY_HEADER_FILENAME "CustomProxyFactory.h") +set(CUSTOM_PROXY_FACTORY_CLASS_NAME "CustomProxyFactory") # Build libmexclass as an external project. include(ExternalProject) @@ -397,6 +399,8 @@ ExternalProject_Add( "-D CUSTOM_PROXY_INCLUDE_DIR:STRING=${CUSTOM_PROXY_INCLUDE_DIR}" "-D CUSTOM_PROXY_LINK_LIBRARIES:STRING=${CUSTOM_PROXY_LINK_LIBRARIES}" "-D CUSTOM_PROXY_RUNTIME_LIBRARIES:STRING=${CUSTOM_PROXY_RUNTIME_LIBRARIES}" + "-D CUSTOM_PROXY_FACTORY_HEADER_FILENAME:STRING=${CUSTOM_PROXY_FACTORY_HEADER_FILENAME}" + "-D CUSTOM_PROXY_FACTORY_CLASS_NAME:STIRNG=${CUSTOM_PROXY_FACTORY_CLASS_NAME}" INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install ) @@ -615,4 +619,4 @@ if(MATLAB_ADD_INSTALL_DIR_TO_SEARCH_PATH OR MATLAB_ADD_INSTALL_DIR_TO_STARTUP_FI # to the MATLAB Search Path or add a command to the MATLAB startup file to add the # install directory to the MATLAB Search Path. install(SCRIPT "${TOOLS_DIR}/UpdateMatlabSearchPath.cmake") -endif() \ No newline at end of file +endif() From 80805b9b46ed205c3ccfcb681277756e69b6de15 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 08:12:48 -0400 Subject: [PATCH 11/57] Remove Proxy subclasses. --- matlab/src/matlab/+arrow/+proxy/+array/DoubleArrayProxy.m | 2 -- matlab/src/matlab/+arrow/+proxy/+array/UInt64ArrayProxy.m | 2 -- matlab/src/matlab/+arrow/+proxy/+array/UInt8ArrayProxy.m | 2 -- 3 files changed, 6 deletions(-) delete mode 100644 matlab/src/matlab/+arrow/+proxy/+array/DoubleArrayProxy.m delete mode 100644 matlab/src/matlab/+arrow/+proxy/+array/UInt64ArrayProxy.m delete mode 100644 matlab/src/matlab/+arrow/+proxy/+array/UInt8ArrayProxy.m diff --git a/matlab/src/matlab/+arrow/+proxy/+array/DoubleArrayProxy.m b/matlab/src/matlab/+arrow/+proxy/+array/DoubleArrayProxy.m deleted file mode 100644 index 1ebe6bb583a..00000000000 --- a/matlab/src/matlab/+arrow/+proxy/+array/DoubleArrayProxy.m +++ /dev/null @@ -1,2 +0,0 @@ -classdef DoubleArrayProxy < libmexclass.proxy.Proxy -end diff --git a/matlab/src/matlab/+arrow/+proxy/+array/UInt64ArrayProxy.m b/matlab/src/matlab/+arrow/+proxy/+array/UInt64ArrayProxy.m deleted file mode 100644 index 8444045c2af..00000000000 --- a/matlab/src/matlab/+arrow/+proxy/+array/UInt64ArrayProxy.m +++ /dev/null @@ -1,2 +0,0 @@ -classdef UInt64ArrayProxy < libmexclass.proxy.Proxy -end diff --git a/matlab/src/matlab/+arrow/+proxy/+array/UInt8ArrayProxy.m b/matlab/src/matlab/+arrow/+proxy/+array/UInt8ArrayProxy.m deleted file mode 100644 index 0735dbbb87d..00000000000 --- a/matlab/src/matlab/+arrow/+proxy/+array/UInt8ArrayProxy.m +++ /dev/null @@ -1,2 +0,0 @@ -classdef UInt8ArrayProxy < libmexclass.proxy.Proxy -end From 1e4db947d061dc836be59df0792fad6005cfb824 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 09:33:07 -0400 Subject: [PATCH 12/57] Add basic custom display to arrow.array.DoubleArray which calls Print method. --- matlab/src/matlab/+arrow/+array/DoubleArray.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/matlab/src/matlab/+arrow/+array/DoubleArray.m b/matlab/src/matlab/+arrow/+array/DoubleArray.m index e9df6ab1ab9..0962ad84b7c 100644 --- a/matlab/src/matlab/+arrow/+array/DoubleArray.m +++ b/matlab/src/matlab/+arrow/+array/DoubleArray.m @@ -19,4 +19,10 @@ function Print(obj) end end + methods (Access=protected) + function displayScalarObject(obj) + obj.Print(); + end + end + end From e000ee100f9c28604f828ab1afc2b98deecdcb4e Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 09:34:43 -0400 Subject: [PATCH 13/57] Remove unused CustomDisplay subclass. --- .../matlab/+arrow/+array/+internal/CustomDisplay.m | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 matlab/src/matlab/+arrow/+array/+internal/CustomDisplay.m diff --git a/matlab/src/matlab/+arrow/+array/+internal/CustomDisplay.m b/matlab/src/matlab/+arrow/+array/+internal/CustomDisplay.m deleted file mode 100644 index a95338d4051..00000000000 --- a/matlab/src/matlab/+arrow/+array/+internal/CustomDisplay.m +++ /dev/null @@ -1,11 +0,0 @@ -classdef CustomDisplay < matlab.mixin.CustomDisplay - methods (Access = protected) - function [pg] = getPropertyGroups(obj) - pg = []; - end - - function displayNonScalarObject(obj) - obj.Print(); - end - end -end \ No newline at end of file From 6ed4274a9b539cd0519ff058087f862e4ac87ae8 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 09:35:09 -0400 Subject: [PATCH 14/57] Remove UInt64Array and UInt8Array. --- matlab/src/matlab/+arrow/+array/UInt64Array.m | 22 ------------------- matlab/src/matlab/+arrow/+array/UInt8Array.m | 22 ------------------- 2 files changed, 44 deletions(-) delete mode 100644 matlab/src/matlab/+arrow/+array/UInt64Array.m delete mode 100644 matlab/src/matlab/+arrow/+array/UInt8Array.m diff --git a/matlab/src/matlab/+arrow/+array/UInt64Array.m b/matlab/src/matlab/+arrow/+array/UInt64Array.m deleted file mode 100644 index 08ed1224d35..00000000000 --- a/matlab/src/matlab/+arrow/+array/UInt64Array.m +++ /dev/null @@ -1,22 +0,0 @@ -classdef UInt64Array - - properties (Access=private) - Proxy - end - - properties (Access=private) - MatlabArray - end - - methods - function obj = UInt64Array(matlabArray) - obj.MatlabArray = uint64(matlabArray); - obj.Proxy = libmexclass.proxy.Proxy("Name", "arrow.proxy.array.UInt64ArrayProxy", "ConstructorArguments", {obj.MatlabArray}); - end - - function Print(obj) - obj.Proxy.Print(); - end - end - -end diff --git a/matlab/src/matlab/+arrow/+array/UInt8Array.m b/matlab/src/matlab/+arrow/+array/UInt8Array.m deleted file mode 100644 index 8f95b32a744..00000000000 --- a/matlab/src/matlab/+arrow/+array/UInt8Array.m +++ /dev/null @@ -1,22 +0,0 @@ -classdef UInt8Array - - properties (Access=private) - Proxy - end - - properties (Access=private) - MatlabArray - end - - methods - function obj = UInt8Array(matlabArray) - obj.MatlabArray = uint8(matlabArray); - obj.Proxy = libmexclass.proxy.Proxy("Name", "arrow.proxy.array.UInt8ArrayProxy", "ConstructorArguments", {obj.MatlabArray}); - end - - function Print(obj) - obj.Proxy.Print(); - end - end - -end From 25fec161cfe3a5d3265dc0561fb4e6e89fef2dc6 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 09:37:02 -0400 Subject: [PATCH 15/57] Remove uint64 and uint8 C++ Proxy source code. --- .../matlab/proxy/array/uint64_array_proxy.cc | 25 ------- .../matlab/proxy/array/uint64_array_proxy.h | 61 ----------------- .../matlab/proxy/array/uint8_array_proxy.cc | 25 ------- .../matlab/proxy/array/uint8_array_proxy.h | 66 ------------------- 4 files changed, 177 deletions(-) delete mode 100644 matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.cc delete mode 100644 matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.h delete mode 100644 matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.cc delete mode 100644 matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.h diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.cc b/matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.cc deleted file mode 100644 index fffcf39d0e2..00000000000 --- a/matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.cc +++ /dev/null @@ -1,25 +0,0 @@ -// 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 "uint64_array_proxy.h" - -namespace proxy::array { -void UInt64ArrayProxy::Print(libmexclass::proxy::method::Context& context) { - // TODO: Return an MDA string representation of the Arrow array. - std::cout << array->ToString() << std::endl; -} -} // namespace proxy::array \ No newline at end of file diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.h b/matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.h deleted file mode 100644 index cd12d5522f0..00000000000 --- a/matlab/src/cpp/arrow/matlab/proxy/array/uint64_array_proxy.h +++ /dev/null @@ -1,61 +0,0 @@ -// 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 "libmexclass/proxy/Proxy.h" - -#include "arrow/array.h" -#include "arrow/builder.h" - -namespace proxy::array { -class UInt64ArrayProxy : public libmexclass::proxy::Proxy { - public: - UInt64ArrayProxy(const libmexclass::proxy::FunctionArguments& constructor_arguments) { - - // Get the mxArray from constructor arguments - const matlab::data::TypedArray uint64_mda = constructor_arguments[0]; - - // Get raw pointer of mxArray - auto it(uint64_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 buffer( - new arrow::Buffer(reinterpret_cast(dt), - sizeof(uint64_t) * uint64_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 array_wrapper( - new arrow::NumericArray(uint64_mda.getNumberOfElements(), buffer, - nullptr, // TODO: fill validity bitmap with data - -1)); - - array = array_wrapper; - - // Register Proxy methods. - REGISTER_METHOD(UInt64ArrayProxy, Print); - } - private: - void Print(libmexclass::proxy::method::Context& context); - - // "Raw" arrow::Array - std::shared_ptr array; -}; -} // namespace proxy::array \ No newline at end of file diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.cc b/matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.cc deleted file mode 100644 index 431892657ea..00000000000 --- a/matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.cc +++ /dev/null @@ -1,25 +0,0 @@ -// 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 "uint8_array_proxy.h" - -namespace proxy::array { -void UInt8ArrayProxy::Print(libmexclass::proxy::method::Context& context) { - // TODO: Return an MDA string representation of the Arrow array. - std::cout << array->ToString() << std::endl; -} -} // namespace proxy::array \ No newline at end of file diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.h b/matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.h deleted file mode 100644 index 5a57a85c1fc..00000000000 --- a/matlab/src/cpp/arrow/matlab/proxy/array/uint8_array_proxy.h +++ /dev/null @@ -1,66 +0,0 @@ -// 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 "libmexclass/proxy/Proxy.h" - -#include "arrow/array.h" -#include "arrow/builder.h" - -namespace proxy::array { -class UInt8ArrayProxy : public libmexclass::proxy::Proxy { - private: - // const matlab::data::TypedArray uint8_mda; - - public: - UInt8ArrayProxy(const libmexclass::proxy::FunctionArguments& constructor_arguments) { - // Fewer copy version - - // Get the mxArray from constructor arguments - const matlab::data::TypedArray uint8_mda = constructor_arguments[0]; - - // Create a shared data copy of uint8_mda and store it as a property of proxy class - // Get raw pointer of mxArray - auto it = uint8_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 buffer( - new arrow::Buffer(reinterpret_cast(dt), - sizeof(uint8_t) * uint8_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 array_wrapper( - new arrow::NumericArray(uint8_mda.getNumberOfElements(), buffer, - nullptr, // TODO: fill validity bitmap with data - -1)); - - array = array_wrapper; - - // Register Proxy methods. - REGISTER_METHOD(UInt8ArrayProxy, Print); - } - private: - void Print(libmexclass::proxy::method::Context& context); - - // "Raw" arrow::Array - std::shared_ptr array; -}; -} // namespace proxy::array \ No newline at end of file From d9afe91d23580656d7f84727f8508bd026cf333d Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 09:38:23 -0400 Subject: [PATCH 16/57] Remove comment about 'No copy version'. --- matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h index 33f8defa7b3..a1487947d42 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h +++ b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h @@ -26,8 +26,6 @@ namespace proxy::array { class DoubleArrayProxy : public libmexclass::proxy::Proxy { public: DoubleArrayProxy(const libmexclass::proxy::FunctionArguments& constructor_arguments) { - // No copy version - // Get the mxArray from constructor arguments const matlab::data::TypedArray double_mda = constructor_arguments[0]; @@ -59,4 +57,4 @@ class DoubleArrayProxy : public libmexclass::proxy::Proxy { // "Raw" arrow::Array std::shared_ptr array; }; -} // namespace proxy::array \ No newline at end of file +} // namespace proxy::array From cd7b7dc53401fe79f0d684db5529226b72715803 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 09:38:51 -0400 Subject: [PATCH 17/57] Rearrange header order. --- matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h index a1487947d42..1d8c6d0306c 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h +++ b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h @@ -17,11 +17,11 @@ #pragma once -#include "libmexclass/proxy/Proxy.h" - #include "arrow/array.h" #include "arrow/builder.h" +#include "libmexclass/proxy/Proxy.h" + namespace proxy::array { class DoubleArrayProxy : public libmexclass::proxy::Proxy { public: From 718ee4b76c084427e52698bf0a2669fb77dd7570 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 09:45:43 -0400 Subject: [PATCH 18/57] Rename CustomProxyFactory to ArrowProxyFactory. --- matlab/CMakeLists.txt | 8 ++++---- .../arrow_proxy_factory.cc} | 4 ++-- .../arrow_proxy_factory.h} | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) rename matlab/src/cpp/arrow/matlab/proxy/{CustomProxyFactory.cc => factory/arrow_proxy_factory.cc} (90%) rename matlab/src/cpp/arrow/matlab/proxy/{CustomProxyFactory.h => factory/arrow_proxy_factory.h} (91%) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index ccaac03bdad..58b9e148044 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -373,8 +373,8 @@ else() endif() # Arguments to build libmexclass. -set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy;${CMAKE_SOURCE_DIR}/src/cpp") -set(CUSTOM_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc") +set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory;${CMAKE_SOURCE_DIR}/src/cpp") +set(CUSTOM_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc") set(CUSTOM_PROXY_SOURCES_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy") set(CUSTOM_PROXY_SOURCES "${CUSTOM_PROXY_SOURCES_DIR}/array/double_array_proxy.cc" "${CUSTOM_PROXY_SOURCES_DIR}/array/uint64_array_proxy.cc" "${CUSTOM_PROXY_SOURCES_DIR}/array/uint8_array_proxy.cc" ) set(CUSTOM_PROXY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp;${ARROW_INCLUDE_DIR}") @@ -382,8 +382,8 @@ set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_LINK_LIB}) # On Windows, arrow.dll must be installed regardless of whether Arrow_FOUND is true or false. # Pass this to libmexclass to copy over to the packaged install folder +libmexclass during install. set(CUSTOM_PROXY_RUNTIME_LIBRARIES ${ARROW_SHARED_LIB}) -set(CUSTOM_PROXY_FACTORY_HEADER_FILENAME "CustomProxyFactory.h") -set(CUSTOM_PROXY_FACTORY_CLASS_NAME "CustomProxyFactory") +set(CUSTOM_PROXY_FACTORY_HEADER_FILENAME "arrow_proxy_factory.h") +set(CUSTOM_PROXY_FACTORY_CLASS_NAME "ArrowProxyFactory") # Build libmexclass as an external project. include(ExternalProject) diff --git a/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc b/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc similarity index 90% rename from matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc rename to matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc index 91c0cff2851..8c8a62e402b 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.cc +++ b/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc @@ -19,11 +19,11 @@ #include "arrow/matlab/proxy/array/uint64_array_proxy.h" #include "arrow/matlab/proxy/array/uint8_array_proxy.h" -#include "CustomProxyFactory.h" +#include "ArrowProxyFactory.h" #include -std::shared_ptr CustomProxyFactory::make_proxy(const ClassName& class_name, const FunctionArguments& constructor_arguments) { +std::shared_ptr ArrowProxyFactory::make_proxy(const ClassName& class_name, const FunctionArguments& constructor_arguments) { // Link MATLAB proxy classes with corresponding C++ proxy classes REGISTER_PROXY(arrow.proxy.array.DoubleArrayProxy, proxy::array::DoubleArrayProxy); diff --git a/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.h b/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.h similarity index 91% rename from matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.h rename to matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.h index 428c73669bc..a0d40d3ef1c 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/CustomProxyFactory.h +++ b/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.h @@ -21,8 +21,8 @@ using namespace libmexclass::proxy; -class CustomProxyFactory : public libmexclass::proxy::Factory { +class ArrowProxyFactory : public libmexclass::proxy::Factory { public: - CustomProxyFactory() { } + ArrowProxyFactory() { } virtual std::shared_ptr make_proxy(const ClassName& class_name, const FunctionArguments& constructor_arguments); }; From 64b2d0412802d5dfaecdf7be7283deef8ecc9c11 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 09:47:55 -0400 Subject: [PATCH 19/57] Change namespace from proxy::array to arrow::matlab::proxy::array. --- matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.cc | 4 ++-- matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.cc b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.cc index 74a21a881a6..a78f69c8238 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.cc +++ b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.cc @@ -17,9 +17,9 @@ #include "double_array_proxy.h" -namespace proxy::array { +namespace arrow::matlab::proxy::array { void DoubleArrayProxy::Print(libmexclass::proxy::method::Context& context) { // TODO: Return an MDA string representation of the Arrow array. std::cout << array->ToString() << std::endl; } -} // namespace proxy::array \ No newline at end of file +} // namespace arrow::matlab::proxy::array diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h index 1d8c6d0306c..8554b8bce5d 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h +++ b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h @@ -22,7 +22,7 @@ #include "libmexclass/proxy/Proxy.h" -namespace proxy::array { +namespace arrow::matlab::proxy::array { class DoubleArrayProxy : public libmexclass::proxy::Proxy { public: DoubleArrayProxy(const libmexclass::proxy::FunctionArguments& constructor_arguments) { @@ -57,4 +57,4 @@ class DoubleArrayProxy : public libmexclass::proxy::Proxy { // "Raw" arrow::Array std::shared_ptr array; }; -} // namespace proxy::array +} // namespace arrow::matlab::proxy::array From 84acd9daded4909188a5d20300c9eaad5e810e6e Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 09:51:11 -0400 Subject: [PATCH 20/57] Remove calls to REGISTER_PROXY for UInt64Array and UInt8Array. --- .../cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc b/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc index 8c8a62e402b..33e3fe62464 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc +++ b/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc @@ -16,8 +16,6 @@ // under the License. #include "arrow/matlab/proxy/array/double_array_proxy.h" -#include "arrow/matlab/proxy/array/uint64_array_proxy.h" -#include "arrow/matlab/proxy/array/uint8_array_proxy.h" #include "ArrowProxyFactory.h" @@ -25,10 +23,8 @@ std::shared_ptr ArrowProxyFactory::make_proxy(const ClassName& class_name, const FunctionArguments& constructor_arguments) { - // Link MATLAB proxy classes with corresponding C++ proxy classes - REGISTER_PROXY(arrow.proxy.array.DoubleArrayProxy, proxy::array::DoubleArrayProxy); - REGISTER_PROXY(arrow.proxy.array.UInt64ArrayProxy, proxy::array::UInt64ArrayProxy); - REGISTER_PROXY(arrow.proxy.array.UInt8ArrayProxy, proxy::array::UInt8ArrayProxy); + // Register MATLAB Proxy classes with corresponding C++ Proxy classes. + REGISTER_PROXY(arrow.proxy.array.DoubleArrayProxy, arrow::matlab::proxy::array::DoubleArrayProxy); // TODO: Decide what to do in the case that there isn't a Proxy match. std::cout << "Did not find a matching C++ proxy for: " + class_name << std::endl; From 03b8132362233309d70d56b73531489e468254db Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 09:51:51 -0400 Subject: [PATCH 21/57] Update #include for arrow_proxy_factory.h. --- .../src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc b/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc index 33e3fe62464..c52fbce2a75 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc +++ b/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc @@ -17,7 +17,7 @@ #include "arrow/matlab/proxy/array/double_array_proxy.h" -#include "ArrowProxyFactory.h" +#include "arrow_proxy_factory.h" #include From cc3abaaaa057d22ca37bd106fec6a7bdd05b42ba Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 09:58:06 -0400 Subject: [PATCH 22/57] Remove references to UInt64 and UInt8 source files in CMakeLists.txt. --- matlab/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index 58b9e148044..30de7b98d33 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -376,7 +376,7 @@ endif() set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory;${CMAKE_SOURCE_DIR}/src/cpp") set(CUSTOM_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc") set(CUSTOM_PROXY_SOURCES_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy") -set(CUSTOM_PROXY_SOURCES "${CUSTOM_PROXY_SOURCES_DIR}/array/double_array_proxy.cc" "${CUSTOM_PROXY_SOURCES_DIR}/array/uint64_array_proxy.cc" "${CUSTOM_PROXY_SOURCES_DIR}/array/uint8_array_proxy.cc" ) +set(CUSTOM_PROXY_SOURCES "${CUSTOM_PROXY_SOURCES_DIR}/array/double_array_proxy.cc") set(CUSTOM_PROXY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp;${ARROW_INCLUDE_DIR}") set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_LINK_LIB}) # On Windows, arrow.dll must be installed regardless of whether Arrow_FOUND is true or false. From 433cf3551c38ccb04d6314039fee232234f7a1a6 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 10:08:41 -0400 Subject: [PATCH 23/57] Use scope resolution operator to resolve MDA symbol look-up issues. --- matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h index 8554b8bce5d..376cb9cef07 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h +++ b/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h @@ -27,7 +27,7 @@ class DoubleArrayProxy : public libmexclass::proxy::Proxy { public: DoubleArrayProxy(const libmexclass::proxy::FunctionArguments& constructor_arguments) { // Get the mxArray from constructor arguments - const matlab::data::TypedArray double_mda = constructor_arguments[0]; + const ::matlab::data::TypedArray double_mda = constructor_arguments[0]; // Get raw pointer of mxArray auto it(double_mda.cbegin()); From 5f3e5b43d8753c153a91042f12ae352ea3fc600d Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 10:09:38 -0400 Subject: [PATCH 24/57] Fix STRING typo in CMakeLists.txt. --- matlab/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index 30de7b98d33..eec2d53a613 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -400,7 +400,7 @@ ExternalProject_Add( "-D CUSTOM_PROXY_LINK_LIBRARIES:STRING=${CUSTOM_PROXY_LINK_LIBRARIES}" "-D CUSTOM_PROXY_RUNTIME_LIBRARIES:STRING=${CUSTOM_PROXY_RUNTIME_LIBRARIES}" "-D CUSTOM_PROXY_FACTORY_HEADER_FILENAME:STRING=${CUSTOM_PROXY_FACTORY_HEADER_FILENAME}" - "-D CUSTOM_PROXY_FACTORY_CLASS_NAME:STIRNG=${CUSTOM_PROXY_FACTORY_CLASS_NAME}" + "-D CUSTOM_PROXY_FACTORY_CLASS_NAME:STRING=${CUSTOM_PROXY_FACTORY_CLASS_NAME}" INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install ) From ac591ad710c4b381ebf842a9e7e125618335502f Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 10:40:11 -0400 Subject: [PATCH 25/57] Change registered Proxy name from arrow.proxy.array.DoubleArrayProxy to arrow.array.proxy.DoubleArray. --- .../src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc b/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc index c52fbce2a75..332209c89f7 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc +++ b/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -#include "arrow/matlab/proxy/array/double_array_proxy.h" +#include "arrow/matlab/array/proxy/double_array.h" #include "arrow_proxy_factory.h" @@ -25,6 +25,7 @@ std::shared_ptr ArrowProxyFactory::make_proxy(const ClassName& class_name // Register MATLAB Proxy classes with corresponding C++ Proxy classes. REGISTER_PROXY(arrow.proxy.array.DoubleArrayProxy, arrow::matlab::proxy::array::DoubleArrayProxy); + REGISTER_PROXY(arrow.array.proxy.DoubleArray, arrow::matlab::array::proxy::DoubleArray); // TODO: Decide what to do in the case that there isn't a Proxy match. std::cout << "Did not find a matching C++ proxy for: " + class_name << std::endl; From e294427e5b66949365e2c009f6ed6ad263713402 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 10:49:05 -0400 Subject: [PATCH 26/57] Move double_array_proxy source code to array/proxy folder structure. --- .../matlab/{proxy/array => array/proxy}/double_array_proxy.cc | 0 .../matlab/{proxy/array => array/proxy}/double_array_proxy.h | 0 matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc | 1 - 3 files changed, 1 deletion(-) rename matlab/src/cpp/arrow/matlab/{proxy/array => array/proxy}/double_array_proxy.cc (100%) rename matlab/src/cpp/arrow/matlab/{proxy/array => array/proxy}/double_array_proxy.h (100%) diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.cc b/matlab/src/cpp/arrow/matlab/array/proxy/double_array_proxy.cc similarity index 100% rename from matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.cc rename to matlab/src/cpp/arrow/matlab/array/proxy/double_array_proxy.cc diff --git a/matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h b/matlab/src/cpp/arrow/matlab/array/proxy/double_array_proxy.h similarity index 100% rename from matlab/src/cpp/arrow/matlab/proxy/array/double_array_proxy.h rename to matlab/src/cpp/arrow/matlab/array/proxy/double_array_proxy.h diff --git a/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc b/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc index 332209c89f7..8c9cc7e0b12 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc +++ b/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc @@ -24,7 +24,6 @@ std::shared_ptr ArrowProxyFactory::make_proxy(const ClassName& class_name, const FunctionArguments& constructor_arguments) { // Register MATLAB Proxy classes with corresponding C++ Proxy classes. - REGISTER_PROXY(arrow.proxy.array.DoubleArrayProxy, arrow::matlab::proxy::array::DoubleArrayProxy); REGISTER_PROXY(arrow.array.proxy.DoubleArray, arrow::matlab::array::proxy::DoubleArray); // TODO: Decide what to do in the case that there isn't a Proxy match. From 6dfba2853513dba0d1c79dd23e273756a17335e2 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 10:52:02 -0400 Subject: [PATCH 27/57] Rename DoubleArrayProxy to DoubleArray. --- .../proxy/{double_array_proxy.cc => double_array.cc} | 8 ++++---- .../proxy/{double_array_proxy.h => double_array.h} | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) rename matlab/src/cpp/arrow/matlab/array/proxy/{double_array_proxy.cc => double_array.cc} (82%) rename matlab/src/cpp/arrow/matlab/array/proxy/{double_array_proxy.h => double_array.h} (88%) diff --git a/matlab/src/cpp/arrow/matlab/array/proxy/double_array_proxy.cc b/matlab/src/cpp/arrow/matlab/array/proxy/double_array.cc similarity index 82% rename from matlab/src/cpp/arrow/matlab/array/proxy/double_array_proxy.cc rename to matlab/src/cpp/arrow/matlab/array/proxy/double_array.cc index a78f69c8238..414a5312216 100644 --- a/matlab/src/cpp/arrow/matlab/array/proxy/double_array_proxy.cc +++ b/matlab/src/cpp/arrow/matlab/array/proxy/double_array.cc @@ -15,11 +15,11 @@ // specific language governing permissions and limitations // under the License. -#include "double_array_proxy.h" +#include "double_array.h" -namespace arrow::matlab::proxy::array { -void DoubleArrayProxy::Print(libmexclass::proxy::method::Context& context) { +namespace arrow::matlab::array::proxy { +void DoubleArray::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::proxy::array +} // namespace arrow::matlab::array::proxy diff --git a/matlab/src/cpp/arrow/matlab/array/proxy/double_array_proxy.h b/matlab/src/cpp/arrow/matlab/array/proxy/double_array.h similarity index 88% rename from matlab/src/cpp/arrow/matlab/array/proxy/double_array_proxy.h rename to matlab/src/cpp/arrow/matlab/array/proxy/double_array.h index 376cb9cef07..d4901348289 100644 --- a/matlab/src/cpp/arrow/matlab/array/proxy/double_array_proxy.h +++ b/matlab/src/cpp/arrow/matlab/array/proxy/double_array.h @@ -22,10 +22,10 @@ #include "libmexclass/proxy/Proxy.h" -namespace arrow::matlab::proxy::array { -class DoubleArrayProxy : public libmexclass::proxy::Proxy { +namespace arrow::matlab::array::proxy { +class DoubleArray : public libmexclass::proxy::Proxy { public: - DoubleArrayProxy(const libmexclass::proxy::FunctionArguments& constructor_arguments) { + DoubleArray(const libmexclass::proxy::FunctionArguments& constructor_arguments) { // Get the mxArray from constructor arguments const ::matlab::data::TypedArray double_mda = constructor_arguments[0]; @@ -49,7 +49,7 @@ class DoubleArrayProxy : public libmexclass::proxy::Proxy { array = array_wrapper; // Register Proxy methods. - REGISTER_METHOD(DoubleArrayProxy, Print); + REGISTER_METHOD(DoubleArray, Print); } private: void Print(libmexclass::proxy::method::Context& context); @@ -57,4 +57,4 @@ class DoubleArrayProxy : public libmexclass::proxy::Proxy { // "Raw" arrow::Array std::shared_ptr array; }; -} // namespace arrow::matlab::proxy::array +} // namespace arrow::matlab::array::proxy From 8b86eaa4f16ab3b11401906fdc85cb4d430eedf5 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 10:53:31 -0400 Subject: [PATCH 28/57] Update CMakeLists.txt. --- matlab/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index eec2d53a613..899a95b496f 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -376,7 +376,7 @@ endif() set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory;${CMAKE_SOURCE_DIR}/src/cpp") set(CUSTOM_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc") set(CUSTOM_PROXY_SOURCES_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy") -set(CUSTOM_PROXY_SOURCES "${CUSTOM_PROXY_SOURCES_DIR}/array/double_array_proxy.cc") +set(CUSTOM_PROXY_SOURCES "${CUSTOM_PROXY_SOURCES_DIR}/array/proxy/double_array.cc") set(CUSTOM_PROXY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp;${ARROW_INCLUDE_DIR}") set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_LINK_LIB}) # On Windows, arrow.dll must be installed regardless of whether Arrow_FOUND is true or false. From 64f054f653006bd7bc226732f6c336af254a4a73 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 10:55:11 -0400 Subject: [PATCH 29/57] Update MATLAB Proxy constructor call for arrow.array.DoubleArray to use arrow.array.proxy.DoubleArray. --- matlab/src/matlab/+arrow/+array/DoubleArray.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/src/matlab/+arrow/+array/DoubleArray.m b/matlab/src/matlab/+arrow/+array/DoubleArray.m index 0962ad84b7c..4f84b6026f9 100644 --- a/matlab/src/matlab/+arrow/+array/DoubleArray.m +++ b/matlab/src/matlab/+arrow/+array/DoubleArray.m @@ -11,7 +11,7 @@ methods function obj = DoubleArray(matlabArray) obj.MatlabArray = matlabArray; - obj.Proxy = libmexclass.proxy.Proxy("Name", "arrow.proxy.array.DoubleArrayProxy", "ConstructorArguments", {obj.MatlabArray}); + obj.Proxy = libmexclass.proxy.Proxy("Name", "arrow.array.proxy.DoubleArray", "ConstructorArguments", {obj.MatlabArray}); end function Print(obj) From b69b598882ad58df712f65bcb4665cf06bb2b3d4 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 11:04:22 -0400 Subject: [PATCH 30/57] Rename ArrowProxyFactory to Factory. --- matlab/CMakeLists.txt | 8 ++++---- .../proxy/{factory/arrow_proxy_factory.cc => factory.cc} | 8 ++++++-- .../proxy/{factory/arrow_proxy_factory.h => factory.h} | 8 +++++--- 3 files changed, 15 insertions(+), 9 deletions(-) rename matlab/src/cpp/arrow/matlab/proxy/{factory/arrow_proxy_factory.cc => factory.cc} (87%) rename matlab/src/cpp/arrow/matlab/proxy/{factory/arrow_proxy_factory.h => factory.h} (88%) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index 899a95b496f..59de3e0f807 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -373,8 +373,8 @@ else() endif() # Arguments to build libmexclass. -set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory;${CMAKE_SOURCE_DIR}/src/cpp") -set(CUSTOM_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc") +set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy;${CMAKE_SOURCE_DIR}/src/cpp") +set(CUSTOM_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory.cc") set(CUSTOM_PROXY_SOURCES_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy") set(CUSTOM_PROXY_SOURCES "${CUSTOM_PROXY_SOURCES_DIR}/array/proxy/double_array.cc") set(CUSTOM_PROXY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp;${ARROW_INCLUDE_DIR}") @@ -382,8 +382,8 @@ set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_LINK_LIB}) # On Windows, arrow.dll must be installed regardless of whether Arrow_FOUND is true or false. # Pass this to libmexclass to copy over to the packaged install folder +libmexclass during install. set(CUSTOM_PROXY_RUNTIME_LIBRARIES ${ARROW_SHARED_LIB}) -set(CUSTOM_PROXY_FACTORY_HEADER_FILENAME "arrow_proxy_factory.h") -set(CUSTOM_PROXY_FACTORY_CLASS_NAME "ArrowProxyFactory") +set(CUSTOM_PROXY_FACTORY_HEADER_FILENAME "factory.h") +set(CUSTOM_PROXY_FACTORY_CLASS_NAME "arrow::matlab::proxy::Factory") # Build libmexclass as an external project. include(ExternalProject) diff --git a/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc b/matlab/src/cpp/arrow/matlab/proxy/factory.cc similarity index 87% rename from matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc rename to matlab/src/cpp/arrow/matlab/proxy/factory.cc index 8c9cc7e0b12..05a743fabc4 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.cc +++ b/matlab/src/cpp/arrow/matlab/proxy/factory.cc @@ -17,11 +17,13 @@ #include "arrow/matlab/array/proxy/double_array.h" -#include "arrow_proxy_factory.h" +#include "factory.h" #include -std::shared_ptr ArrowProxyFactory::make_proxy(const ClassName& class_name, const FunctionArguments& constructor_arguments) { +namespace arrow::matlab::proxy { + +std::shared_ptr Factory::make_proxy(const ClassName& class_name, const FunctionArguments& constructor_arguments) { // Register MATLAB Proxy classes with corresponding C++ Proxy classes. REGISTER_PROXY(arrow.array.proxy.DoubleArray, arrow::matlab::array::proxy::DoubleArray); @@ -30,3 +32,5 @@ std::shared_ptr ArrowProxyFactory::make_proxy(const ClassName& class_name std::cout << "Did not find a matching C++ proxy for: " + class_name << std::endl; return nullptr; }; + +} diff --git a/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.h b/matlab/src/cpp/arrow/matlab/proxy/factory.h similarity index 88% rename from matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.h rename to matlab/src/cpp/arrow/matlab/proxy/factory.h index a0d40d3ef1c..a7ea4ca1cac 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/factory/arrow_proxy_factory.h +++ b/matlab/src/cpp/arrow/matlab/proxy/factory.h @@ -19,10 +19,12 @@ #include "libmexclass/proxy/Factory.h" -using namespace libmexclass::proxy; +namespace arrow::matlab::proxy { -class ArrowProxyFactory : public libmexclass::proxy::Factory { +class Factory : public libmexclass::proxy::Factory { public: - ArrowProxyFactory() { } + Factory() { } virtual std::shared_ptr make_proxy(const ClassName& class_name, const FunctionArguments& constructor_arguments); }; + +} From cff73648711a9f7e96b292861fe2e8a102eb9cc6 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 11:07:38 -0400 Subject: [PATCH 31/57] Update value of CUSTOM_PROXY_SOURCES to reflect new directory structure. --- matlab/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index 59de3e0f807..d7d0fdaf325 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -375,8 +375,7 @@ endif() # Arguments to build libmexclass. set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy;${CMAKE_SOURCE_DIR}/src/cpp") set(CUSTOM_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory.cc") -set(CUSTOM_PROXY_SOURCES_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy") -set(CUSTOM_PROXY_SOURCES "${CUSTOM_PROXY_SOURCES_DIR}/array/proxy/double_array.cc") +set(CUSTOM_PROXY_SOURCES "${CUSTOM_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/double_array.cc") set(CUSTOM_PROXY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp;${ARROW_INCLUDE_DIR}") set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_LINK_LIB}) # On Windows, arrow.dll must be installed regardless of whether Arrow_FOUND is true or false. From c89d0fb88392785c1eff2196993e633e12ceeea4 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 11:08:39 -0400 Subject: [PATCH 32/57] Fix CMAKE_SOURCE_DIR typo. --- matlab/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index d7d0fdaf325..890194fd25a 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -375,7 +375,7 @@ endif() # Arguments to build libmexclass. set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy;${CMAKE_SOURCE_DIR}/src/cpp") set(CUSTOM_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory.cc") -set(CUSTOM_PROXY_SOURCES "${CUSTOM_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/double_array.cc") +set(CUSTOM_PROXY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/double_array.cc") set(CUSTOM_PROXY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp;${ARROW_INCLUDE_DIR}") set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_LINK_LIB}) # On Windows, arrow.dll must be installed regardless of whether Arrow_FOUND is true or false. From f704e195d3a654e2c3bd7e07ad29b1d0273f8059 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 11:10:53 -0400 Subject: [PATCH 33/57] Add using namespace declaration for libmexclass::proxy to arrow::matlab::proxy namespace. --- matlab/src/cpp/arrow/matlab/proxy/factory.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/matlab/src/cpp/arrow/matlab/proxy/factory.h b/matlab/src/cpp/arrow/matlab/proxy/factory.h index a7ea4ca1cac..6f68ff4ac9c 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/factory.h +++ b/matlab/src/cpp/arrow/matlab/proxy/factory.h @@ -21,6 +21,8 @@ namespace arrow::matlab::proxy { +using namespace libmexclass::proxy; + class Factory : public libmexclass::proxy::Factory { public: Factory() { } From 2ff931c3c2b76d8ce43c56609dacab9a401f4f0d Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 14:10:08 -0400 Subject: [PATCH 34/57] Disable warning output from find_package(Arrow) call by adding the QUIET flag. --- matlab/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index 890194fd25a..881c574fb63 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -237,7 +237,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 @@ -267,7 +267,7 @@ 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() @@ -275,7 +275,7 @@ if(MATLAB_BUILD_TESTS) endif() else() - find_package(Arrow) + find_package(Arrow QUIET) if(NOT Arrow_FOUND) build_arrow() endif() From 0d800a2ac9bf85e115f4793bc3c8fc79a160b09e Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 14:15:28 -0400 Subject: [PATCH 35/57] Add tools/cmake to CMAKE_MODULE_PATH. --- matlab/CMakeLists.txt | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index 881c574fb63..5ff91957334 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -207,13 +207,8 @@ 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() - -# set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake_modules) +# Add tools/cmake directory to the CMAKE_MODULE_PATH. +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/tools/cmake) # Get find_package(Arrow) by setting Arrow_DIR to CPP interface ArrowConfig.cmake # TODO: Make sure this works on all platforms submitting From dbc58819ea6f94854e813f78da710b7c6013d379 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 14:18:13 -0400 Subject: [PATCH 36/57] Create tools/cmake directory. Add MATLAB_ARROW_INTERFACE flag. --- matlab/CMakeLists.txt | 4 ++++ matlab/tools/cmake/BuildMatlabArrowInterface.cmake | 1 + 2 files changed, 5 insertions(+) create mode 100644 matlab/tools/cmake/BuildMatlabArrowInterface.cmake diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index 5ff91957334..46581277aa8 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -224,6 +224,10 @@ else() set(MATLAB_BUILD_OUTPUT_DIR "${CMAKE_BINARY_DIR}") endif() +if(MATLAB_ARROW_INTERFACE) + include(BuildMatlabArrowInterface) +endif() + # Only build the MATLAB interface C++ tests if MATLAB_BUILD_TESTS=ON. if(MATLAB_BUILD_TESTS) # find_package(GTest) supports custom GTEST_ROOT as well as package managers. diff --git a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake new file mode 100644 index 00000000000..36c0506c447 --- /dev/null +++ b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake @@ -0,0 +1 @@ +message(STATUS "Building MATLAB Interface to Arrow...") From 8e7a3e73a3d2d79ce772da66f2c88f605757f9c4 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 13 Mar 2023 14:32:41 -0400 Subject: [PATCH 37/57] Move libmexclass code into tools/cmake directory. --- matlab/CMakeLists.txt | 40 ---------------- .../cmake/BuildMatlabArrowInterface.cmake | 48 +++++++++++++++++++ 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index 46581277aa8..db5cc2b5793 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -371,40 +371,6 @@ else() message(STATUS "ARROW_INCLUDE_DIR: ${ARROW_INCLUDE_DIR}") endif() -# Arguments to build libmexclass. -set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy;${CMAKE_SOURCE_DIR}/src/cpp") -set(CUSTOM_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory.cc") -set(CUSTOM_PROXY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/double_array.cc") -set(CUSTOM_PROXY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp;${ARROW_INCLUDE_DIR}") -set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_LINK_LIB}) -# On Windows, arrow.dll must be installed regardless of whether Arrow_FOUND is true or false. -# Pass this to libmexclass to copy over to the packaged install folder +libmexclass during install. -set(CUSTOM_PROXY_RUNTIME_LIBRARIES ${ARROW_SHARED_LIB}) -set(CUSTOM_PROXY_FACTORY_HEADER_FILENAME "factory.h") -set(CUSTOM_PROXY_FACTORY_CLASS_NAME "arrow::matlab::proxy::Factory") - -# Build libmexclass as an external project. -include(ExternalProject) -ExternalProject_Add( - libmexclass - # TODO: Consider using SSH URL for the Git Repository when libmexclass is accessible for CI without permission issues. - GIT_REPOSITORY https://github.com/mathworks/libmexclass.git - GIT_TAG main - SOURCE_SUBDIR libmexclass/cpp - CMAKE_CACHE_ARGS "-D CUSTOM_PROXY_FACTORY_INCLUDE_DIR:STRING=${CUSTOM_PROXY_FACTORY_INCLUDE_DIR}" - "-D CUSTOM_PROXY_FACTORY_SOURCES:STRING=${CUSTOM_PROXY_FACTORY_SOURCES}" - "-D CUSTOM_PROXY_SOURCES:STRING=${CUSTOM_PROXY_SOURCES}" - "-D CUSTOM_PROXY_INCLUDE_DIR:STRING=${CUSTOM_PROXY_INCLUDE_DIR}" - "-D CUSTOM_PROXY_LINK_LIBRARIES:STRING=${CUSTOM_PROXY_LINK_LIBRARIES}" - "-D CUSTOM_PROXY_RUNTIME_LIBRARIES:STRING=${CUSTOM_PROXY_RUNTIME_LIBRARIES}" - "-D CUSTOM_PROXY_FACTORY_HEADER_FILENAME:STRING=${CUSTOM_PROXY_FACTORY_HEADER_FILENAME}" - "-D CUSTOM_PROXY_FACTORY_CLASS_NAME:STRING=${CUSTOM_PROXY_FACTORY_CLASS_NAME}" - INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install -) - -message(STATUS "End configure libmexclass") -############# libmexclass ################################# - # ############################################################################## # C++ Tests # ############################################################################## @@ -484,12 +450,6 @@ endif() # Create a subdirectory at CMAKE_INSTALL_PREFIX to install the interface. set(CMAKE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/arrow_matlab") -# Install libmexclass. -# Get the installation directory for libmexclass. -ExternalProject_Get_Property(libmexclass BINARY_DIR) -# Copy only the packaged folder +libmexclass from the libmexclass installation directory. -install(DIRECTORY ${BINARY_DIR}/+libmexclass DESTINATION ${CMAKE_INSTALL_DIR}) - # Create a package hierarchy at CMAKE_INSTALL_PREFIX to install the mex function # and dependencies. set(CMAKE_PACKAGED_INSTALL_DIR "${CMAKE_INSTALL_DIR}/+arrow/+cpp") diff --git a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake index 36c0506c447..9dd863adadd 100644 --- a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake +++ b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake @@ -1 +1,49 @@ +# ------- +# Build +# ------- message(STATUS "Building MATLAB Interface to Arrow...") + +# Arguments to build libmexclass. +set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy;${CMAKE_SOURCE_DIR}/src/cpp") +set(CUSTOM_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory.cc") +set(CUSTOM_PROXY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/double_array.cc") +set(CUSTOM_PROXY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp;${ARROW_INCLUDE_DIR}") +set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_LINK_LIB}) +# On Windows, arrow.dll must be installed regardless of whether Arrow_FOUND is true or false. +# Pass this to libmexclass to copy over to the packaged install folder +libmexclass during install. +set(CUSTOM_PROXY_RUNTIME_LIBRARIES ${ARROW_SHARED_LIB}) +set(CUSTOM_PROXY_FACTORY_HEADER_FILENAME "factory.h") +set(CUSTOM_PROXY_FACTORY_CLASS_NAME "arrow::matlab::proxy::Factory") + +# Build libmexclass as an external project. +include(ExternalProject) +ExternalProject_Add( + libmexclass + # TODO: Consider using SSH URL for the Git Repository when libmexclass is accessible for CI without permission issues. + GIT_REPOSITORY https://github.com/mathworks/libmexclass.git + GIT_TAG main + SOURCE_SUBDIR libmexclass/cpp + CMAKE_CACHE_ARGS "-D CUSTOM_PROXY_FACTORY_INCLUDE_DIR:STRING=${CUSTOM_PROXY_FACTORY_INCLUDE_DIR}" + "-D CUSTOM_PROXY_FACTORY_SOURCES:STRING=${CUSTOM_PROXY_FACTORY_SOURCES}" + "-D CUSTOM_PROXY_SOURCES:STRING=${CUSTOM_PROXY_SOURCES}" + "-D CUSTOM_PROXY_INCLUDE_DIR:STRING=${CUSTOM_PROXY_INCLUDE_DIR}" + "-D CUSTOM_PROXY_LINK_LIBRARIES:STRING=${CUSTOM_PROXY_LINK_LIBRARIES}" + "-D CUSTOM_PROXY_RUNTIME_LIBRARIES:STRING=${CUSTOM_PROXY_RUNTIME_LIBRARIES}" + "-D CUSTOM_PROXY_FACTORY_HEADER_FILENAME:STRING=${CUSTOM_PROXY_FACTORY_HEADER_FILENAME}" + "-D CUSTOM_PROXY_FACTORY_CLASS_NAME:STRING=${CUSTOM_PROXY_FACTORY_CLASS_NAME}" + INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install +) + +message(STATUS "Successfully built MATLAB Interface to Arrow.") + +# ------- +# Install +# ------- +message(STATUS "Installing MATLAB Interface to Arrow...") +# Install libmexclass. +# Get the installation directory for libmexclass. +# ExternalProject_Get_Property(libmexclass BINARY_DIR) +# Copy only the packaged folder +libmexclass from the libmexclass installation directory. +# install(DIRECTORY ${BINARY_DIR}/+libmexclass DESTINATION ${CMAKE_INSTALL_DIR}) + +message(STATUS "Successfully installed MATLAB Interface to Arrow.") From 884d2b1a9f4b89b1126ce356d50a1b5275504d19 Mon Sep 17 00:00:00 2001 From: shegden Date: Tue, 14 Mar 2023 01:10:49 -0400 Subject: [PATCH 38/57] Fixed build error for MATLAB_ARROW_INTERFACE with include. --- matlab/CMakeLists.txt | 10 +++++----- matlab/tools/cmake/BuildMatlabArrowInterface.cmake | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index db5cc2b5793..4c8c0ad85c7 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -224,10 +224,6 @@ else() set(MATLAB_BUILD_OUTPUT_DIR "${CMAKE_BINARY_DIR}") endif() -if(MATLAB_ARROW_INTERFACE) - include(BuildMatlabArrowInterface) -endif() - # Only build the MATLAB interface C++ tests if MATLAB_BUILD_TESTS=ON. if(MATLAB_BUILD_TESTS) # find_package(GTest) supports custom GTEST_ROOT as well as package managers. @@ -450,6 +446,10 @@ 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_DIR}/+arrow/+cpp") @@ -577,4 +577,4 @@ if(MATLAB_ADD_INSTALL_DIR_TO_SEARCH_PATH OR MATLAB_ADD_INSTALL_DIR_TO_STARTUP_FI # to the MATLAB Search Path or add a command to the MATLAB startup file to add the # install directory to the MATLAB Search Path. install(SCRIPT "${TOOLS_DIR}/UpdateMatlabSearchPath.cmake") -endif() +endif() \ No newline at end of file diff --git a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake index 9dd863adadd..1e43ca12a12 100644 --- a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake +++ b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake @@ -42,8 +42,8 @@ message(STATUS "Successfully built MATLAB Interface to Arrow.") message(STATUS "Installing MATLAB Interface to Arrow...") # Install libmexclass. # Get the installation directory for libmexclass. -# ExternalProject_Get_Property(libmexclass BINARY_DIR) +ExternalProject_Get_Property(libmexclass BINARY_DIR) # Copy only the packaged folder +libmexclass from the libmexclass installation directory. -# install(DIRECTORY ${BINARY_DIR}/+libmexclass DESTINATION ${CMAKE_INSTALL_DIR}) +install(DIRECTORY ${BINARY_DIR}/+libmexclass DESTINATION ${CMAKE_INSTALL_DIR}) -message(STATUS "Successfully installed MATLAB Interface to Arrow.") +message(STATUS "Successfully installed MATLAB Interface to Arrow.") \ No newline at end of file From 0ea2eb36ba9d6007f9b3aa3085adfd945c1f1097 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Tue, 14 Mar 2023 07:51:10 -0400 Subject: [PATCH 39/57] Inherit from matlab.mixin.CustomDisplay. --- matlab/src/matlab/+arrow/+array/DoubleArray.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/src/matlab/+arrow/+array/DoubleArray.m b/matlab/src/matlab/+arrow/+array/DoubleArray.m index 4f84b6026f9..df9fa392704 100644 --- a/matlab/src/matlab/+arrow/+array/DoubleArray.m +++ b/matlab/src/matlab/+arrow/+array/DoubleArray.m @@ -1,4 +1,4 @@ -classdef DoubleArray < arrow.array.internal.CustomDisplay +classdef DoubleArray < matlab.mixin.CustomDisplay properties (Access=private) Proxy From cb85f7b64fe07c3115e845e3e44553eca6434d64 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Tue, 14 Mar 2023 07:56:11 -0400 Subject: [PATCH 40/57] Remove comments referring to libmexclass in CMakeLists.txt. --- matlab/CMakeLists.txt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index 4c8c0ad85c7..72c1bfc76ee 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -321,11 +321,6 @@ matlab_add_mex(R2018a target_include_directories(mexcall PRIVATE ${CPP_SOURCE_DIR}) -############# libmexclass ################################# -message(STATUS "Start configure libmexclass") - -message(STATUS "Arrow_FOUND is ${Arrow_FOUND}.") - # 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) @@ -577,4 +572,4 @@ if(MATLAB_ADD_INSTALL_DIR_TO_SEARCH_PATH OR MATLAB_ADD_INSTALL_DIR_TO_STARTUP_FI # to the MATLAB Search Path or add a command to the MATLAB startup file to add the # install directory to the MATLAB Search Path. install(SCRIPT "${TOOLS_DIR}/UpdateMatlabSearchPath.cmake") -endif() \ No newline at end of file +endif() From d845a92e1ddcedea0847846b517d973ca46e0c42 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Tue, 14 Mar 2023 07:58:07 -0400 Subject: [PATCH 41/57] Remove debug messages. --- matlab/tools/cmake/BuildMatlabArrowInterface.cmake | 6 ------ 1 file changed, 6 deletions(-) diff --git a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake index 1e43ca12a12..996b3f6d568 100644 --- a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake +++ b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake @@ -1,7 +1,6 @@ # ------- # Build # ------- -message(STATUS "Building MATLAB Interface to Arrow...") # Arguments to build libmexclass. set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy;${CMAKE_SOURCE_DIR}/src/cpp") @@ -34,16 +33,11 @@ ExternalProject_Add( INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install ) -message(STATUS "Successfully built MATLAB Interface to Arrow.") - # ------- # Install # ------- -message(STATUS "Installing MATLAB Interface to Arrow...") # Install libmexclass. # Get the installation directory for libmexclass. ExternalProject_Get_Property(libmexclass BINARY_DIR) # Copy only the packaged folder +libmexclass from the libmexclass installation directory. install(DIRECTORY ${BINARY_DIR}/+libmexclass DESTINATION ${CMAKE_INSTALL_DIR}) - -message(STATUS "Successfully installed MATLAB Interface to Arrow.") \ No newline at end of file From 383afdcf8a2c8a349bba5f8aa8244e023018b06f Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Tue, 14 Mar 2023 08:32:47 -0400 Subject: [PATCH 42/57] Modify comments. Add success message for libmexclass build. --- .../cmake/BuildMatlabArrowInterface.cmake | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake index 996b3f6d568..4bff9404362 100644 --- a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake +++ b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake @@ -1,24 +1,30 @@ # ------- -# Build +# Config # ------- -# Arguments to build libmexclass. +# Build configuration for libmexclass. set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy;${CMAKE_SOURCE_DIR}/src/cpp") set(CUSTOM_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory.cc") set(CUSTOM_PROXY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/double_array.cc") set(CUSTOM_PROXY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp;${ARROW_INCLUDE_DIR}") set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_LINK_LIB}) -# On Windows, arrow.dll must be installed regardless of whether Arrow_FOUND is true or false. -# Pass this to libmexclass to copy over to the packaged install folder +libmexclass during install. +# On Windows, arrow.dll must be installed regardless of +# whether Arrow_FOUND is true or false. Therefore, we explicitly +# copy ARROW_SHARED_LIB to the installation folder +libmexclass/+proxy. set(CUSTOM_PROXY_RUNTIME_LIBRARIES ${ARROW_SHARED_LIB}) set(CUSTOM_PROXY_FACTORY_HEADER_FILENAME "factory.h") set(CUSTOM_PROXY_FACTORY_CLASS_NAME "arrow::matlab::proxy::Factory") +# ------- +# Build +# ------- + # Build libmexclass as an external project. include(ExternalProject) ExternalProject_Add( libmexclass - # TODO: Consider using SSH URL for the Git Repository when libmexclass is accessible for CI without permission issues. + # TODO: Consider using SSH URL for the Git Repository when + # libmexclass is accessible for CI without permission issues. GIT_REPOSITORY https://github.com/mathworks/libmexclass.git GIT_TAG main SOURCE_SUBDIR libmexclass/cpp @@ -33,11 +39,20 @@ ExternalProject_Add( INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install ) +add_custom_command(TARGET libmexclass + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green --bold --no-newline "✓ Success " + VERBATIM) +add_custom_command(TARGET libmexclass + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --white "libmexclass build successful." + VERBATIM) + # ------- # Install # ------- + # Install libmexclass. -# Get the installation directory for libmexclass. ExternalProject_Get_Property(libmexclass BINARY_DIR) # Copy only the packaged folder +libmexclass from the libmexclass installation directory. install(DIRECTORY ${BINARY_DIR}/+libmexclass DESTINATION ${CMAKE_INSTALL_DIR}) From 6b1bad9e889acdc9ae2e1763a2964f2fad9bceac Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Tue, 14 Mar 2023 09:33:35 -0400 Subject: [PATCH 43/57] Add MATLAB_ARROW_INTERFACE=ON to matlab_build.sh CI script. --- ci/scripts/matlab_build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/scripts/matlab_build.sh b/ci/scripts/matlab_build.sh index 656805275ed..db45e57e120 100755 --- a/ci/scripts/matlab_build.sh +++ b/ci/scripts/matlab_build.sh @@ -25,6 +25,6 @@ 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} From 807f743f58e4917f06eb93449f50f3686b0bc5cb Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Tue, 14 Mar 2023 10:36:24 -0400 Subject: [PATCH 44/57] Add arrow_ep as a dependency of libmexclass target. --- matlab/tools/cmake/BuildMatlabArrowInterface.cmake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake index 4bff9404362..2352e08486a 100644 --- a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake +++ b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake @@ -39,6 +39,11 @@ ExternalProject_Add( INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install ) +# When building Arrow from source, Arrow must be built before building libmexclass. +if(TARGET arrow_ep) + add_dependencies(libmexclass arrow_ep) +endif() + add_custom_command(TARGET libmexclass POST_BUILD COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green --bold --no-newline "✓ Success " From 95dbd1297ad2235315aca44ed93b9645088982a4 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Tue, 14 Mar 2023 12:32:47 -0400 Subject: [PATCH 45/57] Add basic MATLAB test for arrow.array.DoubleArray. --- matlab/test/arrow/array/tDoubleArray.m | 41 ++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 matlab/test/arrow/array/tDoubleArray.m diff --git a/matlab/test/arrow/array/tDoubleArray.m b/matlab/test/arrow/array/tDoubleArray.m new file mode 100755 index 00000000000..8133e7e69f4 --- /dev/null +++ b/matlab/test/arrow/array/tDoubleArray.m @@ -0,0 +1,41 @@ +classdef tDoubleArray < matlab.unittest.TestCase + % Tests for arrow.array.DoubleArray + + % 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. + + methods(TestClassSetup) + function verifyOnMatlabPath(testCase) + % arrow.cpp.DoubleArray must be on the MATLAB path. + testCase.assertTrue(~isempty(which('arrow.array.DoubleArray')), ... + '''arrow.array.DoubleArray'' must be on the MATLAB path. Use ''addpath'' to add folders to the MATLAB path.'); + end + end + + methods(TestMethodSetup) + function setupTempWorkingDirectory(testCase) + import matlab.unittest.fixtures.WorkingFolderFixture; + testCase.applyFixture(WorkingFolderFixture); + end + end + + methods(Test) + function Basic(testCase) + A = arrow.array.DoubleArray([1, 2, 3]); + className = string(class(A)); + testCase.verifyEqual(className, "arrow.array.DoubleArray"); + end + end +end From 239ceaa06d65194c43c89ff8b6e7e866a668304b Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Tue, 14 Mar 2023 12:46:58 -0400 Subject: [PATCH 46/57] Add missing license headers. --- matlab/src/matlab/+arrow/+array/DoubleArray.m | 16 ++++++++++++++++ .../tools/cmake/BuildMatlabArrowInterface.cmake | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/matlab/src/matlab/+arrow/+array/DoubleArray.m b/matlab/src/matlab/+arrow/+array/DoubleArray.m index df9fa392704..ad509c4a2f2 100644 --- a/matlab/src/matlab/+arrow/+array/DoubleArray.m +++ b/matlab/src/matlab/+arrow/+array/DoubleArray.m @@ -1,4 +1,20 @@ classdef DoubleArray < matlab.mixin.CustomDisplay + % arrow.array.DoubleArray + + % 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. properties (Access=private) Proxy diff --git a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake index 2352e08486a..aec0f48ded1 100644 --- a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake +++ b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake @@ -1,3 +1,20 @@ +# 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. + # ------- # Config # ------- From 4bf1153eda754e67da18a78003cf733c6e8824e9 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Tue, 14 Mar 2023 13:09:13 -0400 Subject: [PATCH 47/57] Fix linting isssues in CMakeLists.txt. --- matlab/CMakeLists.txt | 50 +++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index 72c1bfc76ee..d6e6a7835d0 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -324,42 +324,46 @@ 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) + 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}") + # 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() + # 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}") + # 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) + 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}") + # 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() # ############################################################################## @@ -442,7 +446,7 @@ endif() set(CMAKE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/arrow_matlab") if(MATLAB_ARROW_INTERFACE) - include(BuildMatlabArrowInterface) + include(BuildMatlabArrowInterface) endif() # Create a package hierarchy at CMAKE_INSTALL_PREFIX to install the mex function From 5451d762eb7af7973775426c834bdb310dacf2f1 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Tue, 14 Mar 2023 14:58:34 -0400 Subject: [PATCH 48/57] Rename arrow.array.DoubleArray to arrow.array.Float64Array. --- .../proxy/{double_array.cc => float64_array.cc} | 4 ++-- .../proxy/{double_array.h => float64_array.h} | 6 +++--- matlab/src/cpp/arrow/matlab/proxy/factory.cc | 4 ++-- .../+array/{DoubleArray.m => Float64Array.m} | 8 ++++---- .../array/{tDoubleArray.m => tFloat64Array.m} | 14 +++++++------- matlab/tools/cmake/BuildMatlabArrowInterface.cmake | 2 +- 6 files changed, 19 insertions(+), 19 deletions(-) rename matlab/src/cpp/arrow/matlab/array/proxy/{double_array.cc => float64_array.cc} (90%) rename matlab/src/cpp/arrow/matlab/array/proxy/{double_array.h => float64_array.h} (92%) rename matlab/src/matlab/+arrow/+array/{DoubleArray.m => Float64Array.m} (86%) rename matlab/test/arrow/array/{tDoubleArray.m => tFloat64Array.m} (72%) diff --git a/matlab/src/cpp/arrow/matlab/array/proxy/double_array.cc b/matlab/src/cpp/arrow/matlab/array/proxy/float64_array.cc similarity index 90% rename from matlab/src/cpp/arrow/matlab/array/proxy/double_array.cc rename to matlab/src/cpp/arrow/matlab/array/proxy/float64_array.cc index 414a5312216..4f25912b9ea 100644 --- a/matlab/src/cpp/arrow/matlab/array/proxy/double_array.cc +++ b/matlab/src/cpp/arrow/matlab/array/proxy/float64_array.cc @@ -15,10 +15,10 @@ // specific language governing permissions and limitations // under the License. -#include "double_array.h" +#include "float64_array.h" namespace arrow::matlab::array::proxy { -void DoubleArray::Print(libmexclass::proxy::method::Context& context) { +void Float64Array::Print(libmexclass::proxy::method::Context& context) { // TODO: Return an MDA string representation of the Arrow array. std::cout << array->ToString() << std::endl; } diff --git a/matlab/src/cpp/arrow/matlab/array/proxy/double_array.h b/matlab/src/cpp/arrow/matlab/array/proxy/float64_array.h similarity index 92% rename from matlab/src/cpp/arrow/matlab/array/proxy/double_array.h rename to matlab/src/cpp/arrow/matlab/array/proxy/float64_array.h index d4901348289..3d6e449326e 100644 --- a/matlab/src/cpp/arrow/matlab/array/proxy/double_array.h +++ b/matlab/src/cpp/arrow/matlab/array/proxy/float64_array.h @@ -23,9 +23,9 @@ #include "libmexclass/proxy/Proxy.h" namespace arrow::matlab::array::proxy { -class DoubleArray : public libmexclass::proxy::Proxy { +class Float64Array : public libmexclass::proxy::Proxy { public: - DoubleArray(const libmexclass::proxy::FunctionArguments& constructor_arguments) { + Float64Array(const libmexclass::proxy::FunctionArguments& constructor_arguments) { // Get the mxArray from constructor arguments const ::matlab::data::TypedArray double_mda = constructor_arguments[0]; @@ -49,7 +49,7 @@ class DoubleArray : public libmexclass::proxy::Proxy { array = array_wrapper; // Register Proxy methods. - REGISTER_METHOD(DoubleArray, Print); + REGISTER_METHOD(Float64Array, Print); } private: void Print(libmexclass::proxy::method::Context& context); diff --git a/matlab/src/cpp/arrow/matlab/proxy/factory.cc b/matlab/src/cpp/arrow/matlab/proxy/factory.cc index 05a743fabc4..9bf7ec2dc9f 100644 --- a/matlab/src/cpp/arrow/matlab/proxy/factory.cc +++ b/matlab/src/cpp/arrow/matlab/proxy/factory.cc @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -#include "arrow/matlab/array/proxy/double_array.h" +#include "arrow/matlab/array/proxy/float64_array.h" #include "factory.h" @@ -26,7 +26,7 @@ namespace arrow::matlab::proxy { std::shared_ptr Factory::make_proxy(const ClassName& class_name, const FunctionArguments& constructor_arguments) { // Register MATLAB Proxy classes with corresponding C++ Proxy classes. - REGISTER_PROXY(arrow.array.proxy.DoubleArray, arrow::matlab::array::proxy::DoubleArray); + REGISTER_PROXY(arrow.array.proxy.Float64Array, arrow::matlab::array::proxy::Float64Array); // TODO: Decide what to do in the case that there isn't a Proxy match. std::cout << "Did not find a matching C++ proxy for: " + class_name << std::endl; diff --git a/matlab/src/matlab/+arrow/+array/DoubleArray.m b/matlab/src/matlab/+arrow/+array/Float64Array.m similarity index 86% rename from matlab/src/matlab/+arrow/+array/DoubleArray.m rename to matlab/src/matlab/+arrow/+array/Float64Array.m index ad509c4a2f2..71d56e6cc0a 100644 --- a/matlab/src/matlab/+arrow/+array/DoubleArray.m +++ b/matlab/src/matlab/+arrow/+array/Float64Array.m @@ -1,5 +1,5 @@ -classdef DoubleArray < matlab.mixin.CustomDisplay - % arrow.array.DoubleArray +classdef Float64Array < matlab.mixin.CustomDisplay + % arrow.array.Float64Array % Licensed to the Apache Software Foundation (ASF) under one or more % contributor license agreements. See the NOTICE file distributed with @@ -25,9 +25,9 @@ end methods - function obj = DoubleArray(matlabArray) + function obj = Float64Array(matlabArray) obj.MatlabArray = matlabArray; - obj.Proxy = libmexclass.proxy.Proxy("Name", "arrow.array.proxy.DoubleArray", "ConstructorArguments", {obj.MatlabArray}); + obj.Proxy = libmexclass.proxy.Proxy("Name", "arrow.array.proxy.Float64Array", "ConstructorArguments", {obj.MatlabArray}); end function Print(obj) diff --git a/matlab/test/arrow/array/tDoubleArray.m b/matlab/test/arrow/array/tFloat64Array.m similarity index 72% rename from matlab/test/arrow/array/tDoubleArray.m rename to matlab/test/arrow/array/tFloat64Array.m index 8133e7e69f4..f104ad4a7d5 100755 --- a/matlab/test/arrow/array/tDoubleArray.m +++ b/matlab/test/arrow/array/tFloat64Array.m @@ -1,5 +1,5 @@ -classdef tDoubleArray < matlab.unittest.TestCase - % Tests for arrow.array.DoubleArray +classdef tFloat64Array < matlab.unittest.TestCase + % Tests for arrow.array.Float64Array % Licensed to the Apache Software Foundation (ASF) under one or more % contributor license agreements. See the NOTICE file distributed with @@ -18,9 +18,9 @@ methods(TestClassSetup) function verifyOnMatlabPath(testCase) - % arrow.cpp.DoubleArray must be on the MATLAB path. - testCase.assertTrue(~isempty(which('arrow.array.DoubleArray')), ... - '''arrow.array.DoubleArray'' must be on the MATLAB path. Use ''addpath'' to add folders to the MATLAB path.'); + % arrow.array.Float64Array must be on the MATLAB path. + testCase.assertTrue(~isempty(which('arrow.array.Float64Array')), ... + '''arrow.array.Float64Array'' must be on the MATLAB path. Use ''addpath'' to add folders to the MATLAB path.'); end end @@ -33,9 +33,9 @@ function setupTempWorkingDirectory(testCase) methods(Test) function Basic(testCase) - A = arrow.array.DoubleArray([1, 2, 3]); + A = arrow.array.Float64Array([1, 2, 3]); className = string(class(A)); - testCase.verifyEqual(className, "arrow.array.DoubleArray"); + testCase.verifyEqual(className, "arrow.array.Float64Array"); end end end diff --git a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake index aec0f48ded1..86467d43fb1 100644 --- a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake +++ b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake @@ -22,7 +22,7 @@ # Build configuration for libmexclass. set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy;${CMAKE_SOURCE_DIR}/src/cpp") set(CUSTOM_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory.cc") -set(CUSTOM_PROXY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/double_array.cc") +set(CUSTOM_PROXY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/float64_array.cc") set(CUSTOM_PROXY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp;${ARROW_INCLUDE_DIR}") set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_LINK_LIB}) # On Windows, arrow.dll must be installed regardless of From 6f00627fa0a2fcbe90f9e61d3b1695d335bd2fb4 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 3 Apr 2023 16:06:13 -0400 Subject: [PATCH 49/57] Use refactored libmexclass functionality via FetchContent. Co-authored-by: Sreehari Hegden --- matlab/src/cpp/arrow/matlab/mex/gateway.cc | 30 ++++ .../cmake/BuildMatlabArrowInterface.cmake | 135 +++++++++++------- 2 files changed, 112 insertions(+), 53 deletions(-) create mode 100644 matlab/src/cpp/arrow/matlab/mex/gateway.cc diff --git a/matlab/src/cpp/arrow/matlab/mex/gateway.cc b/matlab/src/cpp/arrow/matlab/mex/gateway.cc new file mode 100644 index 00000000000..78ce6e274e9 --- /dev/null +++ b/matlab/src/cpp/arrow/matlab/mex/gateway.cc @@ -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(inputs, outputs, getEngine()); + } +}; diff --git a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake index 86467d43fb1..df5d08b26e1 100644 --- a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake +++ b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake @@ -15,66 +15,95 @@ # specific language governing permissions and limitations # under the License. -# ------- -# Config -# ------- +# ---------------------------------- +# Configure libmexclass FetchContent +# ---------------------------------- -# Build configuration for libmexclass. -set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy;${CMAKE_SOURCE_DIR}/src/cpp") -set(CUSTOM_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory.cc") -set(CUSTOM_PROXY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/float64_array.cc") -set(CUSTOM_PROXY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp;${ARROW_INCLUDE_DIR}") -set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_LINK_LIB}) -# On Windows, arrow.dll must be installed regardless of -# whether Arrow_FOUND is true or false. Therefore, we explicitly -# copy ARROW_SHARED_LIB to the installation folder +libmexclass/+proxy. -set(CUSTOM_PROXY_RUNTIME_LIBRARIES ${ARROW_SHARED_LIB}) -set(CUSTOM_PROXY_FACTORY_HEADER_FILENAME "factory.h") -set(CUSTOM_PROXY_FACTORY_CLASS_NAME "arrow::matlab::proxy::Factory") +set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_FETCH_CONTENT_NAME libmexclass) +# TODO: Consider using SSH URL for the Git Repository when +# libmexclass is accessible for CI without permission issues. +set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_FETCH_CONTENT_GIT_REPOSITORY "https://github.com/mathworks/libmexclass.git") +# Use a specific Git commit hash to avoid libmexclass version changing unexpectedly. +set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_FETCH_CONTENT_GIT_TAG "44c15d0") +set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_FETCH_CONTENT_SOURCE_SUBDIR "libmexclass/cpp") -# ------- -# Build -# ------- +# ------------------------------------------ +# Configure libmexclass Client Proxy Library +# ------------------------------------------ -# Build libmexclass as an external project. -include(ExternalProject) -ExternalProject_Add( - libmexclass - # TODO: Consider using SSH URL for the Git Repository when - # libmexclass is accessible for CI without permission issues. - GIT_REPOSITORY https://github.com/mathworks/libmexclass.git - GIT_TAG main - SOURCE_SUBDIR libmexclass/cpp - CMAKE_CACHE_ARGS "-D CUSTOM_PROXY_FACTORY_INCLUDE_DIR:STRING=${CUSTOM_PROXY_FACTORY_INCLUDE_DIR}" - "-D CUSTOM_PROXY_FACTORY_SOURCES:STRING=${CUSTOM_PROXY_FACTORY_SOURCES}" - "-D CUSTOM_PROXY_SOURCES:STRING=${CUSTOM_PROXY_SOURCES}" - "-D CUSTOM_PROXY_INCLUDE_DIR:STRING=${CUSTOM_PROXY_INCLUDE_DIR}" - "-D CUSTOM_PROXY_LINK_LIBRARIES:STRING=${CUSTOM_PROXY_LINK_LIBRARIES}" - "-D CUSTOM_PROXY_RUNTIME_LIBRARIES:STRING=${CUSTOM_PROXY_RUNTIME_LIBRARIES}" - "-D CUSTOM_PROXY_FACTORY_HEADER_FILENAME:STRING=${CUSTOM_PROXY_FACTORY_HEADER_FILENAME}" - "-D CUSTOM_PROXY_FACTORY_CLASS_NAME:STRING=${CUSTOM_PROXY_FACTORY_CLASS_NAME}" - INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install +set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_LIBRARY_NAME arrowproxy) +set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_LIBRARY_ROOT_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp") +set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy") +set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/float64_array.cc") +set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy") +set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory.cc") +set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_LIBRARY_INCLUDE_DIRS ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_LIBRARY_ROOT_INCLUDE_DIR} + ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_INCLUDE_DIR} + ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_FACTORY_INCLUDE_DIR} + ${ARROW_INCLUDE_DIRS}) +set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_LIBRARY_SOURCES ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_SOURCES} + ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_FACTORY_SOURCES}) +# ---------------------------------------- +# Configure libmexclass Client MEX Gateway +# ---------------------------------------- + +set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_MEX_GATEWAY_NAME gateway) +set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_MEX_GATEWAY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/mex/gateway.cc") + +# --------------------------------------- +# Download libmexclass Using FetchContent +# --------------------------------------- + +# Include libmexclass using FetchContent. +include(FetchContent) +FetchContent_Declare( + ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_FETCH_CONTENT_NAME} + GIT_REPOSITORY ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_FETCH_CONTENT_GIT_REPOSITORY} + GIT_TAG ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_FETCH_CONTENT_GIT_TAG} + SOURCE_SUBDIR ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_FETCH_CONTENT_SOURCE_SUBDIR} +) +FetchContent_MakeAvailable( + ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_FETCH_CONTENT_NAME} +) + +# ------------------------------------ +# Add libmexclass Client Proxy Library +# ------------------------------------ + +if(NOT TARGET arrow_shared) + message(FATAL_ERROR "The Arrow C++ libraries must be available to build the MATLAB Interface to Arrow.") +endif() + +libmexclass_client_add_proxy_library( + NAME ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_LIBRARY_NAME} + SOURCES ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_LIBRARY_SOURCES} + INCLUDE_DIRS ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_LIBRARY_INCLUDE_DIRS} + LINK_LIBRARIES arrow_shared ) +# Use C++17 +target_compile_features(${MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_LIBRARY_NAME} PRIVATE cxx_std_17) -# When building Arrow from source, Arrow must be built before building libmexclass. +# When building Arrow from source, Arrow must be built before building the client Proxy library. if(TARGET arrow_ep) - add_dependencies(libmexclass arrow_ep) + add_dependencies(${MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_LIBRARY_NAME} arrow_ep) endif() -add_custom_command(TARGET libmexclass - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green --bold --no-newline "✓ Success " - VERBATIM) -add_custom_command(TARGET libmexclass - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --white "libmexclass build successful." - VERBATIM) +# ---------------------------------- +# Add libmexclass Client MEX Gateway +# ---------------------------------- -# ------- -# Install -# ------- +libmexclass_client_add_mex_gateway( + NAME ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_MEX_GATEWAY_NAME} + CLIENT_PROXY_LIBRARY_NAME ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_LIBRARY_NAME} + SOURCES ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_MEX_GATEWAY_SOURCES} +) + +# -------------------------- +# Install libmexclass Client +# -------------------------- -# Install libmexclass. -ExternalProject_Get_Property(libmexclass BINARY_DIR) -# Copy only the packaged folder +libmexclass from the libmexclass installation directory. -install(DIRECTORY ${BINARY_DIR}/+libmexclass DESTINATION ${CMAKE_INSTALL_DIR}) +libmexclass_client_install( + CLIENT_PROXY_LIBRARY_NAME ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_LIBRARY_NAME} + CLIENT_MEX_GATEWAY_NAME ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_MEX_GATEWAY_NAME} + DESTINATION ${CMAKE_INSTALL_DIR} +) From 0a22524ae1fd0dbd7b81b1a8e7d4c6f504707a81 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Tue, 18 Apr 2023 17:03:44 -0400 Subject: [PATCH 50/57] Use list(PREPEND ...) to modify CMAKE_MODULE_PATH. Co-authored-by: Sutou Kouhei --- matlab/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index d6e6a7835d0..c78f7c85ebc 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -208,7 +208,7 @@ endif() option(MATLAB_BUILD_TESTS "Build the C++ tests for the MATLAB interface" OFF) # Add tools/cmake directory to the CMAKE_MODULE_PATH. -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/tools/cmake) +list(PREPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/tools/cmake) # Get find_package(Arrow) by setting Arrow_DIR to CPP interface ArrowConfig.cmake # TODO: Make sure this works on all platforms submitting From 2ddf1285fc765c0ac6575771a2131246ba0ba933 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Tue, 18 Apr 2023 17:39:35 -0400 Subject: [PATCH 51/57] Set Arrow_ROOT instead of modifying CMAKE_PREFIX_PATH to configure find_package search behavior for Arrow C++ libraries. --- matlab/CMakeLists.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index c78f7c85ebc..a43862f24f6 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -210,9 +210,13 @@ option(MATLAB_BUILD_TESTS "Build the C++ tests for the MATLAB interface" OFF) # Add tools/cmake directory to the CMAKE_MODULE_PATH. list(PREPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/tools/cmake) -# Get find_package(Arrow) by setting Arrow_DIR to CPP interface ArrowConfig.cmake -# TODO: Make sure this works on all platforms submitting -set(CMAKE_PREFIX_PATH "${ARROW_HOME}/lib/cmake/Arrow") +# 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 From 38f967ab8d28381f3b994bb146a1324e583206bc Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Wed, 19 Apr 2023 13:36:46 -0400 Subject: [PATCH 52/57] Refactor logic for building Arrow from source in order to build GoogleTest. --- matlab/CMakeLists.txt | 110 ++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 58 deletions(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index a43862f24f6..64c12015283 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -32,44 +32,61 @@ function(build_arrow) message(SEND_ERROR "Error: unrecognized arguments: ${ARG_UNPARSED_ARGUMENTS}") endif() - # If Arrow build available, set ARROW_PREFIX to the ARROW_HOME specified with cmake. - if(Arrow_FOUND) - set(ARROW_PREFIX "${ARROW_HOME}") - else() - # 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") - endif() - - 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_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/arrow_ep-prefix") 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. @@ -84,30 +101,7 @@ function(build_arrow) BINARY_DIR "${ARROW_BINARY_DIR}" 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) From 2e59596b0dd7a16351ee3889f87df6e3813481a0 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Wed, 19 Apr 2023 14:26:27 -0400 Subject: [PATCH 53/57] Error when building in Debug mode on Windows by default. --- matlab/CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index 64c12015283..a35c84669b0 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -17,6 +17,18 @@ cmake_minimum_required(VERSION 3.20) +set(MATLAB_ARROW_INTERFACE_ERROR_WHEN_WINDOWS_DEBUG "ON" CACHE STRING "") +if(CMAKE_BUILD_TYPE EQUAL "Debug" AND WIN32) + if(MATLAB_ARROW_INTERFACE_ERROR_WHEN_WINDOWS_DEBUG) + message(FATAL_ERROR "Debug builds of the MATLAB Interface to Arrow \ + are not supported on Windows due to incompatibilities \ + between the MSVC Runtime libraries used by Debug builds of \ + the Arrow C++ libraries and MATLAB. To disable this error, \ + pass '-D MATLAB_ARROW_INTERFACE_ERROR_WHEN_WINDOWS_DEBUG=OFF' \ + to the cmake command.") + endif() +endif() + # Build the Arrow C++ libraries. function(build_arrow) set(options BUILD_GTEST) From 37470dd914160c04c2960c2c5cc7d2c7c3182088 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Wed, 19 Apr 2023 14:51:34 -0400 Subject: [PATCH 54/57] Revert changes related to erroring for Debug builds. --- matlab/CMakeLists.txt | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index a35c84669b0..64c12015283 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -17,18 +17,6 @@ cmake_minimum_required(VERSION 3.20) -set(MATLAB_ARROW_INTERFACE_ERROR_WHEN_WINDOWS_DEBUG "ON" CACHE STRING "") -if(CMAKE_BUILD_TYPE EQUAL "Debug" AND WIN32) - if(MATLAB_ARROW_INTERFACE_ERROR_WHEN_WINDOWS_DEBUG) - message(FATAL_ERROR "Debug builds of the MATLAB Interface to Arrow \ - are not supported on Windows due to incompatibilities \ - between the MSVC Runtime libraries used by Debug builds of \ - the Arrow C++ libraries and MATLAB. To disable this error, \ - pass '-D MATLAB_ARROW_INTERFACE_ERROR_WHEN_WINDOWS_DEBUG=OFF' \ - to the cmake command.") - endif() -endif() - # Build the Arrow C++ libraries. function(build_arrow) set(options BUILD_GTEST) From 66f354870468630fe29c797688f4576ebbe8310e Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Wed, 19 Apr 2023 14:58:12 -0400 Subject: [PATCH 55/57] Fix linting issues with matlab/CMakeLists.txt. --- matlab/CMakeLists.txt | 109 ++++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 52 deletions(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index 64c12015283..ed3efbd6ea2 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -36,57 +36,62 @@ function(build_arrow) 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") - - 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) + + 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() - 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() + 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. @@ -101,7 +106,7 @@ function(build_arrow) BINARY_DIR "${ARROW_BINARY_DIR}" CMAKE_ARGS "${ARROW_CMAKE_ARGS}" BUILD_BYPRODUCTS "${ARROW_BUILD_BYPRODUCTS}") - + add_dependencies(${ARROW_LIBRARY_TARGET} arrow_ep) if(ARG_BUILD_GTEST) @@ -209,7 +214,7 @@ list(PREPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/tools/cmake) # 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}") + set(Arrow_ROOT "${ARROW_HOME}") endif() # Multi-Configuration generators (e.g. Visual Studio or XCode) place their build artifacts From 737950a5f7e2caca2ad15375324cc16aa65c26f2 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Fri, 21 Apr 2023 12:05:50 -0400 Subject: [PATCH 56/57] Add newlines for readability in ci/scripts/matlab_build.sh. Co-authored-by: Sutou Kouhei --- ci/scripts/matlab_build.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ci/scripts/matlab_build.sh b/ci/scripts/matlab_build.sh index db45e57e120..4acd4d3b82a 100755 --- a/ci/scripts/matlab_build.sh +++ b/ci/scripts/matlab_build.sh @@ -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_ARROW_INTERFACE=ON -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} From 28721d76292b0c3c2e352bd811ea056ebd2ee95e Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 24 Apr 2023 14:08:38 -0400 Subject: [PATCH 57/57] Remove $ARROW_INCLUDE_DIRS from $MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_LIBRARY_INCLUDE_DIRS. Co-authored-by: Sreehari Hegden --- matlab/tools/cmake/BuildMatlabArrowInterface.cmake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake index df5d08b26e1..59c48c02356 100644 --- a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake +++ b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake @@ -39,8 +39,7 @@ set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DI set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory.cc") set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_LIBRARY_INCLUDE_DIRS ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_LIBRARY_ROOT_INCLUDE_DIR} ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_INCLUDE_DIR} - ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_FACTORY_INCLUDE_DIR} - ${ARROW_INCLUDE_DIRS}) + ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_FACTORY_INCLUDE_DIR}) set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_LIBRARY_SOURCES ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_SOURCES} ${MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_FACTORY_SOURCES}) # ----------------------------------------