]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/cpp/src/arrow/python/numpy_convert.h
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / cpp / src / arrow / python / numpy_convert.h
CommitLineData
1d09f67e
TL
1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18// Functions for converting between pandas's NumPy-based data representation
19// and Arrow data structures
20
21#pragma once
22
23#include "arrow/python/platform.h"
24
25#include <memory>
26#include <string>
27#include <vector>
28
29#include "arrow/buffer.h"
30#include "arrow/python/visibility.h"
31#include "arrow/sparse_tensor.h"
32
33namespace arrow {
34
35class DataType;
36class MemoryPool;
37class Status;
38class Tensor;
39
40namespace py {
41
42class ARROW_PYTHON_EXPORT NumPyBuffer : public Buffer {
43 public:
44 explicit NumPyBuffer(PyObject* arr);
45 virtual ~NumPyBuffer();
46
47 private:
48 PyObject* arr_;
49};
50
51ARROW_PYTHON_EXPORT
52Status NumPyDtypeToArrow(PyObject* dtype, std::shared_ptr<DataType>* out);
53ARROW_PYTHON_EXPORT
54Status NumPyDtypeToArrow(PyArray_Descr* descr, std::shared_ptr<DataType>* out);
55
56ARROW_PYTHON_EXPORT Status NdarrayToTensor(MemoryPool* pool, PyObject* ao,
57 const std::vector<std::string>& dim_names,
58 std::shared_ptr<Tensor>* out);
59
60ARROW_PYTHON_EXPORT Status TensorToNdarray(const std::shared_ptr<Tensor>& tensor,
61 PyObject* base, PyObject** out);
62
63ARROW_PYTHON_EXPORT Status
64SparseCOOTensorToNdarray(const std::shared_ptr<SparseCOOTensor>& sparse_tensor,
65 PyObject* base, PyObject** out_data, PyObject** out_coords);
66
67Status SparseCSXMatrixToNdarray(const std::shared_ptr<SparseTensor>& sparse_tensor,
68 PyObject* base, PyObject** out_data,
69 PyObject** out_indptr, PyObject** out_indices);
70
71ARROW_PYTHON_EXPORT Status SparseCSRMatrixToNdarray(
72 const std::shared_ptr<SparseCSRMatrix>& sparse_tensor, PyObject* base,
73 PyObject** out_data, PyObject** out_indptr, PyObject** out_indices);
74
75ARROW_PYTHON_EXPORT Status SparseCSCMatrixToNdarray(
76 const std::shared_ptr<SparseCSCMatrix>& sparse_tensor, PyObject* base,
77 PyObject** out_data, PyObject** out_indptr, PyObject** out_indices);
78
79ARROW_PYTHON_EXPORT Status SparseCSFTensorToNdarray(
80 const std::shared_ptr<SparseCSFTensor>& sparse_tensor, PyObject* base,
81 PyObject** out_data, PyObject** out_indptr, PyObject** out_indices);
82
83ARROW_PYTHON_EXPORT Status NdarraysToSparseCOOTensor(
84 MemoryPool* pool, PyObject* data_ao, PyObject* coords_ao,
85 const std::vector<int64_t>& shape, const std::vector<std::string>& dim_names,
86 std::shared_ptr<SparseCOOTensor>* out);
87
88ARROW_PYTHON_EXPORT Status NdarraysToSparseCSRMatrix(
89 MemoryPool* pool, PyObject* data_ao, PyObject* indptr_ao, PyObject* indices_ao,
90 const std::vector<int64_t>& shape, const std::vector<std::string>& dim_names,
91 std::shared_ptr<SparseCSRMatrix>* out);
92
93ARROW_PYTHON_EXPORT Status NdarraysToSparseCSCMatrix(
94 MemoryPool* pool, PyObject* data_ao, PyObject* indptr_ao, PyObject* indices_ao,
95 const std::vector<int64_t>& shape, const std::vector<std::string>& dim_names,
96 std::shared_ptr<SparseCSCMatrix>* out);
97
98ARROW_PYTHON_EXPORT Status NdarraysToSparseCSFTensor(
99 MemoryPool* pool, PyObject* data_ao, PyObject* indptr_ao, PyObject* indices_ao,
100 const std::vector<int64_t>& shape, const std::vector<int64_t>& axis_order,
101 const std::vector<std::string>& dim_names, std::shared_ptr<SparseCSFTensor>* out);
102
103ARROW_PYTHON_EXPORT Status
104TensorToSparseCOOTensor(const std::shared_ptr<Tensor>& tensor,
105 std::shared_ptr<SparseCOOTensor>* csparse_tensor);
106
107ARROW_PYTHON_EXPORT Status
108TensorToSparseCSRMatrix(const std::shared_ptr<Tensor>& tensor,
109 std::shared_ptr<SparseCSRMatrix>* csparse_tensor);
110
111ARROW_PYTHON_EXPORT Status
112TensorToSparseCSCMatrix(const std::shared_ptr<Tensor>& tensor,
113 std::shared_ptr<SparseCSCMatrix>* csparse_tensor);
114
115ARROW_PYTHON_EXPORT Status
116TensorToSparseCSFTensor(const std::shared_ptr<Tensor>& tensor,
117 std::shared_ptr<SparseCSFTensor>* csparse_tensor);
118
119} // namespace py
120} // namespace arrow