Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
numpy_interop.h
Go to the documentation of this file.
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 #ifndef PYARROW_NUMPY_INTEROP_H
19 #define PYARROW_NUMPY_INTEROP_H
20 
21 #include "arrow/python/platform.h"
22 
23 #include <numpy/numpyconfig.h>
24 
25 // Don't use the deprecated Numpy functions
26 #ifdef NPY_1_7_API_VERSION
27 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
28 #else
29 #define NPY_ARRAY_NOTSWAPPED NPY_NOTSWAPPED
30 #define NPY_ARRAY_ALIGNED NPY_ALIGNED
31 #define NPY_ARRAY_WRITEABLE NPY_WRITEABLE
32 #define NPY_ARRAY_UPDATEIFCOPY NPY_UPDATEIFCOPY
33 #endif
34 
35 // This is required to be able to access the NumPy C API properly in C++ files
36 // other than this main one
37 #define PY_ARRAY_UNIQUE_SYMBOL arrow_ARRAY_API
38 #ifndef NUMPY_IMPORT_ARRAY
39 #define NO_IMPORT_ARRAY
40 #endif
41 
42 #include <numpy/arrayobject.h>
43 #include <numpy/ufuncobject.h>
44 
45 namespace arrow {
46 namespace py {
47 
48 inline int import_numpy() {
49 #ifdef NUMPY_IMPORT_ARRAY
50  import_array1(-1);
51  import_umath1(-1);
52 #endif
53 
54  return 0;
55 }
56 
57 } // namespace py
58 } // namespace arrow
59 
60 #endif // PYARROW_NUMPY_INTEROP_H
int import_numpy()
Definition: numpy_interop.h:48
Top-level namespace for Apache Arrow C++ API.
Definition: allocator.h:29