[python-arrayfire] 89/250: Syle changes and converting util functions to be private
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Mar 28 22:59:35 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 82d8282384202759650e4e92e8aae77899c51226
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date: Tue Sep 1 14:45:58 2015 -0400
Syle changes and converting util functions to be private
---
arrayfire/__init__.py | 26 +------------
arrayfire/algorithm.py | 42 ++++++++++----------
arrayfire/arith.py | 104 ++++++++++++++++++++++++-------------------------
arrayfire/array.py | 103 ++++++++++++++++++++++++------------------------
arrayfire/blas.py | 10 ++---
arrayfire/data.py | 4 +-
arrayfire/device.py | 4 +-
arrayfire/graphics.py | 14 +++----
arrayfire/image.py | 38 +++++++++---------
arrayfire/index.py | 16 ++++----
arrayfire/library.py | 6 +--
arrayfire/signal.py | 16 ++++----
arrayfire/util.py | 2 +-
arrayfire/vision.py | 12 +++---
14 files changed, 187 insertions(+), 210 deletions(-)
diff --git a/arrayfire/__init__.py b/arrayfire/__init__.py
index 9ac5a67..0f78ed4 100644
--- a/arrayfire/__init__.py
+++ b/arrayfire/__init__.py
@@ -31,31 +31,7 @@ del inspect
del numbers
del os
-#do not export internal classes
-del BaseArray
-del uidx
-del Seq
-del Index
-del Cell
-del bcast
-
#do not export internal functions
-del binary_func
-del binary_funcr
-del create_array
-del constant_array
-del parallel_dim
-del reduce_all
-del arith_unary_func
-del arith_binary_func
-del brange
-del dim4_tuple
+del bcast
del is_number
-del to_str
del safe_call
-del get_indices
-del get_assign_dims
-del slice_to_length
-del ctype_to_lists
-del to_dtype
-del to_c_type
diff --git a/arrayfire/algorithm.py b/arrayfire/algorithm.py
index fbe3e20..43f22fc 100644
--- a/arrayfire/algorithm.py
+++ b/arrayfire/algorithm.py
@@ -10,12 +10,12 @@
from .library import *
from .array import *
-def parallel_dim(a, dim, c_func):
+def _parallel_dim(a, dim, c_func):
out = Array()
safe_call(c_func(ct.pointer(out.arr), a.arr, ct.c_int(dim)))
return out
-def reduce_all(a, c_func):
+def _reduce_all(a, c_func):
real = ct.c_double(0)
imag = ct.c_double(0)
safe_call(c_func(ct.pointer(real), ct.pointer(imag), a.arr))
@@ -25,45 +25,45 @@ def reduce_all(a, c_func):
def sum(a, dim=None):
if dim is not None:
- return parallel_dim(a, dim, backend.get().af_sum)
+ return _parallel_dim(a, dim, backend.get().af_sum)
else:
- return reduce_all(a, backend.get().af_sum_all)
+ return _reduce_all(a, backend.get().af_sum_all)
def product(a, dim=None):
if dim is not None:
- return parallel_dim(a, dim, backend.get().af_product)
+ return _parallel_dim(a, dim, backend.get().af_product)
else:
- return reduce_all(a, backend.get().af_product_all)
+ return _reduce_all(a, backend.get().af_product_all)
def min(a, dim=None):
if dim is not None:
- return parallel_dim(a, dim, backend.get().af_min)
+ return _parallel_dim(a, dim, backend.get().af_min)
else:
- return reduce_all(a, backend.get().af_min_all)
+ return _reduce_all(a, backend.get().af_min_all)
def max(a, dim=None):
if dim is not None:
- return parallel_dim(a, dim, backend.get().af_max)
+ return _parallel_dim(a, dim, backend.get().af_max)
else:
- return reduce_all(a, backend.get().af_max_all)
+ return _reduce_all(a, backend.get().af_max_all)
def all_true(a, dim=None):
if dim is not None:
- return parallel_dim(a, dim, backend.get().af_all_true)
+ return _parallel_dim(a, dim, backend.get().af_all_true)
else:
- return reduce_all(a, backend.get().af_all_true_all)
+ return _reduce_all(a, backend.get().af_all_true_all)
def any_true(a, dim=None):
if dim is not None:
- return parallel_dim(a, dim, backend.get().af_any_true)
+ return _parallel_dim(a, dim, backend.get().af_any_true)
else:
- return reduce_all(a, backend.get().af_any_true_all)
+ return _reduce_all(a, backend.get().af_any_true_all)
def count(a, dim=None):
if dim is not None:
- return parallel_dim(a, dim, backend.get().af_count)
+ return _parallel_dim(a, dim, backend.get().af_count)
else:
- return reduce_all(a, backend.get().af_count_all)
+ return _reduce_all(a, backend.get().af_count_all)
def imin(a, dim=None):
if dim is not None:
@@ -99,7 +99,7 @@ def imax(a, dim=None):
def accum(a, dim=0):
- return parallel_dim(a, dim, backend.get().af_accum)
+ return _parallel_dim(a, dim, backend.get().af_accum)
def where(a):
out = Array()
@@ -107,10 +107,10 @@ def where(a):
return out
def diff1(a, dim=0):
- return parallel_dim(a, dim, backend.get().af_diff1)
+ return _parallel_dim(a, dim, backend.get().af_diff1)
def diff2(a, dim=0):
- return parallel_dim(a, dim, backend.get().af_diff2)
+ return _parallel_dim(a, dim, backend.get().af_diff2)
def sort(a, dim=0, is_ascending=True):
out = Array()
@@ -121,14 +121,14 @@ def sort_index(a, dim=0, is_ascending=True):
out = Array()
idx = Array()
safe_call(backend.get().af_sort_index(ct.pointer(out.arr), ct.pointer(idx.arr), a.arr,
- ct.c_uint(dim), ct.c_bool(is_ascending)))
+ ct.c_uint(dim), ct.c_bool(is_ascending)))
return out,idx
def sort_by_key(iv, ik, dim=0, is_ascending=True):
ov = Array()
ok = Array()
safe_call(backend.get().af_sort_by_key(ct.pointer(ov.arr), ct.pointer(ok.arr),
- iv.arr, ik.arr, ct.c_uint(dim), ct.c_bool(is_ascending)))
+ iv.arr, ik.arr, ct.c_uint(dim), ct.c_bool(is_ascending)))
return ov,ok
def set_unique(a, is_sorted=False):
diff --git a/arrayfire/arith.py b/arrayfire/arith.py
index 2e88f77..4fca5a8 100644
--- a/arrayfire/arith.py
+++ b/arrayfire/arith.py
@@ -11,7 +11,7 @@ from .library import *
from .array import *
from .broadcast import *
-def arith_binary_func(lhs, rhs, c_func):
+def _arith_binary_func(lhs, rhs, c_func):
out = Array()
is_left_array = isinstance(lhs, Array)
@@ -24,14 +24,14 @@ def arith_binary_func(lhs, rhs, c_func):
safe_call(c_func(ct.pointer(out.arr), lhs.arr, rhs.arr, bcast.get()))
elif (is_number(rhs)):
- ldims = dim4_tuple(lhs.dims())
+ 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.get()))
else:
- rdims = dim4_tuple(rhs.dims())
+ 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)
@@ -39,7 +39,7 @@ def arith_binary_func(lhs, rhs, c_func):
return out
-def arith_unary_func(a, c_func):
+def _arith_unary_func(a, c_func):
out = Array()
safe_call(c_func(ct.pointer(out.arr), a.arr))
return out
@@ -50,145 +50,145 @@ def cast(a, dtype=f32):
return out
def minof(lhs, rhs):
- return arith_binary_func(lhs, rhs, backend.get().af_minof)
+ return _arith_binary_func(lhs, rhs, backend.get().af_minof)
def maxof(lhs, rhs):
- return arith_binary_func(lhs, rhs, backend.get().af_maxof)
+ return _arith_binary_func(lhs, rhs, backend.get().af_maxof)
def rem(lhs, rhs):
- return arith_binary_func(lhs, rhs, backend.get().af_rem)
+ return _arith_binary_func(lhs, rhs, backend.get().af_rem)
def abs(a):
- return arith_unary_func(a, backend.get().af_abs)
+ return _arith_unary_func(a, backend.get().af_abs)
def arg(a):
- return arith_unary_func(a, backend.get().af_arg)
+ return _arith_unary_func(a, backend.get().af_arg)
def sign(a):
- return arith_unary_func(a, backend.get().af_sign)
+ return _arith_unary_func(a, backend.get().af_sign)
def round(a):
- return arith_unary_func(a, backend.get().af_round)
+ return _arith_unary_func(a, backend.get().af_round)
def trunc(a):
- return arith_unary_func(a, backend.get().af_trunc)
+ return _arith_unary_func(a, backend.get().af_trunc)
def floor(a):
- return arith_unary_func(a, backend.get().af_floor)
+ return _arith_unary_func(a, backend.get().af_floor)
def ceil(a):
- return arith_unary_func(a, backend.get().af_ceil)
+ return _arith_unary_func(a, backend.get().af_ceil)
def hypot(lhs, rhs):
- return arith_binary_func(lhs, rhs, backend.get().af_hypot)
+ return _arith_binary_func(lhs, rhs, backend.get().af_hypot)
def sin(a):
- return arith_unary_func(a, backend.get().af_sin)
+ return _arith_unary_func(a, backend.get().af_sin)
def cos(a):
- return arith_unary_func(a, backend.get().af_cos)
+ return _arith_unary_func(a, backend.get().af_cos)
def tan(a):
- return arith_unary_func(a, backend.get().af_tan)
+ return _arith_unary_func(a, backend.get().af_tan)
def asin(a):
- return arith_unary_func(a, backend.get().af_asin)
+ return _arith_unary_func(a, backend.get().af_asin)
def acos(a):
- return arith_unary_func(a, backend.get().af_acos)
+ return _arith_unary_func(a, backend.get().af_acos)
def atan(a):
- return arith_unary_func(a, backend.get().af_atan)
+ return _arith_unary_func(a, backend.get().af_atan)
def atan2(lhs, rhs):
- return arith_binary_func(lhs, rhs, backend.get().af_atan2)
+ return _arith_binary_func(lhs, rhs, backend.get().af_atan2)
def cplx(lhs, rhs=None):
if rhs is None:
- return arith_unary_func(lhs, backend.get().af_cplx)
+ return _arith_unary_func(lhs, backend.get().af_cplx)
else:
- return arith_binary_func(lhs, rhs, backend.get().af_cplx2)
+ return _arith_binary_func(lhs, rhs, backend.get().af_cplx2)
def real(lhs):
- return arith_unary_func(lhs, backend.get().af_real)
+ return _arith_unary_func(lhs, backend.get().af_real)
def imag(lhs):
- return arith_unary_func(lhs, backend.get().af_imag)
+ return _arith_unary_func(lhs, backend.get().af_imag)
def conjg(lhs):
- return arith_unary_func(lhs, backend.get().af_conjg)
+ return _arith_unary_func(lhs, backend.get().af_conjg)
def sinh(a):
- return arith_unary_func(a, backend.get().af_sinh)
+ return _arith_unary_func(a, backend.get().af_sinh)
def cosh(a):
- return arith_unary_func(a, backend.get().af_cosh)
+ return _arith_unary_func(a, backend.get().af_cosh)
def tanh(a):
- return arith_unary_func(a, backend.get().af_tanh)
+ return _arith_unary_func(a, backend.get().af_tanh)
def asinh(a):
- return arith_unary_func(a, backend.get().af_asinh)
+ return _arith_unary_func(a, backend.get().af_asinh)
def acosh(a):
- return arith_unary_func(a, backend.get().af_acosh)
+ return _arith_unary_func(a, backend.get().af_acosh)
def atanh(a):
- return arith_unary_func(a, backend.get().af_atanh)
+ return _arith_unary_func(a, backend.get().af_atanh)
def root(lhs, rhs):
- return arith_binary_func(lhs, rhs, backend.get().af_root)
+ return _arith_binary_func(lhs, rhs, backend.get().af_root)
def pow(lhs, rhs):
- return arith_binary_func(lhs, rhs, backend.get().af_pow)
+ return _arith_binary_func(lhs, rhs, backend.get().af_pow)
def pow2(a):
- return arith_unary_func(a, backend.get().af_pow2)
+ return _arith_unary_func(a, backend.get().af_pow2)
def exp(a):
- return arith_unary_func(a, backend.get().af_exp)
+ return _arith_unary_func(a, backend.get().af_exp)
def expm1(a):
- return arith_unary_func(a, backend.get().af_expm1)
+ return _arith_unary_func(a, backend.get().af_expm1)
def erf(a):
- return arith_unary_func(a, backend.get().af_erf)
+ return _arith_unary_func(a, backend.get().af_erf)
def erfc(a):
- return arith_unary_func(a, backend.get().af_erfc)
+ return _arith_unary_func(a, backend.get().af_erfc)
def log(a):
- return arith_unary_func(a, backend.get().af_log)
+ return _arith_unary_func(a, backend.get().af_log)
def log1p(a):
- return arith_unary_func(a, backend.get().af_log1p)
+ return _arith_unary_func(a, backend.get().af_log1p)
def log10(a):
- return arith_unary_func(a, backend.get().af_log10)
+ return _arith_unary_func(a, backend.get().af_log10)
def log2(a):
- return arith_unary_func(a, backend.get().af_log2)
+ return _arith_unary_func(a, backend.get().af_log2)
def sqrt(a):
- return arith_unary_func(a, backend.get().af_sqrt)
+ return _arith_unary_func(a, backend.get().af_sqrt)
def cbrt(a):
- return arith_unary_func(a, backend.get().af_cbrt)
+ return _arith_unary_func(a, backend.get().af_cbrt)
def factorial(a):
- return arith_unary_func(a, backend.get().af_factorial)
+ return _arith_unary_func(a, backend.get().af_factorial)
def tgamma(a):
- return arith_unary_func(a, backend.get().af_tgamma)
+ return _arith_unary_func(a, backend.get().af_tgamma)
def lgamma(a):
- return arith_unary_func(a, backend.get().af_lgamma)
+ return _arith_unary_func(a, backend.get().af_lgamma)
def iszero(a):
- return arith_unary_func(a, backend.get().af_iszero)
+ return _arith_unary_func(a, backend.get().af_iszero)
def isinf(a):
- return arith_unary_func(a, backend.get().af_isinf)
+ return _arith_unary_func(a, backend.get().af_isinf)
def isnan(a):
- return arith_unary_func(a, backend.get().af_isnan)
+ return _arith_unary_func(a, backend.get().af_isnan)
diff --git a/arrayfire/array.py b/arrayfire/array.py
index 81ff5e3..a2038e4 100644
--- a/arrayfire/array.py
+++ b/arrayfire/array.py
@@ -14,7 +14,7 @@ from .broadcast import *
from .base import *
from .index import *
-def create_array(buf, numdims, idims, dtype):
+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),
@@ -54,12 +54,12 @@ def constant_array(val, d0, d1=None, d2=None, d3=None, dtype=f32):
return out
-def binary_func(lhs, rhs, c_func):
+def _binary_func(lhs, rhs, c_func):
out = Array()
other = rhs
if (is_number(rhs)):
- ldims = dim4_tuple(lhs.dims())
+ 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)
@@ -70,12 +70,12 @@ def binary_func(lhs, rhs, c_func):
return out
-def binary_funcr(lhs, rhs, c_func):
+def _binary_funcr(lhs, rhs, c_func):
out = Array()
other = lhs
if (is_number(lhs)):
- rdims = dim4_tuple(rhs.dims())
+ 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)
@@ -94,18 +94,18 @@ def transpose(a, conj=False):
def transpose_inplace(a, conj=False):
safe_call(backend.get().af_transpose_inplace(a.arr, conj))
-def ctype_to_lists(ctype_arr, dim, shape, offset=0):
+def _ctype_to_lists(ctype_arr, dim, shape, offset=0):
if (dim == 0):
return list(ctype_arr[offset : offset + shape[0]])
else:
dim_len = shape[dim]
res = [[]] * dim_len
for n in range(dim_len):
- res[n] = ctype_to_lists(ctype_arr, dim - 1, shape, offset)
+ res[n] = _ctype_to_lists(ctype_arr, dim - 1, shape, offset)
offset += shape[0]
return res
-def get_info(dims, buf_len):
+def _get_info(dims, buf_len):
elements = 1
numdims = len(dims)
idims = [1]*4
@@ -148,15 +148,15 @@ class Array(BaseArray):
if isinstance(src, host.array):
buf,buf_len = src.buffer_info()
_type_char = src.typecode
- numdims, idims = get_info(dims, buf_len)
+ numdims, idims = _get_info(dims, buf_len)
elif isinstance(src, list):
tmp = host.array('f', src)
buf,buf_len = tmp.buffer_info()
_type_char = tmp.typecode
- numdims, idims = get_info(dims, buf_len)
+ numdims, idims = _get_info(dims, buf_len)
elif isinstance(src, int) or isinstance(src, ct.c_ulonglong):
buf = src
- numdims, idims = get_info(dims, buf_len)
+ numdims, idims = _get_info(dims, buf_len)
elements = 1
for dim in idims:
@@ -177,7 +177,7 @@ class Array(BaseArray):
type_char != _type_char):
raise TypeError("Can not create array of requested type from input data type")
- self.arr = create_array(buf, numdims, idims, to_dtype[_type_char])
+ self.arr = _create_array(buf, numdims, idims, to_dtype[_type_char])
def copy(self):
out = Array()
@@ -287,128 +287,127 @@ class Array(BaseArray):
return res.value
def __add__(self, other):
- return binary_func(self, other, backend.get().af_add)
+ return _binary_func(self, other, backend.get().af_add)
def __iadd__(self, other):
- self = binary_func(self, other, backend.get().af_add)
+ self = _binary_func(self, other, backend.get().af_add)
return self
def __radd__(self, other):
- return binary_funcr(other, self, backend.get().af_add)
+ return _binary_funcr(other, self, backend.get().af_add)
def __sub__(self, other):
- return binary_func(self, other, backend.get().af_sub)
+ return _binary_func(self, other, backend.get().af_sub)
def __isub__(self, other):
- self = binary_func(self, other, backend.get().af_sub)
+ self = _binary_func(self, other, backend.get().af_sub)
return self
def __rsub__(self, other):
- return binary_funcr(other, self, backend.get().af_sub)
+ return _binary_funcr(other, self, backend.get().af_sub)
def __mul__(self, other):
- return binary_func(self, other, backend.get().af_mul)
+ return _binary_func(self, other, backend.get().af_mul)
def __imul__(self, other):
- self = binary_func(self, other, backend.get().af_mul)
+ self = _binary_func(self, other, backend.get().af_mul)
return self
def __rmul__(self, other):
- return binary_funcr(other, self, backend.get().af_mul)
+ return _binary_funcr(other, self, backend.get().af_mul)
# Necessary for python3
def __truediv__(self, other):
- return binary_func(self, other, backend.get().af_div)
+ return _binary_func(self, other, backend.get().af_div)
def __itruediv__(self, other):
- self = binary_func(self, other, backend.get().af_div)
+ self = _binary_func(self, other, backend.get().af_div)
return self
def __rtruediv__(self, other):
- return binary_funcr(other, self, backend.get().af_div)
+ return _binary_funcr(other, self, backend.get().af_div)
- # Necessary for python2
def __div__(self, other):
- return binary_func(self, other, backend.get().af_div)
+ return _binary_func(self, other, backend.get().af_div)
def __idiv__(self, other):
- self = binary_func(self, other, backend.get().af_div)
+ self = _binary_func(self, other, backend.get().af_div)
return self
def __rdiv__(self, other):
- return binary_funcr(other, self, backend.get().af_div)
+ return _binary_funcr(other, self, backend.get().af_div)
def __mod__(self, other):
- return binary_func(self, other, backend.get().af_mod)
+ return _binary_func(self, other, backend.get().af_mod)
def __imod__(self, other):
- self = binary_func(self, other, backend.get().af_mod)
+ self = _binary_func(self, other, backend.get().af_mod)
return self
def __rmod__(self, other):
- return binary_funcr(other, self, backend.get().af_mod)
+ return _binary_funcr(other, self, backend.get().af_mod)
def __pow__(self, other):
- return binary_func(self, other, backend.get().af_pow)
+ return _binary_func(self, other, backend.get().af_pow)
def __ipow__(self, other):
- self = binary_func(self, other, backend.get().af_pow)
+ self = _binary_func(self, other, backend.get().af_pow)
return self
def __rpow__(self, other):
- return binary_funcr(other, self, backend.get().af_pow)
+ return _binary_funcr(other, self, backend.get().af_pow)
def __lt__(self, other):
- return binary_func(self, other, backend.get().af_lt)
+ return _binary_func(self, other, backend.get().af_lt)
def __gt__(self, other):
- return binary_func(self, other, backend.get().af_gt)
+ return _binary_func(self, other, backend.get().af_gt)
def __le__(self, other):
- return binary_func(self, other, backend.get().af_le)
+ return _binary_func(self, other, backend.get().af_le)
def __ge__(self, other):
- return binary_func(self, other, backend.get().af_ge)
+ return _binary_func(self, other, backend.get().af_ge)
def __eq__(self, other):
- return binary_func(self, other, backend.get().af_eq)
+ return _binary_func(self, other, backend.get().af_eq)
def __ne__(self, other):
- return binary_func(self, other, backend.get().af_neq)
+ return _binary_func(self, other, backend.get().af_neq)
def __and__(self, other):
- return binary_func(self, other, backend.get().af_bitand)
+ return _binary_func(self, other, backend.get().af_bitand)
def __iand__(self, other):
- self = binary_func(self, other, backend.get().af_bitand)
+ self = _binary_func(self, other, backend.get().af_bitand)
return self
def __or__(self, other):
- return binary_func(self, other, backend.get().af_bitor)
+ return _binary_func(self, other, backend.get().af_bitor)
def __ior__(self, other):
- self = binary_func(self, other, backend.get().af_bitor)
+ self = _binary_func(self, other, backend.get().af_bitor)
return self
def __xor__(self, other):
- return binary_func(self, other, backend.get().af_bitxor)
+ return _binary_func(self, other, backend.get().af_bitxor)
def __ixor__(self, other):
- self = binary_func(self, other, backend.get().af_bitxor)
+ self = _binary_func(self, other, backend.get().af_bitxor)
return self
def __lshift__(self, other):
- return binary_func(self, other, backend.get().af_bitshiftl)
+ return _binary_func(self, other, backend.get().af_bitshiftl)
def __ilshift__(self, other):
- self = binary_func(self, other, backend.get().af_bitshiftl)
+ self = _binary_func(self, other, backend.get().af_bitshiftl)
return self
def __rshift__(self, other):
- return binary_func(self, other, backend.get().af_bitshiftr)
+ return _binary_func(self, other, backend.get().af_bitshiftr)
def __irshift__(self, other):
- self = binary_func(self, other, backend.get().af_bitshiftr)
+ self = _binary_func(self, other, backend.get().af_bitshiftr)
return self
def __neg__(self):
@@ -493,7 +492,7 @@ class Array(BaseArray):
def to_list(self, row_major=False):
ct_array, shape = self.to_ctype(row_major, True)
- return ctype_to_lists(ct_array, len(shape) - 1, shape)
+ return _ctype_to_lists(ct_array, len(shape) - 1, shape)
def __repr__(self):
# Having __repr__ directly print things is a bad idea
@@ -512,3 +511,5 @@ def display(a):
if (expr is not None):
print('%s' % expr[0].split('display(')[1][:-2])
safe_call(backend.get().af_print_array(a.arr))
+
+del BaseArray
diff --git a/arrayfire/blas.py b/arrayfire/blas.py
index d51fa12..29a8f93 100644
--- a/arrayfire/blas.py
+++ b/arrayfire/blas.py
@@ -13,29 +13,29 @@ from .array import *
def matmul(lhs, rhs, lhs_opts=AF_MAT_NONE, rhs_opts=AF_MAT_NONE):
out = Array()
safe_call(backend.get().af_matmul(ct.pointer(out.arr), lhs.arr, rhs.arr,
- lhs_opts, rhs_opts))
+ lhs_opts, rhs_opts))
return out
def matmulTN(lhs, rhs):
out = Array()
safe_call(backend.get().af_matmul(ct.pointer(out.arr), lhs.arr, rhs.arr,
- AF_MAT_TRANS, AF_MAT_NONE))
+ AF_MAT_TRANS, AF_MAT_NONE))
return out
def matmulNT(lhs, rhs):
out = Array()
safe_call(backend.get().af_matmul(ct.pointer(out.arr), lhs.arr, rhs.arr,
- AF_MAT_NONE, AF_MAT_TRANS))
+ AF_MAT_NONE, AF_MAT_TRANS))
return out
def matmulTT(lhs, rhs):
out = Array()
safe_call(backend.get().af_matmul(ct.pointer(out.arr), lhs.arr, rhs.arr,
- AF_MAT_TRANS, AF_MAT_TRANS))
+ AF_MAT_TRANS, AF_MAT_TRANS))
return out
def dot(lhs, rhs, lhs_opts=AF_MAT_NONE, rhs_opts=AF_MAT_NONE):
out = Array()
safe_call(backend.get().af_dot(ct.pointer(out.arr), lhs.arr, rhs.arr,
- lhs_opts, rhs_opts))
+ lhs_opts, rhs_opts))
return out
diff --git a/arrayfire/data.py b/arrayfire/data.py
index 94f88a2..04c143b 100644
--- a/arrayfire/data.py
+++ b/arrayfire/data.py
@@ -18,7 +18,7 @@ def constant(val, d0, d1=None, d2=None, d3=None, dtype=f32):
return out
# Store builtin range function to be used later
-brange = range
+_brange = range
def range(d0, d1=None, d2=None, d3=None, dim=-1, dtype=f32):
@@ -47,7 +47,7 @@ def iota(d0, d1=None, d2=None, d3=None, dim=-1, tile_dims=None, dtype=f32):
td=[1]*4
if tile_dims is not None:
- for i in brange(len(tile_dims)):
+ for i in _brange(len(tile_dims)):
td[i] = tile_dims[i]
tdims = dim4(td[0], td[1], td[2], td[3])
diff --git a/arrayfire/device.py b/arrayfire/device.py
index 4072236..28961a6 100644
--- a/arrayfire/device.py
+++ b/arrayfire/device.py
@@ -21,7 +21,7 @@ def device_info():
compute = c_char_256()
safe_call(backend.get().af_device_info(ct.pointer(device_name), ct.pointer(backend_name),
- ct.pointer(toolkit), ct.pointer(compute)))
+ ct.pointer(toolkit), ct.pointer(compute)))
dev_info = {}
dev_info['device'] = to_str(device_name)
dev_info['backend'] = to_str(backend_name)
@@ -59,7 +59,7 @@ def device_mem_info():
lock_bytes = ct.c_size_t(0)
lock_buffers = ct.c_size_t(0)
safe_call(backend.get().af_device_mem_info(ct.pointer(alloc_bytes), ct.pointer(alloc_buffers),
- ct.pointer(lock_bytes), ct.pointer(lock_buffers)))
+ ct.pointer(lock_bytes), ct.pointer(lock_buffers)))
mem_info = {}
mem_info['alloc'] = {'buffers' : alloc_buffers.value, 'bytes' : alloc_bytes.value}
mem_info['lock'] = {'buffers' : lock_buffers.value, 'bytes' : lock_bytes.value}
diff --git a/arrayfire/graphics.py b/arrayfire/graphics.py
index 2777311..5b66a14 100644
--- a/arrayfire/graphics.py
+++ b/arrayfire/graphics.py
@@ -10,7 +10,7 @@
from .library import *
from .array import *
-class Cell(ct.Structure):
+class _Cell(ct.Structure):
_fields_ = [("row", ct.c_int),
("col", ct.c_int),
("title", ct.c_char_p),
@@ -37,7 +37,7 @@ class window(object):
_title = _title.encode("ascii")
safe_call(backend.get().af_create_window(ct.pointer(self._wnd),
- ct.c_int(_width), ct.c_int(_height), ct.c_char_p(_title)))
+ ct.c_int(_width), ct.c_int(_height), ct.c_char_p(_title)))
def __del__(self):
safe_call(backend.get().af_destroy_window(self._wnd))
@@ -52,18 +52,18 @@ class window(object):
self._cmap = cmap
def image(self, img, title=None):
- _cell = Cell(self._r, self._c, title, self._cmap)
+ _cell = _Cell(self._r, self._c, title, self._cmap)
safe_call(backend.get().af_draw_image(self._wnd, img.arr, ct.pointer(_cell)))
def plot(self, X, Y, title=None):
- _cell = Cell(self._r, self._c, title, self._cmap)
+ _cell = _Cell(self._r, self._c, title, self._cmap)
safe_call(backend.get().af_draw_plot(self._wnd, X.arr, Y.arr, ct.pointer(_cell)))
def hist(self, X, min_val, max_val, title=None):
- _cell = Cell(self._r, self._c, title, self._cmap)
+ _cell = _Cell(self._r, self._c, title, self._cmap)
safe_call(backend.get().af_draw_hist(self._wnd, X.arr,
- ct.c_double(max_val), ct.c_double(min_val),
- ct.pointer(_cell)))
+ ct.c_double(max_val), ct.c_double(min_val),
+ ct.pointer(_cell)))
def grid(rows, cols):
safe_call(af_grid(self._wnd, ct.c_int(rows), ct.c_int(cols)))
diff --git a/arrayfire/image.py b/arrayfire/image.py
index 0d4a327..6b3415f 100644
--- a/arrayfire/image.py
+++ b/arrayfire/image.py
@@ -22,7 +22,7 @@ def load_image(file_name, is_color=False):
assert(os.path.isfile(file_name))
image = Array()
safe_call(backend.get().af_load_image(ct.pointer(image.arr),
- ct.c_char_p(file_name.encode('ascii')), is_color))
+ ct.c_char_p(file_name.encode('ascii')), is_color))
return image
def save_image(image, file_name):
@@ -42,15 +42,15 @@ def resize(image, scale=None, odim0=None, odim1=None, method=AF_INTERP_NEAREST):
output = Array()
safe_call(backend.get().af_resize(ct.pointer(output.arr),
- image.arr, ct.c_longlong(odim0), ct.c_longlong(odim1), method))
+ image.arr, ct.c_longlong(odim0), ct.c_longlong(odim1), method))
return output
def transform(image, transform, odim0 = 0, odim1 = 0, method=AF_INTERP_NEAREST, is_inverse=True):
output = Array()
safe_call(backend.get().af_transform(ct.pointer(output.arr),
- image.arr, transform.arr,
- ct.c_longlong(odim0), ct.c_longlong(odim1), method, is_inverse))
+ image.arr, transform.arr,
+ ct.c_longlong(odim0), ct.c_longlong(odim1), method, is_inverse))
return output
def rotate(image, theta, is_crop = True, method = AF_INTERP_NEAREST):
@@ -61,21 +61,21 @@ def rotate(image, theta, is_crop = True, method = AF_INTERP_NEAREST):
def translate(image, trans0, trans1, odim0 = 0, odim1 = 0, method = AF_INTERP_NEAREST):
output = Array()
safe_call(backend.get().af_translate(ct.pointer(output.arr),
- image.arr, trans0, trans1, ct.c_longlong(odim0), ct.c_longlong(odim1), method))
+ image.arr, trans0, trans1, ct.c_longlong(odim0), ct.c_longlong(odim1), method))
return output
def scale(image, scale0, scale1, odim0 = 0, odim1 = 0, method = AF_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), method))
+ image.arr, ct.c_double(scale0), ct.c_double(scale1),
+ ct.c_longlong(odim0), ct.c_longlong(odim1), method))
return output
def skew(image, skew0, skew1, odim0 = 0, odim1 = 0, method = AF_INTERP_NEAREST, is_inverse=True):
output = Array()
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), method, is_inverse))
+ image.arr, ct.c_double(skew0), ct.c_double(skew1),
+ ct.c_longlong(odim0), ct.c_longlong(odim1), method, is_inverse))
return output
@@ -91,7 +91,7 @@ def histogram(image, nbins, min_val = None, max_val = None):
output = Array()
safe_call(backend.get().af_histogram(ct.pointer(output.arr),
- image.arr, ct.c_uint(nbins), ct.c_double(min_val), ct.c_double(max_val)))
+ image.arr, ct.c_uint(nbins), ct.c_double(min_val), ct.c_double(max_val)))
return output
def hist_equal(image, hist):
@@ -142,32 +142,32 @@ def erode3(image, mask = None):
def bilateral(image, s_sigma, c_sigma, is_color = False):
output = Array()
safe_call(backend.get().af_bilateral(ct.pointer(output.arr),
- image.arr, ct.c_double(s_sigma), ct.c_double(c_sigma), is_color))
+ image.arr, ct.c_double(s_sigma), ct.c_double(c_sigma), is_color))
return output
def mean_shift(image, s_sigma, c_sigma, n_iter, is_color = False):
output = Array()
safe_call(backend.get().af_mean_shift(ct.pointer(output.arr),
- image.arr, ct.c_double(s_sigma), ct.c_double(c_sigma),
- ct.c_uint(n_iter), is_color))
+ image.arr, ct.c_double(s_sigma), ct.c_double(c_sigma),
+ ct.c_uint(n_iter), is_color))
return output
def medfilt(image, w_len = 3, w_wid = 3, edge_pad = AF_PAD_ZERO):
output = Array()
safe_call(backend.get().af_medfilt(ct.pointer(output.arr),
- image.arr, ct.c_longlong(w_len), ct.c_longlong(w_wid), edge_pad))
+ image.arr, ct.c_longlong(w_len), ct.c_longlong(w_wid), edge_pad))
return output
def minfilt(image, w_len = 3, w_wid = 3, edge_pad = AF_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), edge_pad))
+ image.arr, ct.c_longlong(w_len), ct.c_longlong(w_wid), edge_pad))
return output
def maxfilt(image, w_len = 3, w_wid = 3, edge_pad = AF_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), edge_pad))
+ image.arr, ct.c_longlong(w_len), ct.c_longlong(w_wid), edge_pad))
return output
def regions(image, connectivity = AF_CONNECTIVITY_4, out_type = f32):
@@ -179,7 +179,7 @@ def sobel_derivatives(image, w_len=3):
dx = Array()
dy = Array()
safe_call(backend.get().af_sobel_operator(ct.pointer(dx.arr), ct.pointer(dy.arr),
- image.arr, ct.c_uint(w_len)))
+ image.arr, ct.c_uint(w_len)))
return dx,dy
def sobel_filter(image, w_len = 3, is_fast = False):
@@ -195,13 +195,13 @@ def sobel_filter(image, w_len = 3, is_fast = False):
def rgb2gray(image, r_factor = 0.2126, g_factor = 0.7152, b_factor = 0.0722):
output=Array()
safe_call(backend.get().af_rgb2gray(ct.pointer(output.arr),
- image.arr, ct.c_float(r_factor), ct.c_float(g_factor), ct.c_float(b_factor)))
+ image.arr, ct.c_float(r_factor), ct.c_float(g_factor), ct.c_float(b_factor)))
return output
def gray2rgb(image, r_factor = 1.0, g_factor = 1.0, b_factor = 1.0):
output=Array()
safe_call(backend.get().af_gray2rgb(ct.pointer(output.arr),
- image.arr, ct.c_float(r_factor), ct.c_float(g_factor), ct.c_float(b_factor)))
+ image.arr, ct.c_float(r_factor), ct.c_float(g_factor), ct.c_float(b_factor)))
return output
def hsv2rgb(image):
diff --git a/arrayfire/index.py b/arrayfire/index.py
index 608b062..73fbc99 100644
--- a/arrayfire/index.py
+++ b/arrayfire/index.py
@@ -62,7 +62,7 @@ class ParallelRange(Seq):
def __next__(self):
return self.next()
-def slice_to_length(key, dim):
+def _slice_to_length(key, dim):
tkey = [key.start, key.stop, key.step]
if tkey[0] is None:
@@ -80,18 +80,18 @@ def slice_to_length(key, dim):
return int(((tkey[1] - tkey[0] - 1) / tkey[2]) + 1)
-class uidx(ct.Union):
+class _uidx(ct.Union):
_fields_ = [("arr", ct.c_void_p),
("seq", Seq)]
class Index(ct.Structure):
- _fields_ = [("idx", uidx),
+ _fields_ = [("idx", _uidx),
("isSeq", ct.c_bool),
("isBatch", ct.c_bool)]
def __init__ (self, idx):
- self.idx = uidx()
+ self.idx = _uidx()
self.isBatch = False
self.isSeq = True
@@ -130,10 +130,10 @@ def get_assign_dims(key, idims):
dims[0] = 1
return dims
elif isinstance(key, slice):
- dims[0] = slice_to_length(key, idims[0])
+ dims[0] = _slice_to_length(key, idims[0])
return dims
elif isinstance(key, ParallelRange):
- dims[0] = slice_to_length(key.S, idims[0])
+ dims[0] = _slice_to_length(key.S, idims[0])
return dims
elif isinstance(key, BaseArray):
dims[0] = key.elements()
@@ -147,9 +147,9 @@ def get_assign_dims(key, idims):
elif (isinstance(key[n], BaseArray)):
dims[n] = key[n].elements()
elif (isinstance(key[n], slice)):
- dims[n] = slice_to_length(key[n], idims[n])
+ dims[n] = _slice_to_length(key[n], idims[n])
elif (isinstance(key[n], ParallelRange)):
- dims[n] = slice_to_length(key[n].S, idims[n])
+ dims[n] = _slice_to_length(key[n].S, idims[n])
else:
raise IndexError("Invalid type while assigning to arrayfire.array")
diff --git a/arrayfire/library.py b/arrayfire/library.py
index d3b18b4..9aff623 100644
--- a/arrayfire/library.py
+++ b/arrayfire/library.py
@@ -10,7 +10,7 @@
import platform
import ctypes as ct
-class clibrary(object):
+class _clibrary(object):
def __libname(self, name):
platform_name = platform.system()
@@ -67,8 +67,8 @@ class clibrary(object):
def lock(self):
self.__lock = True
-backend = clibrary()
-del clibrary
+backend = _clibrary()
+del _clibrary
AF_SUCCESS = ct.c_int(0)
diff --git a/arrayfire/signal.py b/arrayfire/signal.py
index 2b8c955..a37854d 100644
--- a/arrayfire/signal.py
+++ b/arrayfire/signal.py
@@ -13,13 +13,13 @@ from .array import *
def approx1(signal, pos0, method=AF_INTERP_LINEAR, off_grid=0.0):
output = Array()
safe_call(backend.get().af_approx1(ct.pointer(output.arr), signal.arr, pos0.arr,
- method, ct.c_double(off_grid)))
+ method, ct.c_double(off_grid)))
return output
def approx2(signal, pos0, pos1, method=AF_INTERP_LINEAR, off_grid=0.0):
output = Array()
safe_call(backend.get().af_approx2(ct.pointer(output.arr), signal.arr,
- pos0.arr, pos1.arr, method, ct.c_double(off_grid)))
+ pos0.arr, pos1.arr, method, ct.c_double(off_grid)))
return output
def fft(signal, dim0 = None , scale = None):
@@ -47,7 +47,7 @@ def fft2(signal, dim0 = None, dim1 = None , scale = None):
output = Array()
safe_call(backend.get().af_fft2(ct.pointer(output.arr), signal.arr, ct.c_double(scale),
- ct.c_longlong(dim0), ct.c_longlong(dim1)))
+ ct.c_longlong(dim0), ct.c_longlong(dim1)))
return output
def fft3(signal, dim0 = None, dim1 = None , dim2 = None, scale = None):
@@ -66,7 +66,7 @@ def fft3(signal, dim0 = None, dim1 = None , dim2 = None, scale = None):
output = Array()
safe_call(backend.get().af_fft3(ct.pointer(output.arr), signal.arr, ct.c_double(scale),
- ct.c_longlong(dim0), ct.c_longlong(dim1), ct.c_longlong(dim2)))
+ ct.c_longlong(dim0), ct.c_longlong(dim1), ct.c_longlong(dim2)))
return output
def ifft(signal, dim0 = None , scale = None):
@@ -99,7 +99,7 @@ def ifft2(signal, dim0 = None, dim1 = None , scale = None):
output = Array()
safe_call(backend.get().af_ifft2(ct.pointer(output.arr), signal.arr, ct.c_double(scale),
- ct.c_longlong(dim0), ct.c_longlong(dim1)))
+ ct.c_longlong(dim0), ct.c_longlong(dim1)))
return output
def ifft3(signal, dim0 = None, dim1 = None , dim2 = None, scale = None):
@@ -123,12 +123,12 @@ def ifft3(signal, dim0 = None, dim1 = None , dim2 = None, scale = None):
output = Array()
safe_call(backend.get().af_ifft3(ct.pointer(output.arr), signal.arr, ct.c_double(scale),
- ct.c_longlong(dim0), ct.c_longlong(dim1), ct.c_longlong(dim2)))
+ ct.c_longlong(dim0), ct.c_longlong(dim1), ct.c_longlong(dim2)))
return output
def dft(signal, scale = None, odims=(None, None, None, None)):
- odims4 = dim4_tuple(odims, default=None)
+ odims4 = dim4_to_tuple(odims, default=None)
dims = signal.dims()
ndims = len(dims)
@@ -142,7 +142,7 @@ def dft(signal, scale = None, odims=(None, None, None, None)):
def idft(signal, scale = None, odims=(None, None, None, None)):
- odims4 = dim4_tuple(odims, default=None)
+ odims4 = dim4_to_tuple(odims, default=None)
dims = signal.dims()
ndims = len(dims)
diff --git a/arrayfire/util.py b/arrayfire/util.py
index 1cca212..d6ad2df 100644
--- a/arrayfire/util.py
+++ b/arrayfire/util.py
@@ -51,7 +51,7 @@ def implicit_dtype(number, a_dtype):
return n_dtype
-def dim4_tuple(dims, default=1):
+def dim4_to_tuple(dims, default=1):
assert(isinstance(dims, tuple))
if (default is not None):
diff --git a/arrayfire/vision.py b/arrayfire/vision.py
index 79a3269..0c0248b 100644
--- a/arrayfire/vision.py
+++ b/arrayfire/vision.py
@@ -13,24 +13,24 @@ from .features import *
def fast(image, threshold=20.0, arc_length=9, non_max=True, feature_ratio=0.05, edge=3):
out = Features()
safe_call(backend.get().af_fast(ct.pointer(out.feat),
- image.arr, ct.c_float(threshold), ct.c_uint(arc_length), non_max,
- ct.c_float(feature_ratio), ct.c_uint(edge)))
+ image.arr, ct.c_float(threshold), ct.c_uint(arc_length), non_max,
+ ct.c_float(feature_ratio), ct.c_uint(edge)))
return out
def orb(image, threshold=20.0, max_features=400, scale = 1.5, num_levels = 4, blur_image = False):
feat = Features()
desc = Array()
safe_call(backend.get().af_orb(ct.pointer(feat.feat), ct.pointer(desc.arr),
- ct.c_float(threshold), ct.c_uint(max_features),
- ct.c_float(scale), ct.c_uint(num_levels), blur_image))
+ ct.c_float(threshold), ct.c_uint(max_features),
+ ct.c_float(scale), ct.c_uint(num_levels), blur_image))
return feat, desc
def hamming_matcher(query, database, dim = 0, num_nearest = 1):
index = Array()
dist = Array()
safe_call(backend.get().af_hamming_matcher(ct.pointer(idx.arr), ct.pointer(dist.arr),
- query.arr, database.arr,
- ct.c_longlong(dim), ct.c_longlong(num_nearest)))
+ query.arr, database.arr,
+ ct.c_longlong(dim), ct.c_longlong(num_nearest)))
return index, dist
def match_template(image, template, match_type = AF_SAD):
--
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