casacore
Loading...
Searching...
No Matches
PycArrayComH.h
Go to the documentation of this file.
1// # PycArrayComH.h: Common code to convert an Array to/from a Python array
2// # Copyright (C) 2006
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26// Check if the PyObject is an array object.
27Bool PycArrayCheck(PyObject* obj_ptr);
28
29// Check if the API is or can be imported.
30// <group>
32inline Bool canImport() { return True; }
34void loadAPI();
35// </group>
36
37// Convert the python array to a Casacore array in the ValueHolder.
38// If copyData is True, the array data is always copied.
39// Otherwise only if needed.
40ValueHolder makeArray(PyObject* obj_ptr, Bool copyData);
41
42// Copy/convert the array data as needed.
43// Specializations are defined for complex and string.
44// <group>
45template <typename T>
46struct ArrayCopy {
47 static void toPy(void* to, const T* from, size_t nr);
48 static void fromPy(T* to, const void* from, size_t nr);
49 static Array<T> toArray(const IPosition& shape, void* data, bool copy);
50};
51
52template <>
53struct ArrayCopy<Complex> {
54 static void toPy(void* to, const Complex* from, size_t nr);
55 static void fromPy(Complex* to, const void* from, size_t nr);
56 static Array<Complex> toArray(const IPosition& shape, void* data, bool copy);
57};
58
59template <>
60struct ArrayCopy<DComplex> {
61 static void toPy(void* to, const DComplex* from, size_t nr);
62 static void fromPy(DComplex* to, const void* from, size_t nr);
63 static Array<DComplex> toArray(const IPosition& shape, void* data, bool copy);
64};
65
66template <>
67struct ArrayCopy<String> {
68 static void toPy(void* to, const String* from, size_t nr);
69 static void fromPy(String* to, const void* from, size_t nr);
70 static Array<String> toArray(const IPosition& shape, void* data, bool copy);
71};
72// </group>
73
74Array<String> ArrayCopyStr_toArray(const IPosition& shape, void* data, size_t slen);
75
76Array<String> ArrayCopyUnicode_toArray(const IPosition& shape, void* data, size_t slen);
77
78// Convert a Casacore array to a Python array object.
79template <typename T>
80boost::python::object makePyArrayObject(casacore::Array<T> const& arr);
Bool canImport()
Array< String > ArrayCopyUnicode_toArray(const IPosition &shape, void *data, size_t slen)
boost::python::object makePyArrayObject(casacore::Array< T > const &arr)
Convert a Casacore array to a Python array object.
Bool PycArrayCheck(PyObject *obj_ptr)
Array< String > ArrayCopyStr_toArray(const IPosition &shape, void *data, size_t slen)
Bool isImported()
Check if the API is or can be imported.
ValueHolder makeArray(PyObject *obj_ptr, Bool copyData)
Convert the python array to a Casacore array in the ValueHolder.
Bool importArray()
void loadAPI()
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
Copy/convert the array data as needed.
static void toPy(void *to, const T *from, size_t nr)
static void fromPy(T *to, const void *from, size_t nr)
static Array< T > toArray(const IPosition &shape, void *data, bool copy)