From 95530541d5f6ba979e14eae6dee503b927f5e03f Mon Sep 17 00:00:00 2001 From: Sarah Gilmore Date: Wed, 16 Aug 2023 11:39:15 -0400 Subject: [PATCH 1/6] Comment out MEX-specific lines in the CMakeLists.txt file Co-authored-by: Kevin Gurney --- matlab/CMakeLists.txt | 120 +++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index 51aec0c3c14..b79782caca6 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -285,44 +285,44 @@ find_package(Matlab REQUIRED COMPONENTS MAIN_PROGRAM) message(STATUS "Mex Library: ${Matlab_MEX_LIBRARY}") message(STATUS "Mex Include Folder: ${Matlab_INCLUDE_DIRS}") -set(CPP_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src/cpp) -set(MATLAB_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab) +#set(CPP_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src/cpp) +#set(MATLAB_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab) -set(arrow_matlab_sources - mex/mex_util.cc - feather/feather_reader.cc - feather/feather_writer.cc - feather/feather_functions.cc - feather/util/handle_status.cc - feather/util/unicode_conversion.cc) -list(TRANSFORM arrow_matlab_sources PREPEND ${CPP_SOURCE_DIR}/arrow/matlab/) +#set(arrow_matlab_sources +# mex/mex_util.cc +# feather/feather_reader.cc +# feather/feather_writer.cc +# feather/feather_functions.cc +# feather/util/handle_status.cc +# feather/util/unicode_conversion.cc) +#list(TRANSFORM arrow_matlab_sources PREPEND ${CPP_SOURCE_DIR}/arrow/matlab/) -add_library(arrow_matlab SHARED ${arrow_matlab_sources}) +#add_library(arrow_matlab SHARED ${arrow_matlab_sources}) # Declare a dependency on arrow_shared (libarrow.so/dylib/dll). -target_link_libraries(arrow_matlab arrow_shared) +#target_link_libraries(arrow_matlab arrow_shared) # Declare a dependency on the MEX shared library (libmex.so/dylib/dll). -target_link_libraries(arrow_matlab ${Matlab_MX_LIBRARY}) -target_link_libraries(arrow_matlab ${Matlab_MEX_LIBRARY}) +#target_link_libraries(arrow_matlab ${Matlab_MX_LIBRARY}) +#target_link_libraries(arrow_matlab ${Matlab_MEX_LIBRARY}) # Include the MATLAB MEX headers. -target_include_directories(arrow_matlab PRIVATE ${Matlab_INCLUDE_DIRS}) -target_include_directories(arrow_matlab PRIVATE ${CPP_SOURCE_DIR}) -target_include_directories(arrow_matlab PRIVATE ${ARROW_INCLUDE_DIR}) -target_compile_definitions(arrow_matlab PRIVATE ARROW_MATLAB_EXPORTING) +#target_include_directories(arrow_matlab PRIVATE ${Matlab_INCLUDE_DIRS}) +#target_include_directories(arrow_matlab PRIVATE ${CPP_SOURCE_DIR}) +#target_include_directories(arrow_matlab PRIVATE ${ARROW_INCLUDE_DIR}) +#target_compile_definitions(arrow_matlab PRIVATE ARROW_MATLAB_EXPORTING) -set(mexcall_sources mex/call.cc) -list(TRANSFORM mexcall_sources PREPEND ${CPP_SOURCE_DIR}/arrow/matlab/) +#set(mexcall_sources mex/call.cc) +#list(TRANSFORM mexcall_sources PREPEND ${CPP_SOURCE_DIR}/arrow/matlab/) # Build call MEX binary. -matlab_add_mex(R2018a - NAME mexcall - OUTPUT_NAME call - SRC ${mexcall_sources} - LINK_TO arrow_matlab) +#matlab_add_mex(R2018a +# NAME mexcall +# OUTPUT_NAME call +# SRC ${mexcall_sources} +# LINK_TO arrow_matlab) -target_include_directories(mexcall PRIVATE ${CPP_SOURCE_DIR}) +#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. @@ -379,7 +379,7 @@ if(MATLAB_BUILD_TESTS) # Define a test executable target. TODO: Remove the placeholder test. This is # just for testing GoogleTest integration. add_executable(placeholder_test ${CMAKE_SOURCE_DIR}/src/placeholder_test.cc) - add_executable(mex_util_test ${CPP_SOURCE_DIR}/arrow/matlab/mex/mex_util_test.cc) + #add_executable(mex_util_test ${CPP_SOURCE_DIR}/arrow/matlab/mex/mex_util_test.cc) # Declare a dependency on the GTest::gtest and GTest::gtest_main IMPORTED # targets. @@ -387,28 +387,28 @@ if(MATLAB_BUILD_TESTS) # Declare a dependency on the GTest::gtest and GTest::gtest_main IMPORTED # targets. - target_link_libraries(mex_util_test GTest::gtest GTest::gtest_main) - target_link_libraries(mex_util_test arrow_matlab) +# target_link_libraries(mex_util_test GTest::gtest GTest::gtest_main) +# target_link_libraries(mex_util_test arrow_matlab) # Include the MATLAB MEX headers. - target_include_directories(mex_util_test PRIVATE ${Matlab_INCLUDE_DIRS}) + # target_include_directories(mex_util_test PRIVATE ${Matlab_INCLUDE_DIRS}) # Include the C++ source headers. - target_include_directories(mex_util_test PRIVATE ${CPP_SOURCE_DIR}) + # target_include_directories(mex_util_test PRIVATE ${CPP_SOURCE_DIR}) # Add test targets for C++ tests. add_test(PlaceholderTestTarget placeholder_test) - add_test(CheckNumArgsTestTarget mex_util_test) + # add_test(CheckNumArgsTestTarget mex_util_test) # On macOS, add the directory of libarrow.dylib to the $DYLD_LIBRARY_PATH for # running CheckNumArgsTestTarget. - if(APPLE) - get_target_property(ARROW_SHARED_LIB arrow_shared IMPORTED_LOCATION) - get_filename_component(ARROW_SHARED_LIB_DIR ${ARROW_SHARED_LIB} DIRECTORY) + # if(APPLE) + # get_target_property(ARROW_SHARED_LIB arrow_shared IMPORTED_LOCATION) + # get_filename_component(ARROW_SHARED_LIB_DIR ${ARROW_SHARED_LIB} DIRECTORY) - set_tests_properties(CheckNumArgsTestTarget - PROPERTIES ENVIRONMENT - "DYLD_LIBRARY_PATH=${ARROW_SHARED_LIB_DIR}") - endif() + # set_tests_properties(CheckNumArgsTestTarget + # PROPERTIES ENVIRONMENT + # "DYLD_LIBRARY_PATH=${ARROW_SHARED_LIB_DIR}") + # endif() # On Windows: # Add the directory of gtest.dll and gtest_main.dll to the %PATH% for running @@ -433,12 +433,12 @@ if(MATLAB_BUILD_TESTS) get_target_property(ARROW_SHARED_LIB arrow_shared IMPORTED_LOCATION) get_filename_component(ARROW_SHARED_LIB_DIR ${ARROW_SHARED_LIB} DIRECTORY) - set(MATLAB_DLL_DEPENDENCIES_DIR "${Matlab_ROOT_DIR}/bin/win64") + # set(MATLAB_DLL_DEPENDENCIES_DIR "${Matlab_ROOT_DIR}/bin/win64") - set_tests_properties(CheckNumArgsTestTarget - PROPERTIES ENVIRONMENT - "PATH=${ARROW_SHARED_LIB_DIR}\;${MATLAB_DLL_DEPENDENCIES_DIR}\;${GTEST_SHARED_LIB_DIR}\;${GTEST_MAIN_SHARED_LIB_DIR}\;$ENV{PATH}" - ) + # set_tests_properties(CheckNumArgsTestTarget + # PROPERTIES ENVIRONMENT + # "PATH=${ARROW_SHARED_LIB_DIR}\;${MATLAB_DLL_DEPENDENCIES_DIR}\;${GTEST_SHARED_LIB_DIR}\;${GTEST_MAIN_SHARED_LIB_DIR}\;$ENV{PATH}" + # ) endif() endif() @@ -454,7 +454,7 @@ 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") +#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. @@ -465,48 +465,48 @@ install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/matlab/" # Install arrow_matlab and mexcall. # Use the RUNTIME output artifact keyword for Windows. # Use the LIBRARY output artifact keyword for macOS and Linux. -install(TARGETS arrow_matlab mexcall - RUNTIME DESTINATION ${CMAKE_PACKAGED_INSTALL_DIR} - LIBRARY DESTINATION ${CMAKE_PACKAGED_INSTALL_DIR}) +#install(TARGETS arrow_matlab mexcall +# RUNTIME DESTINATION ${CMAKE_PACKAGED_INSTALL_DIR} +# LIBRARY DESTINATION ${CMAKE_PACKAGED_INSTALL_DIR}) get_filename_component(ARROW_SHARED_LIB_DIR ${ARROW_SHARED_LIB} DIRECTORY) get_filename_component(ARROW_SHARED_LIB_FILENAME ${ARROW_SHARED_LIB} NAME_WE) # On macOS, use the RPATH values below for runtime dependency resolution. This enables # relocation of the installation directory. -if(APPLE) +#if(APPLE) # Setting INSTALL_RPATH_USE_LINK_PATH to true will add the paths to external dependencies # to the RPATH of arrow_matlab and mexcall, including the MATLAB dependencies. # If Arrow_FOUND is true, this also includes the path to arrow_shared. - set_target_properties(arrow_matlab mexcall PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE) + # set_target_properties(arrow_matlab mexcall PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE) # Add @loader_path to the RPATH of mexcall so that libarrow_matlab.dylib can be found # at runtime. - set_target_properties(mexcall PROPERTIES INSTALL_RPATH "@loader_path") +# set_target_properties(mexcall PROPERTIES INSTALL_RPATH "@loader_path") # Add @loader_path to the RPATH of arrow_matlab so that libarrow.dylib can be found # at runtime. - set_target_properties(arrow_matlab PROPERTIES INSTALL_RPATH "@loader_path") -endif() + # set_target_properties(arrow_matlab PROPERTIES INSTALL_RPATH "@loader_path") +#endif() # On Linux, use the RUNPATH values below for runtime dependency resolution. This enables # relocation of the installation directory. -if(UNIX - AND NOT APPLE - AND NOT CYGWIN) +#if(UNIX +# AND NOT APPLE +# AND NOT CYGWIN) # Setting INSTALL_RPATH_USE_LINK_PATH to true will add the paths to external dependencies # to the RUNPATH of arrow_matlab and mexcall, including the MATLAB dependencies. # If Arrow_FOUND is true, this also includes the path to arrow_shared. - set_target_properties(arrow_matlab mexcall PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE) + #set_target_properties(arrow_matlab mexcall PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE) # Add $ORIGIN to the RUNPATH of mexcall so that libarrow_matlab.so can be found # at runtime. - set_target_properties(mexcall PROPERTIES INSTALL_RPATH $ORIGIN) + # set_target_properties(mexcall PROPERTIES INSTALL_RPATH $ORIGIN) # Add $ORIGIN to the RUNPATH of arrow_matlab so that libarrow.so can be found # at runtime. - set_target_properties(arrow_matlab PROPERTIES INSTALL_RPATH $ORIGIN) -endif() + # set_target_properties(arrow_matlab PROPERTIES INSTALL_RPATH $ORIGIN) +#endif() if(NOT Arrow_FOUND) # If Arrow_FOUND is false, Arrow is built by the arrow_shared target and needs From 16779f72d0921a2400d95a66ab69362dfdf38416 Mon Sep 17 00:00:00 2001 From: Sarah Gilmore Date: Wed, 16 Aug 2023 11:53:38 -0400 Subject: [PATCH 2/6] 1. Set CMAKE_PACKAGED_INSTALL_DIR to ${CMAKE_INSTALL_DIR}/+arrow to fix cmake error 2. Remove commented out MEX-specific lines in CMakeLists.txt Co-authored-by: Kevin Gurney --- matlab/CMakeLists.txt | 118 ++---------------------------------------- 1 file changed, 3 insertions(+), 115 deletions(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index b79782caca6..34e97e59aab 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -285,44 +285,6 @@ find_package(Matlab REQUIRED COMPONENTS MAIN_PROGRAM) message(STATUS "Mex Library: ${Matlab_MEX_LIBRARY}") message(STATUS "Mex Include Folder: ${Matlab_INCLUDE_DIRS}") -#set(CPP_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src/cpp) -#set(MATLAB_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab) - -#set(arrow_matlab_sources -# mex/mex_util.cc -# feather/feather_reader.cc -# feather/feather_writer.cc -# feather/feather_functions.cc -# feather/util/handle_status.cc -# feather/util/unicode_conversion.cc) -#list(TRANSFORM arrow_matlab_sources PREPEND ${CPP_SOURCE_DIR}/arrow/matlab/) - -#add_library(arrow_matlab SHARED ${arrow_matlab_sources}) - -# Declare a dependency on arrow_shared (libarrow.so/dylib/dll). -#target_link_libraries(arrow_matlab arrow_shared) - -# Declare a dependency on the MEX shared library (libmex.so/dylib/dll). -#target_link_libraries(arrow_matlab ${Matlab_MX_LIBRARY}) -#target_link_libraries(arrow_matlab ${Matlab_MEX_LIBRARY}) - -# Include the MATLAB MEX headers. -#target_include_directories(arrow_matlab PRIVATE ${Matlab_INCLUDE_DIRS}) -#target_include_directories(arrow_matlab PRIVATE ${CPP_SOURCE_DIR}) -#target_include_directories(arrow_matlab PRIVATE ${ARROW_INCLUDE_DIR}) -#target_compile_definitions(arrow_matlab PRIVATE ARROW_MATLAB_EXPORTING) - -#set(mexcall_sources mex/call.cc) -#list(TRANSFORM mexcall_sources PREPEND ${CPP_SOURCE_DIR}/arrow/matlab/) - -# Build call MEX binary. -#matlab_add_mex(R2018a -# NAME mexcall -# OUTPUT_NAME call -# SRC ${mexcall_sources} -# LINK_TO arrow_matlab) - -#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. @@ -379,36 +341,13 @@ if(MATLAB_BUILD_TESTS) # Define a test executable target. TODO: Remove the placeholder test. This is # just for testing GoogleTest integration. add_executable(placeholder_test ${CMAKE_SOURCE_DIR}/src/placeholder_test.cc) - #add_executable(mex_util_test ${CPP_SOURCE_DIR}/arrow/matlab/mex/mex_util_test.cc) # Declare a dependency on the GTest::gtest and GTest::gtest_main IMPORTED # targets. target_link_libraries(placeholder_test GTest::gtest GTest::gtest_main) - # Declare a dependency on the GTest::gtest and GTest::gtest_main IMPORTED - # targets. -# target_link_libraries(mex_util_test GTest::gtest GTest::gtest_main) -# target_link_libraries(mex_util_test arrow_matlab) - - # Include the MATLAB MEX headers. - # target_include_directories(mex_util_test PRIVATE ${Matlab_INCLUDE_DIRS}) - # Include the C++ source headers. - # target_include_directories(mex_util_test PRIVATE ${CPP_SOURCE_DIR}) - # Add test targets for C++ tests. add_test(PlaceholderTestTarget placeholder_test) - # add_test(CheckNumArgsTestTarget mex_util_test) - - # On macOS, add the directory of libarrow.dylib to the $DYLD_LIBRARY_PATH for - # running CheckNumArgsTestTarget. - # if(APPLE) - # get_target_property(ARROW_SHARED_LIB arrow_shared IMPORTED_LOCATION) - # get_filename_component(ARROW_SHARED_LIB_DIR ${ARROW_SHARED_LIB} DIRECTORY) - - # set_tests_properties(CheckNumArgsTestTarget - # PROPERTIES ENVIRONMENT - # "DYLD_LIBRARY_PATH=${ARROW_SHARED_LIB_DIR}") - # endif() # On Windows: # Add the directory of gtest.dll and gtest_main.dll to the %PATH% for running @@ -432,13 +371,6 @@ if(MATLAB_BUILD_TESTS) get_target_property(ARROW_SHARED_LIB arrow_shared IMPORTED_LOCATION) get_filename_component(ARROW_SHARED_LIB_DIR ${ARROW_SHARED_LIB} DIRECTORY) - - # set(MATLAB_DLL_DEPENDENCIES_DIR "${Matlab_ROOT_DIR}/bin/win64") - - # set_tests_properties(CheckNumArgsTestTarget - # PROPERTIES ENVIRONMENT - # "PATH=${ARROW_SHARED_LIB_DIR}\;${MATLAB_DLL_DEPENDENCIES_DIR}\;${GTEST_SHARED_LIB_DIR}\;${GTEST_MAIN_SHARED_LIB_DIR}\;$ENV{PATH}" - # ) endif() endif() @@ -452,62 +384,15 @@ 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") - # Install MATLAB source files. # On macOS, exclude '.DS_Store' files in the source tree from installation. install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/matlab/" DESTINATION ${CMAKE_INSTALL_DIR} PATTERN ".DS_Store" EXCLUDE) -# Install arrow_matlab and mexcall. -# Use the RUNTIME output artifact keyword for Windows. -# Use the LIBRARY output artifact keyword for macOS and Linux. -#install(TARGETS arrow_matlab mexcall -# RUNTIME DESTINATION ${CMAKE_PACKAGED_INSTALL_DIR} -# LIBRARY DESTINATION ${CMAKE_PACKAGED_INSTALL_DIR}) - get_filename_component(ARROW_SHARED_LIB_DIR ${ARROW_SHARED_LIB} DIRECTORY) get_filename_component(ARROW_SHARED_LIB_FILENAME ${ARROW_SHARED_LIB} NAME_WE) -# On macOS, use the RPATH values below for runtime dependency resolution. This enables -# relocation of the installation directory. -#if(APPLE) - # Setting INSTALL_RPATH_USE_LINK_PATH to true will add the paths to external dependencies - # to the RPATH of arrow_matlab and mexcall, including the MATLAB dependencies. - # If Arrow_FOUND is true, this also includes the path to arrow_shared. - # set_target_properties(arrow_matlab mexcall PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE) - - # Add @loader_path to the RPATH of mexcall so that libarrow_matlab.dylib can be found - # at runtime. -# set_target_properties(mexcall PROPERTIES INSTALL_RPATH "@loader_path") - - # Add @loader_path to the RPATH of arrow_matlab so that libarrow.dylib can be found - # at runtime. - # set_target_properties(arrow_matlab PROPERTIES INSTALL_RPATH "@loader_path") -#endif() - -# On Linux, use the RUNPATH values below for runtime dependency resolution. This enables -# relocation of the installation directory. -#if(UNIX -# AND NOT APPLE -# AND NOT CYGWIN) - # Setting INSTALL_RPATH_USE_LINK_PATH to true will add the paths to external dependencies - # to the RUNPATH of arrow_matlab and mexcall, including the MATLAB dependencies. - # If Arrow_FOUND is true, this also includes the path to arrow_shared. - #set_target_properties(arrow_matlab mexcall PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE) - - # Add $ORIGIN to the RUNPATH of mexcall so that libarrow_matlab.so can be found - # at runtime. - # set_target_properties(mexcall PROPERTIES INSTALL_RPATH $ORIGIN) - - # Add $ORIGIN to the RUNPATH of arrow_matlab so that libarrow.so can be found - # at runtime. - # set_target_properties(arrow_matlab PROPERTIES INSTALL_RPATH $ORIGIN) -#endif() - if(NOT Arrow_FOUND) # If Arrow_FOUND is false, Arrow is built by the arrow_shared target and needs # to be copied to CMAKE_PACKAGED_INSTALL_DIR. @@ -539,6 +424,9 @@ if(NOT Arrow_FOUND) # Note: The following CMake Issue suggests enabling an option to exclude all # folders that would be empty after installation: # https://gitlab.kitware.com/cmake/cmake/-/issues/17122 + + set(CMAKE_PACKAGED_INSTALL_DIR "${CMAKE_INSTALL_DIR}/+arrow") + install(DIRECTORY "${ARROW_SHARED_LIB_DIR}/" DESTINATION ${CMAKE_PACKAGED_INSTALL_DIR} FILES_MATCHING From 1be39be9529bd17e3cd50f3ac0e9292b26ac7bce Mon Sep 17 00:00:00 2001 From: Sarah Gilmore Date: Wed, 16 Aug 2023 12:03:32 -0400 Subject: [PATCH 3/6] Delete old c-mex based feather v1 code Co-authored-by: Kevin Gurney --- .../arrow/matlab/feather/feather_functions.cc | 55 --- .../arrow/matlab/feather/feather_functions.h | 34 -- .../arrow/matlab/feather/feather_reader.cc | 278 ------------- .../cpp/arrow/matlab/feather/feather_reader.h | 77 ---- .../arrow/matlab/feather/feather_writer.cc | 369 ------------------ .../cpp/arrow/matlab/feather/feather_writer.h | 70 ---- .../cpp/arrow/matlab/feather/matlab_traits.h | 101 ----- .../matlab/feather/util/handle_status.cc | 93 ----- .../arrow/matlab/feather/util/handle_status.h | 35 -- .../matlab/feather/util/unicode_conversion.cc | 65 --- .../matlab/feather/util/unicode_conversion.h | 36 -- matlab/src/cpp/arrow/matlab/mex/call.cc | 28 -- .../src/cpp/arrow/matlab/mex/mex_functions.h | 40 -- matlab/src/cpp/arrow/matlab/mex/mex_util.cc | 53 --- matlab/src/cpp/arrow/matlab/mex/mex_util.h | 42 -- .../src/cpp/arrow/matlab/mex/mex_util_test.cc | 30 -- 16 files changed, 1406 deletions(-) delete mode 100644 matlab/src/cpp/arrow/matlab/feather/feather_functions.cc delete mode 100644 matlab/src/cpp/arrow/matlab/feather/feather_functions.h delete mode 100644 matlab/src/cpp/arrow/matlab/feather/feather_reader.cc delete mode 100644 matlab/src/cpp/arrow/matlab/feather/feather_reader.h delete mode 100644 matlab/src/cpp/arrow/matlab/feather/feather_writer.cc delete mode 100644 matlab/src/cpp/arrow/matlab/feather/feather_writer.h delete mode 100644 matlab/src/cpp/arrow/matlab/feather/matlab_traits.h delete mode 100644 matlab/src/cpp/arrow/matlab/feather/util/handle_status.cc delete mode 100644 matlab/src/cpp/arrow/matlab/feather/util/handle_status.h delete mode 100644 matlab/src/cpp/arrow/matlab/feather/util/unicode_conversion.cc delete mode 100644 matlab/src/cpp/arrow/matlab/feather/util/unicode_conversion.h delete mode 100644 matlab/src/cpp/arrow/matlab/mex/call.cc delete mode 100644 matlab/src/cpp/arrow/matlab/mex/mex_functions.h delete mode 100644 matlab/src/cpp/arrow/matlab/mex/mex_util.cc delete mode 100644 matlab/src/cpp/arrow/matlab/mex/mex_util.h delete mode 100644 matlab/src/cpp/arrow/matlab/mex/mex_util_test.cc diff --git a/matlab/src/cpp/arrow/matlab/feather/feather_functions.cc b/matlab/src/cpp/arrow/matlab/feather/feather_functions.cc deleted file mode 100644 index f5b5a394083..00000000000 --- a/matlab/src/cpp/arrow/matlab/feather/feather_functions.cc +++ /dev/null @@ -1,55 +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 "feather_functions.h" - -#include - -#include "feather_reader.h" -#include "feather_writer.h" -#include "util/handle_status.h" - -namespace arrow { -namespace matlab { -namespace feather { - -void featherwrite(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) { - const std::string filename{mxArrayToUTF8String(prhs[0])}; - - // Open a Feather file at the provided file path for writing. - std::shared_ptr feather_writer{nullptr}; - util::HandleStatus(FeatherWriter::Open(filename, &feather_writer)); - - // Write the Feather file table variables and table metadata from MATLAB. - util::HandleStatus(feather_writer->WriteVariables(prhs[1], prhs[2])); -} - -void featherread(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) { - const std::string filename{mxArrayToUTF8String(prhs[0])}; - - // Read the given Feather file into memory. - std::shared_ptr feather_reader{nullptr}; - util::HandleStatus(FeatherReader::Open(filename, &feather_reader)); - - // Return the Feather file table variables and table metadata to MATLAB. - plhs[0] = feather_reader->ReadVariables(); - plhs[1] = feather_reader->ReadMetadata(); -} - -} // namespace feather -} // namespace matlab -} // namespace arrow \ No newline at end of file diff --git a/matlab/src/cpp/arrow/matlab/feather/feather_functions.h b/matlab/src/cpp/arrow/matlab/feather/feather_functions.h deleted file mode 100644 index c055e9582c0..00000000000 --- a/matlab/src/cpp/arrow/matlab/feather/feather_functions.h +++ /dev/null @@ -1,34 +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 - -#include "arrow/matlab/api/visibility.h" - -namespace arrow { -namespace matlab { -namespace feather { - -ARROW_MATLAB_EXPORT void featherwrite(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]); - -ARROW_MATLAB_EXPORT void featherread(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]); - -} // namespace feather -} // namespace matlab -} // namespace arrow diff --git a/matlab/src/cpp/arrow/matlab/feather/feather_reader.cc b/matlab/src/cpp/arrow/matlab/feather/feather_reader.cc deleted file mode 100644 index 413b7f153e9..00000000000 --- a/matlab/src/cpp/arrow/matlab/feather/feather_reader.cc +++ /dev/null @@ -1,278 +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 "feather_reader.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "matlab_traits.h" -#include "util/handle_status.h" -#include "util/unicode_conversion.h" - -namespace arrow { -namespace matlab { -namespace feather { -namespace internal { - -// Read the name of variable i from the Feather file as a mxArray*. -mxArray* ReadVariableName(const std::string& column_name) { - return util::ConvertUTF8StringToUTF16CharMatrix(column_name); -} - -template -mxArray* ReadNumericVariableData(const std::shared_ptr& column) { - using MatlabType = typename MatlabTraits::MatlabType; - using ArrowArrayType = typename TypeTraits::ArrayType; - - const mxClassID matlab_class_id = MatlabTraits::matlab_class_id; - // Allocate a numeric mxArray* with the correct mxClassID based on the type of the - // arrow::Array. - mxArray* variable_data = - mxCreateNumericMatrix(column->length(), 1, matlab_class_id, mxREAL); - - auto arrow_numeric_array = std::static_pointer_cast(column); - - // Get a raw pointer to the Arrow array data. - const MatlabType* source = arrow_numeric_array->raw_values(); - - // Get a mutable pointer to the MATLAB array data and std::copy the - // Arrow array data into it. - MatlabType* destination = MatlabTraits::GetData(variable_data); - std::copy(source, source + column->length(), destination); - - return variable_data; -} - -// Read the data of variable i from the Feather file as a mxArray*. -mxArray* ReadVariableData(const std::shared_ptr& column, - const std::string& column_name) { - std::shared_ptr type = column->type(); - - switch (type->id()) { - case Type::FLOAT: - return ReadNumericVariableData(column); - case Type::DOUBLE: - return ReadNumericVariableData(column); - case Type::UINT8: - return ReadNumericVariableData(column); - case Type::UINT16: - return ReadNumericVariableData(column); - case Type::UINT32: - return ReadNumericVariableData(column); - case Type::UINT64: - return ReadNumericVariableData(column); - case Type::INT8: - return ReadNumericVariableData(column); - case Type::INT16: - return ReadNumericVariableData(column); - case Type::INT32: - return ReadNumericVariableData(column); - case Type::INT64: - return ReadNumericVariableData(column); - default: { - mexErrMsgIdAndTxt("MATLAB:arrow:UnsupportedArrowType", - "Unsupported arrow::Type '%s' for variable '%s'", - type->name().c_str(), column_name.c_str()); - break; - } - } - - return nullptr; -} - -// arrow::Buffers are bit-packed, while mxLogical arrays aren't. This utility -// uses an Arrow utility to copy each bit of an arrow::Buffer into each byte -// of an mxLogical array. -void BitUnpackBuffer(const std::shared_ptr& source, int64_t length, - mxLogical* destination) { - const uint8_t* source_data = source->data(); - - // Call into an Arrow utility to visit each bit in the bitmap. - auto visitFcn = [&](mxLogical is_valid) { *destination++ = is_valid; }; - - const int64_t start_offset = 0; - arrow::internal::VisitBitsUnrolled(source_data, start_offset, length, visitFcn); -} - -// Populates the validity bitmap from an arrow::Array. -// writes to a zero-initialized destination buffer. -// Implements a fast path for the fully-valid and fully-invalid cases. -// Returns true if the destination buffer was successfully populated. -bool TryBitUnpackFastPath(const std::shared_ptr& array, mxLogical* destination) { - const int64_t null_count = array->null_count(); - const int64_t length = array->length(); - - if (null_count == length) { - // The source array is filled with invalid values. Since mxCreateLogicalMatrix - // zero-initializes the destination buffer, we can return without changing anything - // in the destination buffer. - return true; - } else if (null_count == 0) { - // The source array contains only valid values. Fill the destination buffer - // with 'true'. - std::fill(destination, destination + length, true); - return true; - } - - // Return false to indicate that we couldn't fill the entire validity bitmap. - return false; -} - -// Read the validity (null) bitmap of variable i from the Feather -// file as an mxArray*. -mxArray* ReadVariableValidityBitmap(const std::shared_ptr& column) { - // Allocate an mxLogical array to store the validity (null) bitmap values. - // Note: All Arrow arrays can have an associated validity (null) bitmap. - // The Apache Arrow specification defines 0 (false) to represent an - // invalid (null) array entry and 1 (true) to represent a valid - // (non-null) array entry. - mxArray* validity_bitmap = mxCreateLogicalMatrix(column->length(), 1); - mxLogical* validity_bitmap_unpacked = mxGetLogicals(validity_bitmap); - - if (!TryBitUnpackFastPath(column, validity_bitmap_unpacked)) { - // Couldn't fill the full validity bitmap at once. Call an optimized loop-unrolled - // implementation instead that goes byte-by-byte and populates the validity bitmap. - BitUnpackBuffer(column->null_bitmap(), column->length(), validity_bitmap_unpacked); - } - - return validity_bitmap; -} - -// Read the type name of an arrow::Array as an mxChar array. -mxArray* ReadVariableType(const std::shared_ptr& column) { - return util::ConvertUTF8StringToUTF16CharMatrix(column->type()->name()); -} - -// MATLAB arrays cannot be larger than 2^48 elements. -static constexpr uint64_t MAX_MATLAB_SIZE = static_cast(0x01) << 48; - -} // namespace internal - -Status FeatherReader::Open(const std::string& filename, - std::shared_ptr* feather_reader) { - *feather_reader = std::shared_ptr(new FeatherReader()); - - // Open file with given filename as a ReadableFile. - ARROW_ASSIGN_OR_RAISE(auto readable_file, io::ReadableFile::Open(filename)); - - // Open the Feather file for reading with a TableReader. - ARROW_ASSIGN_OR_RAISE(auto reader, ipc::feather::Reader::Open(readable_file)); - - // Set the internal reader_ object. - (*feather_reader)->reader_ = reader; - - // Check the feather file version - auto version = reader->version(); - if (version == ipc::feather::kFeatherV2Version) { - return Status::NotImplemented("Support for Feather V2 has not been implemented."); - } else if (version != ipc::feather::kFeatherV1Version) { - return Status::Invalid("Unknown Feather format version."); - } - - // read the table metadata from the Feather file - (*feather_reader)->num_variables_ = reader->schema()->num_fields(); - return Status::OK(); -} - -// Read the table metadata from the Feather file as a mxArray*. -mxArray* FeatherReader::ReadMetadata() const { - const int32_t num_metadata_fields = 3; - const char* fieldnames[] = {"NumRows", "NumVariables", "Description"}; - - // Create a mxArray struct array containing the table metadata to be passed back to - // MATLAB. - mxArray* metadata = mxCreateStructMatrix(1, 1, num_metadata_fields, fieldnames); - - // Returning double values to MATLAB since that is the default type. - - // Set the number of rows. - mxSetField(metadata, 0, "NumRows", - mxCreateDoubleScalar(static_cast(num_rows_))); - - // Set the number of variables. - mxSetField(metadata, 0, "NumVariables", - mxCreateDoubleScalar(static_cast(num_variables_))); - - return metadata; -} - -// Read the table variables from the Feather file as a mxArray*. -mxArray* FeatherReader::ReadVariables() { - const int32_t num_variable_fields = 4; - const char* fieldnames[] = {"Name", "Type", "Data", "Valid"}; - - // Create an mxArray* struct array containing the table variables to be passed back to - // MATLAB. - mxArray* variables = - mxCreateStructMatrix(1, num_variables_, num_variable_fields, fieldnames); - - std::shared_ptr table; - auto status = reader_->Read(&table); - if (!status.ok()) { - mexErrMsgIdAndTxt("MATLAB:arrow:FeatherReader::FailedToReadTable", - "Failed to read arrow::Table from Feather file. Reason: %s", - status.message().c_str()); - } - - // Set the number of rows - num_rows_ = table->num_rows(); - - if (num_rows_ > internal::MAX_MATLAB_SIZE || - num_variables_ > internal::MAX_MATLAB_SIZE) { - mexErrMsgIdAndTxt("MATLAB:arrow:SizeTooLarge", - "The table size exceeds MATLAB limits: %u x %u", num_rows_, - num_variables_); - } - - auto column_names = table->ColumnNames(); - - for (int64_t i = 0; i < num_variables_; ++i) { - auto column = table->column(i); - if (column->num_chunks() != 1) { - mexErrMsgIdAndTxt("MATLAB:arrow:FeatherReader::ReadVariables", - "Chunked columns not yet supported"); - } - std::shared_ptr chunk = column->chunk(0); - const std::string column_name = column_names[i]; - - // set the struct fields data - mxSetField(variables, i, "Name", internal::ReadVariableName(column_name)); - mxSetField(variables, i, "Type", internal::ReadVariableType(chunk)); - mxSetField(variables, i, "Data", internal::ReadVariableData(chunk, column_name)); - mxSetField(variables, i, "Valid", internal::ReadVariableValidityBitmap(chunk)); - } - - return variables; -} - -} // namespace feather -} // namespace matlab -} // namespace arrow \ No newline at end of file diff --git a/matlab/src/cpp/arrow/matlab/feather/feather_reader.h b/matlab/src/cpp/arrow/matlab/feather/feather_reader.h deleted file mode 100644 index 0e2089d3672..00000000000 --- a/matlab/src/cpp/arrow/matlab/feather/feather_reader.h +++ /dev/null @@ -1,77 +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 -#include -#include -#include - -#include -#include - -namespace arrow { -namespace matlab { -namespace feather { - -class FeatherReader { - public: - ~FeatherReader() = default; - - /// \brief Read the table metadata as an mxArray* struct from the given - /// Feather file. - /// The returned mxArray* struct contains the following fields: - /// - "Description" :: Nx1 mxChar array, table-level description - /// - "NumRows" :: scalar mxDouble array, number of rows in the - /// table - /// - "NumVariables" :: scalar mxDouble array, number of variables in - /// the table - /// Clients are responsible for freeing the returned mxArray memory - /// when it is no longer needed, or passing it to MATLAB to be managed. - /// \return metadata mxArray* scalar struct containing table level metadata - mxArray* ReadMetadata() const; - - /// \brief Read the table variable data as an mxArray* struct array from the - /// given Feather file. - /// The returned mxArray* struct array has the following fields: - /// - "Name" :: Nx1 mxChar array, name of the variable - /// - "Type" :: Nx1 mxChar array, the variable's Arrow datatype - /// - "Data" :: Nx1 mxArray, data for the variable - /// - "Valid" :: Nx1 mxLogical array, validity (null) bitmap - /// Clients are responsible for freeing the returned mxArray memory - /// when it is no longer needed, or passing it to MATLAB to be managed. - /// \return variables mxArray* struct array containing table variable data - mxArray* ReadVariables(); - - /// \brief Initialize a FeatherReader object from a given Feather file. - /// \param[in] filename path to a Feather file - /// \param[out] feather_reader uninitialized FeatherReader object - static Status Open(const std::string& filename, - std::shared_ptr* feather_reader); - - private: - FeatherReader() = default; - std::shared_ptr reader_; - int64_t num_rows_; - int64_t num_variables_; - std::string description_; -}; - -} // namespace feather -} // namespace matlab -} // namespace arrow \ No newline at end of file diff --git a/matlab/src/cpp/arrow/matlab/feather/feather_writer.cc b/matlab/src/cpp/arrow/matlab/feather/feather_writer.cc deleted file mode 100644 index f67d8dc2fba..00000000000 --- a/matlab/src/cpp/arrow/matlab/feather/feather_writer.cc +++ /dev/null @@ -1,369 +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 "feather_writer.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include /* for std::multiplies */ -#include /* for std::accumulate */ - -#include "matlab_traits.h" -#include "util/handle_status.h" - -namespace arrow { -namespace matlab { -namespace feather { -namespace internal { - -// Returns the arrow::DataType that corresponds to the input type string -std::shared_ptr ConvertMatlabTypeStringToArrowDataType( - const std::string& t) { - if (t == "double") { - return arrow::float64(); - } else if (t == "single") { - return arrow::float32(); - } else if (t == "uint64") { - return arrow::uint64(); - } else if (t == "uint32") { - return arrow::uint32(); - } else if (t == "uint16") { - return arrow::uint16(); - } else if (t == "uint8") { - return arrow::uint8(); - } else if (t == "int64") { - return arrow::int64(); - } else if (t == "int32") { - return arrow::int32(); - } else if (t == "int16") { - return arrow::int16(); - } else if (t == "int8") { - return arrow::int8(); - } - mexErrMsgIdAndTxt("MATLAB:arrow:UnsupportedMatlabTypeString", - "Unsupported MATLAB type string: '%s'", t.c_str()); - - // mexErrMsgIdAndTxt throws unconditionally so we should never reach this line - return nullptr; -} - -// Utility that helps verify the input mxArray struct field name and type. -// Returns void since any errors will throw and terminate MEX execution. -void ValidateMxStructField(const mxArray* struct_array, const char* fieldname, - mxClassID expected_class_id, bool can_be_empty) { - // Check that the input mxArray is a struct array. - if (!mxIsStruct(struct_array)) { - mexErrMsgIdAndTxt("MATLAB:arrow:IncorrectDimensionsOrType", - "Input needs to be a struct array"); - } - - // Return early if an empty table is provided as input. - if (mxIsEmpty(struct_array)) { - return; - } - - mxArray* field = mxGetField(struct_array, 0, fieldname); - - if (!field) { - mexErrMsgIdAndTxt("MATLAB:arrow:MissingStructField", - "Missing field '%s' in input struct array", fieldname); - } - - mxClassID actual_class_id = mxGetClassID(field); - - // Avoid type check if an mxUNKNOWN_CLASS is provided since the UNKNOWN type is used to - // signify genericity in the input type. - if (expected_class_id != mxUNKNOWN_CLASS) { - if (expected_class_id != actual_class_id) { - mexErrMsgIdAndTxt("MATLAB:arrow:MissingStructField", - "Incorrect type '%s' for struct array field '%s'", - mxGetClassName(field), fieldname); - } - } - // Some struct fields (like Data) can be empty, while others - // (like NumRows) should never be empty. This conditional helps account for both cases. - if (!can_be_empty) { - // Ensure that individual mxStructArray fields are non-empty. - // We can call mxGetData after this without needing another null check. - if (mxIsEmpty(field)) { - mexErrMsgIdAndTxt("MATLAB:arrow:EmptyStructField", - "Struct array field '%s' cannot be empty", fieldname); - } - } -} - -// Utility function to convert mxChar mxArray* to std::string while preserving -// Unicode code points. -std::string MxArrayToString(const mxArray* array) { - // Return empty std::string if a mxChar array is not passed in. - if (!mxIsChar(array)) { - return std::string(); - } - - // Convert mxArray first to a C-style char array, then copy into a std::string. - char* utf8_array = mxArrayToUTF8String(array); - std::string output(utf8_array); - - // Free the allocated char* from the MEX runtime. - mxFree(utf8_array); - - return output; -} - -// Compare number of columns and exit out to the MATLAB layer if incorrect. -void ValidateNumColumns(int64_t actual, int64_t expected) { - if (actual != expected) { - mexErrMsgIdAndTxt("MATLAB:arrow:IncorrectNumberOfColumns", - "Received only '%d' columns but expected '%d' columns", actual, - expected); - } -} - -// Compare number of rows and exit out to the MATLAB layer if incorrect. -void ValidateNumRows(int64_t actual, int64_t expected) { - if (actual != expected) { - mexErrMsgIdAndTxt("MATLAB:arrow:IncorrectNumberOfRows", - "Received only '%d' rows but expected '%d' rows", actual, expected); - } -} - -// Calculate the number of bytes required in the bit-packed validity buffer. -int64_t BitPackedLength(int64_t num_elements) { - // Since mxLogicalArray encodes [0, 1] in a full byte, we can compress that byte - // down to a bit...therefore dividing the mxLogicalArray length by 8 here. - return static_cast(std::ceil(num_elements / 8.0)); -} - -// Calculate the total number of elements in an mxArray -// We have to do this separately since mxGetNumberOfElements only works in numeric arrays -size_t GetNumberOfElements(const mxArray* array) { - // Get the dimensions and the total number of dimensions from the mxArray*. - const size_t num_dimensions = mxGetNumberOfDimensions(array); - const size_t* dimensions = mxGetDimensions(array); - - // Iterate over the dimensions array and accumulate the total number of elements. - return std::accumulate(dimensions, dimensions + num_dimensions, size_t{1}, - std::multiplies()); -} - -// Write an mxLogicalArray* into a bit-packed arrow::MutableBuffer -void BitPackBuffer(const mxArray* logical_array, - std::shared_ptr packed_buffer) { - // Error out if the incorrect type is passed in. - if (!mxIsLogical(logical_array)) { - mexErrMsgIdAndTxt( - "MATLAB:arrow:IncorrectType", - "Expected mxLogical array as input but received mxArray of class '%s'", - mxGetClassName(logical_array)); - } - - // Validate that the input arrow::Buffer has sufficient size to store a full bit-packed - // representation of the input mxLogicalArray - int64_t unpacked_buffer_length = GetNumberOfElements(logical_array); - if (BitPackedLength(unpacked_buffer_length) > packed_buffer->capacity()) { - mexErrMsgIdAndTxt("MATLAB:arrow:BufferSizeExceeded", - "Buffer of size %d bytes cannot store %d bytes of data", - packed_buffer->capacity(), BitPackedLength(unpacked_buffer_length)); - } - - // Get pointers to the internal uint8_t arrays behind arrow::Buffer and mxArray - uint8_t* packed_buffer_ptr = packed_buffer->mutable_data(); - mxLogical* unpacked_buffer_ptr = mxGetLogicals(logical_array); - - // Iterate over the mxLogical array and write bit-packed bools to the arrow::Buffer. - // Call into a loop-unrolled Arrow utility for better performance when bit-packing. - auto generator = [&]() -> bool { return *(unpacked_buffer_ptr++); }; - const int64_t start_offset = 0; - arrow::internal::GenerateBitsUnrolled(packed_buffer_ptr, start_offset, - unpacked_buffer_length, generator); -} - -// Write numeric datatypes to the Feather file. -template -std::unique_ptr WriteNumericData(const mxArray* data, - const std::shared_ptr validity_bitmap) { - // Alias the type name for the underlying MATLAB type. - using MatlabType = typename MatlabTraits::MatlabType; - - // Get a pointer to the underlying mxArray data. - // We need to (temporarily) cast away const here since the mxGet* functions do not - // accept a const input parameter for compatibility reasons. - const MatlabType* dt = MatlabTraits::GetData(const_cast(data)); - - // Construct an arrow::Buffer that points to the underlying mxArray without copying. - // - The lifetime of the mxArray buffer exceeds that of the arrow::Buffer here since - // MATLAB should only free this region on garbage-collection after the MEX function - // is executed. Therefore it is safe for arrow::Buffer to point to this location. - // - However arrow::Buffer must not free this region by itself, since that could cause - // segfaults if the input array is used later in MATLAB. - // - The Doxygen doc for arrow::Buffer's constructor implies that it is not an RAII - // type, so this should be safe from possible double-free here. - std::shared_ptr buffer = - std::make_shared(reinterpret_cast(dt), - mxGetElementSize(data) * mxGetNumberOfElements(data)); - - // Construct arrow::NumericArray specialization using arrow::Buffer. - // Pass in nulls information...we could compute and provide the number of nulls here - // too, but passing -1 for now so that Arrow recomputes it if necessary. - return std::unique_ptr(new NumericArray( - mxGetNumberOfElements(data), buffer, validity_bitmap, -1)); -} - -// Dispatch MATLAB column data to the correct arrow::Array converter. -std::unique_ptr WriteVariableData(const mxArray* data, const std::string& type, - const std::shared_ptr validity_bitmap) { - // Get the underlying type of the mxArray data. - const mxClassID mxclass = mxGetClassID(data); - - switch (mxclass) { - case mxSINGLE_CLASS: - return WriteNumericData(data, validity_bitmap); - case mxDOUBLE_CLASS: - return WriteNumericData(data, validity_bitmap); - case mxUINT8_CLASS: - return WriteNumericData(data, validity_bitmap); - case mxUINT16_CLASS: - return WriteNumericData(data, validity_bitmap); - case mxUINT32_CLASS: - return WriteNumericData(data, validity_bitmap); - case mxUINT64_CLASS: - return WriteNumericData(data, validity_bitmap); - case mxINT8_CLASS: - return WriteNumericData(data, validity_bitmap); - case mxINT16_CLASS: - return WriteNumericData(data, validity_bitmap); - case mxINT32_CLASS: - return WriteNumericData(data, validity_bitmap); - case mxINT64_CLASS: - return WriteNumericData(data, validity_bitmap); - default: { - mexErrMsgIdAndTxt("MATLAB:arrow:UnsupportedArrowType", - "Unsupported arrow::Type '%s' for variable '%s'", - mxGetClassName(data), type.c_str()); - } - } - - // We shouldn't ever reach this branch, but if we do, return nullptr. - return nullptr; -} - -} // namespace internal - -Status FeatherWriter::Open(const std::string& filename, - std::shared_ptr* feather_writer) { - // Allocate shared_ptr out parameter. - *feather_writer = std::shared_ptr(new FeatherWriter()); - - // Open a FileOutputStream corresponding to the provided filename. - ARROW_ASSIGN_OR_RAISE( - (*feather_writer)->file_output_stream_, - io::FileOutputStream::Open(filename, &((*feather_writer)->file_output_stream_))); - return Status::OK(); -} - -// Write mxArrays from MATLAB into a Feather file. -Status FeatherWriter::WriteVariables(const mxArray* variables, const mxArray* metadata) { - // Verify that all required fieldnames are provided. - internal::ValidateMxStructField(variables, "Name", mxCHAR_CLASS, true); - internal::ValidateMxStructField(variables, "Type", mxCHAR_CLASS, false); - internal::ValidateMxStructField(variables, "Data", mxUNKNOWN_CLASS, true); - internal::ValidateMxStructField(variables, "Valid", mxLOGICAL_CLASS, true); - - // Verify that all required fieldnames are provided. - internal::ValidateMxStructField(metadata, "NumRows", mxDOUBLE_CLASS, false); - internal::ValidateMxStructField(metadata, "NumVariables", mxDOUBLE_CLASS, false); - - // Get the number of columns in the struct array. - size_t num_columns = internal::GetNumberOfElements(variables); - - // Get the NumRows field in the struct array and set on TableWriter. - num_rows_ = static_cast(mxGetScalar(mxGetField(metadata, 0, "NumRows"))); - // Get the total number of variables. This is checked later for consistency with - // the provided number of columns before finishing the file write. - num_variables_ = - static_cast(mxGetScalar(mxGetField(metadata, 0, "NumVariables"))); - - // Verify that we have all the columns required for writing - // Currently we need all columns to be passed in together in the WriteVariables method. - internal::ValidateNumColumns(static_cast(num_columns), num_variables_); - - arrow::SchemaBuilder schema_builder; - std::vector> table_columns; - - const int64_t bitpacked_length = internal::BitPackedLength(num_rows_); - - // Iterate over the input columns and generate arrow arrays. - for (int idx = 0; idx < num_columns; ++idx) { - // Unwrap constituent mxArray*s from the mxStructArray*. This is safe since we - // already checked for existence and non-nullness of these types. - const mxArray* name = mxGetField(variables, idx, "Name"); - const mxArray* data = mxGetField(variables, idx, "Data"); - const mxArray* type = mxGetField(variables, idx, "Type"); - const mxArray* valid = mxGetField(variables, idx, "Valid"); - - // Convert column and type name to a std::string from mxArray*. - std::string name_str = internal::MxArrayToString(name); - std::string type_str = internal::MxArrayToString(type); - - auto datatype = internal::ConvertMatlabTypeStringToArrowDataType(type_str); - auto field = std::make_shared(name_str, datatype); - - ARROW_ASSIGN_OR_RAISE( - std::shared_ptr validity_bitmap, - arrow::AllocateResizableBuffer(internal::BitPackedLength(num_rows_))); - - // Populate bit-packed arrow::Buffer using validity data in the mxArray*. - internal::BitPackBuffer(valid, validity_bitmap); - - // Wrap mxArray data in an arrow::Array of the equivalent type. - auto array = internal::WriteVariableData(data, type_str, validity_bitmap); - - // Verify that the arrow::Array has the right number of elements. - internal::ValidateNumRows(array->length(), num_rows_); - - // Append the field to the schema builder - RETURN_NOT_OK(schema_builder.AddField(field)); - - // Store the table column - table_columns.push_back(std::move(array)); - } - // Create the table schema - ARROW_ASSIGN_OR_RAISE(auto table_schema, schema_builder.Finish()); - - // Specify the feather file format version as V1 - arrow::ipc::feather::WriteProperties write_props; - write_props.version = arrow::ipc::feather::kFeatherV1Version; - - std::shared_ptr table = arrow::Table::Make(table_schema, table_columns); - // Write the Feather file metadata to the end of the file. - return ipc::feather::WriteTable(*table, file_output_stream_.get(), write_props); -} - -} // namespace feather -} // namespace matlab -} // namespace arrow diff --git a/matlab/src/cpp/arrow/matlab/feather/feather_writer.h b/matlab/src/cpp/arrow/matlab/feather/feather_writer.h deleted file mode 100644 index 0042d4ac694..00000000000 --- a/matlab/src/cpp/arrow/matlab/feather/feather_writer.h +++ /dev/null @@ -1,70 +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 -#include -#include -#include - -#include -#include - -namespace arrow { -namespace matlab { -namespace feather { - -class FeatherWriter { - public: - ~FeatherWriter() = default; - - /// \brief Write mxArrays to a Feather file. The first input must be a N-by-1 mxStruct - /// array with the following fields: - /// - "Name" :: Nx1 mxChar array, name of the column - /// - "Type" :: Nx1 mxChar array, the variable's MATLAB datatype - /// - "Data" :: Nx1 mxArray, data for this variable - /// - "Valid" :: Nx1 mxLogical array, 0 represents invalid (null) values and - /// 1 represents valid (non-null) values - /// The second input must be a scalar mxStruct with the following - /// fields: - /// - "NumRows" :: scalar mxDouble array, number of rows in table - /// - "NumVariables" :: scalar mxDouble array, total number of variables - /// \param[in] variables mxArray* struct array containing table variable data - /// \param[in] metadata mxArray* scalar struct containing table-level metadata - /// \return status - Status WriteVariables(const mxArray* variables, const mxArray* metadata); - - /// \brief Initialize a FeatherWriter object that writes to a Feather file - /// \param[in] filename path to the new Feather file - /// \param[out] feather_writer uninitialized FeatherWriter object - /// \return status - static Status Open(const std::string& filename, - std::shared_ptr* feather_writer); - - private: - FeatherWriter() = default; - - int64_t num_rows_; - int64_t num_variables_; - std::string description_; - std::shared_ptr file_output_stream_; -}; - -} // namespace feather -} // namespace matlab -} // namespace arrow \ No newline at end of file diff --git a/matlab/src/cpp/arrow/matlab/feather/matlab_traits.h b/matlab/src/cpp/arrow/matlab/feather/matlab_traits.h deleted file mode 100644 index 8ef5aea933a..00000000000 --- a/matlab/src/cpp/arrow/matlab/feather/matlab_traits.h +++ /dev/null @@ -1,101 +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 -#include - -namespace arrow { -namespace matlab { - -/// \brief A type traits class mapping Arrow types to MATLAB types. -template -struct MatlabTraits; - -template <> -struct MatlabTraits { - static constexpr mxClassID matlab_class_id = mxSINGLE_CLASS; - using MatlabType = mxSingle; - static MatlabType* GetData(mxArray* pa) { return mxGetSingles(pa); } -}; - -template <> -struct MatlabTraits { - static constexpr mxClassID matlab_class_id = mxDOUBLE_CLASS; - using MatlabType = mxDouble; - static MatlabType* GetData(mxArray* pa) { return mxGetDoubles(pa); } -}; - -template <> -struct MatlabTraits { - static constexpr mxClassID matlab_class_id = mxUINT8_CLASS; - using MatlabType = mxUint8; - static MatlabType* GetData(mxArray* pa) { return mxGetUint8s(pa); } -}; - -template <> -struct MatlabTraits { - static constexpr mxClassID matlab_class_id = mxUINT16_CLASS; - using MatlabType = mxUint16; - static MatlabType* GetData(mxArray* pa) { return mxGetUint16s(pa); } -}; - -template <> -struct MatlabTraits { - static constexpr mxClassID matlab_class_id = mxUINT32_CLASS; - using MatlabType = mxUint32; - static MatlabType* GetData(mxArray* pa) { return mxGetUint32s(pa); } -}; - -template <> -struct MatlabTraits { - static constexpr mxClassID matlab_class_id = mxUINT64_CLASS; - using MatlabType = mxUint64; - static MatlabType* GetData(mxArray* pa) { return mxGetUint64s(pa); } -}; - -template <> -struct MatlabTraits { - static constexpr mxClassID matlab_class_id = mxINT8_CLASS; - using MatlabType = mxInt8; - static MatlabType* GetData(mxArray* pa) { return mxGetInt8s(pa); } -}; - -template <> -struct MatlabTraits { - static constexpr mxClassID matlab_class_id = mxINT16_CLASS; - using MatlabType = mxInt16; - static MatlabType* GetData(mxArray* pa) { return mxGetInt16s(pa); } -}; - -template <> -struct MatlabTraits { - static constexpr mxClassID matlab_class_id = mxINT32_CLASS; - using MatlabType = mxInt32; - static MatlabType* GetData(mxArray* pa) { return mxGetInt32s(pa); } -}; - -template <> -struct MatlabTraits { - static constexpr mxClassID matlab_class_id = mxINT64_CLASS; - using MatlabType = mxInt64; - static MatlabType* GetData(mxArray* pa) { return mxGetInt64s(pa); } -}; - -} // namespace matlab -} // namespace arrow diff --git a/matlab/src/cpp/arrow/matlab/feather/util/handle_status.cc b/matlab/src/cpp/arrow/matlab/feather/util/handle_status.cc deleted file mode 100644 index 86d6c1c79cf..00000000000 --- a/matlab/src/cpp/arrow/matlab/feather/util/handle_status.cc +++ /dev/null @@ -1,93 +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 -#include - -namespace arrow { -namespace matlab { -namespace feather { -namespace util { - -void HandleStatus(const Status& status) { - const char* arrow_error_message = "Arrow error: %s"; - switch (status.code()) { - case StatusCode::OK: { - break; - } - case StatusCode::OutOfMemory: { - mexErrMsgIdAndTxt("MATLAB:arrow:status:OutOfMemory", arrow_error_message, - status.ToString().c_str()); - break; - } - case StatusCode::KeyError: { - mexErrMsgIdAndTxt("MATLAB:arrow:status:KeyError", arrow_error_message, - status.ToString().c_str()); - break; - } - case StatusCode::TypeError: { - mexErrMsgIdAndTxt("MATLAB:arrow:status:TypeError", arrow_error_message, - status.ToString().c_str()); - break; - } - case StatusCode::Invalid: { - mexErrMsgIdAndTxt("MATLAB:arrow:status:Invalid", arrow_error_message, - status.ToString().c_str()); - break; - } - case StatusCode::IOError: { - mexErrMsgIdAndTxt("MATLAB:arrow:status:IOError", arrow_error_message, - status.ToString().c_str()); - break; - } - case StatusCode::CapacityError: { - mexErrMsgIdAndTxt("MATLAB:arrow:status:CapacityError", arrow_error_message, - status.ToString().c_str()); - break; - } - case StatusCode::IndexError: { - mexErrMsgIdAndTxt("MATLAB:arrow:status:IndexError", arrow_error_message, - status.ToString().c_str()); - break; - } - case StatusCode::UnknownError: { - mexErrMsgIdAndTxt("MATLAB:arrow:status:UnknownError", arrow_error_message, - status.ToString().c_str()); - break; - } - case StatusCode::NotImplemented: { - mexErrMsgIdAndTxt("MATLAB:arrow:status:NotImplemented", arrow_error_message, - status.ToString().c_str()); - break; - } - case StatusCode::SerializationError: { - mexErrMsgIdAndTxt("MATLAB:arrow:status:SerializationError", arrow_error_message, - status.ToString().c_str()); - break; - } - default: { - mexErrMsgIdAndTxt("MATLAB:arrow:status:UnknownStatus", arrow_error_message, - "Unknown status"); - break; - } - } -} - -} // namespace util -} // namespace feather -} // namespace matlab -} // namespace arrow diff --git a/matlab/src/cpp/arrow/matlab/feather/util/handle_status.h b/matlab/src/cpp/arrow/matlab/feather/util/handle_status.h deleted file mode 100644 index 3025b3b2080..00000000000 --- a/matlab/src/cpp/arrow/matlab/feather/util/handle_status.h +++ /dev/null @@ -1,35 +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 - -namespace arrow { -namespace matlab { -namespace feather { -namespace util { - -// Terminates execution and returns to the MATLAB prompt, -// displaying an error message if the given status -// indicates that an error has occurred. -void HandleStatus(const Status& status); - -} // namespace util -} // namespace feather -} // namespace matlab -} // namespace arrow diff --git a/matlab/src/cpp/arrow/matlab/feather/util/unicode_conversion.cc b/matlab/src/cpp/arrow/matlab/feather/util/unicode_conversion.cc deleted file mode 100644 index 623943d0ca6..00000000000 --- a/matlab/src/cpp/arrow/matlab/feather/util/unicode_conversion.cc +++ /dev/null @@ -1,65 +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 "unicode_conversion.h" - -#include /* for std::codecvt_utf8_utf16 */ -#include /* for std::wstring_convert */ - -namespace arrow { -namespace matlab { -namespace feather { -namespace util { - -mxArray* ConvertUTF8StringToUTF16CharMatrix(const std::string& utf8_string) { - // Get pointers to the start and end of the std::string data. - const char* string_start = utf8_string.c_str(); - const char* string_end = string_start + utf8_string.length(); - - // Due to this issue on MSVC: https://stackoverflow.com/q/32055357 we cannot - // directly use a destination type of char16_t. -#if _MSC_VER >= 1900 - using CharType = int16_t; -#else - using CharType = char16_t; -#endif - using ConverterType = std::codecvt_utf8_utf16; - std::wstring_convert code_converter{}; - - std::basic_string utf16_string; - try { - utf16_string = code_converter.from_bytes(string_start, string_end); - } catch (...) { - // In the case that any error occurs, just try returning a string in the - // user's current locale instead. - return mxCreateString(string_start); - } - - // Store the converter UTF-16 string in a mxCharMatrix and return it. - const mwSize dimensions[2] = {1, utf16_string.size()}; - mxArray* character_matrix = mxCreateCharArray(2, dimensions); - mxChar* character_matrix_pointer = mxGetChars(character_matrix); - std::copy(utf16_string.data(), utf16_string.data() + utf16_string.size(), - character_matrix_pointer); - - return character_matrix; -} - -} // namespace util -} // namespace feather -} // namespace matlab -} // namespace arrow \ No newline at end of file diff --git a/matlab/src/cpp/arrow/matlab/feather/util/unicode_conversion.h b/matlab/src/cpp/arrow/matlab/feather/util/unicode_conversion.h deleted file mode 100644 index 8a41f08605a..00000000000 --- a/matlab/src/cpp/arrow/matlab/feather/util/unicode_conversion.h +++ /dev/null @@ -1,36 +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 - -#include - -namespace arrow { -namespace matlab { -namespace feather { -namespace util { - -// Converts a UTF-8 encoded std::string to a heap-allocated UTF-16 encoded -// mxCharArray. -mxArray* ConvertUTF8StringToUTF16CharMatrix(const std::string& utf8_string); - -} // namespace util -} // namespace feather -} // namespace matlab -} // namespace arrow diff --git a/matlab/src/cpp/arrow/matlab/mex/call.cc b/matlab/src/cpp/arrow/matlab/mex/call.cc deleted file mode 100644 index c1205b071c1..00000000000 --- a/matlab/src/cpp/arrow/matlab/mex/call.cc +++ /dev/null @@ -1,28 +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 - -#include "mex_util.h" - -void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) { - using namespace arrow::matlab::mex; - - checkNumArgs(nrhs); - auto fcn = lookup_function(get_function_name(prhs[0])); - fcn(nlhs, plhs, nrhs - 1, ++prhs); -} diff --git a/matlab/src/cpp/arrow/matlab/mex/mex_functions.h b/matlab/src/cpp/arrow/matlab/mex/mex_functions.h deleted file mode 100644 index aa09fc863b2..00000000000 --- a/matlab/src/cpp/arrow/matlab/mex/mex_functions.h +++ /dev/null @@ -1,40 +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 -#include -#include - -#include - -#include "arrow/matlab/feather/feather_functions.h" - -namespace arrow { -namespace matlab { -namespace mex { - -using namespace arrow::matlab::feather; - -using mex_fcn_t = - std::function; - -static const std::unordered_map FUNCTION_MAP = { - {"featherread", featherread}, {"featherwrite", featherwrite}}; - -} // namespace mex -} // namespace matlab -} // namespace arrow \ No newline at end of file diff --git a/matlab/src/cpp/arrow/matlab/mex/mex_util.cc b/matlab/src/cpp/arrow/matlab/mex/mex_util.cc deleted file mode 100644 index bc1bb96b085..00000000000 --- a/matlab/src/cpp/arrow/matlab/mex/mex_util.cc +++ /dev/null @@ -1,53 +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 "mex_util.h" - -namespace arrow { -namespace matlab { -namespace mex { - -void checkNumArgs(int nrhs) { - if (nrhs < 1) { - mexErrMsgIdAndTxt("MATLAB:arrow:minrhs", - "'arrow.cpp.call' requires at least one input argument, which must be the " - "name of the C++ function to call."); - } -} - -std::string get_function_name(const mxArray* input) { - std::string opname; - if (!mxIsChar(input)) { - mexErrMsgIdAndTxt("MATLAB:arrow:FunctionNameDataType", - "The first input argument to 'arrow.cpp.call' must be a character vector."); - } - const char* c_str = mxArrayToUTF8String(input); - return std::string{c_str}; -} - -mex_fcn_t lookup_function(const std::string& function_name) { - auto kv_pair = FUNCTION_MAP.find(function_name); - if (kv_pair == FUNCTION_MAP.end()) { - mexErrMsgIdAndTxt("MATLAB:arrow:UnknownCppFunction", "Unrecognized C++ function '%s'", - function_name.c_str()); - } - return kv_pair->second; -} - -} // namespace mex -} // namespace matlab -} // namespace arrow diff --git a/matlab/src/cpp/arrow/matlab/mex/mex_util.h b/matlab/src/cpp/arrow/matlab/mex/mex_util.h deleted file mode 100644 index 8e02084a288..00000000000 --- a/matlab/src/cpp/arrow/matlab/mex/mex_util.h +++ /dev/null @@ -1,42 +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 -#include -#include - -#include - -#include "mex_functions.h" - -#include "arrow/matlab/api/visibility.h" - -namespace arrow { -namespace matlab { -namespace mex { - -ARROW_MATLAB_EXPORT void checkNumArgs(int nrhs); - -ARROW_MATLAB_EXPORT std::string get_function_name(const mxArray* input); - -ARROW_MATLAB_EXPORT mex_fcn_t lookup_function(const std::string& function_name); - -} // namespace mex -} // namespace matlab -} // namespace arrow diff --git a/matlab/src/cpp/arrow/matlab/mex/mex_util_test.cc b/matlab/src/cpp/arrow/matlab/mex/mex_util_test.cc deleted file mode 100644 index 8f2c65c75f3..00000000000 --- a/matlab/src/cpp/arrow/matlab/mex/mex_util_test.cc +++ /dev/null @@ -1,30 +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 - -#include "mex_util.h" - -namespace arrow { -namespace matlab { -namespace mex { -TEST(CheckNumArgsTests, TooFewArgsError) { - EXPECT_THROW(checkNumArgs(0), std::exception); -} -} // namespace mex -} // namespace matlab -} // namespace arrow From bc0e3043fc923a7a98aef951c29774c0a846b8c7 Mon Sep 17 00:00:00 2001 From: Sarah Gilmore Date: Wed, 16 Aug 2023 12:07:12 -0400 Subject: [PATCH 4/6] Delete api visibility symbol export logic now that the only client code (the old c-mex feather implementation) has been deleted. --- matlab/src/cpp/arrow/matlab/api/visibility.h | 28 -------------------- 1 file changed, 28 deletions(-) delete mode 100644 matlab/src/cpp/arrow/matlab/api/visibility.h diff --git a/matlab/src/cpp/arrow/matlab/api/visibility.h b/matlab/src/cpp/arrow/matlab/api/visibility.h deleted file mode 100644 index 51efac972ee..00000000000 --- a/matlab/src/cpp/arrow/matlab/api/visibility.h +++ /dev/null @@ -1,28 +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 - -#if defined(_WIN32) || defined(__CYGWIN__) -#ifdef ARROW_MATLAB_EXPORTING -#define ARROW_MATLAB_EXPORT __declspec(dllexport) -#else -#define ARROW_MATLAB_EXPORT __declspec(dllimport) -#endif -#else // Not Windows -#define ARROW_MATLAB_EXPORT __attribute__((visibility("default"))) -#endif From 0dad9eb8fc800e1f355345c9ab4a336593d64163 Mon Sep 17 00:00:00 2001 From: Sarah Gilmore Date: Wed, 16 Aug 2023 12:10:38 -0400 Subject: [PATCH 5/6] Delete unused build_support functionality. Co-authored-by: Kevin Gurney --- matlab/build_support/common_vars.m | 24 ----------------- matlab/build_support/compile.m | 41 ------------------------------ matlab/build_support/test.m | 28 -------------------- 3 files changed, 93 deletions(-) delete mode 100644 matlab/build_support/common_vars.m delete mode 100644 matlab/build_support/compile.m delete mode 100644 matlab/build_support/test.m diff --git a/matlab/build_support/common_vars.m b/matlab/build_support/common_vars.m deleted file mode 100644 index a7c9d6a32fe..00000000000 --- a/matlab/build_support/common_vars.m +++ /dev/null @@ -1,24 +0,0 @@ -function vars = common_vars() -% 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. - -fileDir = fileparts(mfilename("fullpath")); - -vars.srcDir = fullfile(fileDir, "..", "src"); -vars.testDir = fullfile(fileDir, "..", "test"); -vars.buildDir = fullfile(fileDir, "..", "build"); -end \ No newline at end of file diff --git a/matlab/build_support/compile.m b/matlab/build_support/compile.m deleted file mode 100644 index d436dadfe8d..00000000000 --- a/matlab/build_support/compile.m +++ /dev/null @@ -1,41 +0,0 @@ -function compile() -% 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. - -vars = common_vars(); - -mkdir(vars.buildDir); - -ldflags = string.empty; -if isunix - arrowHome = getenv("ARROW_HOME"); - if isempty(arrowHome) - error("The ARROW_HOME environment variable must be set."); - end - ldflags(end+1) = "-Wl"; - ldflags(end+1) = "-rpath '" + fullfile(arrowHome, "lib") + "'"; -end - -mex(fullfile(vars.srcDir, "featherreadmex.cc"), ... - fullfile(vars.srcDir, "feather_reader.cc"), ... - fullfile(vars.srcDir, "util", "handle_status.cc"), ... - "-L" + fullfile(arrowHome, "lib"), "-larrow", ... - "-I" + fullfile(arrowHome, "include"), ... - "LDFLAGS=""\$LDFLAGS " + strjoin(ldflags, ",") + """", ... - "-outdir", vars.buildDir, ... - "-R2018a", "-v"); -end diff --git a/matlab/build_support/test.m b/matlab/build_support/test.m deleted file mode 100644 index 990549e3b31..00000000000 --- a/matlab/build_support/test.m +++ /dev/null @@ -1,28 +0,0 @@ -function test() -% 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. - -vars = common_vars(); - -compile(); - -originalPath = addpath(vars.srcDir, vars.buildDir); -restoreOriginalPath = onCleanup(@()path(originalPath)); - -results = runtests(vars.testDir, "IncludeSubfolders", true, "OutputDetail", 3); -assert(all(~[results.Failed])); -end From 1a01840b419f8097d3180315e43b1ff0c67e69d2 Mon Sep 17 00:00:00 2001 From: Sarah Gilmore Date: Wed, 16 Aug 2023 13:29:25 -0400 Subject: [PATCH 6/6] Fix lint errors in matlab/CMakeLists.txt --- matlab/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index 34e97e59aab..c7be74de8a9 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -285,7 +285,6 @@ find_package(Matlab REQUIRED COMPONENTS MAIN_PROGRAM) message(STATUS "Mex Library: ${Matlab_MEX_LIBRARY}") message(STATUS "Mex Include Folder: ${Matlab_INCLUDE_DIRS}") - # 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) @@ -425,7 +424,7 @@ if(NOT Arrow_FOUND) # folders that would be empty after installation: # https://gitlab.kitware.com/cmake/cmake/-/issues/17122 - set(CMAKE_PACKAGED_INSTALL_DIR "${CMAKE_INSTALL_DIR}/+arrow") + set(CMAKE_PACKAGED_INSTALL_DIR "${CMAKE_INSTALL_DIR}/+arrow") install(DIRECTORY "${ARROW_SHARED_LIB_DIR}/" DESTINATION ${CMAKE_PACKAGED_INSTALL_DIR}