Skip to content

Commit 82dc730

Browse files
Add information about memory profiling for Python programs.
1 parent 597ab21 commit 82dc730

15 files changed

+4030
-8
lines changed
0 Bytes
Binary file not shown.

notes/report/scratch-pad.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ Submission: Feb 12, 2020, anywhere on Earth
826826

827827

828828

829+
829830
+ finish automated regression for the *data analysis tool*:
830831
- data_analysis_tool.py
831832
* get_percent_error(experimental_value=1,theoretical_value=1).
@@ -840,6 +841,9 @@ Submission: Feb 12, 2020, anywhere on Earth
840841

841842

842843
+ perform ***performance sensitivity analysis and the optimization***
844+
+ [ ] memory profiling of *Python* programs
845+
- https://code.tutsplus.com/tutorials/understand-how-much-memory-your-python-objects-use--cms-25609
846+
843847

844848

845849
Need 27 classroom hours; I have 15 + 4 + 9 = 28 hours.

source/random_process_models/random_process_generator.py

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
2020
Revision History:
2121
September 6, 2019 Version 0.1 Script.
22+
23+
References:
24+
+ \cite[From section 'Built-in Functions']{DrakeJr2016b}.
25+
- Available online from Python: Python 3.8.2rc1
26+
documentation: The Python Standard Library:
27+
Built-in Functions at: https://docs.python.org/3/library/functions.html#bin;
28+
February 12, 2020 was the last accessed date.
29+
+ \cite{KiteStaff2020}
2230
"""
2331

2432
__author__ = 'Zhiyang Ong'
@@ -220,9 +228,10 @@ def gen_rand_signal_uniform_distributn(type_of_signal=bv_signal, n=16):
220228
"""
221229
return random_signal
222230
# ============================================================
223-
## Method to generate a discrete-time random signal/process
224-
# for "n" values, using another method from the random
225-
# module of the Python Standard Library.
231+
## Method to generate a bit vector -based discrete-time
232+
# random signal/process for "n" values, using another
233+
# method from the random module of the Python Standard
234+
# Library.
226235
#
227236
# Use the Python Standard Library's random module to call the
228237
# random.getrandbits(k) function that is based on the
@@ -233,13 +242,69 @@ def gen_rand_signal_uniform_distributn(type_of_signal=bv_signal, n=16):
233242
# - low value: "0"
234243
#
235244
# @param n - number of discrete values used to represent the
236-
# random signal/"process".
237-
# Its default value is: 16.
245+
# random bit vector signal/"process".
246+
# Its default value is: 16.
238247
# @return - Nothing.
239248
# O(1) method.
249+
#
250+
# Reference:
251+
# + [KiteStaff2020]
252+
# - Kite staff, "getrandbits", from Kite: The Python Language:
253+
# Kite Docs: random, Kite, San Francisco, CA, no date.
254+
# Available online from Kite: The Python Language:
255+
# Kite Docs: random at: https://kite.com/python/docs/random.getrandbits;
256+
# February 12, 2020 was the last accessed date.
257+
#
258+
# Additional resources:
259+
# + https://pythonhosted.org/bitstring/bitarray.html
260+
# + https://wiki.python.org/moin/BitArrays
261+
240262
@staticmethod
241263
def gen_bit_vector_getrandbits(n=16):
242-
return random.getrandbits(n)
264+
# Empty list representation of a random bit vector/signal.
265+
list_of_int_representation_of_bv = []
266+
"""
267+
Since the method call random.getrandbits(n) generates
268+
an integer representation of a bit-vector, the
269+
bin() method is needed to map/transform the
270+
integer-representation of a bit-vector into a
271+
binary string representation.
272+
273+
Add one to the input argument of random.getrandbits(),
274+
since it would only generate (n-1) values/digits
275+
otherwise.
276+
277+
References for using bin() to convert integers
278+
into a binary string.
279+
+ \cite[From section 'Built-in Functions']{DrakeJr2016b}.
280+
- Available online from Python: Python 3.8.2rc1
281+
documentation: The Python Standard Library:
282+
Built-in Functions at: https://docs.python.org/3/library/functions.html#bin;
283+
February 12, 2020 was the last accessed date.
284+
+ \cite{KiteStaff2020}
285+
"""
286+
#bin_representation_of_bv = bin(random.getrandbits(n+1))
287+
bin_representation_of_bv = bin(random.getrandbits(n))
288+
print("!!! bin_representation_of_bv is:",bin_representation_of_bv,".")
289+
print("!!! bin_representation_of_bv[2:] is:",bin_representation_of_bv[2:],".")
290+
"""
291+
Map/transform the integer-representation of a
292+
bit-vector into a binary string representation.
293+
"""
294+
list_representation_of_bv = list(bin_representation_of_bv[2:])
295+
"""
296+
For each value/digit/bit in the random bit vector
297+
signal/"process",
298+
"""
299+
#for value_in_bv in list_representation_of_bv:
300+
for index_in_bv in range(len(list_representation_of_bv)):
301+
"""
302+
Cast it into an integer and add it to the
303+
list representation of the random integer
304+
bits.
305+
"""
306+
list_of_int_representation_of_bv.append(int(list_representation_of_bv[index_in_bv]))
307+
return list_of_int_representation_of_bv
243308

244309

245310

source/random_process_models/random_process_generator_tester.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,23 @@ def test_gen_rand_signal_uniform_distributn():
145145
# O(1) method.
146146
@staticmethod
147147
def test_gen_bit_vector_getrandbits():
148+
print(" Testing gen_bit_vector_getrandbits().")
149+
prompt = " ... Test random bit vector generation: default 16 bits. {}"
148150
# Number of discrete values representing a random signal/"process".
151+
k = 16
152+
statistical_analysis.increment_number_test_cases_used()
153+
temp_rand_signal = rand_signal_generator.gen_bit_vector_getrandbits()
154+
#print("!!! temp_rand_signal is:",temp_rand_signal,".")
155+
if (k == len(temp_rand_signal)) and ((0 in temp_rand_signal) or (1 in temp_rand_signal)) and (not (-1 in temp_rand_signal)) and (not (3.14 in temp_rand_signal)):
156+
print(prompt .format("OK"))
157+
statistical_analysis.increment_number_test_cases_passed()
158+
else:
159+
print(prompt .format("FAIL!!!"))
160+
prompt = " ... Test random bit vector generation: 8 bits. {}"
149161
k = 8
150-
print(" Testing gen_rand_signal_uniform_distributn().")
151-
prompt = " ... Test: type of signal = bit vector. {}"
152162
statistical_analysis.increment_number_test_cases_used()
153163
temp_rand_signal = rand_signal_generator.gen_bit_vector_getrandbits(k)
164+
#print("!!! temp_rand_signal is:",temp_rand_signal,".")
154165
if (k == len(temp_rand_signal)) and ((0 in temp_rand_signal) or (1 in temp_rand_signal)) and (not (-1 in temp_rand_signal)) and (not (3.14 in temp_rand_signal)):
155166
print(prompt .format("OK"))
156167
statistical_analysis.increment_number_test_cases_passed()

0 commit comments

Comments
 (0)