spateo.alignment.methods.utils ============================== .. py:module:: spateo.alignment.methods.utils Attributes ---------- .. autoapisummary:: spateo.alignment.methods.utils.intersect_lsts spateo.alignment.methods.utils.to_dense_matrix spateo.alignment.methods.utils.extract_data_matrix spateo.alignment.methods.utils.nx_torch spateo.alignment.methods.utils._cat spateo.alignment.methods.utils._unique spateo.alignment.methods.utils._var spateo.alignment.methods.utils._data spateo.alignment.methods.utils._unsqueeze spateo.alignment.methods.utils._mul spateo.alignment.methods.utils._power spateo.alignment.methods.utils._psi spateo.alignment.methods.utils._pinv spateo.alignment.methods.utils._dot spateo.alignment.methods.utils._identity spateo.alignment.methods.utils._linalg spateo.alignment.methods.utils._prod spateo.alignment.methods.utils._pi spateo.alignment.methods.utils._chunk spateo.alignment.methods.utils._randperm spateo.alignment.methods.utils._roll spateo.alignment.methods.utils._choice spateo.alignment.methods.utils._topk spateo.alignment.methods.utils._dstack spateo.alignment.methods.utils._vstack spateo.alignment.methods.utils._hstack spateo.alignment.methods.utils._split spateo.alignment.methods.utils._where spateo.alignment.methods.utils._repeat_interleave spateo.alignment.methods.utils._copy Functions --------- .. autoapisummary:: spateo.alignment.methods.utils.check_backend spateo.alignment.methods.utils.check_spatial_coords spateo.alignment.methods.utils.check_exp spateo.alignment.methods.utils.check_obs spateo.alignment.methods.utils.check_rep_layer spateo.alignment.methods.utils.check_label_transfer_dict spateo.alignment.methods.utils.check_label_transfer spateo.alignment.methods.utils.generate_label_transfer_dict spateo.alignment.methods.utils.get_rep spateo.alignment.methods.utils.filter_common_genes spateo.alignment.methods.utils.normalize_coords spateo.alignment.methods.utils.normalize_exps spateo.alignment.methods.utils._kl_distance_backend spateo.alignment.methods.utils._cosine_distance_backend spateo.alignment.methods.utils._euc_distance_backend spateo.alignment.methods.utils._label_distance_backend spateo.alignment.methods.utils._correlation_distance_backend spateo.alignment.methods.utils._jaccard_distance_backend spateo.alignment.methods.utils._chebyshev_distance_backend spateo.alignment.methods.utils._canberra_distance_backend spateo.alignment.methods.utils._braycurtis_distance_backend spateo.alignment.methods.utils._hamming_distance_backend spateo.alignment.methods.utils._minkowski_distance_backend spateo.alignment.methods.utils.calc_distance spateo.alignment.methods.utils.calc_probability spateo.alignment.methods.utils.get_P_core spateo.alignment.methods.utils.solve_RT_by_correspondence spateo.alignment.methods.utils.con_K spateo.alignment.methods.utils.construct_knn_graph spateo.alignment.methods.utils.con_K_graph spateo.alignment.methods.utils.inlier_from_NN spateo.alignment.methods.utils.voxel_data spateo.alignment.methods.utils._init_guess_sigma2 spateo.alignment.methods.utils._get_anneling_factor spateo.alignment.methods.utils._dense_to_sparse spateo.alignment.methods.utils.empty_cache spateo.alignment.methods.utils.torch_like_split spateo.alignment.methods.utils._sort spateo.alignment.methods.utils._SparseTensor spateo.alignment.methods.utils.sparse_tensor_to_scipy Module Contents --------------- .. py:data:: intersect_lsts .. py:data:: to_dense_matrix .. py:data:: extract_data_matrix .. py:function:: check_backend(device: str = 'cpu', dtype: str = 'float32', verbose: bool = True) Check the proper backend for the device. :param device: Equipment used to run the program. You can also set the specified GPU for running. E.g.: '0'. :param dtype: The floating-point number type. Only float32 and float64. :param verbose: If ``True``, print progress updates. :returns: The proper backend. type_as: The type_as.device is the device used to run the program and the type_as.dtype is the floating-point number type. :rtype: backend .. py:function:: check_spatial_coords(sample: anndata.AnnData, spatial_key: str = 'spatial') -> numpy.ndarray Check and return the spatial coordinate information from an AnnData object. :param sample: An AnnData object containing the sample data. :type sample: AnnData :param spatial_key: The key in `.obsm` that corresponds to the raw spatial coordinates. Defaults to "spatial". :type spatial_key: str, optional :returns: The spatial coordinates. :rtype: np.ndarray :raises KeyError: If the specified spatial_key is not found in `sample.obsm`. .. py:function:: check_exp(sample: anndata.AnnData, layer: str = 'X') -> numpy.ndarray Check expression matrix. :param sample: An AnnData object containing the sample data. :type sample: AnnData :param layer: The key in `.layers` that corresponds to the expression matrix. Defaults to "X". :type layer: str, optional :returns: The expression matrix. :raises KeyError: If the specified layer is not found in `sample.layers`. .. py:function:: check_obs(rep_layer: List[str], rep_field: List[str]) -> Optional[str] Check that the number of occurrences of 'obs' in the list of representation fields is no more than one. :param rep_layer: A list of representations to check. :type rep_layer: List[str] :param rep_field: A list of representation types corresponding to the representations in `rep_layer`. :type rep_field: List[str] :returns: The representation key if 'obs' occurs exactly once, otherwise None. :rtype: Optional[str] :raises ValueError: If 'obs' occurs more than once in the list. .. py:function:: check_rep_layer(samples: List[anndata.AnnData], rep_layer: Union[str, List[str]] = 'X', rep_field: Union[str, List[str]] = 'layer') -> bool Check if specified representations exist in the `.layers`, `.obsm`, or `.obs` attributes of AnnData objects. :param samples: A list of AnnData objects containing the data samples. :type samples: List[AnnData] :param rep_layer: The representation layer(s) to check. Defaults to "X". :type rep_layer: Union[str, List[str]], optional :param rep_field: The field(s) indicating the type of representation. Acceptable values are "layer", "obsm", and "obs". Defaults to "layer". :type rep_field: Union[str, List[str]], optional :returns: True if all specified representations exist in the corresponding attributes of all AnnData objects, False otherwise. :rtype: bool :raises ValueError: If the specified representation is not found in the specified attribute or if the attribute type is invalid. .. py:function:: check_label_transfer_dict(catA: List[str], catB: List[str], label_transfer_dict: Dict[str, Dict[str, float]]) Check the label transfer dictionary for consistency with given categories. :param catA: List of category labels from the first dataset. :type catA: List[str] :param catB: List of category labels from the second dataset. :type catB: List[str] :param label_transfer_dict: Dictionary defining the transfer probabilities between categories. :type label_transfer_dict: Dict[str, Dict[str, float]] :raises KeyError: If a category from `catA` is not found in `label_transfer_dict`. :raises KeyError: If a category from `catB` is not found in the nested dictionary of `label_transfer_dict`. .. py:function:: check_label_transfer(nx: Union[spateo.alignment.methods.backend.TorchBackend, spateo.alignment.methods.backend.NumpyBackend], type_as: Union[torch.Tensor, numpy.ndarray], sampleA: anndata.AnnData, sampleB: anndata.AnnData, obs_key: str, label_transfer_dict: Optional[Dict[str, Dict[str, float]]] = None) -> List[Union[numpy.ndarray, torch.Tensor]] Check and generate label transfer matrices for the given samples. :param nx: Backend module (e.g., numpy or torch). :type nx: module :param type_as: Type to which the output should be cast. :type type_as: type :param samples: List of AnnData objects containing the samples. :type samples: List[AnnData] :param obs_key: The key in `.obs` that corresponds to the labels. :type obs_key: str :param label_transfer_dict: List of dictionaries defining the label transfer cost between categories of each pair of samples. Defaults to None. :type label_transfer_dict: Optional[List[Dict[str, Dict[str, float]]]], optional :returns: List of label transfer matrices, each as either a NumPy array or torch Tensor. :rtype: List[Union[np.ndarray, torch.Tensor]] :raises ValueError: If the length of `label_transfer_dict` does not match `len(samples) - 1`. .. py:function:: generate_label_transfer_dict(cat1: List[str], cat2: List[str], positive_pairs: Optional[List[Dict[str, Union[List[str], float]]]] = None, negative_pairs: Optional[List[Dict[str, Union[List[str], float]]]] = None, default_positive_value: float = 10.0, default_negative_value: float = 1.0) -> Dict[str, Dict[str, float]] Generate a label transfer dictionary with normalized values. :param cat1: List of categories from the first dataset. :type cat1: List[str] :param cat2: List of categories from the second dataset. :type cat2: List[str] :param positive_pairs: List of positive pairs with transfer values. Each dictionary should have 'left', 'right', and 'value' keys. Defaults to None. :type positive_pairs: Optional[List[Dict[str, Union[List[str], float]]]], optional :param negative_pairs: List of negative pairs with transfer values. Each dictionary should have 'left', 'right', and 'value' keys. Defaults to None. :type negative_pairs: Optional[List[Dict[str, Union[List[str], float]]]], optional :param default_positive_value: Default value for positive pairs if none are provided. Defaults to 10.0. :type default_positive_value: float, optional :param default_negative_value: Default value for negative pairs if none are provided. Defaults to 1.0. :type default_negative_value: float, optional :returns: A normalized label transfer dictionary. :rtype: Dict[str, Dict[str, float]] .. py:function:: get_rep(nx: Union[spateo.alignment.methods.backend.TorchBackend, spateo.alignment.methods.backend.NumpyBackend], type_as: Union[torch.Tensor, numpy.ndarray], sample: anndata.AnnData, rep: str = 'X', rep_field: str = 'layer', genes: Optional[Union[list, numpy.ndarray]] = None) -> numpy.ndarray Get the specified representation from the AnnData object. :param nx: Backend module (e.g., numpy or torch). :type nx: module :param type_as: Type to which the output should be cast. :type type_as: type :param sample: The AnnData object containing the sample data. :type sample: AnnData :param rep: The name of the representation to retrieve. Defaults to "X". :type rep: str, optional :param rep_field: The type of representation. Acceptable values are "layer", "obs" and "obsm". Defaults to "layer". :type rep_field: str, optional :param genes: List of genes to filter if `rep_field` is "layer". Defaults to None. :type genes: Optional[Union[list, np.ndarray]], optional :returns: The requested representation from the AnnData object, cast to the specified type. :rtype: Union[np.ndarray, torch.Tensor] :raises ValueError: If `rep_field` is not one of the expected values. :raises KeyError: If the specified representation is not found in the AnnData object. .. py:function:: filter_common_genes(*genes, verbose: bool = True) -> list Filters for the intersection of genes between all samples. :param genes: List of genes. :param verbose: If ``True``, print progress updates. .. py:function:: normalize_coords(nx: Union[spateo.alignment.methods.backend.TorchBackend, spateo.alignment.methods.backend.NumpyBackend], coords: List[Union[numpy.ndarray, torch.Tensor]], verbose: bool = True, separate_scale: bool = True, separate_mean: bool = True) -> Tuple[List[Union[numpy.ndarray, torch.Tensor]], List[Union[numpy.ndarray, torch.Tensor]], List[Union[numpy.ndarray, torch.Tensor]]] Normalize the spatial coordinate. :param coords: Spatial coordinates of the samples. Each element in the list can be a numpy array or a torch tensor. :type coords: List[Union[np.ndarray, torch.Tensor]] :param nx: The backend to use for computations. Default is `NumpyBackend`. :type nx: Union[TorchBackend, NumpyBackend], optional :param verbose: If `True`, print progress updates. Default is `True`. :type verbose: bool, optional :param separate_scale: If `True`, normalize each coordinate axis independently. When doing the global refinement, this weill be set to False. Default is `True`. :type separate_scale: bool, optional :param separate_mean: If `True`, normalize each coordinate axis to have zero mean independently. When doing the global refinement, this weill be set to False. Default is `True`. :type separate_mean: bool, optional :returns: A tuple containing: - coords: List of normalized spatial coordinates. - normalize_scales: List of normalization scale factors applied to each coordinate axis. - normalize_means: List of mean values used for normalization of each coordinate axis. :rtype: Tuple[List[Union[np.ndarray, torch.Tensor]], List[Union[np.ndarray, torch.Tensor]], List[Union[np.ndarray, torch.Tensor]]] .. py:function:: normalize_exps(nx: Union[spateo.alignment.methods.backend.TorchBackend, spateo.alignment.methods.backend.NumpyBackend], exp_layers: List[List[Union[numpy.ndarray, torch.Tensor]]], rep_field: Union[str, List[str]] = 'layer', verbose: bool = True) -> List[List[Union[numpy.ndarray, torch.Tensor]]] Normalize the gene expression matrices. :param nx: The backend to use for computations. Defaults to `NumpyBackend`. :type nx: Union[TorchBackend, NumpyBackend], optional :param exp_layers: Gene expression and optionally the representation matrices of the samples. Each element in the list can be a numpy array or a torch tensor. :type exp_layers: List[List[Union[np.ndarray, torch.Tensor]]] :param rep_field: Field(s) indicating the type of representation. If 'layer', normalization can be applied. Defaults to "layer". :type rep_field: Union[str, List[str]], optional :param verbose: If `True`, print progress updates. Default is `True`. :type verbose: bool, optional :returns: A list of lists containing normalized gene expression matrices. Each matrix in the list is a numpy array or a torch tensor. :rtype: List[List[Union[np.ndarray, torch.Tensor]]] .. py:function:: _kl_distance_backend(X: Union[numpy.ndarray, torch.Tensor], Y: Union[numpy.ndarray, torch.Tensor], probabilistic: bool = True, eps: float = 1e-08) -> Union[numpy.ndarray, torch.Tensor] Compute the pairwise KL divergence between all pairs of samples in matrices X and Y. :param X: Matrix with shape (N, D), where each row represents a sample. :type X: np.ndarray or torch.Tensor :param Y: Matrix with shape (M, D), where each row represents a sample. :type Y: np.ndarray or torch.Tensor :param probabilistic: If True, normalize the rows of X and Y to sum to 1 (to interpret them as probabilities). Default is True. :type probabilistic: bool, optional :param eps: A small value to avoid division by zero. Default is 1e-8. :type eps: float, optional :returns: Pairwise KL divergence matrix with shape (N, M). :rtype: np.ndarray :raises AssertionError: If the number of features in X and Y do not match. .. py:function:: _cosine_distance_backend(X: Union[numpy.ndarray, torch.Tensor], Y: Union[numpy.ndarray, torch.Tensor], eps: float = 1e-08) -> Union[numpy.ndarray, torch.Tensor] Compute the pairwise cosine similarity between all pairs of samples in matrices X and Y. :param X: Matrix with shape (N, D), where each row represents a sample. :type X: np.ndarray or torch.Tensor :param Y: Matrix with shape (M, D), where each row represents a sample. :type Y: np.ndarray or torch.Tensor :param eps: A small value to avoid division by zero. Default is 1e-8. :type eps: float, optional :returns: Pairwise cosine similarity matrix with shape (N, M). :rtype: np.ndarray or torch.Tensor :raises AssertionError: If the number of features in X and Y do not match. .. py:function:: _euc_distance_backend(X: Union[numpy.ndarray, torch.Tensor], Y: Union[numpy.ndarray, torch.Tensor], squared: bool = True) -> Union[numpy.ndarray, torch.Tensor] Compute the pairwise Euclidean distance between all pairs of samples in matrices X and Y. :param X: Matrix with shape (N, D), where each row represents a sample. :type X: np.ndarray or torch.Tensor :param Y: Matrix with shape (M, D), where each row represents a sample. :type Y: np.ndarray or torch.Tensor :param squared: If True, return squared Euclidean distances. Default is True. :type squared: bool, optional :returns: Pairwise Euclidean distance matrix with shape (N, M). :rtype: np.ndarray or torch.Tensor :raises AssertionError: If the number of features in X and Y do not match. .. py:function:: _label_distance_backend(X: Union[numpy.ndarray, torch.Tensor], Y: Union[numpy.ndarray, torch.Tensor], label_transfer: Union[numpy.ndarray, torch.Tensor]) -> Union[numpy.ndarray, torch.Tensor] Generate a matrix of size (N, M) by indexing into the label_transfer matrix using the values in X and Y. :param X: Array with shape (N, ) containing integer values ranging from 0 to K. :type X: np.ndarray or torch.Tensor :param Y: Array with shape (M, ) containing integer values ranging from 0 to L. :type Y: np.ndarray or torch.Tensor :param label_transfer: Matrix with shape (K, L) containing the label transfer cost. :type label_transfer: np.ndarray or torch.Tensor :returns: Matrix with shape (N, M) where each element is the value from label_transfer indexed by the corresponding values in X and Y. :rtype: np.ndarray or torch.Tensor :raises AssertionError: If the shape of X or Y is not one-dimensional or if they contain non-integer values. .. py:function:: _correlation_distance_backend(X, Y) .. py:function:: _jaccard_distance_backend(X, Y) .. py:function:: _chebyshev_distance_backend(X, Y) .. py:function:: _canberra_distance_backend(X, Y) .. py:function:: _braycurtis_distance_backend(X, Y) .. py:function:: _hamming_distance_backend(X, Y) .. py:function:: _minkowski_distance_backend(X, Y) .. py:function:: calc_distance(X: Union[List[Union[numpy.ndarray, torch.Tensor]], Union[numpy.ndarray, torch.Tensor]], Y: Union[List[Union[numpy.ndarray, torch.Tensor]], Union[numpy.ndarray, torch.Tensor]], metric: Union[List[str], str] = 'euc', label_transfer: Optional[Union[numpy.ndarray, torch.Tensor]] = None) -> Union[numpy.ndarray, torch.Tensor] Calculate the distance between all pairs of samples in matrices X and Y using the specified metric. :param X: Matrix with shape (N, D), where each row represents a sample. :type X: np.ndarray or torch.Tensor :param Y: Matrix with shape (M, D), where each row represents a sample. :type Y: np.ndarray or torch.Tensor :param metric: The metric to use for calculating distances. Options are 'euc', 'euclidean', 'square_euc', 'square_euclidean', 'kl', 'sym_kl', 'cos', 'cosine', 'label'. Default is 'euc'. :type metric: str, optional :param label_transfer: Matrix with shape (K, L) containing the label transfer cost. Required if metric is 'label'. Default is None. :type label_transfer: Optional[np.ndarray or torch.Tensor], optional :returns: Pairwise distance matrix with shape (N, M). :rtype: np.ndarray or torch.Tensor :raises AssertionError: If the number of features in X and Y do not match. If `metric` is not one of the supported metrics. If `label_transfer` is required but not provided. .. py:function:: calc_probability(nx, distance_matrix: Union[numpy.ndarray, torch.Tensor], probability_type: str = 'gauss', probability_parameter: Optional[float] = None) -> Union[numpy.ndarray, torch.Tensor] Calculate probability based on the distance matrix and specified probability type. :param distance_matrix: The distance matrix. :type distance_matrix: np.ndarray or torch.Tensor :param probability_type: The type of probability to calculate. Options are 'Gauss', 'cos_prob', and 'prob'. Default is 'Gauss'. :type probability_type: str, optional :param probability_parameter: The parameter for the probability calculation. Required for certain probability types. Default is None. :type probability_parameter: Optional[float], optional :returns: The calculated probability matrix. :rtype: np.ndarray or torch.Tensor :raises ValueError: If `probability_type` is not one of the supported types or if required parameters are missing. .. py:function:: get_P_core(nx: Union[spateo.alignment.methods.backend.TorchBackend, spateo.alignment.methods.backend.NumpyBackend], type_as: Union[torch.Tensor, numpy.ndarray], Dim: Union[torch.Tensor, numpy.ndarray], spatial_dist: Union[numpy.ndarray, torch.Tensor], exp_dist: List[Union[numpy.ndarray, torch.Tensor]], sigma2: Union[int, float, numpy.ndarray, torch.Tensor], model_mul: Union[numpy.ndarray, torch.Tensor], gamma: Union[float, numpy.ndarray, torch.Tensor], samples_s: Optional[List[float]] = None, sigma2_variance: float = 1, probability_type: Union[str, List[str]] = 'Gauss', probability_parameters: Optional[List] = None, eps: float = 1e-08, sparse_calculation_mode: bool = False, top_k: int = -1) Compute assignment matrix P and additional results based on given distances and parameters. :param nx: Backend module (e.g., numpy or torch). :type nx: module :param type_as: Type to which the output should be cast. :type type_as: type :param spatial_dist: Spatial distance matrix. :type spatial_dist: np.ndarray or torch.Tensor :param exp_dist: List of expression distance matrices. :type exp_dist: List[np.ndarray or torch.Tensor] :param sigma2: Sigma squared value. :type sigma2: int, float, np.ndarray or torch.Tensor :param alpha: Alpha values. :type alpha: np.ndarray or torch.Tensor :param gamma: Gamma value. :type gamma: float, np.ndarray or torch.Tensor :param Sigma: Sigma values. :type Sigma: np.ndarray or torch.Tensor :param samples_s: Samples. Default is None. :type samples_s: Optional[List[float]], optional :param sigma2_variance: Sigma squared variance. Default is 1. :type sigma2_variance: float, optional :param probability_type: Probability type. Default is 'Gauss'. :type probability_type: Union[str, List[str]], optional :param probability_parameters: Probability parameters. Default is None. :type probability_parameters: Optional[List[float]], optional :returns: * *np.ndarray or torch.Tensor* -- Assignment matrix P. * *dict* -- Additional results. .. py:function:: solve_RT_by_correspondence(X: numpy.ndarray, Y: numpy.ndarray, return_s=False) .. py:function:: con_K(X: Union[numpy.ndarray, torch.Tensor], Y: Union[numpy.ndarray, torch.Tensor], beta: Union[int, float] = 0.01) -> Union[numpy.ndarray, torch.Tensor] con_K constructs the Squared Exponential (SE) kernel, where K(i,j)=k(X_i,Y_j)=exp(-beta*||X_i-Y_j||^2). :param X: The first vector X\in\mathbb{R}^{N imes d} :param Y: The second vector X\in\mathbb{R}^{M imes d} :param beta: The length-scale of the SE kernel. :param use_chunk: Whether to use chunk to reduce the GPU memory usage. Note that if set to ``True'' it will slow down the calculation. Defaults to False. :type use_chunk: bool, optional :returns: The kernel K\in\mathbb{R}^{N imes M} :rtype: K .. py:function:: construct_knn_graph(points: Union[numpy.ndarray, torch.Tensor], knn: int = 10) Construct a k-nearest neighbor graph from the given points. :param points: The points to construct the graph from. :param knn: The number of nearest neighbors to consider. :returns: The networks graph object. .. py:function:: con_K_graph(graph: networkx.Graph, inducing_idx: Union[numpy.ndarray, torch.Tensor], beta: Union[int, float] = 0.01) Construct the kernel matrix from the given graph and inducing points. :param graph: The graph object. :param inducing_idx: The indices of the inducing points. :returns: The kernel matrix. .. py:function:: inlier_from_NN(train_x, train_y, distance) .. py:function:: voxel_data(nx: Union[spateo.alignment.methods.backend.TorchBackend, spateo.alignment.methods.backend.NumpyBackend], coords: Union[numpy.ndarray, torch.Tensor], gene_exp: Union[numpy.ndarray, torch.Tensor], voxel_size: Optional[float] = None, voxel_num: Optional[int] = 10000) Voxelization of the data. :param coords: The coordinates of the data points. :type coords: np.ndarray or torch.Tensor :param gene_exp: The gene expression of the data points. :type gene_exp: np.ndarray or torch.Tensor :param voxel_size: The size of the voxel. :type voxel_size: float :param voxel_num: The number of voxels. :type voxel_num: int :returns: * **voxel_coords** (*np.ndarray or torch.Tensor*) -- The coordinates of the voxels. * **voxel_gene_exp** (*np.ndarray or torch.Tensor*) -- The gene expression of the voxels. .. py:function:: _init_guess_sigma2(XA, XB, subsample=20000) .. py:function:: _get_anneling_factor(nx, type_as, start, end, iter) .. py:function:: _dense_to_sparse(nx, type_as, mat: Union[numpy.ndarray, torch.Tensor], sparse_method: str = 'topk', threshold: Union[int, float] = 100, axis: int = 0, descending=False) .. py:function:: empty_cache(device: str = 'cpu') .. py:data:: nx_torch .. py:data:: _cat .. py:data:: _unique .. py:data:: _var .. py:data:: _data .. py:data:: _unsqueeze .. py:data:: _mul .. py:data:: _power .. py:data:: _psi .. py:data:: _pinv .. py:data:: _dot .. py:data:: _identity .. py:data:: _linalg .. py:data:: _prod .. py:data:: _pi .. py:data:: _chunk .. py:data:: _randperm .. py:data:: _roll .. py:data:: _choice .. py:data:: _topk .. py:data:: _dstack .. py:data:: _vstack .. py:data:: _hstack .. py:data:: _split .. py:function:: torch_like_split(arr, size, dim=0) .. py:data:: _where .. py:data:: _repeat_interleave .. py:data:: _copy .. py:function:: _sort(nx, arr, axis=-1, descending=False) .. py:function:: _SparseTensor(nx, row, col, value, sparse_sizes) .. py:function:: sparse_tensor_to_scipy(sparse_tensor)