/
formatting.py
76 lines (49 loc) · 2.33 KB
/
formatting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import numpy
import cupy
def array_repr(arr, max_line_width=None, precision=None, suppress_small=None):
"""Returns the string representation of an array.
Args:
arr (array_like): Input array. It should be able to feed to
:func:`cupy.asnumpy`.
max_line_width (int): The maximum number of line lengths.
precision (int): Floating point precision. It uses the current printing
precision of NumPy.
suppress_small (bool): If ``True``, very small numbers are printed as
zeros
Returns:
str: The string representation of ``arr``.
.. seealso:: :func:`numpy.array_repr`
"""
return numpy.array_repr(cupy.asnumpy(arr), max_line_width, precision,
suppress_small)
def array_str(arr, max_line_width=None, precision=None, suppress_small=None):
"""Returns the string representation of the content of an array.
Args:
arr (array_like): Input array. It should be able to feed to
:func:`cupy.asnumpy`.
max_line_width (int): The maximum number of line lengths.
precision (int): Floating point precision. It uses the current printing
precision of NumPy.
suppress_small (bool): If ``True``, very small number are printed as
zeros.
.. seealso:: :func:`numpy.array_str`
"""
return numpy.array_str(cupy.asnumpy(arr), max_line_width, precision,
suppress_small)
def array2string(a, *args, **kwargs):
"""Return a string representation of an array.
.. seealso:: :func:`numpy.array2string`
"""
return numpy.array2string(cupy.asnumpy(a), *args, **kwargs)
def format_float_positional(x, *args, **kwargs):
"""Format a floating-point scalar as a decimal string in positional notation.
See :func:`numpy.format_float_positional` for the list of arguments.
.. seealso:: :func:`numpy.format_float_positional`
"""
return numpy.format_float_positional(cupy.asnumpy(x), *args, **kwargs)
def format_float_scientific(x, *args, **kwargs):
"""Format a floating-point scalar as a decimal string in scientific notation.
See :func:`numpy.format_float_scientific` for the list of arguments.
.. seealso:: :func:`numpy.format_float_scientific`
"""
return numpy.format_float_scientific(cupy.asnumpy(x), *args, **kwargs)