[python-arrayfire] 114/250: Removing unnecessary deletes

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 303bea3cd1fb153a9b6c3b8dea7b526ce24bbe5c
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Wed Sep 9 16:46:27 2015 -0400

    Removing unnecessary deletes
    
    - Converted the variables to private variables
---
 arrayfire/__init__.py |  5 -----
 arrayfire/arith.py    | 11 ++++++-----
 arrayfire/array.py    | 17 +++++++++--------
 arrayfire/bcast.py    |  6 +++---
 arrayfire/graphics.py |  3 ++-
 arrayfire/index.py    | 11 ++++++-----
 arrayfire/library.py  | 34 +++++++++++++++-------------------
 arrayfire/util.py     |  4 ++--
 8 files changed, 43 insertions(+), 48 deletions(-)

diff --git a/arrayfire/__init__.py b/arrayfire/__init__.py
index 9ab49fc..e719c13 100644
--- a/arrayfire/__init__.py
+++ b/arrayfire/__init__.py
@@ -58,8 +58,3 @@ del ct
 del inspect
 del numbers
 del os
-
-#do not export internal functions
-del bcast_var
-del is_number
-del safe_call
diff --git a/arrayfire/arith.py b/arrayfire/arith.py
index 1aacc91..cb88644 100644
--- a/arrayfire/arith.py
+++ b/arrayfire/arith.py
@@ -13,7 +13,8 @@ Math functions for ArrayFire
 
 from .library import *
 from .array import *
-from .bcast import *
+from .bcast import _bcast_var
+from .util import _is_number
 
 def _arith_binary_func(lhs, rhs, c_func):
     out = Array()
@@ -25,21 +26,21 @@ def _arith_binary_func(lhs, rhs, c_func):
         raise TypeError("Atleast one input needs to be of type arrayfire.array")
 
     elif (is_left_array and is_right_array):
-        safe_call(c_func(ct.pointer(out.arr), lhs.arr, rhs.arr, bcast_var.get()))
+        safe_call(c_func(ct.pointer(out.arr), lhs.arr, rhs.arr, _bcast_var.get()))
 
-    elif (is_number(rhs)):
+    elif (_is_number(rhs)):
         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], rty)
-        safe_call(c_func(ct.pointer(out.arr), lhs.arr, other.arr, bcast_var.get()))
+        safe_call(c_func(ct.pointer(out.arr), lhs.arr, other.arr, _bcast_var.get()))
 
     else:
         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], lty)
-        safe_call(c_func(ct.pointer(out.arr), other.arr, rhs.arr, bcast_var.get()))
+        safe_call(c_func(ct.pointer(out.arr), other.arr, rhs.arr, _bcast_var.get()))
 
     return out
 
diff --git a/arrayfire/array.py b/arrayfire/array.py
index c4d6681..7b8e28c 100644
--- a/arrayfire/array.py
+++ b/arrayfire/array.py
@@ -14,7 +14,8 @@ arrayfire.Array class and helper functions.
 import inspect
 from .library import *
 from .util import *
-from .bcast import *
+from .util import _is_number
+from .bcast import _bcast_var
 from .base import *
 from .index import *
 from .index import _Index4
@@ -75,7 +76,7 @@ def _binary_func(lhs, rhs, c_func):
     out = Array()
     other = rhs
 
-    if (is_number(rhs)):
+    if (_is_number(rhs)):
         ldims = dim4_to_tuple(lhs.dims())
         rty = implicit_dtype(rhs, lhs.type())
         other = Array()
@@ -83,7 +84,7 @@ def _binary_func(lhs, rhs, c_func):
     elif not isinstance(rhs, Array):
         raise TypeError("Invalid parameter to binary function")
 
-    safe_call(c_func(ct.pointer(out.arr), lhs.arr, other.arr, bcast_var.get()))
+    safe_call(c_func(ct.pointer(out.arr), lhs.arr, other.arr, _bcast_var.get()))
 
     return out
 
@@ -91,7 +92,7 @@ def _binary_funcr(lhs, rhs, c_func):
     out = Array()
     other = lhs
 
-    if (is_number(lhs)):
+    if (_is_number(lhs)):
         rdims = dim4_to_tuple(rhs.dims())
         lty = implicit_dtype(lhs, rhs.type())
         other = Array()
@@ -99,7 +100,7 @@ def _binary_funcr(lhs, rhs, c_func):
     elif not isinstance(lhs, Array):
         raise TypeError("Invalid parameter to binary function")
 
-    c_func(ct.pointer(out.arr), other.arr, rhs.arr, bcast_var.get())
+    c_func(ct.pointer(out.arr), other.arr, rhs.arr, _bcast_var.get())
 
     return out
 
@@ -172,7 +173,7 @@ def _get_assign_dims(key, idims):
     for n in range(len(idims)):
         dims[n] = idims[n]
 
-    if is_number(key):
+    if _is_number(key):
         dims[0] = 1
         return dims
     elif isinstance(key, slice):
@@ -188,7 +189,7 @@ def _get_assign_dims(key, idims):
         n_inds = len(key)
 
         for n in range(n_inds):
-            if (is_number(key[n])):
+            if (_is_number(key[n])):
                 dims[n] = 1
             elif (isinstance(key[n], BaseArray)):
                 dims[n] = key[n].elements()
@@ -891,7 +892,7 @@ class Array(BaseArray):
         try:
             n_dims = self.numdims()
 
-            if (is_number(val)):
+            if (_is_number(val)):
                 tdims = _get_assign_dims(key, self.dims())
                 other_arr = constant_array(val, tdims[0], tdims[1], tdims[2], tdims[3], self.type())
                 del_other = True
diff --git a/arrayfire/bcast.py b/arrayfire/bcast.py
index 9918797..0b81092 100644
--- a/arrayfire/bcast.py
+++ b/arrayfire/bcast.py
@@ -22,7 +22,7 @@ class _bcast(object):
     def toggle(self):
         _bcast._flag ^= True
 
-bcast_var = _bcast()
+_bcast_var = _bcast()
 
 def broadcast(func, *args):
     """
@@ -85,9 +85,9 @@ def broadcast(func, *args):
     """
 
     def wrapper(*func_args):
-        bcast_var.toggle()
+        _bcast_var.toggle()
         res = func(*func_args)
-        bcast_var.toggle()
+        _bcast_var.toggle()
         return res
 
     if len(args) == 0:
diff --git a/arrayfire/graphics.py b/arrayfire/graphics.py
index f2161b1..25f6859 100644
--- a/arrayfire/graphics.py
+++ b/arrayfire/graphics.py
@@ -13,6 +13,7 @@ graphics functions for arrayfire
 
 from .library import *
 from .array import *
+from .util import _is_number
 
 class _Cell(ct.Structure):
     _fields_ = [("row", ct.c_int),
@@ -219,7 +220,7 @@ class Window(object):
             raise IndexError("Window expects indexing along two dimensions")
         if len(keys) != 2:
             raise IndexError("Window expects indexing along two dimensions only")
-        if not (is_number(keys[0]) and is_number(keys[1])):
+        if not (_is_number(keys[0]) and _is_number(keys[1])):
             raise IndexError("Window expects the indices to be numbers")
         self._r = keys[0]
         self._c = keys[1]
diff --git a/arrayfire/index.py b/arrayfire/index.py
index ed7061c..baad324 100644
--- a/arrayfire/index.py
+++ b/arrayfire/index.py
@@ -12,8 +12,9 @@ classes required for indexing operations
 
 from .library import *
 from .util import *
+from .util import _is_number
 from .base import *
-from .bcast import *
+from .bcast import _bcast_var
 import math
 
 class Seq(ct.Structure):
@@ -47,7 +48,7 @@ class Seq(ct.Structure):
         self.end   = ct.c_double(-1)
         self.step  = ct.c_double( 1)
 
-        if is_number(S):
+        if _is_number(S):
             self.begin = ct.c_double(S)
             self.end   = ct.c_double(S)
         elif isinstance(S, slice):
@@ -131,11 +132,11 @@ class ParallelRange(Seq):
         """
         Function called by the iterator in Python 2
         """
-        if bcast_var.get() is True:
-            bcast_var.toggle()
+        if _bcast_var.get() is True:
+            _bcast_var.toggle()
             raise StopIteration
         else:
-            bcast_var.toggle()
+            _bcast_var.toggle()
             return self
 
     def __next__(self):
diff --git a/arrayfire/library.py b/arrayfire/library.py
index 4a85b47..ce833b5 100644
--- a/arrayfire/library.py
+++ b/arrayfire/library.py
@@ -15,11 +15,11 @@ import platform
 import ctypes as ct
 
 try:
-    from enum import Enum
+    from enum import Enum as _Enum
     def _Enum_Type(v):
         return v
 except:
-    class Enum(object):
+    class _Enum(object):
         pass
 
     class _Enum_Type(object):
@@ -84,10 +84,8 @@ class _clibrary(object):
         self.__lock = True
 
 backend = _clibrary()
-del _clibrary
 
-
-class ERR(Enum):
+class ERR(_Enum):
     """
     Error values. For internal use only.
     """
@@ -119,7 +117,7 @@ class ERR(Enum):
     INTERNAL       = _Enum_Type(998)
     UNKNOWN        = _Enum_Type(999)
 
-class Dtype(Enum):
+class Dtype(_Enum):
     """
     Error values. For internal use only.
     """
@@ -134,14 +132,14 @@ class Dtype(Enum):
     s64 = _Enum_Type(8)
     u64 = _Enum_Type(9)
 
-class Source(Enum):
+class Source(_Enum):
     """
     Source of the pointer
     """
     device = _Enum_Type(0)
     host   = _Enum_Type(1)
 
-class INTERP(Enum):
+class INTERP(_Enum):
     """
     Interpolation method
     """
@@ -150,28 +148,28 @@ class INTERP(Enum):
     BILINEAR  = _Enum_Type(2)
     CUBIC     = _Enum_Type(3)
 
-class PAD(Enum):
+class PAD(_Enum):
     """
     Edge padding types
     """
     ZERO = _Enum_Type(0)
     SYM  = _Enum_Type(1)
 
-class CONNECTIVITY(Enum):
+class CONNECTIVITY(_Enum):
     """
     Neighborhood connectivity
     """
     FOUR  = _Enum_Type(4)
     EIGHT = _Enum_Type(8)
 
-class CONV_MODE(Enum):
+class CONV_MODE(_Enum):
     """
     Convolution mode
     """
     DEFAULT = _Enum_Type(0)
     EXPAND  = _Enum_Type(1)
 
-class CONV_DOMAIN(Enum):
+class CONV_DOMAIN(_Enum):
     """
     Convolution domain
     """
@@ -179,7 +177,7 @@ class CONV_DOMAIN(Enum):
     SPATIAL = _Enum_Type(1)
     FREQ    = _Enum_Type(2)
 
-class MATCH(Enum):
+class MATCH(_Enum):
     """
     Match type
     """
@@ -229,7 +227,7 @@ class MATCH(Enum):
     """
     SHD  = _Enum_Type(8)
 
-class CSPACE(Enum):
+class CSPACE(_Enum):
     """
     Colorspace formats
     """
@@ -237,7 +235,7 @@ class CSPACE(Enum):
     RGB  = _Enum_Type(1)
     HSV  = _Enum_Type(2)
 
-class MATPROP(Enum):
+class MATPROP(_Enum):
     """
     Matrix properties
     """
@@ -297,7 +295,7 @@ class MATPROP(Enum):
     """
     BLOCK_DIAG = _Enum_Type(8192)
 
-class NORM(Enum):
+class NORM(_Enum):
     """
     Norm types
     """
@@ -311,7 +309,7 @@ class NORM(Enum):
     MATRIX_L_PQ = _Enum_Type(7)
     EUCLID      = VECTOR_2
 
-class COLORMAP(Enum):
+class COLORMAP(_Enum):
     """
     Colormaps
     """
@@ -322,5 +320,3 @@ class COLORMAP(Enum):
     MOOD     = _Enum_Type(4)
     HEAT     = _Enum_Type(5)
     BLUE     = _Enum_Type(6)
-
-del Enum
diff --git a/arrayfire/util.py b/arrayfire/util.py
index 19e1770..26a8b48 100644
--- a/arrayfire/util.py
+++ b/arrayfire/util.py
@@ -19,7 +19,7 @@ def dim4(d0=1, d1=1, d2=1, d3=1):
 
     return out
 
-def is_number(a):
+def _is_number(a):
     return isinstance(a, numbers.Number)
 
 def number_dtype(a):
@@ -55,7 +55,7 @@ def dim4_to_tuple(dims, default=1):
     assert(isinstance(dims, tuple))
 
     if (default is not None):
-        assert(is_number(default))
+        assert(_is_number(default))
 
     out = [default]*4
 

-- 
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