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.
27 Bool PycArrayCheck (PyObject* obj_ptr);
28
29 // Check if the API is or can be imported.
30 // <group>
32 inline Bool canImport()
33 { return True; }
35 void loadAPI();
36 // </group>
37
38 // Convert the python array to a Casacore array in the ValueHolder.
39 // If copyData is True, the array data is always copied.
40 // Otherwise only if needed.
41 ValueHolder makeArray (PyObject* obj_ptr, Bool copyData);
42
43 // Copy/convert the array data as needed.
44 // Specializations are defined for complex and string.
45 // <group>
46 template <typename T> struct ArrayCopy
47 {
48 static void toPy (void* to, const T* from, size_t nr);
49 static void fromPy (T* to, const void* from, size_t nr);
50 static Array<T> toArray (const IPosition& shape,
51 void* data, bool copy);
52 };
53
54 template <> struct ArrayCopy<Complex>
55 {
56 static void toPy (void* to, const Complex* from, size_t nr);
57 static void fromPy (Complex* to, const void* from, size_t nr);
58 static Array<Complex> toArray (const IPosition& shape,
59 void* data, bool copy);
60 };
61
62 template <> struct ArrayCopy<DComplex>
63 {
64 static void toPy (void* to, const DComplex* from, size_t nr);
65 static void fromPy (DComplex* to, const void* from, size_t nr);
66 static Array<DComplex> toArray (const IPosition& shape,
67 void* data, bool copy);
68 };
69
70 template <> struct ArrayCopy<String>
71 {
72 static void toPy (void* to, const String* from, size_t nr);
73 static void fromPy (String* to, const void* from, size_t nr);
74 static Array<String> toArray (const IPosition& shape,
75 void* data, bool copy);
76 };
77 // </group>
78
79 Array<String> ArrayCopyStr_toArray (const IPosition& shape,
80 void* data, size_t slen);
81
82 Array<String> ArrayCopyUnicode_toArray (const IPosition& shape,
83 void* data, size_t slen);
84
85 // Convert a Casacore array to a Python array object.
86 template <typename T>
87 boost::python::object makePyArrayObject (casacore::Array<T> const& arr);
88
89
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)
Check if the PyObject is an array object.
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)