def _rstrip_inplace(array): """ Performs an in-place rstrip operation on string arrays. This is necessary since the built-in `np.char.rstrip` in Numpy does not perform an in-place calculation. """ # The following implementation convert the string to unsigned integers of # the right length. Trailing spaces (which are represented as 32) are then # converted to null characters (represented as zeros). To avoid creating # large temporary mask arrays, we loop over chunks (attempting to do that # on a 1-D version of the array; large memory may still be needed in the # unlikely case that a string array has small first dimension and cannot # be represented as a contiguous 1-D array in memory). dt = array.dtype if dt.kind not in 'SU': raise TypeError("This function can only be used on string arrays") # View the array as appropriate integers. The last dimension will # equal the number of characters in each string. bpc = 1 if dt.kind == 'S' else 4 dt_int = f"({dt.itemsize // bpc},){dt.byteorder}u{bpc}" b = array.view(dt_int, np.ndarray) # For optimal speed, work in chunks of the internal ufunc buffer size. bufsize = np.getbufsize() # Attempt to have the strings as a 1-D array to give the chunk known size. # Note: the code will work if this fails; the chunks will just be larger. if b.ndim > 2: try: b.shape = -1, b.shape[-1] except AttributeError: # can occur for non-contiguous arrays pass for j in range(0, b.shape[0], bufsize): c = b[j:j + bufsize] # Mask which will tell whether we're in a sequence of trailing spaces. mask = np.ones(c.shape[:-1], dtype=bool) # Loop over the characters in the strings, in reverse order. We process # the i-th character of all strings in the chunk at the same time. If # the character is 32, this corresponds to a space, and we then change # this to 0. We then construct a new mask to find rows where the # i-th character is 0 (null) and the i-1-th is 32 (space) and repeat. for i in range(-1, -c.shape[-1], -1): mask &= c[..., i] == 32 c[..., i][mask] = 0 mask = c[..., i] == 0 return array
def _rstrip_inplace(array): """ Performs an in-place rstrip operation on string arrays. This is necessary since the built-in `np.char.rstrip` in Numpy does not perform an in-place calculation. """ # The following implementation convert the string to unsigned integers of # the right length. Trailing spaces (which are represented as 32) are then # converted to null characters (represented as zeros). To avoid creating # large temporary mask arrays, we loop over chunks (attempting to do that # on a 1-D version of the array; large memory may still be needed in the # unlikely case that a string array has small first dimension and cannot # be represented as a contiguous 1-D array in memory). dt = array.dtype if dt.kind not in 'SU': raise TypeError("This function can only be used on string arrays") # View the array as appropriate integers. The last dimension will # equal the number of characters in each string. bpc = 1 if dt.kind == 'S' else 4 dt_int = "{0}{1}u{2}".format(dt.itemsize // bpc, dt.byteorder, bpc) b = array.view(dt_int, np.ndarray) # For optimal speed, work in chunks of the internal ufunc buffer size. bufsize = np.getbufsize() # Attempt to have the strings as a 1-D array to give the chunk known size. # Note: the code will work if this fails; the chunks will just be larger. if b.ndim > 2: try: b.shape = -1, b.shape[-1] except AttributeError: # can occur for non-contiguous arrays pass for j in range(0, b.shape[0], bufsize): c = b[j:j + bufsize] # Mask which will tell whether we're in a sequence of trailing spaces. mask = np.ones(c.shape[:-1], dtype=bool) # Loop over the characters in the strings, in reverse order. We process # the i-th character of all strings in the chunk at the same time. If # the character is 32, this corresponds to a space, and we then change # this to 0. We then construct a new mask to find rows where the # i-th character is 0 (null) and the i-1-th is 32 (space) and repeat. for i in range(-1, -c.shape[-1], -1): mask &= c[..., i] == 32 c[..., i][mask] = 0 mask = c[..., i] == 0 return array
import numpy numpy.getbufsize()
coded by: Roi Tzadok version: 1.0 date:4.4.2017 a simple client that is able to communicate with the server """ import shutil import os import urllib2 import socket import numpy import platform import webbrowser import zipfile MY_PLATFORM = platform.system() BUFF_SIZE = numpy.getbufsize() def unzip(file_path, file_dst): """ unzip a nupkg file @param file_path: the zip file path @param file_dst: where to unzip to """ zip_ref = zipfile.ZipFile(file_path) zip_ref.extractall(file_dst) zip_ref.close() def try_to_download_from_choco(client_socket, file_name): """
def func1(a: str, b: int) -> None: ... def func2(a: str, b: int, c: float = ...) -> None: ... def func3(a: str, b: int) -> int: ... class Write1: def write(self, a: str) -> None: ... class Write2: def write(self, a: str, b: int = ...) -> None: ... class Write3: def write(self, a: str) -> int: ... _err_default = np.geterr() _bufsize_default = np.getbufsize() _errcall_default = np.geterrcall() try: np.seterr(all=None) np.seterr(divide="ignore") np.seterr(over="warn") np.seterr(under="call") np.seterr(invalid="raise") np.geterr() np.setbufsize(4096) np.getbufsize() np.seterrcall(func1) np.seterrcall(func2)
reveal_type( np.seterr(all=None)) # E: TypedDict('numpy.core._ufunc_config._ErrDict' reveal_type(np.seterr( divide="ignore")) # E: TypedDict('numpy.core._ufunc_config._ErrDict' reveal_type( np.seterr(over="warn")) # E: TypedDict('numpy.core._ufunc_config._ErrDict' reveal_type(np.seterr( under="call")) # E: TypedDict('numpy.core._ufunc_config._ErrDict' reveal_type(np.seterr( invalid="raise")) # E: TypedDict('numpy.core._ufunc_config._ErrDict' reveal_type(np.geterr()) # E: TypedDict('numpy.core._ufunc_config._ErrDict' reveal_type(np.setbufsize(4096)) # E: int reveal_type(np.getbufsize()) # E: int reveal_type( np.seterrcall(func) ) # E: Union[None, def (builtins.str, builtins.int) -> Any, numpy.core._ufunc_config._SupportsWrite] reveal_type( np.seterrcall(Write()) ) # E: Union[None, def (builtins.str, builtins.int) -> Any, numpy.core._ufunc_config._SupportsWrite] reveal_type( np.geterrcall() ) # E: Union[None, def (builtins.str, builtins.int) -> Any, numpy.core._ufunc_config._SupportsWrite] reveal_type(np.errstate( call=func, all="call")) # E: numpy.errstate[def (a: builtins.str, b: builtins.int)] reveal_type(np.errstate(call=Write(), divide="log",