commonutils
commonutils ¶
Module for common utils
Functions¶
check_instance ¶
Checks whether 'obj_instance' is an instance of 'class_type'. Returns 'obj_instance' if True. Raises TypeError if not.
Parameters:
-
obj_instance
(Any
) –Object to check the instance type for
-
class_type
(Any
) –instance type which is expected
Returns:
-
Any
–'obj_instance' if the type is correct
Source code in niceml/utilities/commonutils.py
human_readable_size ¶
Returns human-readable size in bytes of an object as string
Parameters:
-
obj
(Any
) –object to check the size for
Returns:
-
str
–Size of the object in bytes; e.g. "1.23 GB"
Source code in niceml/utilities/commonutils.py
items_from_shuffled_list ¶
Generates a shuffled list of 'item_list', where 'count' is the number of items in that list. The order is randomized. If 'count' is smaller than len(item_list), some items won't appear in the output. If 'count' is equal to len(item_list), all items in item_list will appear in the output. If there are more than one copy of an item in the input, then it will also appear multiple times in the output.
Parameters:
-
item_list
(list
) –list of items, e.g. [1,2,3,4]
-
count
(int
) –number of required items in the output; can be bigger than len('item_list'), e.g. 4
Returns: list of items which are shuffled, e.g. [3,2,1,4]
Source code in niceml/utilities/commonutils.py
partition_indices ¶
QUEST: still used?¶
Splits the length of an iterable (totalsize) into a given number of equal parts and returns the start and end indices of these parts.
Parameters:
-
totalsize
(int
) –length of the iterable to be partitioned
-
numberofpartitions
(int
) –number of the partitions generated
Returns: List of tuples containing the start and end indices for each partition