Index: tools/swilena/ChangeLog
from Nicolas Burrus <burrus_n(a)lrde.epita.fr>
* meta/swilena_ntg.i: Define typemaps for python.
* meta/swilena_image.i: Don't define set, at and ref methods
taking point2d for python and ruby.
* python/tests/simple1.py: Adjust consequently.
* ruby/tests/simple1.rb: Likewise.
* doc/examples/python/simple.py: Likewise.
* doc/examples/ruby/simple.rb: Likewise.
Index: tools/swilena/meta/swilena_ntg.i
--- tools/swilena/meta/swilena_ntg.i Sat, 27 Sep 2003 19:02:23 +0200 burrus_n
(oln/s/33_swilena_nt 1.4 640)
+++ tools/swilena/meta/swilena_ntg.i Sun, 28 Sep 2003 22:01:27 +0200 burrus_n
(oln/s/33_swilena_nt 1.5 640)
@@ -237,3 +237,15 @@
%template(cplx_polar) ntg::cplx< ntg::polar, ntg_float >;
#define ntg_cplx_polar ntg::cplx< ntg::polar, ntg_float >
+
+#if defined(SWIGPYTHON)
+%typemap(in) ntg_uint {
+ $1 = ntg::int_u<32, ntg::strict>(PyLong_AsLong($input));
+}
+%typemap(in) ntg_sint {
+ $1 = ntg::int_s<32, ntg::strict>(PyLong_AsLong($input));
+}
+%typemap(in) ntg_bin {
+ $1 = ntg::bin(PyInt_AsLong($input));
+}
+#endif
Index: tools/swilena/meta/swilena_image.i
--- tools/swilena/meta/swilena_image.i Sat, 27 Sep 2003 18:32:13 +0200 burrus_n
(oln/s/36_swilena_im 1.5 640)
+++ tools/swilena/meta/swilena_image.i Sun, 28 Sep 2003 22:01:27 +0200 burrus_n
(oln/s/36_swilena_im 1.6 640)
@@ -4,7 +4,6 @@
| oln::image structures |
`----------------------*/
-
%define image_methods(T, Val, Dim)
// default constructor
@@ -24,18 +23,18 @@
bool hold(const point ## Dim ## d&) const;
%extend {
+#if defined(SWIGPYTHON) || defined(SWIGRUBY)
+ Val __getitem__(const point ## Dim ## d& p)
+ { return (*self)[p]; }
+ T& __setitem__(const point ## Dim ## d& p, Val v)
+ { (*self)[p] = v; return *self; }
+#else
Val at(const point ## Dim ## d& p)
{ return (*self)[p]; }
T& set(const point ## Dim ## d& p, Val v)
{ (*self)[p] = v; return *self; }
Val& ref(const point ## Dim ## d& p)
{ return (*self)[p]; }
-
-#if defined(SWIGPYTHON) || defined(SWIGRUBY)
- Val __getitem__(const point ## Dim ## d& p)
- { return (*self)[p]; }
- T& __setitem__(const point ## Dim ## d& p, Val v)
- { (*self)[p] = v; return *self; }
#endif
}
@@ -51,10 +50,11 @@
{ return (*self)(x); }
T __setitem__(coord x, Val v)
{ (*self)(x) = v; return *self; }
-#endif
+#else
Val at(coord x) { return (*self)(x); }
T& set(coord x, Val v) { (*self)(x) = v; return *self; }
Val& ref(coord x) { return (*self)(x); }
+#endif
}
#elif Dim == 2
@@ -67,13 +67,14 @@
{ return (*self)(x, y); }
T __setitem__(coord x, coord y, Val v)
{ (*self)(x, y) = v; return *self; }
-#endif
+#else
Val at(coord x, coord y)
{ return (*self)(x, y); }
T& set(coord x, coord y, Val v)
{ (*self)(x, y) = v; return *self; }
Val& ref(coord x, coord y)
{ return (*self)(x, y); }
+#endif
}
#elif Dim == 3
@@ -86,13 +87,14 @@
{ return (*self)(x, y, z); }
T __setitem__(coord x, coord y, coord z, Val v)
{ (*self)(x, y, z) = v; return *self; }
-#endif
+#else
Val at(coord x, coord y, coord z)
{ return (*self)(x, y, z); }
T& set(coord x, coord y, coord z, Val v)
{ (*self)(x, y, z) = v; return *self; }
Val& ref(coord x, coord y, coord z)
{ return (*self)(x, y, z); }
+#endif
}
#endif
Index: tools/swilena/python/tests/simple1.py
--- tools/swilena/python/tests/simple1.py Sat, 27 Sep 2003 19:02:23 +0200 burrus_n
(oln/v/16_simple1.py 1.2 700)
+++ tools/swilena/python/tests/simple1.py Sun, 28 Sep 2003 22:01:27 +0200 burrus_n
(oln/v/16_simple1.py 1.3 700)
@@ -12,7 +12,7 @@
# FIXME: uncomment when ready
#assert(lena.has_impl())
-lena.set(5, 5, uint(51))
+lena.set(5, 5, 51)
lena.ref(6, 6).value(42)
assert(lena.at(5, 5).value() == 51)
Index: tools/swilena/ruby/tests/simple1.rb
--- tools/swilena/ruby/tests/simple1.rb Sat, 27 Sep 2003 19:02:23 +0200 burrus_n
(oln/v/19_simple1.rb 1.2 700)
+++ tools/swilena/ruby/tests/simple1.rb Sun, 28 Sep 2003 22:01:27 +0200 burrus_n
(oln/v/19_simple1.rb 1.3 700)
@@ -16,8 +16,8 @@
# FIXME: uncomment when ready
#exit 1 unless lena.has_impl()
-lena.set(5, 5, Uint.new(51))
-lena.ref(6, 6).value(42)
+lena[5, 5] = Uint.new(51)
+lena[6, 6] = Uint.new(42)
-exit 1 unless lena.at(5, 5).value() == 51
-exit 1 unless lena.at(6, 6).value() == 42
+exit 1 unless lena[5, 5].value() == 51
+exit 1 unless lena[6, 6].value() == 42
Index: tools/swilena/doc/examples/ruby/simple.rb
--- tools/swilena/doc/examples/ruby/simple.rb Sat, 27 Sep 2003 19:02:23 +0200 burrus_n
(oln/v/22_simple.rb 1.2 600)
+++ tools/swilena/doc/examples/ruby/simple.rb Sun, 28 Sep 2003 22:01:27 +0200 burrus_n
(oln/v/22_simple.rb 1.3 600)
@@ -19,7 +19,7 @@
for i in 0..5 do
for j in 0..5 do
- ima.set(i, j, Uint.new(i + j))
+ ima[i, j] = Uint.new(i + j)
end
end
Index: tools/swilena/doc/examples/python/simple.py
--- tools/swilena/doc/examples/python/simple.py Sat, 27 Sep 2003 19:02:23 +0200 burrus_n
(oln/v/23_simple.py 1.2 600)
+++ tools/swilena/doc/examples/python/simple.py Sun, 28 Sep 2003 22:01:27 +0200 burrus_n
(oln/v/23_simple.py 1.3 600)
@@ -13,7 +13,7 @@
ima = image2d_uint(5,5)
print ima.at(5,5).value()
-ima.set(2,2,uint(2))
+ima.set(2, 2, 2)
print ima
p = ima.ref(1,1)