forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da1ca86
commit cdaee14
Showing
6 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// 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. | ||
|
||
// 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/array.h" | ||
#include "arrow/c/bridge.h" | ||
|
||
#include "arrow/matlab/c/proxy/array_importer.h" | ||
#include "arrow/matlab/array/proxy/wrap.h" | ||
#include "arrow/matlab/error/error.h" | ||
|
||
#include "libmexclass/proxy/ProxyManager.h" | ||
|
||
namespace arrow::matlab::c::proxy { | ||
|
||
ArrayImporter::ArrayImporter() { | ||
// Register Proxy methods. | ||
REGISTER_METHOD(ArrayImporter, importFromC); | ||
} | ||
|
||
libmexclass::proxy::MakeResult ArrayImporter::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) { | ||
return std::make_shared<ArrayImporter>(); | ||
} | ||
|
||
void ArrayImporter::importFromC(libmexclass::proxy::method::Context& context) { | ||
namespace mda = ::matlab::data; | ||
using namespace libmexclass::proxy; | ||
|
||
mda::StructArray args = context.inputs[0]; | ||
const mda::TypedArray<uint64_t> array_address_mda = args[0]["ArrowArrayAddress"]; | ||
const mda::TypedArray<uint64_t> schema_address_mda = args[0]["ArrowSchemaAddress"]; | ||
|
||
const auto array_address = uint64_t(array_address_mda[0]); | ||
const auto schema_address = uint64_t(schema_address_mda[0]); | ||
|
||
struct ArrowArray* arrow_array = reinterpret_cast<struct ArrowArray*>(array_address); | ||
struct ArrowSchema* arrow_schema = reinterpret_cast<struct ArrowSchema*>(schema_address); | ||
|
||
MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(std::shared_ptr<arrow::Array> array, | ||
arrow::ImportArray(arrow_array, arrow_schema), | ||
context, "arrow:c:ImportFailed"); | ||
|
||
MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto array_proxy, | ||
arrow::matlab::array::proxy::wrap(array), context, | ||
error::UNKNOWN_PROXY_FOR_ARRAY_TYPE); | ||
|
||
mda::ArrayFactory factory; | ||
const auto array_proxy_id = ProxyManager::manageProxy(array_proxy); | ||
const auto array_proxy_id_mda = factory.createScalar(array_proxy_id); | ||
const auto array_type_id_mda = factory.createScalar(static_cast<int32_t>(array->type_id())); | ||
|
||
context.outputs[0] = array_proxy_id_mda; | ||
context.outputs[1] = array_type_id_mda; | ||
} | ||
} // namespace arrow::matlab::c::proxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// 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" | ||
|
||
namespace arrow::matlab::c::proxy { | ||
|
||
class ArrayImporter : public libmexclass::proxy::Proxy { | ||
public: | ||
ArrayImporter(); | ||
|
||
~ArrayImporter() = default; | ||
|
||
static libmexclass::proxy::MakeResult make( | ||
const libmexclass::proxy::FunctionArguments& constructor_arguments); | ||
|
||
protected: | ||
void importFromC(libmexclass::proxy::method::Context& context); | ||
}; | ||
|
||
} // namespace arrow::matlab::c::proxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters