Skip to content

Commit 8f5c6c8

Browse files
committed
Add doc for decimal2bitarray.
1 parent c67aa2a commit 8f5c6c8

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

commpy/utilities.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,26 @@
99
.. autosummary::
1010
:toctree: generated/
1111
12-
dec2bitarray -- Integer to binary (bit array).
12+
dec2bitarray -- Integer or array-like of integers to binary (bit array).
13+
decimal2bitarray -- Specialized version for one integer to binary (bit array).
1314
bitarray2dec -- Binary (bit array) to integer.
1415
hamming_dist -- Hamming distance.
1516
euclid_dist -- Squared Euclidean distance.
1617
upsample -- Upsample by an integral factor (zero insertion).
1718
signal_power -- Compute the power of a discrete time signal.
1819
"""
1920

20-
import itertools as it
21-
2221
import numpy as np
2322

24-
__all__ = ['dec2bitarray', 'bitarray2dec', 'hamming_dist', 'euclid_dist', 'upsample',
23+
__all__ = ['dec2bitarray', 'decimal2bitarray', 'bitarray2dec', 'hamming_dist', 'euclid_dist', 'upsample',
2524
'signal_power']
2625

2726
vectorized_binary_repr = np.vectorize(np.binary_repr)
2827

2928

3029
def dec2bitarray(in_number, bit_width):
3130
"""
32-
Converts a positive integer to NumPy array of the specified size containing
31+
Converts a positive integer or an array-like of positive integers to NumPy array of the specified size containing
3332
bits (0 and 1).
3433
3534
Parameters
@@ -42,21 +41,39 @@ def dec2bitarray(in_number, bit_width):
4241
4342
Returns
4443
-------
45-
bitarray : 1D ndarray of ints
44+
bitarray : 1D ndarray of numpy.int8
4645
Array containing the binary representation of all the input decimal(s).
4746
4847
"""
4948

5049
if isinstance(in_number, (np.integer, int)):
5150
return decimal2bitarray(in_number, bit_width)
52-
result = np.zeros(bit_width * len(in_number), 'int')
51+
result = np.zeros(bit_width * len(in_number), np.int8)
5352
for pox, number in enumerate(in_number):
5453
result[pox * bit_width:(pox + 1) * bit_width] = decimal2bitarray(number, bit_width)
5554
return result
5655

5756

5857
def decimal2bitarray(number, bit_width):
59-
result = np.zeros(bit_width, 'int')
58+
"""
59+
Converts a positive integer to NumPy array of the specified size containing bits (0 and 1). This version is slightly
60+
quicker that dec2bitarray but only work for one integer.
61+
62+
Parameters
63+
----------
64+
in_number : int
65+
Positive integer to be converted to a bit array.
66+
67+
bit_width : int
68+
Size of the output bit array.
69+
70+
Returns
71+
-------
72+
bitarray : 1D ndarray of numpy.int8
73+
Array containing the binary representation of all the input decimal(s).
74+
75+
"""
76+
result = np.zeros(bit_width, np.int8)
6077
i = 1
6178
pox = 0
6279
while i <= number:

0 commit comments

Comments
 (0)