Arprax Algorithms Library Reference
Welcome to the technical heart of the Arprax ecosystem. This section provides the low-level API details for the arprax-algorithms Python package.
🚀 Core Modules (In Development)
The library is organized into three industrial pillars:
| Module | Purpose | Status |
|---|---|---|
arprax.algos.algorithms |
High-performance sorting and searching. | 🟢 Active |
arprax.algos.utils |
Data generators and helper logic. | 🟢 Active |
arprax.algos.profiler |
Time and Space complexity analysis. | 🟡 Beta |
📦 Installation & Usage
To use these modules in your local environment:
# Core only
pip install arprax-algorithms
# With visual tools
pip install arprax-algorithms[visuals]
# With research tools
pip install arprax-algorithms[research]
from arprax.algos.algorithms import bubble_sort, selection_sort
from arprax.algos.utils import random_array
📖 API Documentation (Live)
The documentation below is automatically pulled from the source code.
📊 Profiler Logic
Arprax Algorithms: Performance Profiling Tools Provides precision timing and algorithmic complexity analysis for research.
Profiler
Industrial-grade performance analyzer for Arprax Lab.
Provides precision timing, statistical analysis, and doubling-test complexity estimation. Designed to work without external dependencies.
Attributes:
| Name | Type | Description |
|---|---|---|
repeats |
int
|
Number of times to run each benchmark. |
warmup |
int
|
Number of discarded runs to prime the CPU cache. |
mode |
str
|
Statistical mode for final result ('min', 'mean', 'median'). |
Source code in src/arprax/algos/profiler.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
__init__(repeats=5, warmup=1, mode='min')
Initializes the Profiler with user-defined benchmark settings.
benchmark(func, *args)
Runs a function with garbage collection disabled to ensure timing purity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable
|
The function to measure. |
required |
*args
|
Any
|
Arguments to pass to the function. |
()
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The measured time in seconds based on the 'mode' setting. |
Source code in src/arprax/algos/profiler.py
print_analysis(func_name, results)
Prints a formatted results table from a doubling test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func_name
|
str
|
Name of the analyzed algorithm. |
required |
results
|
List[Dict]
|
Data from run_doubling_test. |
required |
Source code in src/arprax/algos/profiler.py
print_decorator_report()
Prints a summary table of all tracked functions and stopwatch blocks.
Source code in src/arprax/algos/profiler.py
profile(func)
Decorator to track function execution time during normal program flow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable
|
The function to be decorated. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Callable
|
The wrapped function. |
Source code in src/arprax/algos/profiler.py
run_doubling_test(func, input_gen, start_n=250, rounds=6)
Performs doubling analysis to estimate Big O complexity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable
|
Algorithm to analyze. |
required |
input_gen
|
Callable
|
Function that generates data for size N. |
required |
start_n
|
int
|
Initial input size. |
250
|
rounds
|
int
|
How many times to double N. |
6
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A log of N, Time, Ratio, and estimated Complexity. |
Source code in src/arprax/algos/profiler.py
run_stress_suite(funcs, input_gen, n_values=[1000, 2000, 4000])
Runs multiple algorithms against multiple input sizes for head-to-head comparison.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
funcs
|
Dict
|
Map of {'Name': Function}. |
required |
input_gen
|
Callable
|
Data generator function. |
required |
n_values
|
List[int]
|
List of N sizes to test. |
[1000, 2000, 4000]
|
Returns:
| Type | Description |
|---|---|
Dict[int, Dict[str, float]]
|
Dict[int, Dict[str, float]]: Nested mapping of {N: {Name: Time}}. |
Source code in src/arprax/algos/profiler.py
stopwatch(label='Block')
Context manager for precision timing of a specific code block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Name of the block for the final report. |
'Block'
|
Source code in src/arprax/algos/profiler.py
🛠️ Data Generators
Arprax Algorithms: Data Generators Provides industrial-grade tools for creating research-ready datasets.
large_scale_dataset(n)
High-performance data generator for large-scale research.
Attempts to use NumPy for speed if available; otherwise, falls back to standard Python random generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The number of elements to generate. |
required |
Returns:
| Type | Description |
|---|---|
List[int]
|
List[int]: A list of random integers. |
Source code in src/arprax/algos/utils/generators.py
random_array(n, lo=0, hi=1000)
Generates an array of n random integers using Python's built-in random module.
This serves as the default, dependency-free generator for the library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The number of elements to generate. |
required |
lo
|
int
|
The lower bound of the random range (inclusive). |
0
|
hi
|
int
|
The upper bound of the random range (inclusive). |
1000
|
Returns:
| Type | Description |
|---|---|
List[int]
|
List[int]: A list of n random integers. |
Source code in src/arprax/algos/utils/generators.py
reverse_sorted_array(n)
Legacy wrapper for descending order.
Frequently used for 'Worst Case' algorithm testing in the Arprax Lab.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The number of elements to generate. |
required |
Returns:
| Type | Description |
|---|---|
List[int]
|
List[int]: A list containing integers from n-1 down to 0. |
Source code in src/arprax/algos/utils/generators.py
sorted_array(n, reverse=False)
Generates an array of n integers in sorted order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The number of elements to generate. |
required |
reverse
|
bool
|
If True, returns descending order (Worst Case). |
False
|
Returns:
| Type | Description |
|---|---|
List[int]
|
List[int]: A list containing integers from 0 to n-1 (or reversed). |
Source code in src/arprax/algos/utils/generators.py
🧬 Algorithms
Arprax Algorithms: Sorting Module.
Provides industrial-grade implementations of fundamental sorting algorithms. Includes elementary sorts (Selection, Insertion, Shell) and advanced sorts (Merge, Quick, Heap).
Features
- Generator Support: All functions support a 'visualize=True' flag to yield intermediate states for animation.
- Optimization: Quick Sort uses 3-way partitioning (Dijkstra) for duplicate handling.
- Efficiency: Merge Sort uses a single auxiliary array to reduce memory overhead.
Reference
Algorithms, 4th Edition by Sedgewick and Wayne, Chapter 2.
heap_sort(arr, visualize=False)
Heap Sort: Uses a binary heap to sort in-place. Guarantees O(N log N) time with O(1) space.
Source code in src/arprax/algos/algorithms/sorting.py
insertion_sort(arr, visualize=False)
Insertion Sort: Builds the sort by moving elements one at a time. Excellent for partially sorted arrays or small subarrays.
Complexity: Time O(N^2) (O(N) best case) | Space O(1)
Source code in src/arprax/algos/algorithms/sorting.py
merge_sort(arr, visualize=False)
Merge Sort: Recursive divide-and-conquer. Guarantees O(N log N) time, but requires O(N) auxiliary space.
Source code in src/arprax/algos/algorithms/sorting.py
quick_sort(arr, visualize=False)
Quick Sort (3-Way Partition): The standard for general purpose sorting. Uses Dijkstra's 3-way partitioning to handle duplicate keys efficiently.
Complexity: Time O(N log N) average | Space O(log N) recursion
Source code in src/arprax/algos/algorithms/sorting.py
selection_sort(arr, visualize=False)
Selection Sort: Scans for the minimum item and swaps it into place.
Complexity: Time O(N^2) | Space O(1)
Source code in src/arprax/algos/algorithms/sorting.py
shell_sort(arr, visualize=False)
Shell Sort: An optimized Insertion Sort using 'h-gaps'. Moves elements long distances to produce a partially sorted array, then finishes with standard insertion sort.
Complexity: Time O(N^1.5) approx | Space O(1)