Comments (1)
Thanks for reporting! Please note that there's a bug in the following line:
dummy_entropy_model = constriction.stream.model.CustomModel(cdf ,inverse_cdf, -10, 10)
The argument -10
states that the CustomModel
should support symbols from the integer range {-10, -9, ..., 10}
. Therefore, constriction
correctly assumes that it should be allowed to evaluate the cdf at negative values.
Changing the argument from -10
to 0
fixes the encoding part, but now decoding fails. This is still technically correct behavior as CustomModel
does not guarantee to only probe the cdf within the range of supported symbols (being allowed to probe outside the range of supported symbols slightly simplifies the code that calculates the exact inverse cdf). But looking at this example, I now agree that this can cause confusion, and I'll look into fixing it. Also, I agree that the error messages should be better.
Side Node
Assertions generally can't be used to tell an interpreter or compiler not to do something. They are a tool for (i) documenting invariants for human readers of the source code and for (ii) bailing in case a program or library contains a logic error or is used incorrectly.
This is nothing specific about constriction
(or even about python). For example, the code below throws an AssertionError
because it calls divide
with argument b=0
at some point even though the assert
statement inside divide
states otherwise. This is because an assert
statement never enforces the asserted condition. It just checks if the condition is met, and interrupts control flow if it isn't.
def divide(a, b):
assert b != 0
return a / b
print([divide(1, x) for x in range(-10, 11)])
Preventing callers from calling a function unless certain conditions are met cannot be achieved with assertions inside the function body. It would instead require either a more expressive type system that makes invalid function arguments inexpressible, or a more elaborate mechanism such as design by contract.
from constriction.
Related Issues (10)
- ImportError: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found HOT 2
- Creating a categorical distribution sometimes fails to converge HOT 1
- Output Dict/Struct of Huffman Symbol Codes HOT 2
- Vectorize cdf query of custom model HOT 1
- Different behavior on amd64 and arm HOT 8
- Relax minimal numpy version, if possible HOT 6
- Encoding int8/unit8 streams of symbols HOT 5
- List `LICENSE.html` in `RECORD` file of python wheels HOT 1
- TANS with separate probability HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from constriction.