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.1.tar.gz
(11.1 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.1.tar.gz.
File metadata
- Download URL: hugenats-0.1.1.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
407c5de0d4cf79df3229aa2a64062eadf233331398574fd5406cc2e95916f75b
|
|
| MD5 |
ffe641b2637f8e3a8fbcffddd1326ebb
|
|
| BLAKE2b-256 |
ec93b1a1b4ac839588713058b0d7377ee9a0bce6a4357b453151831dea31bd1e
|
File details
Details for the file hugenats-0.1.1-py3-none-any.whl.
File metadata
- Download URL: hugenats-0.1.1-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 |
2d2e5076cf995bf4befaa6a88b7ae7f038a6a884bc1f69d2a48b4cacdb7860b8
|
|
| MD5 |
f4d948c96c49af9266237ba6da6c1dd4
|
|
| BLAKE2b-256 |
2b27fa0f3f0c347318d6b967b42b94f8953f5942f982efb9bca049411374cb79
|