[Debian-astro-commits] [gyoto] 186/221: Python: support NumPy arrays *in addition* to low level C arrays in Coord1dSets Indices and Angles

Thibaut Jean-Claude Paumard thibaut at moszumanska.debian.org
Fri May 22 20:52:45 UTC 2015


This is an automated email from the git hooks/post-receive script.

thibaut pushed a commit to branch master
in repository gyoto.

commit ad176cbeb4fea6d6079c879c6eebbaa58264955c
Author: Thibaut Paumard <paumard at users.sourceforge.net>
Date:   Sat Jan 10 15:20:00 2015 +0100

    Python: support NumPy arrays *in addition* to low level C arrays in Coord1dSets Indices and Angles
---
 python/example.py     |  8 +++++++-
 python/gyoto.i        | 21 ++++++++++++++++++---
 python/gyoto_lorene.i |  3 ++-
 python/gyoto_std.i    |  3 ++-
 4 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/python/example.py b/python/example.py
index 1c87742..fa185b2 100644
--- a/python/example.py
+++ b/python/example.py
@@ -185,8 +185,14 @@ plt.show()
 # range, Indices can hold arbitrary indices.
 
 ind=numpy.arange(1, res+1, dtype=numpy.uintp) # on 64bit arch...
-
 ii=gyoto.Indices(ind)
+
+# Or:
+# ind=gyoto.array_size_t(res)
+# for i in range(0, res):
+#   ind[i]=i+1
+# ii=gyoto.Indices(ind, res)
+
 jj=gyoto.Range(1, res, 1)
 bucket=gyoto.Bucket(ii, jj)
 
diff --git a/python/gyoto.i b/python/gyoto.i
index 97b8d69..c02ff44 100644
--- a/python/gyoto.i
+++ b/python/gyoto.i
@@ -258,7 +258,8 @@ GyotoSmPtrTypeMapClassDerived(Astrobj, Properties);
 // Handle generic C arrays using a class-like interface
 %include "carrays.i"
 %array_class(double, array_double);
-%array_class(double, array_unsigned_long);
+%array_class(size_t, array_size_t);
+%array_class(unsigned long, array_unsigned_long);
 // Provide conversion between generic C arrays and NumPy ndarrays
 %define ExtendArrayNumPy(name, type)
 %extend name {
@@ -278,6 +279,8 @@ GyotoSmPtrTypeMapClassDerived(Astrobj, Properties);
 %enddef
 
 ExtendArrayNumPy(array_double, double);
+ExtendArrayNumPy(array_unsigned_long, unsigned long);
+ExtendArrayNumPy(array_size_t, size_t);
 
 // ******** INTERFACE ******** //
 // Here starts the actual parsing of the various header files
@@ -489,13 +492,19 @@ protected:
   size_t const sz_;
   size_t i_;
 public:
-  Indices (size_t *IN_ARRAY1, size_t DIM1);
+  Indices (size_t *carray, size_t nel);
   void begin();
   bool valid();
   size_t size();
   Coord1dSet& operator++();
   size_t operator*() const ;
 };
+%extend Indices {
+  Indices (size_t DIM1, size_t *IN_ARRAY1) {
+    return new Indices(IN_ARRAY1, DIM1);
+  }
+
+}
 
 class Angles : public Coord1dSet {
 protected:
@@ -503,13 +512,19 @@ protected:
   size_t const sz_;
   size_t i_;
 public:
-  Angles (double * IN_ARRAY1, size_t DIM1);
+  Angles (double * carray, size_t nel);
   void begin();
   bool valid();
   size_t size();
   Coord1dSet& operator++();
   double angle() const ;
 };
+%extend Angles {
+  Angles (size_t DIM1, double *IN_ARRAY1) {
+    return new Angles(IN_ARRAY1, DIM1);
+  }
+
+}
 
 class RepeatAngle : public Coord1dSet {
 protected:
diff --git a/python/gyoto_lorene.i b/python/gyoto_lorene.i
index 845d3a5..a9771f8 100644
--- a/python/gyoto_lorene.i
+++ b/python/gyoto_lorene.i
@@ -22,7 +22,8 @@
 %}
 
 %array_class(double, array_double)
-%array_class(double, array_unsigned_long)
+%array_class(unsigned long, array_unsigned_long)
+%array_class(size_t, array_size_t)
 
 GyotoSmPtrClassDerived(Metric, RotStar3_1)
 GyotoSmPtrClassDerived(Metric, NumericalMetricLorene)
diff --git a/python/gyoto_std.i b/python/gyoto_std.i
index dfaff73..60a79bb 100644
--- a/python/gyoto_std.i
+++ b/python/gyoto_std.i
@@ -47,7 +47,8 @@ using namespace Gyoto;
 %}
 
 %array_class(double, array_double)
-%array_class(double, array_unsigned_long)
+%array_class(unsigned long, array_unsigned_long)
+%array_class(size_t, array_size_t)
 
 // Typemaps to translate SmartPointer to specific classes
 GyotoSmPtrTypeMapClassDerived(Astrobj, Standard)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-astro/packages/gyoto.git



More information about the Debian-astro-commits mailing list