azaghal / pydenticon

Pydenticon is a small utility library that can be used for deterministically generating identicons based on the hash of provided data.
BSD 3-Clause "New" or "Revised" License
66 stars 10 forks source link

The generator does not work with non-square output sizes #12

Open benelot opened 1 year ago

benelot commented 1 year ago

I tried to print pydenticons for my numpy matrices, which works quite well for square input, but gets a problem with non-square identicons.

data = np.array2string(np_array)

# Instantiate a generator.
generator = Generator(10, 3, digest=hashlib.sha256)

# Call the method and get the results.
asciidenticon = generator.generate(data, 10, 3, output_format="ascii")
print(asciidenticon)

Am I using it incorrectly?

benelot commented 1 year ago

Interestingly, this way around it works quite well, but the height of 4 seems to cause issues, saying two matrices are equal when they are not. But this is related to the vertical symmetry property of the identicons, reducing the entropy of the identicon massively to only a few bits.

data = np.array2string(np_array)

# Instantiate a generator.
generator = Generator(4, 25, digest=hashlib.sha256)

# Call the method and get the results.
asciidenticon = generator.generate(data, 4, 25, output_format="ascii")
print(asciidenticon)
azaghal commented 1 year ago

Hm... You know, I wouldn't be surprised if I never tested with non-square output size. When you say you face a problem, can you elaborate a bit?

benelot commented 1 year ago

Haha, yes I thought so. It is rather atypical to have them non-square, but I use them to compare to numpy matrices so I quickly see if they are the same, so I print the ascii version to console. If I use a non-square output size, I get a classical array index out of bounds error.