Issues with user-defined codecs
- Lingua principale
- Python
- Stelle
- 211
- Fork
- 58
- Merge medio
- 1g 17h
- PR unite (30g)
- 6
Descrizione
I'm facing issues when creating a simple codec that just makes a copy of the data to get familiar with Blosc's registering machinery. I attach the code:
```python
import blosc2
import numpy as np
# Create an User-defined codec (just a memcpy)
def encoder(input, output, meta, schunk: blosc2.SChunk):
print(f"Encoder output size: {output.size}")
output[:schunk.blocksize] = input[:schunk.blocksize]
return schunk.blocksize
def decoder(input, output, meta, schunk: blosc2.SChunk):
output[:schunk.blocksize] = input[:schunk.blocksize]
return schunk.blocksize
# Register the codec
codec_id = 200
blosc2.register_codec('test1', codec_id, encoder, decoder)
# Compress this array with the new codec
shape = (100, 100)
a = np.ones(shape, dtype=np.int64)
cparams = {
'codec': codec_id,
'nthreads': 1,
'filters': [],
'splitmode': blosc2.SplitMode.NEVER_SPLIT,
}
dparams = {
'nthreads': 1,
}
chunks = shape
blocks = (50, 50)
c_a = blosc2.asarray(a, chunks=chunks, blocks=blocks, cparams=cparams, dparams=dparams)
```
However, when I run the previous code, I get the following:
```
Encoder output size: 20000
Encoder output size: 20000
Encoder output size: 20000
Encoder output size: 19968
ValueError: could not broadcast input array from shape (20000,) into shape (19968,)
```
Looking at this, it appears that the last block of the chunk is smaller than the others. Do you know what is happening? Is there something I'm doing wrong?
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia riproducendo l'esempio Python fornito e leggi i callback di register_codec insieme alla configurazione dei blocchi di asarray. Confronta le dimensioni di input e output per il blocco finale, quindi determina come il codec dovrebbe gestire quel blocco parziale; il lavoro è completato quando l'esempio termina senza l'errore di broadcast.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- numpy, python
- Ambito
- data
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100