21
21
22
22
import dpctl .tensor as dpt
23
23
24
- __doc__ = (
25
- "Implementation module for printing " ":class:`dpctl.tensor.usm_ndarray`."
26
- )
24
+ __doc__ = "Print functions for :class:`dpctl.tensor.usm_ndarray`."
27
25
28
26
_print_options = {
29
27
"linewidth" : 75 ,
@@ -107,6 +105,68 @@ def set_print_options(
107
105
sign = None ,
108
106
numpy = False ,
109
107
):
108
+ """
109
+ set_print_options(linewidth=None, edgeitems=None, threshold=None,
110
+ precision=None, floatmode=None, suppress=None, nanstr=None,
111
+ infstr=None, sign=None, numpy=False)
112
+
113
+ Set options for printing ``dpctl.tensor.usm_ndarray`` class.
114
+
115
+ Args:
116
+ linewidth (int, optional): Number of characters printed per line.
117
+ Raises `TypeError` if linewidth is not an integer.
118
+ Default: `75`.
119
+ edgeitems (int, optional): Number of elements at the beginning and end
120
+ when the printed array is abbreviated.
121
+ Raises `TypeError` if edgeitems is not an integer.
122
+ Default: `3`.
123
+ threshold (int, optional): Number of elements that triggers array
124
+ abbreviation.
125
+ Raises `TypeError` if threshold is not an integer.
126
+ Default: `1000`.
127
+ precision (int or None, optional): Number of digits printed for
128
+ floating point numbers. If `floatmode` is not `"fixed",`
129
+ `precision` may be `None` to print each float with as many
130
+ digits as necessary to produce a unique output.
131
+ Raises `TypeError` if precision is not an integer.
132
+ Default: `8`.
133
+ floatmode (str, optional): Controls how floating point
134
+ numbers are interpreted.
135
+
136
+ `"fixed:`: Always prints exactly `precision` digits.
137
+ `"unique"`: Ignores precision, prints the number of
138
+ digits necessary to uniquely specify each number.
139
+ `"maxprec"`: Prints `precision` digits or fewer,
140
+ if fewer will uniquely represent a number.
141
+ `"maxprec_equal"`: Prints an equal number of digits
142
+ for each number. This number is `precision` digits or fewer,
143
+ if fewer will uniquely represent each number.
144
+ Raises `ValueError` if floatmode is not one of
145
+ `fixed`, `unique`, `maxprec`, or `maxprec_equal`.
146
+ Default: "maxprec_equal"
147
+ suppress (bool, optional): If `True,` numbers equal to zero
148
+ in the current precision will print as zero.
149
+ Default: `False`.
150
+ nanstr (str, optional): String used to repesent nan.
151
+ Raises `TypeError` if nanstr is not a string.
152
+ Default: `"nan"`.
153
+ infstr (str, optional): String used to represent infinity.
154
+ Raises `TypeError` if infstr is not a string.
155
+ Default: `"inf"`.
156
+ sign (str, optional): Controls the sign of floating point
157
+ numbers.
158
+ `"-"`: Omit the sign of positive numbers.
159
+ `"+"`: Always print the sign of positive numbers.
160
+ `" "`: Always print a whitespace in place of the
161
+ sign of positive numbers.
162
+ Raises `ValueError` if sign is not one of
163
+ `"-"`, `"+"`, or `" "`.
164
+ Default: `"-"`.
165
+ numpy (bool, optional): If `True,` then before other specified print
166
+ options are set, a dictionary of Numpy's print options
167
+ will be used to initialize dpctl's print options.
168
+ Default: "False"
169
+ """
110
170
options = _options_dict (
111
171
linewidth = linewidth ,
112
172
edgeitems = edgeitems ,
@@ -123,11 +183,34 @@ def set_print_options(
123
183
124
184
125
185
def get_print_options ():
186
+ """
187
+ get_print_options() -> dict
188
+
189
+ Returns a copy of current options for printing
190
+ ``dpctl.tensor.usm_ndarray`` class.
191
+
192
+ Options:
193
+ - "linewidth" : int, default 75
194
+ - "edgeitems" : int, default 3
195
+ - "threshold" : int, default 1000
196
+ - "precision" : int, default 8
197
+ - "floatmode" : str, default "maxprec_equal"
198
+ - "suppress" : bool, default False
199
+ - "nanstr" : str, default "nan"
200
+ - "infstr" : str, default "inf"
201
+ - "sign" : str, default "-"
202
+ """
126
203
return _print_options .copy ()
127
204
128
205
129
206
@contextlib .contextmanager
130
207
def print_options (* args , ** kwargs ):
208
+ """
209
+ Context manager for print options.
210
+
211
+ Set print options for the scope of a `with` block.
212
+ `as` yields dictionary of print options.
213
+ """
131
214
options = dpt .get_print_options ()
132
215
try :
133
216
dpt .set_print_options (* args , ** kwargs )
0 commit comments