casacore
Loading...
Searching...
No Matches
PycArray.h
Go to the documentation of this file.
1//# PycArray.h: Class to convert an Array to/from Python
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
27#ifndef PYRAP_PYCARRAY_H
28#define PYRAP_PYCARRAY_H
29
30//# Includes
31// include first to avoid _POSIX_C_SOURCE redefined warnings
32#include <boost/python.hpp>
33#include <boost/python/object.hpp>
34#include <casacore/casa/Arrays/Array.h>
35#include <casacore/casa/Containers/ValueHolder.h>
36#include <casacore/casa/Utilities/DataType.h>
37#include <casacore/casa/Exceptions/Error.h>
38#include <iostream>
39
40namespace casacore { namespace python {
41
42
43 // <summary>
44 // A class to convert an Array to/from Python objects.
45 // </summary>
46
47 // <use visibility=export>
48 // <reviewed reviewer="" date="" tests="">
49 // </reviewed>
50
51 // <synopsis>
52 // </synopsis>
53
54 // Check if the PyObject is an array object.
55 Bool PycArrayCheck (PyObject* obj_ptr);
56
57 // Check if the PyObject is an array scalar object.
58 Bool PycArrayScalarCheck (PyObject* obj_ptr);
59
60 // Get the data type of the array scalar object.
61 // It returns TpBool, TpInt, TpFloat, or TpComplex.
62 // TpOther is returned if unrecognized.
63 DataType PycArrayScalarType (PyObject* obj_ptr);
64
66 {
67 // Constructs an Array from a Python object.
68 // If copyData=False, the array data is only copied if needed meaning
69 // that the Array object in the ValueHolder can reference the data in
70 // Python array.
71 // That should only be used if the ValueHolder and its Array will be
72 // destructed before the Python array.
73 static ValueHolder makeArray(PyObject* obj_ptr, Bool copyData=False);
74
75 // Construct an Array<String> from a special Python dict object.
76 static ValueHolder makeArrayFromDict (PyObject* obj_ptr);
77
78 // Construct a scalar from an array scalar (i.e. element in array).
79 static ValueHolder makeScalar (PyObject* obj_ptr);
80 };
81
82 // Do the actual making of the PyArrayObject.
83 // Specialize for strings.
84 // <group>
85 template <typename T>
86 boost::python::object makePyArrayObject (casacore::Array<T> const& arr);
87 template <>
88 boost::python::object makePyArrayObject (casacore::Array<String> const& arr);
89 // </group>
90
91 // Convert Array to Python.
92 template <typename T>
94 {
95 static boost::python::object makeobject (Array<T> const& arr)
96 { return makePyArrayObject (arr); }
97 static PyObject* convert (Array<T> const& c)
98 { return boost::python::incref(makeobject(c).ptr()); }
99 };
100
101}}
102
103#endif
Bool PycArrayCheck(PyObject *obj_ptr)
DataType PycArrayScalarType(PyObject *obj_ptr)
Get the data type of the array scalar object.
Bool PycArrayScalarCheck(PyObject *obj_ptr)
Check if the PyObject is an array scalar object.
boost::python::object makePyArrayObject(casacore::Array< T > const &arr)
Do the actual making of the PyArrayObject.
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
static ValueHolder makeArray(PyObject *obj_ptr, Bool copyData=False)
Constructs an Array from a Python object.
static ValueHolder makeScalar(PyObject *obj_ptr)
Construct a scalar from an array scalar (i.e.
static ValueHolder makeArrayFromDict(PyObject *obj_ptr)
Construct an Array<String> from a special Python dict object.
Convert Array to Python.
Definition PycArray.h:94
static PyObject * convert(Array< T > const &c)
Definition PycArray.h:97
static boost::python::object makeobject(Array< T > const &arr)
Definition PycArray.h:95