-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
before enforcing bit def, basck to string
- Loading branch information
1 parent
a3a671d
commit 1b84fb3
Showing
11 changed files
with
188 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,23 @@ | ||
import numpy as np | ||
from ....types import BitsList, AbstractBitsType | ||
from ....types import BitsList | ||
|
||
|
||
def bits_array_from_bits_amount( | ||
bits_amount: int, | ||
bit_format: AbstractBitsType = "int", | ||
) -> BitsList: | ||
def bits_array_from_bits_amount(bits_amount: int) -> BitsList: | ||
""" | ||
Returns an array of bits from a given amount of bits. | ||
Returns an array of bits (in bytes) of a given length. | ||
Args: | ||
bits_amount(int): Amount of bits to generate. | ||
bit_format(str): Format of the bits to generate. | ||
Returns: | ||
bit_array(np.ndarray): Array of bits. | ||
BitsList: List of binary representations in bytes. | ||
""" | ||
maximum_integer_represented = 2 ** (bits_amount) | ||
int_array = np.arange(maximum_integer_represented) | ||
bit_array = np.vectorize(np.base_repr)(int_array) | ||
if bit_format == "int": | ||
pass | ||
elif bit_format == "str": | ||
# Add leading zeros to bit strings | ||
bit_array = np.vectorize(lambda x: x.zfill(bits_amount))(bit_array) | ||
# Generate range of integers from 0 to 2^bits_amount - 1 | ||
maximum_integer_represented = 2 ** bits_amount | ||
|
||
# Convert each integer to its binary representation, padded with leading zeros | ||
bit_array = [ | ||
format(i, f'0{bits_amount}b').encode('ascii') # Convert each binary string to bytes | ||
for i in range(maximum_integer_represented) | ||
] | ||
|
||
return bit_array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,4 +54,5 @@ | |
convert_tuple_to_string, | ||
convert_2d_array_to_string, | ||
convert_to_bits, | ||
convert_dataframe_to_bytes | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.