unipy.utils.wrapper module¶
Docstring for Wrapper
.
High-level Function Wrapper¶
Operation Wrapper |
|
---|---|
multiprocessor |
Functional wrapper for multiprocessing. |
Interfaces |
|
---|---|
uprint |
Print option interface within a function. |
lprint |
stdout the shape of input layer & output layer in DL |
aprint |
Stdout the numpy.ndarray in pretty. |
-
unipy.utils.wrapper.
multiprocessor
(func, worker=2, arg_zip=None, *args, **kwargs)[source]¶ Use multiprocessing as a function.
Just for convenience.
- Parameters
func (Function) – Any function without
lambda
.worker (int (default: 2)) – A number of processes.
arg_zip (zip (default: None)) – A
zip
instance.
- Returns
A list contains results of each processes.
- Return type
See also
multiprocessing.pool
Examples
>>> from unipy.utils.wrapper import multiprocessor >>> alist = [1, 2, 3] >>> blist = [-1, -2, -3] >>> def afunc(x, y): ... return x + y ... >>> multiprocessor(afunc, arg_zip=zip(alist, blist)) [0, 0, 0] >>> def bfunc(x): ... return x + 2 ... >>> multiprocessor(bfunc, arg_zip=zip(alist)) [3, 4, 5]
-
unipy.utils.wrapper.
uprint
(*args, print_ok=True, **kwargs)[source]¶ Print option interface.
This function is equal to
print
function but addedprint_ok
option. This allows you to control printing in a function.- Parameters
*args (whatever
print
allows.) – It is same asprint
does.print_ok (Boolean (default: True)) – An option whether you want to print something out or not.
arg_zip (zip (default: None)) – A
zip
instance.
-
unipy.utils.wrapper.
lprint
(input_x, output, name=None)[source]¶ Print option interface.
This function is to stdout the shape of input layer & output layer in Deep Learning architecture.
- Parameters
input_x (numpy.ndarray) – A
numpy.ndarray
object of input source.output (numpy.ndarray) – A
numpy.ndarray
object of output target.name (str (default: None)) – An optional name you want to print out.
-
unipy.utils.wrapper.
aprint
(*arr, maxlen=None, name_list=None, decimals=None)[source]¶ Stdout the numpy.ndarray in pretty.
It prints the multiple numpy.ndarray out “Side by Side.”
- Parameters
arr (numpy.ndarray) – Any arrays you want to print out.
maxlen (int (default: None)) – A length for each array to print out. It is automatically calculated in case of None.
name_list (list (default: None)) – A list contains the names of each arrays. Upper Alphabet is given in case of None.
decimals (int (default: None)) – A number to a specified number of digits to truncate.
Examples
>>> from unipy.utils.wrapper import aprint >>> arr_x = np.array([ ... [.6, .5, .1], ... [.4, .2, .8], ... ]) >>> arr_y = np.array([ ... [.4, .6], ... [.7, .3,], ... ]) >>> aprint(arr_x, arr_y) ========================================= | A | B | | (2, 3) | (2, 2) | ========================================= | [[0.6 0.5 0.1] | [[0.4 0.6] | | [0.4 0.2 0.8]] | [0.7 0.3]] | ========================================= >>> aprint(arr_x, arr_y, name_list=['X', 'Y']) ========================================= | X | Y | | (2, 3) | (2, 2) | ========================================= | [[0.6 0.5 0.1] | [[0.4 0.6] | | [0.4 0.2 0.8]] | [0.7 0.3]] | ========================================= >>> aprint(arr_x, arr_y, arr_y[:1], name_list=['X', 'Y', 'Y_1']) ============================================================ | X | Y | Y_1 | | (2, 3) | (2, 2) | (1, 2) | ============================================================ | [[0.6 0.5 0.1] | [[0.4 0.6] | [[0.4 0.6]] | | [0.4 0.2 0.8]] | [0.7 0.3]] | | ============================================================