[python-arrayfire] 132/250: Adding Array.__repr__
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Mar 28 22:59:40 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 60fc4ac02b63bc695e29f1a2c985bc32a03514cd
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date: Tue Nov 10 10:14:09 2015 -0500
Adding Array.__repr__
---
arrayfire/array.py | 15 ++++++++-------
arrayfire/util.py | 11 +++++++++++
2 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/arrayfire/array.py b/arrayfire/array.py
index 79a6a4d..5c60ec6 100644
--- a/arrayfire/array.py
+++ b/arrayfire/array.py
@@ -1018,17 +1018,18 @@ class Array(BaseArray):
def __repr__(self):
"""
- Displays the meta data of the arrayfire array.
+ Displays the meta data and contents of the arrayfire array.
Note
----
- Use arrayfire.display(a) to display the contents of the array.
+ You can also use af.display(a, pres) to display the contents of the array with better precision.
"""
- # Having __repr__ directly print things is a bad idea
- # Placeholder for when af_array_to_string is available
- # safe_call(backend.get().af_array_to_string...
- return 'Type: arrayfire.Array()\nShape: %s\nType char: %s' % \
- (self.dims(), to_typecode[self.type()])
+
+ arr_str = ct.c_char_p(0)
+ safe_call(backend.get().af_array_to_string(ct.pointer(arr_str), "", self.arr, 4, True))
+
+ return 'Type: arrayfire.Array()\nType: %s\n' % \
+ (to_typename[self.type()]) + to_str(arr_str)
def __array__(self):
"""
diff --git a/arrayfire/util.py b/arrayfire/util.py
index 26a8b48..bdfb448 100644
--- a/arrayfire/util.py
+++ b/arrayfire/util.py
@@ -115,3 +115,14 @@ to_c_type = {Dtype.f32.value : ct.c_float,
Dtype.u64.value : ct.c_ulonglong,
Dtype.c32.value : ct.c_float * 2,
Dtype.c64.value : ct.c_double * 2}
+
+to_typename = {Dtype.f32.value : 'float',
+ Dtype.f64.value : 'double',
+ Dtype.b8.value : 'bool',
+ Dtype.u8.value : 'unsigned char',
+ Dtype.s32.value : 'int',
+ Dtype.u32.value : 'unsigned int',
+ Dtype.s64.value : 'long int',
+ Dtype.u64.value : 'unsigned long int',
+ Dtype.c32.value : 'float complex',
+ Dtype.c64.value : 'double complex'}
--
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