python : improved documentation

This commit is contained in:
saundersp
2024-04-28 22:35:42 +02:00
parent c71b04f00d
commit 4a42747837
5 changed files with 78 additions and 77 deletions

View File

@@ -4,7 +4,7 @@ import numpy as np
from sys import stderr
import pickle
import os
from config import MODEL_DIR, OUT_DIR
from config import MODEL_DIR, OUT_DIR, __DEBUG
from decorators import njit
def formatted_row(gaps: list[int], titles: list[str], separator: str = '') -> None:
@@ -49,7 +49,7 @@ def header(gaps: list[int], titles: list[str]) -> None:
formatted_line(gaps, '', '', '', '')
def footer(gaps: list[int]) -> None:
"""Print a formatted fooder with the given sizes
"""Print a formatted footer with the given sizes.
Args:
gaps: List of size gaps
@@ -128,7 +128,7 @@ def pickle_multi_loader(filenames: List[str], save_dir: str = MODEL_DIR) -> List
return b
def benchmark_function(step_name: str, column_width: int, fnc: Callable) -> Any:
"""Benchmark a function and display the result of stdout.
"""Benchmark a function and display the result in stdout.
Args:
step_name (str): Name of the function to call
@@ -202,14 +202,14 @@ def state_saver(step_name: str, column_width: int, filename: Union[str, List[str
@njit('boolean(int32[:, :], uint16[:, :])')
def unit_test_argsort_2d(arr: np.ndarray, indices: np.ndarray) -> bool:
"""Test if a given array of indices sort a given array.
"""Test if a given 2D array of indices sort a given 2D array.
Args:
arr (np.ndarray): Array of data
indices (np.ndarray): Indices that sort arr
arr (np.ndarray): 2D Array of data
indices (np.ndarray): 2D Indices that sort the array
Returns:
bool: Success of the test
bool: Whether the test was successful
"""
n = indices.shape[0]
total = indices.shape[0] * indices.shape[1]
@@ -217,6 +217,7 @@ def unit_test_argsort_2d(arr: np.ndarray, indices: np.ndarray) -> bool:
for j in range(sub_indices.shape[0] - 1):
if arr[i, sub_indices[j]] <= arr[i, sub_indices[j + 1]]:
n += 1
if n != total:
print(n, total, n / (total))
if __DEBUG:
if n != total:
print(n, total, n / (total))
return n == total