[python-arrayfire] 111/250: Implement a cleaner way for the Enum class

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Mar 28 22:59:38 UTC 2016


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

ghisvail-guest pushed a commit to branch debian/master
in repository python-arrayfire.

commit fed169f891653a01837d73000a78ff9cd125f02f
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Wed Sep 9 14:30:13 2015 -0400

    Implement a cleaner way for the Enum class
    
    - Revert "Work around for missing Enum class"
    - This reverts commit ce1ae092310347f2ad28fb3585b80c8e4aa5f501.
---
 arrayfire/arith.py    |   2 +-
 arrayfire/array.py    |  25 ++++----
 arrayfire/blas.py     |  10 +--
 arrayfire/data.py     |  12 ++--
 arrayfire/graphics.py |   2 +-
 arrayfire/image.py    |  22 +++----
 arrayfire/index.py    |   3 +-
 arrayfire/lapack.py   |   8 +--
 arrayfire/library.py  | 169 +++++++++++++++++++++++++-------------------------
 arrayfire/signal.py   |  16 ++---
 arrayfire/util.py     |  57 ++++++++---------
 11 files changed, 162 insertions(+), 164 deletions(-)

diff --git a/arrayfire/arith.py b/arrayfire/arith.py
index bec7192..1aacc91 100644
--- a/arrayfire/arith.py
+++ b/arrayfire/arith.py
@@ -74,7 +74,7 @@ def cast(a, dtype):
            array containing the values from `a` after converting to `dtype`.
     """
     out=Array()
-    safe_call(backend.get().af_cast(ct.pointer(out.arr), a.arr, Enum_value(dtype)))
+    safe_call(backend.get().af_cast(ct.pointer(out.arr), a.arr, dtype.value))
     return out
 
 def minof(lhs, rhs):
diff --git a/arrayfire/array.py b/arrayfire/array.py
index 7a41cec..b8ea142 100644
--- a/arrayfire/array.py
+++ b/arrayfire/array.py
@@ -22,14 +22,14 @@ def _create_array(buf, numdims, idims, dtype):
     out_arr = ct.c_void_p(0)
     c_dims = dim4(idims[0], idims[1], idims[2], idims[3])
     safe_call(backend.get().af_create_array(ct.pointer(out_arr), ct.c_void_p(buf),
-                                            numdims, ct.pointer(c_dims), Enum_value(dtype)))
+                                            numdims, ct.pointer(c_dims), dtype.value))
     return out_arr
 
 def _create_empty_array(numdims, idims, dtype):
     out_arr = ct.c_void_p(0)
     c_dims = dim4(idims[0], idims[1], idims[2], idims[3])
     safe_call(backend.get().af_create_handle(ct.pointer(out_arr),
-                                             numdims, ct.pointer(c_dims), Enum_value(dtype)))
+                                             numdims, ct.pointer(c_dims), dtype.value))
     return out_arr
 
 def constant_array(val, d0, d1=None, d2=None, d3=None, dtype=Dtype.f32):
@@ -41,7 +41,7 @@ def constant_array(val, d0, d1=None, d2=None, d3=None, dtype=Dtype.f32):
         if isinstance(dtype, int):
             dtype = ct.c_int(dtype)
         elif isinstance(dtype, Dtype):
-            dtype = ct.c_int(Enum_value(dtype))
+            dtype = ct.c_int(dtype.value)
         else:
             raise TypeError("Invalid dtype")
 
@@ -52,16 +52,15 @@ def constant_array(val, d0, d1=None, d2=None, d3=None, dtype=Dtype.f32):
         c_real = ct.c_double(val.real)
         c_imag = ct.c_double(val.imag)
 
-        if (Enum_value(dtype) != Enum_value(Dtype) and Enum_value(dtype) != Enum_value(Dtype)):
-            dtype = Enum_value(Dtype.c32)
+        if (dtype.value != Dtype.c32.value and dtype.value != Dtype.c64.value):
+            dtype = Dtype.c32.value
 
         safe_call(backend.get().af_constant_complex(ct.pointer(out), c_real, c_imag,
                                                     4, ct.pointer(dims), dtype))
-
-    elif Enum_value(dtype) == Enum_value(Dtype.s64):
+    elif dtype.value == Dtype.s64.value:
         c_val = ct.c_longlong(val.real)
         safe_call(backend.get().af_constant_long(ct.pointer(out), c_val, 4, ct.pointer(dims)))
-    elif Enum_value(dtype) == Enum_value(Dtype.u64):
+    elif dtype.value == Dtype.u64.value:
         c_val = ct.c_ulonglong(val.real)
         safe_call(backend.get().af_constant_ulong(ct.pointer(out), c_val, 4, ct.pointer(dims)))
     else:
@@ -79,7 +78,7 @@ def _binary_func(lhs, rhs, c_func):
         ldims = dim4_to_tuple(lhs.dims())
         rty = implicit_dtype(rhs, lhs.type())
         other = Array()
-        other.arr = constant_array(rhs, ldims[0], ldims[1], ldims[2], ldims[3], Enum_value(rty))
+        other.arr = constant_array(rhs, ldims[0], ldims[1], ldims[2], ldims[3], rty.value)
     elif not isinstance(rhs, Array):
         raise TypeError("Invalid parameter to binary function")
 
@@ -95,7 +94,7 @@ def _binary_funcr(lhs, rhs, c_func):
         rdims = dim4_to_tuple(rhs.dims())
         lty = implicit_dtype(lhs, rhs.type())
         other = Array()
-        other.arr = constant_array(lhs, rdims[0], rdims[1], rdims[2], rdims[3], Enum_value(lty))
+        other.arr = constant_array(lhs, rdims[0], rdims[1], rdims[2], rdims[3], lty.value)
     elif not isinstance(lhs, Array):
         raise TypeError("Invalid parameter to binary function")
 
@@ -351,7 +350,7 @@ class Array(BaseArray):
             if isinstance(dtype, str):
                 type_char = dtype
             else:
-                type_char = to_typecode[Enum_value(dtype)]
+                type_char = to_typecode[dtype.value]
         else:
             type_char = None
 
@@ -463,7 +462,7 @@ class Array(BaseArray):
         """
         Return the data type as a arrayfire.Dtype enum value.
         """
-        dty = ct.c_int(Enum_value(Dtype.f32))
+        dty = ct.c_int(Dtype.f32.value)
         safe_call(backend.get().af_get_type(ct.pointer(dty), self.arr))
         return to_dtype[typecodes[dty.value]]
 
@@ -471,7 +470,7 @@ class Array(BaseArray):
         """
         Return the data type as an int.
         """
-        return Enum_value(self.dtype())
+        return self.dtype().value
 
     def dims(self):
         """
diff --git a/arrayfire/blas.py b/arrayfire/blas.py
index 4de5af9..c476c1c 100644
--- a/arrayfire/blas.py
+++ b/arrayfire/blas.py
@@ -54,7 +54,7 @@ def matmul(lhs, rhs, lhs_opts=MATPROP.NONE, rhs_opts=MATPROP.NONE):
     """
     out = Array()
     safe_call(backend.get().af_matmul(ct.pointer(out.arr), lhs.arr, rhs.arr,
-                                      Enum_value(lhs_opts), Enum_value(rhs_opts)))
+                                      lhs_opts.value, rhs_opts.value))
     return out
 
 def matmulTN(lhs, rhs):
@@ -85,7 +85,7 @@ def matmulTN(lhs, rhs):
     """
     out = Array()
     safe_call(backend.get().af_matmul(ct.pointer(out.arr), lhs.arr, rhs.arr,
-                                      Enum_value(MATPROP.TRANS), Enum_value(MATPROP.NONE)))
+                                      MATPROP.TRANS.value, MATPROP.NONE.value))
     return out
 
 def matmulNT(lhs, rhs):
@@ -116,7 +116,7 @@ def matmulNT(lhs, rhs):
     """
     out = Array()
     safe_call(backend.get().af_matmul(ct.pointer(out.arr), lhs.arr, rhs.arr,
-                                      Enum_value(MATPROP.NONE), Enum_value(MATPROP.TRANS)))
+                                      MATPROP.NONE.value, MATPROP.TRANS.value))
     return out
 
 def matmulTT(lhs, rhs):
@@ -147,7 +147,7 @@ def matmulTT(lhs, rhs):
     """
     out = Array()
     safe_call(backend.get().af_matmul(ct.pointer(out.arr), lhs.arr, rhs.arr,
-                                      Enum_value(MATPROP.TRANS), Enum_value(MATPROP.TRANS)))
+                                      MATPROP.TRANS.value, MATPROP.TRANS.value))
     return out
 
 def dot(lhs, rhs, lhs_opts=MATPROP.NONE, rhs_opts=MATPROP.NONE):
@@ -188,5 +188,5 @@ def dot(lhs, rhs, lhs_opts=MATPROP.NONE, rhs_opts=MATPROP.NONE):
     """
     out = Array()
     safe_call(backend.get().af_dot(ct.pointer(out.arr), lhs.arr, rhs.arr,
-                                   Enum_value(lhs_opts), Enum_value(rhs_opts)))
+                                   lhs_opts.value, rhs_opts.value))
     return out
diff --git a/arrayfire/data.py b/arrayfire/data.py
index 41a50b8..c202aac 100644
--- a/arrayfire/data.py
+++ b/arrayfire/data.py
@@ -52,7 +52,7 @@ def constant(val, d0, d1=None, d2=None, d3=None, dtype=Dtype.f32):
     """
 
     out = Array()
-    out.arr = constant_array(val, d0, d1, d2, d3, Enum_value(dtype))
+    out.arr = constant_array(val, d0, d1, d2, d3, dtype.value)
     return out
 
 # Store builtin range function to be used later
@@ -116,7 +116,7 @@ def range(d0, d1=None, d2=None, d3=None, dim=0, dtype=Dtype.f32):
     out = Array()
     dims = dim4(d0, d1, d2, d3)
 
-    safe_call(backend.get().af_range(ct.pointer(out.arr), 4, ct.pointer(dims), dim, Enum_value(dtype)))
+    safe_call(backend.get().af_range(ct.pointer(out.arr), 4, ct.pointer(dims), dim, dtype.value))
     return out
 
 
@@ -182,7 +182,7 @@ def iota(d0, d1=None, d2=None, d3=None, dim=-1, tile_dims=None, dtype=Dtype.f32)
     tdims = dim4(td[0], td[1], td[2], td[3])
 
     safe_call(backend.get().af_iota(ct.pointer(out.arr), 4, ct.pointer(dims),
-                                    4, ct.pointer(tdims), Enum_value(dtype)))
+                                    4, ct.pointer(tdims), dtype.value))
     return out
 
 def randu(d0, d1=None, d2=None, d3=None, dtype=Dtype.f32):
@@ -219,7 +219,7 @@ def randu(d0, d1=None, d2=None, d3=None, dtype=Dtype.f32):
     out = Array()
     dims = dim4(d0, d1, d2, d3)
 
-    safe_call(backend.get().af_randu(ct.pointer(out.arr), 4, ct.pointer(dims), Enum_value(dtype)))
+    safe_call(backend.get().af_randu(ct.pointer(out.arr), 4, ct.pointer(dims), dtype.value))
     return out
 
 def randn(d0, d1=None, d2=None, d3=None, dtype=Dtype.f32):
@@ -257,7 +257,7 @@ def randn(d0, d1=None, d2=None, d3=None, dtype=Dtype.f32):
     out = Array()
     dims = dim4(d0, d1, d2, d3)
 
-    safe_call(backend.get().af_randn(ct.pointer(out.arr), 4, ct.pointer(dims), Enum_value(dtype)))
+    safe_call(backend.get().af_randn(ct.pointer(out.arr), 4, ct.pointer(dims), dtype.value))
     return out
 
 def set_seed(seed=0):
@@ -318,7 +318,7 @@ def identity(d0, d1, d2=None, d3=None, dtype=Dtype.f32):
     out = Array()
     dims = dim4(d0, d1, d2, d3)
 
-    safe_call(backend.get().af_identity(ct.pointer(out.arr), 4, ct.pointer(dims), Enum_value(dtype)))
+    safe_call(backend.get().af_identity(ct.pointer(out.arr), 4, ct.pointer(dims), dtype.value))
     return out
 
 def diag(a, num=0, extract=True):
diff --git a/arrayfire/graphics.py b/arrayfire/graphics.py
index 6594610..f2161b1 100644
--- a/arrayfire/graphics.py
+++ b/arrayfire/graphics.py
@@ -24,7 +24,7 @@ class _Cell(ct.Structure):
         self.row = r
         self.col = c
         self.title = title if title is not None else ct.c_char_p()
-        self.cmap = Enum_value(cmap)
+        self.cmap = cmap.value
 
 class Window(object):
     """
diff --git a/arrayfire/image.py b/arrayfire/image.py
index bf48fdd..36a279a 100644
--- a/arrayfire/image.py
+++ b/arrayfire/image.py
@@ -123,7 +123,7 @@ def resize(image, scale=None, odim0=None, odim1=None, method=INTERP.NEAREST):
     output = Array()
     safe_call(backend.get().af_resize(ct.pointer(output.arr),
                                       image.arr, ct.c_longlong(odim0),
-                                      ct.c_longlong(odim1), Enum_value(method)))
+                                      ct.c_longlong(odim1), method.value))
 
     return output
 
@@ -167,7 +167,7 @@ def transform(image, trans_mat, odim0 = 0, odim1 = 0, method=INTERP.NEAREST, is_
     safe_call(backend.get().af_transform(ct.pointer(output.arr),
                                          image.arr, trans_mat.arr,
                                          ct.c_longlong(odim0), ct.c_longlong(odim1),
-                                         Enum_value(method), is_inverse))
+                                         method.value, is_inverse))
     return output
 
 def rotate(image, theta, is_crop = True, method = INTERP.NEAREST):
@@ -196,7 +196,7 @@ def rotate(image, theta, is_crop = True, method = INTERP.NEAREST):
     """
     output = Array()
     safe_call(backend.get().af_rotate(ct.pointer(output.arr), image.arr,
-                                      ct.c_double(theta), is_crop, Enum_value(method)))
+                                      ct.c_double(theta), is_crop, method.value))
     return output
 
 def translate(image, trans0, trans1, odim0 = 0, odim1 = 0, method = INTERP.NEAREST):
@@ -238,7 +238,7 @@ def translate(image, trans0, trans1, odim0 = 0, odim1 = 0, method = INTERP.NEARE
     output = Array()
     safe_call(backend.get().af_translate(ct.pointer(output.arr),
                                          image.arr, trans0, trans1,
-                                         ct.c_longlong(odim0), ct.c_longlong(odim1), Enum_value(method)))
+                                         ct.c_longlong(odim0), ct.c_longlong(odim1), method.value))
     return output
 
 def scale(image, scale0, scale1, odim0 = 0, odim1 = 0, method = INTERP.NEAREST):
@@ -280,7 +280,7 @@ def scale(image, scale0, scale1, odim0 = 0, odim1 = 0, method = INTERP.NEAREST):
     output = Array()
     safe_call(backend.get().af_scale(ct.pointer(output.arr),
                                      image.arr, ct.c_double(scale0), ct.c_double(scale1),
-                                     ct.c_longlong(odim0), ct.c_longlong(odim1), Enum_value(method)))
+                                     ct.c_longlong(odim0), ct.c_longlong(odim1), method.value))
     return output
 
 def skew(image, skew0, skew1, odim0 = 0, odim1 = 0, method = INTERP.NEAREST, is_inverse=True):
@@ -326,7 +326,7 @@ def skew(image, skew0, skew1, odim0 = 0, odim1 = 0, method = INTERP.NEAREST, is_
     safe_call(backend.get().af_skew(ct.pointer(output.arr),
                                     image.arr, ct.c_double(skew0), ct.c_double(skew1),
                                     ct.c_longlong(odim0), ct.c_longlong(odim1),
-                                    Enum_value(method), is_inverse))
+                                    method.value, is_inverse))
 
     return output
 
@@ -609,7 +609,7 @@ def medfilt(image, w0 = 3, w1 = 3, edge_pad = PAD.ZERO):
     output = Array()
     safe_call(backend.get().af_medfilt(ct.pointer(output.arr),
                                        image.arr, ct.c_longlong(w0),
-                                       ct.c_longlong(w1), Enum_value(edge_pad)))
+                                       ct.c_longlong(w1), edge_pad.value))
     return output
 
 def minfilt(image, w_len = 3, w_wid = 3, edge_pad = PAD.ZERO):
@@ -641,7 +641,7 @@ def minfilt(image, w_len = 3, w_wid = 3, edge_pad = PAD.ZERO):
     output = Array()
     safe_call(backend.get().af_minfilt(ct.pointer(output.arr),
                                        image.arr, ct.c_longlong(w_len),
-                                       ct.c_longlong(w_wid), Enum_value(edge_pad)))
+                                       ct.c_longlong(w_wid), edge_pad.value))
     return output
 
 def maxfilt(image, w_len = 3, w_wid = 3, edge_pad = PAD.ZERO):
@@ -673,7 +673,7 @@ def maxfilt(image, w_len = 3, w_wid = 3, edge_pad = PAD.ZERO):
     output = Array()
     safe_call(backend.get().af_maxfilt(ct.pointer(output.arr),
                                        image.arr, ct.c_longlong(w_len),
-                                       ct.c_longlong(w_wid), Enum_value(edge_pad)))
+                                       ct.c_longlong(w_wid), edge_pad.value))
     return output
 
 def regions(image, conn = CONNECTIVITY.FOUR, out_type = Dtype.f32):
@@ -700,7 +700,7 @@ def regions(image, conn = CONNECTIVITY.FOUR, out_type = Dtype.f32):
     """
     output = Array()
     safe_call(backend.get().af_regions(ct.pointer(output.arr), image.arr,
-                                       Enum_value(conn), Enum_value(out_type)))
+                                       conn.value, out_type.value))
     return output
 
 def sobel_derivatives(image, w_len=3):
@@ -891,5 +891,5 @@ def color_space(image, to_type, from_type):
     """
     output = Array()
     safe_call(backend.get().af_color_space(ct.pointer(output.arr), image.arr,
-                                           Enum_value(to_type), Enum_value(from_type)))
+                                           to_type.value, from_type.value))
     return output
diff --git a/arrayfire/index.py b/arrayfire/index.py
index e3dca65..5dc2c36 100644
--- a/arrayfire/index.py
+++ b/arrayfire/index.py
@@ -195,8 +195,7 @@ class Index(ct.Structure):
 
             arr = ct.c_void_p(0)
 
-            if (Enum_value(idx.dtype()) ==
-                Enum_value(Dtype.b8)):
+            if (idx.type() == Dtype.b8.value):
                 safe_call(backend.get().af_where(ct.pointer(arr), idx.arr))
             else:
                 safe_call(backend.get().af_retain_array(ct.pointer(arr), idx.arr))
diff --git a/arrayfire/lapack.py b/arrayfire/lapack.py
index 2d2c100..1b15456 100644
--- a/arrayfire/lapack.py
+++ b/arrayfire/lapack.py
@@ -202,7 +202,7 @@ def solve(A, B, options=MATPROP.NONE):
 
     """
     X = Array()
-    safe_call(backend.get().af_solve(ct.pointer(X.arr), A.arr, B.arr, Enum_value(options)))
+    safe_call(backend.get().af_solve(ct.pointer(X.arr), A.arr, B.arr, options.value))
     return X
 
 def solve_lu(A, P, B, options=MATPROP.NONE):
@@ -230,7 +230,7 @@ def solve_lu(A, P, B, options=MATPROP.NONE):
 
     """
     X = Array()
-    safe_call(backend.get().af_solve_lu(ct.pointer(X.arr), A.arr, P.arr, B.arr, Enum_value(options)))
+    safe_call(backend.get().af_solve_lu(ct.pointer(X.arr), A.arr, P.arr, B.arr, options.value))
     return X
 
 def inverse(A, options=MATPROP.NONE):
@@ -260,7 +260,7 @@ def inverse(A, options=MATPROP.NONE):
 
     """
     AI = Array()
-    safe_call(backend.get().af_inverse(ct.pointer(AI.arr), A.arr, Enum_value(options)))
+    safe_call(backend.get().af_inverse(ct.pointer(AI.arr), A.arr, options.value))
     return AI
 
 def rank(A, tol=1E-5):
@@ -336,6 +336,6 @@ def norm(A, norm_type=NORM.EUCLID, p=1.0, q=1.0):
 
     """
     res = ct.c_double(0)
-    safe_call(backend.get().af_norm(ct.pointer(res), A.arr, Enum_value(norm_type),
+    safe_call(backend.get().af_norm(ct.pointer(res), A.arr, norm_type.value,
                                     ct.c_double(p), ct.c_double(q)))
     return res.value
diff --git a/arrayfire/library.py b/arrayfire/library.py
index 749e5a1..4a85b47 100644
--- a/arrayfire/library.py
+++ b/arrayfire/library.py
@@ -16,16 +16,15 @@ import ctypes as ct
 
 try:
     from enum import Enum
-
-    def Enum_value(val):
-        return val.value
-
+    def _Enum_Type(v):
+        return v
 except:
     class Enum(object):
         pass
 
-    def Enum_value(val):
-        return val
+    class _Enum_Type(object):
+        def __init__(self, v):
+            self.value = v
 
 class _clibrary(object):
 
@@ -93,92 +92,92 @@ class ERR(Enum):
     Error values. For internal use only.
     """
 
-    NONE            =   (0)
+    NONE            =   _Enum_Type(0)
 
     #100-199 Errors in environment
-    NO_MEM         = (101)
-    DRIVER         = (102)
-    RUNTIME        = (103)
+    NO_MEM         = _Enum_Type(101)
+    DRIVER         = _Enum_Type(102)
+    RUNTIME        = _Enum_Type(103)
 
     # 200-299 Errors in input parameters
-    INVALID_ARRAY  = (201)
-    ARG            = (202)
-    SIZE           = (203)
-    TYPE           = (204)
-    DIFF_TYPE      = (205)
-    BATCH          = (207)
+    INVALID_ARRAY  = _Enum_Type(201)
+    ARG            = _Enum_Type(202)
+    SIZE           = _Enum_Type(203)
+    TYPE           = _Enum_Type(204)
+    DIFF_TYPE      = _Enum_Type(205)
+    BATCH          = _Enum_Type(207)
 
     # 300-399 Errors for missing software features
-    NOT_SUPPORTED  = (301)
-    NOT_CONFIGURED = (302)
+    NOT_SUPPORTED  = _Enum_Type(301)
+    NOT_CONFIGURED = _Enum_Type(302)
 
     # 400-499 Errors for missing hardware features
-    NO_DBL         = (401)
-    NO_GFX         = (402)
+    NO_DBL         = _Enum_Type(401)
+    NO_GFX         = _Enum_Type(402)
 
     # 900-999 Errors from upstream libraries and runtimes
-    INTERNAL       = (998)
-    UNKNOWN        = (999)
+    INTERNAL       = _Enum_Type(998)
+    UNKNOWN        = _Enum_Type(999)
 
 class Dtype(Enum):
     """
     Error values. For internal use only.
     """
-    f32 = (0)
-    c32 = (1)
-    f64 = (2)
-    c64 = (3)
-    b8  = (4)
-    s32 = (5)
-    u32 = (6)
-    u8  = (7)
-    s64 = (8)
-    u64 = (9)
+    f32 = _Enum_Type(0)
+    c32 = _Enum_Type(1)
+    f64 = _Enum_Type(2)
+    c64 = _Enum_Type(3)
+    b8  = _Enum_Type(4)
+    s32 = _Enum_Type(5)
+    u32 = _Enum_Type(6)
+    u8  = _Enum_Type(7)
+    s64 = _Enum_Type(8)
+    u64 = _Enum_Type(9)
 
 class Source(Enum):
     """
     Source of the pointer
     """
-    device = (0)
-    host   = (1)
+    device = _Enum_Type(0)
+    host   = _Enum_Type(1)
 
 class INTERP(Enum):
     """
     Interpolation method
     """
-    NEAREST   = (0)
-    LINEAR    = (1)
-    BILINEAR  = (2)
-    CUBIC     = (3)
+    NEAREST   = _Enum_Type(0)
+    LINEAR    = _Enum_Type(1)
+    BILINEAR  = _Enum_Type(2)
+    CUBIC     = _Enum_Type(3)
 
 class PAD(Enum):
     """
     Edge padding types
     """
-    ZERO = (0)
-    SYM  = (1)
+    ZERO = _Enum_Type(0)
+    SYM  = _Enum_Type(1)
 
 class CONNECTIVITY(Enum):
     """
     Neighborhood connectivity
     """
-    FOUR  = (4)
-    EIGHT = (8)
+    FOUR  = _Enum_Type(4)
+    EIGHT = _Enum_Type(8)
 
 class CONV_MODE(Enum):
     """
     Convolution mode
     """
-    DEFAULT = (0)
-    EXPAND  = (1)
+    DEFAULT = _Enum_Type(0)
+    EXPAND  = _Enum_Type(1)
 
 class CONV_DOMAIN(Enum):
     """
     Convolution domain
     """
-    AUTO    = (0)
-    SPATIAL = (1)
-    FREQ    = (2)
+    AUTO    = _Enum_Type(0)
+    SPATIAL = _Enum_Type(1)
+    FREQ    = _Enum_Type(2)
 
 class MATCH(Enum):
     """
@@ -188,55 +187,55 @@ class MATCH(Enum):
     """
     Sum of absolute differences
     """
-    SAD  = (0)
+    SAD  = _Enum_Type(0)
 
     """
     Zero mean SAD
     """
-    ZSAD = (1)
+    ZSAD = _Enum_Type(1)
 
     """
     Locally scaled SAD
     """
-    LSAD = (2)
+    LSAD = _Enum_Type(2)
 
     """
     Sum of squared differences
     """
-    SSD  = (3)
+    SSD  = _Enum_Type(3)
 
     """
     Zero mean SSD
     """
-    ZSSD = (4)
+    ZSSD = _Enum_Type(4)
 
     """
     Locally scaled SSD
     """
-    LSSD = (5)
+    LSSD = _Enum_Type(5)
 
     """
     Normalized cross correlation
     """
-    NCC  = (6)
+    NCC  = _Enum_Type(6)
 
     """
     Zero mean NCC
     """
-    ZNCC = (7)
+    ZNCC = _Enum_Type(7)
 
     """
     Sum of hamming distances
     """
-    SHD  = (8)
+    SHD  = _Enum_Type(8)
 
 class CSPACE(Enum):
     """
     Colorspace formats
     """
-    GRAY = (0)
-    RGB  = (1)
-    HSV  = (2)
+    GRAY = _Enum_Type(0)
+    RGB  = _Enum_Type(1)
+    HSV  = _Enum_Type(2)
 
 class MATPROP(Enum):
     """
@@ -246,82 +245,82 @@ class MATPROP(Enum):
     """
     None, general.
     """
-    NONE       = (0)
+    NONE       = _Enum_Type(0)
 
     """
     Transposed.
     """
-    TRANS      = (1)
+    TRANS      = _Enum_Type(1)
 
     """
     Conjugate transposed.
     """
-    CTRANS     = (2)
+    CTRANS     = _Enum_Type(2)
 
     """
     Upper triangular matrix.
     """
-    UPPER      = (32)
+    UPPER      = _Enum_Type(32)
 
     """
     Lower triangular matrix.
     """
-    LOWER      = (64)
+    LOWER      = _Enum_Type(64)
 
     """
     Treat diagonal as units.
     """
-    DIAG_UNIT  = (128)
+    DIAG_UNIT  = _Enum_Type(128)
 
     """
     Symmetric matrix.
     """
-    SYM        = (512)
+    SYM        = _Enum_Type(512)
 
     """
     Positive definite matrix.
     """
-    POSDEF     = (1024)
+    POSDEF     = _Enum_Type(1024)
 
     """
     Orthogonal matrix.
     """
-    ORTHOG     = (2048)
+    ORTHOG     = _Enum_Type(2048)
 
     """
     Tri diagonal matrix.
     """
-    TRI_DIAG   = (4096)
+    TRI_DIAG   = _Enum_Type(4096)
 
     """
     Block diagonal matrix.
     """
-    BLOCK_DIAG = (8192)
+    BLOCK_DIAG = _Enum_Type(8192)
 
 class NORM(Enum):
     """
     Norm types
     """
-    VECTOR_1    = (0)
-    VECTOR_INF  = (1)
-    VECTOR_2    = (2)
-    VECTOR_P    = (3)
-    MATRIX_1    = (4)
-    MATRIX_INF  = (5)
-    MATRIX_2    = (6)
-    MATRIX_L_PQ = (7)
+    VECTOR_1    = _Enum_Type(0)
+    VECTOR_INF  = _Enum_Type(1)
+    VECTOR_2    = _Enum_Type(2)
+    VECTOR_P    = _Enum_Type(3)
+    MATRIX_1    = _Enum_Type(4)
+    MATRIX_INF  = _Enum_Type(5)
+    MATRIX_2    = _Enum_Type(6)
+    MATRIX_L_PQ = _Enum_Type(7)
     EUCLID      = VECTOR_2
 
 class COLORMAP(Enum):
     """
     Colormaps
     """
-    DEFAULT  = (0)
-    SPECTRUM = (1)
-    COLORS   = (2)
-    RED      = (3)
-    MOOD     = (4)
-    HEAT     = (5)
-    BLUE     = (6)
+    DEFAULT  = _Enum_Type(0)
+    SPECTRUM = _Enum_Type(1)
+    COLORS   = _Enum_Type(2)
+    RED      = _Enum_Type(3)
+    MOOD     = _Enum_Type(4)
+    HEAT     = _Enum_Type(5)
+    BLUE     = _Enum_Type(6)
 
 del Enum
diff --git a/arrayfire/signal.py b/arrayfire/signal.py
index 62b1d91..308fd0b 100644
--- a/arrayfire/signal.py
+++ b/arrayfire/signal.py
@@ -49,7 +49,7 @@ def approx1(signal, pos0, method=INTERP.LINEAR, off_grid=0.0):
     """
     output = Array()
     safe_call(backend.get().af_approx1(ct.pointer(output.arr), signal.arr, pos0.arr,
-                                       Enum_value(method), ct.c_double(off_grid)))
+                                       method.value, ct.c_double(off_grid)))
     return output
 
 def approx2(signal, pos0, pos1, method=INTERP.LINEAR, off_grid=0.0):
@@ -91,7 +91,7 @@ def approx2(signal, pos0, pos1, method=INTERP.LINEAR, off_grid=0.0):
     """
     output = Array()
     safe_call(backend.get().af_approx2(ct.pointer(output.arr), signal.arr,
-                                       pos0.arr, pos1.arr, Enum_value(method), ct.c_double(off_grid)))
+                                       pos0.arr, pos1.arr, method.value, ct.c_double(off_grid)))
     return output
 
 def fft(signal, dim0 = None , scale = None):
@@ -507,7 +507,7 @@ def convolve1(signal, kernel, conv_mode = CONV_MODE.DEFAULT, conv_domain = CONV_
     """
     output = Array()
     safe_call(backend.get().af_convolve1(ct.pointer(output.arr), signal.arr, kernel.arr,
-                                         Enum_value(conv_mode), Enum_value(conv_domain)))
+                                         conv_mode.value, conv_domain.value))
     return output
 
 def convolve2(signal, kernel, conv_mode = CONV_MODE.DEFAULT, conv_domain = CONV_DOMAIN.AUTO):
@@ -555,7 +555,7 @@ def convolve2(signal, kernel, conv_mode = CONV_MODE.DEFAULT, conv_domain = CONV_
     """
     output = Array()
     safe_call(backend.get().af_convolve2(ct.pointer(output.arr), signal.arr, kernel.arr,
-                                         Enum_value(conv_mode), Enum_value(conv_domain)))
+                                         conv_mode.value, conv_domain.value))
     return output
 
 def convolve3(signal, kernel, conv_mode = CONV_MODE.DEFAULT, conv_domain = CONV_DOMAIN.AUTO):
@@ -601,7 +601,7 @@ def convolve3(signal, kernel, conv_mode = CONV_MODE.DEFAULT, conv_domain = CONV_
     """
     output = Array()
     safe_call(backend.get().af_convolve3(ct.pointer(output.arr), signal.arr, kernel.arr,
-                                         Enum_value(conv_mode), Enum_value(conv_domain)))
+                                         conv_mode.value, conv_domain.value))
     return output
 
 def convolve(signal, kernel, conv_mode = CONV_MODE.DEFAULT, conv_domain = CONV_DOMAIN.AUTO):
@@ -688,7 +688,7 @@ def fft_convolve1(signal, kernel, conv_mode = CONV_MODE.DEFAULT):
     """
     output = Array()
     safe_call(backend.get().af_fft_convolve1(ct.pointer(output.arr), signal.arr, kernel.arr,
-                                             Enum_value(conv_mode)))
+                                             conv_mode.value))
     return output
 
 def fft_convolve2(signal, kernel, conv_mode = CONV_MODE.DEFAULT):
@@ -732,7 +732,7 @@ def fft_convolve2(signal, kernel, conv_mode = CONV_MODE.DEFAULT):
     """
     output = Array()
     safe_call(backend.get().af_fft_convolve2(ct.pointer(output.arr), signal.arr, kernel.arr,
-                                             Enum_value(conv_mode)))
+                                             conv_mode.value))
     return output
 
 def fft_convolve3(signal, kernel, conv_mode = CONV_MODE.DEFAULT):
@@ -774,7 +774,7 @@ def fft_convolve3(signal, kernel, conv_mode = CONV_MODE.DEFAULT):
     """
     output = Array()
     safe_call(backend.get().af_fft_convolve3(ct.pointer(output.arr), signal.arr, kernel.arr,
-                                             Enum_value(conv_mode)))
+                                             conv_mode.value))
     return output
 
 def fft_convolve(signal, kernel, conv_mode = CONV_MODE.DEFAULT):
diff --git a/arrayfire/util.py b/arrayfire/util.py
index 19be9ad..19e1770 100644
--- a/arrayfire/util.py
+++ b/arrayfire/util.py
@@ -36,12 +36,12 @@ def number_dtype(a):
 
 def implicit_dtype(number, a_dtype):
     n_dtype = number_dtype(number)
-    n_value = Enum_value(n_dtype)
+    n_value = n_dtype.value
 
-    f64v = Enum_value(Dtype.f64)
-    f32v = Enum_value(Dtype.f32)
-    c32v = Enum_value(Dtype.c32)
-    c64v = Enum_value(Dtype.c64)
+    f64v = Dtype.f64.value
+    f32v = Dtype.f32.value
+    c32v = Dtype.c32.value
+    c64v = Dtype.c64.value
 
     if n_value == f64v and (a_dtype == f32v or a_dtype == c32v):
         return Dtype.f32
@@ -68,7 +68,7 @@ def to_str(c_str):
     return str(c_str.value.decode('utf-8'))
 
 def safe_call(af_error):
-    if (af_error != Enum_value(ERR.NONE)):
+    if (af_error != ERR.NONE.value):
         err_str = ct.c_char_p(0)
         err_len = ct.c_longlong(0)
         backend.get().af_get_last_error(ct.pointer(err_str), ct.pointer(err_len))
@@ -81,7 +81,8 @@ def get_version():
     safe_call(backend.get().af_get_version(ct.pointer(major), ct.pointer(minor), ct.pointer(patch)))
     return major,minor,patch
 
-typecodes = ('f', 'F', 'd', 'D', 'b', 'B', 'i', 'I', 'l', 'L')
+typecodes = ['f', 'F', 'd', 'D', 'b', 'B', 'i', 'I', 'l', 'L']
+
 to_dtype = {'f' : Dtype.f32,
             'd' : Dtype.f64,
             'b' : Dtype.b8,
@@ -93,24 +94,24 @@ to_dtype = {'f' : Dtype.f32,
             'F' : Dtype.c32,
             'D' : Dtype.c64}
 
-to_typecode = {Enum_value(Dtype.f32) : 'f',
-               Enum_value(Dtype.f64) : 'd',
-               Enum_value(Dtype.b8 ) : 'b',
-               Enum_value(Dtype.u8 ) : 'B',
-               Enum_value(Dtype.s32) : 'i',
-               Enum_value(Dtype.u32) : 'I',
-               Enum_value(Dtype.s64) : 'l',
-               Enum_value(Dtype.u64) : 'L',
-               Enum_value(Dtype.c32) : 'F',
-               Enum_value(Dtype.c64) : 'D'}
-
-to_c_type = {Enum_value(Dtype.f32) : ct.c_float,
-             Enum_value(Dtype.f64) : ct.c_double,
-             Enum_value(Dtype.b8 ) : ct.c_char,
-             Enum_value(Dtype.u8 ) : ct.c_ubyte,
-             Enum_value(Dtype.s32) : ct.c_int,
-             Enum_value(Dtype.u32) : ct.c_uint,
-             Enum_value(Dtype.s64) : ct.c_longlong,
-             Enum_value(Dtype.u64) : ct.c_ulonglong,
-             Enum_value(Dtype.c32) : ct.c_float * 2,
-             Enum_value(Dtype.c64) : ct.c_double * 2}
+to_typecode = {Dtype.f32.value : 'f',
+               Dtype.f64.value : 'd',
+               Dtype.b8.value : 'b',
+               Dtype.u8.value : 'B',
+               Dtype.s32.value : 'i',
+               Dtype.u32.value : 'I',
+               Dtype.s64.value : 'l',
+               Dtype.u64.value : 'L',
+               Dtype.c32.value : 'F',
+               Dtype.c64.value : 'D'}
+
+to_c_type = {Dtype.f32.value : ct.c_float,
+             Dtype.f64.value : ct.c_double,
+             Dtype.b8.value : ct.c_char,
+             Dtype.u8.value : ct.c_ubyte,
+             Dtype.s32.value : ct.c_int,
+             Dtype.u32.value : ct.c_uint,
+             Dtype.s64.value : ct.c_longlong,
+             Dtype.u64.value : ct.c_ulonglong,
+             Dtype.c32.value : ct.c_float * 2,
+             Dtype.c64.value : ct.c_double * 2}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-arrayfire.git



More information about the debian-science-commits mailing list