]>
Commit | Line | Data |
---|---|---|
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 | ||
33 | namespace arrow { | |
34 | ||
35 | class DataType; | |
36 | class MemoryPool; | |
37 | class Status; | |
38 | class Tensor; | |
39 | ||
40 | namespace py { | |
41 | ||
42 | class ARROW_PYTHON_EXPORT NumPyBuffer : public Buffer { | |
43 | public: | |
44 | explicit NumPyBuffer(PyObject* arr); | |
45 | virtual ~NumPyBuffer(); | |
46 | ||
47 | private: | |
48 | PyObject* arr_; | |
49 | }; | |
50 | ||
51 | ARROW_PYTHON_EXPORT | |
52 | Status NumPyDtypeToArrow(PyObject* dtype, std::shared_ptr<DataType>* out); | |
53 | ARROW_PYTHON_EXPORT | |
54 | Status NumPyDtypeToArrow(PyArray_Descr* descr, std::shared_ptr<DataType>* out); | |
55 | ||
56 | ARROW_PYTHON_EXPORT Status NdarrayToTensor(MemoryPool* pool, PyObject* ao, | |
57 | const std::vector<std::string>& dim_names, | |
58 | std::shared_ptr<Tensor>* out); | |
59 | ||
60 | ARROW_PYTHON_EXPORT Status TensorToNdarray(const std::shared_ptr<Tensor>& tensor, | |
61 | PyObject* base, PyObject** out); | |
62 | ||
63 | ARROW_PYTHON_EXPORT Status | |
64 | SparseCOOTensorToNdarray(const std::shared_ptr<SparseCOOTensor>& sparse_tensor, | |
65 | PyObject* base, PyObject** out_data, PyObject** out_coords); | |
66 | ||
67 | Status SparseCSXMatrixToNdarray(const std::shared_ptr<SparseTensor>& sparse_tensor, | |
68 | PyObject* base, PyObject** out_data, | |
69 | PyObject** out_indptr, PyObject** out_indices); | |
70 | ||
71 | ARROW_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 | ||
75 | ARROW_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 | ||
79 | ARROW_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 | ||
83 | ARROW_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 | ||
88 | ARROW_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 | ||
93 | ARROW_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 | ||
98 | ARROW_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 | ||
103 | ARROW_PYTHON_EXPORT Status | |
104 | TensorToSparseCOOTensor(const std::shared_ptr<Tensor>& tensor, | |
105 | std::shared_ptr<SparseCOOTensor>* csparse_tensor); | |
106 | ||
107 | ARROW_PYTHON_EXPORT Status | |
108 | TensorToSparseCSRMatrix(const std::shared_ptr<Tensor>& tensor, | |
109 | std::shared_ptr<SparseCSRMatrix>* csparse_tensor); | |
110 | ||
111 | ARROW_PYTHON_EXPORT Status | |
112 | TensorToSparseCSCMatrix(const std::shared_ptr<Tensor>& tensor, | |
113 | std::shared_ptr<SparseCSCMatrix>* csparse_tensor); | |
114 | ||
115 | ARROW_PYTHON_EXPORT Status | |
116 | TensorToSparseCSFTensor(const std::shared_ptr<Tensor>& tensor, | |
117 | std::shared_ptr<SparseCSFTensor>* csparse_tensor); | |
118 | ||
119 | } // namespace py | |
120 | } // namespace arrow |