From 719b9c7f6183b959c0d306949ca7710637fc25a8 Mon Sep 17 00:00:00 2001 From: Michel Wermelinger Date: Thu, 14 Mar 2024 17:10:38 +0000 Subject: [PATCH] Fix #22: rename `start_size` to `start`(#25) Conflicted generated docs were removed, will have to be regenerated --- docs/essays/example-jewels/index.html | 10 ++++---- docs/essays/example-two-sum-3/index.html | 10 ++++---- .../template-data-structures/index.html | 4 ++-- docs/library/index.html | 18 +++++++------- docs/writing/index.html | 6 ++--- src/algoesup/time.py | 24 +++++++++---------- src/docs/essays/example-jewels.ipynb | 6 ++--- src/docs/essays/example-two-sum-3.ipynb | 6 ++--- .../essays/template-data-structures.ipynb | 2 +- src/docs/writing.md | 6 ++--- 10 files changed, 46 insertions(+), 46 deletions(-) diff --git a/docs/essays/example-jewels/index.html b/docs/essays/example-jewels/index.html index e45e6a3..34f6c2c 100644 --- a/docs/essays/example-jewels/index.html +++ b/docs/essays/example-jewels/index.html @@ -1285,7 +1285,7 @@
@@ -2260,10 +2260,10 @@

4.2 Best, normal and worst run-times
cases = [best_case, normal_case, worst_case]
-time_cases(count_in_string, cases, start_size=10, double=4)
+time_cases(count_in_string, cases, start=10, double=4)
 
cases = [best_case, normal_case, worst_case] -time_cases(count_in_string, cases, start_size=10, double=4)
+time_cases(count_in_string, cases, start=10, double=4) @@ -2334,9 +2334,9 @@

4.2 Best, normal and worst run-times -
time_cases(count_in_string, cases, start_size=1000, double=4, chart=True)
+
time_cases(count_in_string, cases, start=1000, double=4, chart=True)
 
-
time_cases(count_in_string, cases, start_size=1000, double=4, chart=True)
+
time_cases(count_in_string, cases, start=1000, double=4, chart=True)
diff --git a/docs/essays/example-two-sum-3/index.html b/docs/essays/example-two-sum-3/index.html index 47f3847..8ca3132 100644 --- a/docs/essays/example-two-sum-3/index.html +++ b/docs/essays/example-two-sum-3/index.html @@ -1309,7 +1309,7 @@ @@ -2193,10 +2193,10 @@

4.2 Best, normal and worst case
input_generators = [worst, normal, best]
-time_cases(two_sum_bf, input_generators, start_size=100, double=4, chart=True)
+time_cases(two_sum_bf, input_generators, start=100, double=4, chart=True)
 
input_generators = [worst, normal, best] -time_cases(two_sum_bf, input_generators, start_size=100, double=4, chart=True)
+time_cases(two_sum_bf, input_generators, start=100, double=4, chart=True) @@ -2263,10 +2263,10 @@

4.2 Best, normal and worst case
input_generators = [worst, normal, best]
-time_cases(two_sum_map, input_generators, start_size=100, double=4, chart=True)
+time_cases(two_sum_map, input_generators, start=100, double=4, chart=True)
 
input_generators = [worst, normal, best] -time_cases(two_sum_map, input_generators, start_size=100, double=4, chart=True)
+time_cases(two_sum_map, input_generators, start=100, double=4, chart=True) diff --git a/docs/essays/template-data-structures/index.html b/docs/essays/template-data-structures/index.html index 615c6a9..9e1223a 100644 --- a/docs/essays/template-data-structures/index.html +++ b/docs/essays/template-data-structures/index.html @@ -1750,11 +1750,11 @@

4.2 Best, normal and worst run-times
cases = [best_case, normal_case, worst_case]
 # Change solution_n to the name of your solution.
-time_cases(solution_n, cases, start_size=10, double=4)
+time_cases(solution_n, cases, start=10, double=4)
 
cases = [best_case, normal_case, worst_case] # Change solution_n to the name of your solution. -time_cases(solution_n, cases, start_size=10, double=4)
+time_cases(solution_n, cases, start=10, double=4) diff --git a/docs/library/index.html b/docs/library/index.html index 12e2749..2ef9536 100644 --- a/docs/library/index.html +++ b/docs/library/index.html @@ -1282,7 +1282,7 @@

-
time_cases(function: Callable, cases: list[Callable], start_size: int, double: int, text: bool = True, chart: bool = False) -> None
+
time_cases(function: Callable, cases: list[Callable], start: int, double: int, text: bool = True, chart: bool = False) -> None
 
@@ -1312,7 +1312,7 @@

-

A functions whose run-times will be measured.

+

A function whose run-times will be measured.

@@ -1326,8 +1326,8 @@

-

A list of functions to generate inputs of different cases. -E.g best- normal- and worst-case.

+

A list of 1 to 6 functions to generate inputs of different cases, +e.g. best-, normal- and worst-case.

@@ -1335,7 +1335,7 @@

- start_size + start int @@ -1383,7 +1383,7 @@

-

If True plot the run-times using a chart.

+

If True, plot the run-times using a chart.

@@ -1431,7 +1431,7 @@

-
time_functions_int(functions: list[Callable], generator: Callable = int_value, start_size: int = 1, double: int = 10, text: bool = True, chart: bool = True) -> None
+
time_functions_int(functions: list[Callable], generator: Callable = int_value, start: int = 1, double: int = 10, text: bool = True, chart: bool = True) -> None
 
@@ -1478,7 +1478,7 @@

A function to generate integer inputs. Defaults to -int_value, which should generate an integer based on the input size.

+int_value, which returns a tuple containing the input integer.

@@ -1486,7 +1486,7 @@

- start_size + start int diff --git a/docs/writing/index.html b/docs/writing/index.html index 1129b3d..e1622a7 100644 --- a/docs/writing/index.html +++ b/docs/writing/index.html @@ -1537,7 +1537,7 @@

Comparing cases

Here’s how we could measure the run-times for selection sort on ascending and descending lists.

from algoesup import time_cases
 
-time_cases(selection_sort, [ascending, descending], start_size=100, double=4)
+time_cases(selection_sort, [ascending, descending], start=100, double=4)
 

Output

@@ -1577,7 +1577,7 @@

Comparing functions

Here’s a comparison of the built-in sorted function against selection sort, on descending lists.

from algoesup import time_functions
 
-time_functions([selection_sort, sorted], descending, start_size=100, double=4)
+time_functions([selection_sort, sorted], descending, start=100, double=4)
 

Output

@@ -1643,7 +1643,7 @@

Interpreting run-times

which is counter-intuitive because it does have to reverse them.

If you can’t see any trend in the run-times, or they aren’t what you expect, one possible cause is that the input sizes are too small. -Increase start_size and run again the code cell.

+Increase start and run again the code cell.

If after increasing the start size several times you still don’t get the run-times you expect from your complexity analysis, then there might be other explanations:

    diff --git a/src/algoesup/time.py b/src/algoesup/time.py index 5038831..ba77ea4 100644 --- a/src/algoesup/time.py +++ b/src/algoesup/time.py @@ -51,7 +51,7 @@ def time_it(function: Callable, *args, loops=0, repeat=3) -> float: def time_cases( function: Callable, cases: list[Callable], - start_size: int, + start: int, double: int, text: bool = True, chart: bool = False, @@ -63,23 +63,23 @@ def time_cases( doubled a specified number of times. Args: - function (Callable): A functions whose run-times will be measured. - cases (list[Callable]): A list of functions to generate inputs of different cases. - E.g best- normal- and worst-case. - start_size (int): The starting size for the inputs. Must be positive. + function (Callable): A function whose run-times will be measured. + cases (list[Callable]): A list of 1 to 6 functions to generate inputs of different cases, + e.g. best-, normal- and worst-case. + start (int): The starting size for the inputs. Must be positive. double (int): The number of times to double the input size. Must be non-negative. text (bool, optional): If True, print the run-times in text format. - chart (bool, optional): If True plot the run-times using a chart. + chart (bool, optional): If True, plot the run-times using a chart. Raises: AssertionError: If input conditions are not satisfied. """ - assert start_size > 0, "the start size must be positive" + assert start > 0, "the start size must be positive" assert double >= 0, "must double the input size at least zero times" assert 0 < len(cases) < 7, "there must be 1 to 6 input functions" assert text or chart, "at least one of text and chart must be enabled" - sizes = [start_size] # the input sizes used + sizes = [start] # the input sizes used for _ in range(double): sizes.append(sizes[-1] * 2) scale = unit = None # no scale determined yet @@ -197,7 +197,7 @@ def time_functions( def time_functions_int( functions: list[Callable], generator: Callable = int_value, - start_size: int = 1, + start: int = 1, double: int = 10, text: bool = True, chart: bool = True, @@ -213,12 +213,12 @@ def time_functions_int( functions (list[Callable]): A list of functions whose run-times will be measured. Each function must accept a single integer argument. Must be 1 to 6 functions. generator (Callable, optional): A function to generate integer inputs. Defaults to - `int_value`, which should generate an integer based on the input size. - start_size (int, optional): The starting integer value for inputs. Defaults to 1. + `int_value`, which returns a tuple containing the input integer. + start (int, optional): The starting integer value for inputs. Defaults to 1. Must be positive. double (int, optional): The number of times to double the input integer value. Defaults to 10. Must be non-negative. text (bool, optional): If True, print the run-times in text format. chart (bool, optional): If True, plot the run-times using a chart. """ - time_functions(functions, generator, start_size, double, text, chart, True) + time_functions(functions, generator, start, double, text, chart, True) diff --git a/src/docs/essays/example-jewels.ipynb b/src/docs/essays/example-jewels.ipynb index 2d84248..4f54cf1 100644 --- a/src/docs/essays/example-jewels.ipynb +++ b/src/docs/essays/example-jewels.ipynb @@ -10,7 +10,7 @@ "source": [ "# Jewels and Stones\n", "\n", - "*Michel Wermelinger*, 23 January 2024" + "*Michel Wermelinger*, 23 January 2024, last updated 13 March 2024" ] }, { @@ -681,7 +681,7 @@ ], "source": [ "cases = [best_case, normal_case, worst_case]\n", - "time_cases(count_in_string, cases, start_size=10, double=4)" + "time_cases(count_in_string, cases, start=10, double=4)" ] }, { @@ -754,7 +754,7 @@ } ], "source": [ - "time_cases(count_in_string, cases, start_size=1000, double=4, chart=True)" + "time_cases(count_in_string, cases, start=1000, double=4, chart=True)" ] }, { diff --git a/src/docs/essays/example-two-sum-3.ipynb b/src/docs/essays/example-two-sum-3.ipynb index 93dc4c6..fcb99f8 100644 --- a/src/docs/essays/example-two-sum-3.ipynb +++ b/src/docs/essays/example-two-sum-3.ipynb @@ -7,7 +7,7 @@ "source": [ "# Two sum (three solutions)\n", "\n", - "*Michael Snowden*, 25 January 2024" + "*Michael Snowden*, 25 January 2024, last updated 13 March 2024" ] }, { @@ -730,7 +730,7 @@ ], "source": [ "input_generators = [worst, normal, best]\n", - "time_cases(two_sum_bf, input_generators, start_size=100, double=4, chart=True)" + "time_cases(two_sum_bf, input_generators, start=100, double=4, chart=True)" ] }, { @@ -779,7 +779,7 @@ ], "source": [ "input_generators = [worst, normal, best]\n", - "time_cases(two_sum_map, input_generators, start_size=100, double=4, chart=True)" + "time_cases(two_sum_map, input_generators, start=100, double=4, chart=True)" ] }, { diff --git a/src/docs/essays/template-data-structures.ipynb b/src/docs/essays/template-data-structures.ipynb index bd7ad25..ea2c9e7 100644 --- a/src/docs/essays/template-data-structures.ipynb +++ b/src/docs/essays/template-data-structures.ipynb @@ -294,7 +294,7 @@ "source": [ "cases = [best_case, normal_case, worst_case]\n", "# Change solution_n to the name of your solution.\n", - "time_cases(solution_n, cases, start_size=10, double=4)" + "time_cases(solution_n, cases, start=10, double=4)" ] }, { diff --git a/src/docs/writing.md b/src/docs/writing.md index 01c0c17..523f3eb 100644 --- a/src/docs/writing.md +++ b/src/docs/writing.md @@ -440,7 +440,7 @@ Here's how we could measure the run-times for selection sort on ascending and de ```python from algoesup import time_cases -time_cases(selection_sort, [ascending, descending], start_size=100, double=4) +time_cases(selection_sort, [ascending, descending], start=100, double=4) ``` !!! success "Output" ``` @@ -486,7 +486,7 @@ Here's a comparison of the built-in `sorted` function against selection sort, on ```python from algoesup import time_functions -time_functions([selection_sort, sorted], descending, start_size=100, double=4) +time_functions([selection_sort, sorted], descending, start=100, double=4) ``` !!! success "Output" ``` @@ -559,7 +559,7 @@ which is counter-intuitive because it does have to reverse them. If you can't see any trend in the run-times, or they aren't what you expect, one possible cause is that the input sizes are too small. -Increase `start_size` and run again the code cell. +Increase `start` and run again the code cell. If after increasing the start size several times you still don't get the run-times you expect from your complexity analysis, then there might be other explanations: