diff options
| author | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2019-03-21 16:37:26 +0100 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2019-03-21 16:46:26 +0100 |
| commit | a3663b7b3bdc092fb0667ea6c16b8e9a6cf4cf73 (patch) | |
| tree | 8d0374b40072883b392acf473328dba9887db95c /python | |
| parent | aaf0d2c49f343e909dc69b487056ca31238ffabf (diff) | |
| download | lilliput-ae-implem-a3663b7b3bdc092fb0667ea6c16b8e9a6cf4cf73.tar.xz | |
[implem-python] Utilisation des divisions entières //
Plutôt que int() ; moins de bruit.
… Au passage, simplification (j'espère) de ArrayToBlockbytesMatrix() :
- pas besoin d'initialiser la matrice à zéro ; suffit d'ajouter les
octets et les blocs comme ils viennent,
- AFAICT,
int((length + (BLOCK_BYTES - (length % BLOCK_BYTES))) / BLOCK_BYTES)
quand length % BLOCK_BYTES > 0, c'est juste une façon compliquée
d'écrire
int(length/BLOCK_BYTES) + 1
Diffstat (limited to 'python')
| -rw-r--r-- | python/helpers.py | 27 | ||||
| -rw-r--r-- | python/lilliput_ae_1.py | 11 |
2 files changed, 21 insertions, 17 deletions
diff --git a/python/helpers.py b/python/helpers.py index b02bea4..07affa9 100644 --- a/python/helpers.py +++ b/python/helpers.py @@ -3,20 +3,23 @@ from lilliput_tbc import LilliputTBCEnc def ArrayToBlockbytesMatrix(array): - length = len(array) - pad = 0 - if length % BLOCK_BYTES == 0: - number_blocks = int(length / BLOCK_BYTES) - else: - number_blocks = int((length + (BLOCK_BYTES - (length % BLOCK_BYTES))) / BLOCK_BYTES) - pad = 1 + vector = list(array) + + blocks_nb = len(vector)//BLOCK_BYTES + + block_starts = ( + i*BLOCK_BYTES for i in range(blocks_nb) + ) + + matrix = [ + vector[start:start+BLOCK_BYTES] for start in block_starts + ] - matrix = [[0] * BLOCK_BYTES for block in range(0, number_blocks - pad)] - if pad == 1: - matrix.append([0] * (length % BLOCK_BYTES)) + padding_len = len(vector)%BLOCK_BYTES - for byte in range(0, length): - matrix[int(byte / BLOCK_BYTES)][byte % BLOCK_BYTES] = array[byte] + if padding_len > 0: + padding = vector[-padding_len:] + matrix.append(padding) return matrix diff --git a/python/lilliput_ae_1.py b/python/lilliput_ae_1.py index 9aad3a6..0bc4236 100644 --- a/python/lilliput_ae_1.py +++ b/python/lilliput_ae_1.py @@ -31,13 +31,14 @@ def LowPart(array, number_bits): lower_part = shifted & mask - will_padd = 0 + will_pad = 0 if number_bits % 8 != 0: - will_padd = 1 + will_pad = 1 - lower_part_byte = [0 for byte in range(0, int(number_bits / 8) + will_padd)] - for byte in range(0, int(number_bits / 8) + will_padd): - lower_part_byte[byte] = lower_part & 0xff + lower_part_byte = [] + nb_bytes = number_bits//8 + will_pad + for byte in range(nb_bytes): + lower_part_byte.append(lower_part & 0xff) lower_part = lower_part >> 8 return lower_part_byte |
