sgpykit.util.misc
Functions
|
Append an item to a list and return as a numpy array. |
|
Apply level-to-knots mapping to an index array. |
|
@contextmanager decorator. |
|
Generate all multi-indices for a given shape. |
|
Get the shape of the first Cell object in the list of objects. |
|
Check if values are the integer NaN workaround. |
|
Check if an item is a numeric scalar. |
Convert MATLAB-style index to Python-style index. |
|
|
Merge positional and keyword arguments into a single dictionary. |
Print integer values in a plain format. |
|
Convert Python-style index to MATLAB-style index. |
|
|
Reshape nested lists to a specified number of rows. |
|
Safely stack arrays vertically, filtering out empty arrays. |
|
Measure and print the execution time of a code block. |
|
Create an array of length n with the given item. |
|
Find unique rows in the combined array of A and B, maintaining order. |
Classes
|
A 1D or 2D container class that extends Python's built-in list. |
- sgpykit.util.misc.append(some_list, item)[source]
Append an item to a list and return as a numpy array.
- Parameters:
- some_listlist
List to append to.
- itemany
Item to append.
- Returns:
- numpy.ndarray
Array with the item appended.
- sgpykit.util.misc.apply_lev2knots(i, lev2knots, N=None)[source]
Apply level-to-knots mapping to an index array.
- Parameters:
- inumpy.ndarray
Array of 0-based indices.
- lev2knotslist or Cell or callable
Level-to-knots mapping function or list of functions.
- Nint, optional
Number of dimensions (default is None).
- Returns:
- numpy.ndarray
Mapped indices.
- sgpykit.util.misc.generate_multi_indices(shape, min_idx=0)[source]
Generate all multi-indices for a given shape.
- Parameters:
- shapetuple
Shape of the multi-indices to generate.
- min_idxint, optional
Minimum index value (default is 0).
- Returns:
- numpy.ndarray
Array of multi-indices.
- sgpykit.util.misc.get_shape_of_cells(objects)[source]
Get the shape of the first Cell object in the list of objects.
- Parameters:
- objectslist
List of objects to check for Cell type and shape.
- Returns:
- numpy.ndarray or None
Shape of the first Cell object found, or None if no Cell object is found.
- sgpykit.util.misc.is_int_nan(values)[source]
Check if values are the integer NaN workaround.
- Parameters:
- valuesnumpy.ndarray
Values to check.
- Returns:
- numpy.ndarray
Boolean array indicating which values are the integer NaN workaround.
- sgpykit.util.misc.matlab_to_python_index(var)[source]
Convert MATLAB-style index to Python-style index.
- Parameters:
- varint or numpy.ndarray
MATLAB-style index or array of indices.
- Returns:
- int or numpy.ndarray
Python-style index or array of indices.
- sgpykit.util.misc.merge_all_args_to_kwargs(args, kwargs, to_lowercase=False)[source]
Merge positional and keyword arguments into a single dictionary.
- Parameters:
- argslist
Positional arguments.
- kwargsdict
Keyword arguments.
- to_lowercasebool, optional
Convert keys to lowercase (default is False).
- Returns:
- tuple
Tuple of merged keyword arguments and format string.
- sgpykit.util.misc.print_plain_int(x)[source]
Print integer values in a plain format.
- Parameters:
- xint or list or tuple
Integer or list/tuple of integers to print.
- sgpykit.util.misc.python_to_matlab_index(var)[source]
Convert Python-style index to MATLAB-style index.
- Parameters:
- varint or array-like
Python-style index or array of indices.
- Returns:
- int or numpy.ndarray
MATLAB-style index or array of indices.
- sgpykit.util.misc.reshape_nested_lists_to_nrows(obj, nrows=2)[source]
Reshape nested lists to a specified number of rows.
- Parameters:
- objlist
Nested list to reshape.
- nrowsint, optional
Number of rows (default is 2).
- Returns:
- list
Reshaped list.
- sgpykit.util.misc.safe_vstack(*arrays)[source]
Safely stack arrays vertically, filtering out empty arrays.
- Parameters:
- *arraysnumpy.ndarray
Arrays to stack.
- Returns:
- numpy.ndarray
Stacked array.
- sgpykit.util.misc.time_block(description='')[source]
Measure and print the execution time of a code block.
- Args:
description (str): Optional description of the timed block.