Wrapper de int para numeros naturales grandes con slicing por bits
Project description
HugeNats
HugeNats es una clase HugeNat para representar numeros naturales grandes (ℕ₀) como un wrapper de int, con indexado y slicing por bits, mas utilidades compatibles con int.
Instalacion
pip install HugeNats
Uso rapido
from hugenat import HugeNat
import numpy as np
x = HugeNat(123456789)
limbs = np.array([0xFFFFFFFFFFFFFFFF, 0x1], dtype=np.uint64)
y = HugeNat(limbs)
z = HugeNat([0, 1, 0, 2])
Caracteristicas
- Solo naturales (incluye 0)
- Bit indexing y slicing por bits
- Metodos tipo
int:bit_length,bit_count,to_bytes,from_bytes - Vista de bits:
bits(order="msb->lsb" | "lsb->msb", length=None) - Nucleo Numba-friendly con
to_core()yfrom_core()
Bits e indexado
x = HugeNat(0b1101101)
x[0] # 1 (LSB)
x[-1] # 1 (MSB)
x[100] # 0 (fuera de rango)
x[0:3] # bits 0..2, recompactados
x[1:6:2] # slicing con step arbitrario
Numba (core)
from numba import njit
from hugenat import HugeNat
@njit
def popcount_core(limbs, nbits):
total = 0
for i in range(limbs.size):
total += int(limbs[i]).bit_count()
return total
h = HugeNat(1234)
limbs, nbits = h.to_core()
popcount_core(limbs, nbits)
Limbs
- 1D
uint64little-endian por palabra limbs[0]contiene los bits 0..63- Se recortan ceros lideres al final del array
Licencia
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
hugenats-0.1.0.tar.gz
(11.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hugenats-0.1.0.tar.gz.
File metadata
- Download URL: hugenats-0.1.0.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d257e6e5806297bdd9dc067212f11068aebee4a8189b5ed38bce65986519da2d
|
|
| MD5 |
d7f5603e7ed2b92b0bbedf92277a4e82
|
|
| BLAKE2b-256 |
357dd46a3b9ce7342fff84257a385ffa855911939edf5fb7b764102dc8ed66fb
|
File details
Details for the file hugenats-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hugenats-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30319e2d709760e56d62638080c5223f9e650b678b5251272798a3be36b2364a
|
|
| MD5 |
8e5e2447519443cde1fefb1fbd226e98
|
|
| BLAKE2b-256 |
5d3eff92a969275f7663f3047913fe2f53f46040bd72745aa33b1e51e335081e
|