casacore
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: aips2-request@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 //# $Id: PycArrayComH.h,v 1.2 2006/11/07 00:17:23 gvandiep Exp $
27 
28  // Check if the PyObject is an array object.
29  Bool PycArrayCheck (PyObject* obj_ptr);
30 
31  // Check if the API is or can be imported.
32  // <group>
33  Bool isImported();
34  inline Bool canImport()
35  { return True; }
37  void loadAPI();
38  // </group>
39 
40  // Convert the python array to a Casacore array in the ValueHolder.
41  // If copyData is True, the array data is always copied.
42  // Otherwise only if needed.
43  ValueHolder makeArray (PyObject* obj_ptr, Bool copyData);
44 
45  // Copy/convert the array data as needed.
46  // Specializations are defined for complex and string.
47  // <group>
48  template <typename T> struct ArrayCopy
49  {
50  static void toPy (void* to, const T* from, size_t nr);
51  static void fromPy (T* to, const void* from, size_t nr);
52  static Array<T> toArray (const IPosition& shape,
53  void* data, bool copy);
54  };
55 
56  template <> struct ArrayCopy<Complex>
57  {
58  static void toPy (void* to, const Complex* from, size_t nr);
59  static void fromPy (Complex* to, const void* from, size_t nr);
60  static Array<Complex> toArray (const IPosition& shape,
61  void* data, bool copy);
62  };
63 
64  template <> struct ArrayCopy<DComplex>
65  {
66  static void toPy (void* to, const DComplex* from, size_t nr);
67  static void fromPy (DComplex* to, const void* from, size_t nr);
68  static Array<DComplex> toArray (const IPosition& shape,
69  void* data, bool copy);
70  };
71 
72  template <> struct ArrayCopy<String>
73  {
74  static void toPy (void* to, const String* from, size_t nr);
75  static void fromPy (String* to, const void* from, size_t nr);
76  static Array<String> toArray (const IPosition& shape,
77  void* data, bool copy);
78  };
79  // </group>
80 
81  Array<String> ArrayCopyStr_toArray (const IPosition& shape,
82  void* data, size_t slen);
83 
84  Array<String> ArrayCopyUnicode_toArray (const IPosition& shape,
85  void* data, size_t slen);
86 
87  // Convert a Casacore array to a Python array object.
88  template <typename T>
89  boost::python::object makePyArrayObject (casacore::Array<T> const& arr);
90 
91 
Bool canImport()
Definition: PycArrayComH.h:34
Array< String > ArrayCopyStr_toArray(const IPosition &shape, void *data, size_t slen)
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.
Definition: PycArrayComCC.h:35
Bool isImported()
Check if the API is or can be imported.
Definition: PycArrayComCC.h:44
ValueHolder makeArray(PyObject *obj_ptr, Bool copyData)
Convert the python array to a Casacore array in the ValueHolder.
Bool importArray()
void loadAPI()
Definition: PycArrayComCC.h:54
StatsData< AccumType > copy(const StatsData< AccumType > &stats)
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape.
Definition: ExprNode.h:1987
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
const Bool True
Definition: aipstype.h:43
Copy/convert the array data as needed.
Definition: PycArrayComH.h:49
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)