utils¶
Module contents¶
-
poornn.utils.
take_slice
(arr, sls, axis)¶ take slices along specific axis.
Parameters: - arr (ndarray) – target array.
- sls (slice) – the target sector.
- axis (int) – the target axis.
Returns: result array.
Return type: ndarray
-
poornn.utils.
scan2csc
(kernel_shape, img_in_shape, strides, boundary)¶ Scan target shape with filter, and transform it into csc_matrix.
Parameters: - kernel_shape (tuple) – shape of kernel.
- img_in_shape (tuple) – shape of image dimension.
- strides (tuple) – strides for image dimensions.
- boundary ('P'|'O') – boundary condition.
Returns: indptr for csc maitrx, indices of csc matrix, output image shape.
Return type: (1darray, 1darray, tuple)
-
poornn.utils.
typed_random
(dtype, shape)¶ generate a random numbers with specific data type.
Parameters: - dtype (str) – data type.
- shape (tuple) – shape of desired array.
Returns: random array in ‘F’ order.
Return type: ndarray
-
poornn.utils.
typed_randn
(dtype, shape)¶ generate a normal distributed random numbers with specific data type.
Parameters: - dtype (str) – data type.
- shape (tuple) – shape of desired array.
Returns: random array in ‘F’ order.
Return type: ndarray
-
poornn.utils.
typed_uniform
(dtype, shape, low=-1.0, high=1.0)¶ generate a uniformly distributed random numbers with specific data type.
Parameters: - dtype (str) – data type.
- shape (tuple) – shape of desired array.
Returns: random array in ‘F’ order.
Return type: ndarray
-
poornn.utils.
tuple_prod
(tp)¶ product over a tuple of numbers.
Parameters: tp (tuple) – the target tuple to product over. Returns: product of tuple. Return type: number
-
poornn.utils.
masked_concatenate
(vl, mask)¶ concatenate multiple arrays with mask True.
Parameters: - vl (list<ndarray>) – arrays.
- mask (list<bool>) – masks for arrays.
Returns: result array.
Return type: ndarray
-
poornn.utils.
dtype2token
(dtype)¶ Parse data type to token.
Parameters: dtype ('float32'|'float64'|'complex64'|'complex128') – data type. Returns: ‘s’|’d’|’c’|’z’ Return type: str
-
poornn.utils.
dtype_c2r
(complex_dtype)¶ Get corresponding real data type from complex data type.
Parameters: dtype ('complex64'|'complex128') – data type. Returns: (‘float32’|’float64’) Return type: str
-
poornn.utils.
dtype_r2c
(real_dtype)¶ Get corresponding complex data type from real data type :param dtype: data type. :type dtype: ‘float32’|’float64’
Returns: (‘complex64’|’complex128’) Return type: str
-
poornn.utils.
complex_backward
(dz, dzc)¶ Complex propagation rule.
Parameters: - dz (ndarray) – \(\partial J/\partial z\)
- dzc (ndarray) – \(\partial J/\partial z^*\)
Returns: backward function that take xy and dy as input.
Return type: func
-
poornn.utils.
fsign
(x)¶ sign function that work properly for complex numbers \(x/|x|\),
Parameters: x (ndarray) – input array. Returns: sign of x. Return type: ndarray Note
if x is 0, return 0.