nejucomo / dimana Goto Github PK
View Code? Open in Web Editor NEWDIMensional ANAlysis library for python - Extend Decimal arithmetic with arbitrary named units with unit error detection.
DIMensional ANAlysis library for python - Extend Decimal arithmetic with arbitrary named units with unit error detection.
It would be convenient to have parsers for both a unit specification and a complete value.
These would look something like:
>>> Watt = dimana.parse_unit('KG * M^2 / SEC^3')
>>> x = Watt(3)
>>> x
3 [KG * M^2 / SEC^3]
>>> x == dimana.parse('3.000 [KG * M^2 / SEC^3]')
True
I had a unity number stored in a variable named T1
, and then I did this::
>>> from decimal import Decimal
>>> D=Decimal
>>> D('0.16') * T1 - O1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for *: 'Decimal' and 'Dimensional_Units_1'
I had expected it to multiple T1
by the (dimensionless) 0.16 for me.
Allegedly there is a way to do this in dimana, using dimana.Dimensional('0.16)
instead of Decimal('0.16')
. So I have several requests/suggestions:
Dimensional
? That sounds wrong.Decimals
automatically to Dimensionlesses
? I guess there's a risk that a user would have a number stored in a Decimal
when they intended it to be a dimensioned number, like the number of Frobs, and forcing them to explicitly put Dimensionless('0.19')
would let them realize that they actually need Dimensional.get_dimension('Frobs')
. But I'm skeptical—why does Dimensionless('0.19')
help them notice that any better than Decimal('0.19')
helps them notice?In #1 @zooko considers it confusing that Dimensional('1.0')
is unitless, and also asks why not automatically coerce Decimals
to unitless Dimensionals
.
The docs should clarify the type checking philosophy of dimana, which is to always require application code to be explicit, and never to coerce values.
Rather than justify to users why a value without dimensional units is still considered "dimensional", just rename the class to Dimana
to reinforce the fact that it's a particular abstraction with a particular API, and to avoid different assumptions different users may have depending on their backgrounds.
The unittests only exercise dimensionless units by dint of being the result of raising a dimensional quantity to the zero-th power. It would be nice to have more tests which use dimensionless quantities, such as ratios, and zero powers.
Note: This is related to a user experience in #1.
Decimal
powers should be supported. They are supported by Decimal.__pow__
so the API follows both by analogy and by having a well-defined semantics to which Dimana
can delegate.
It's currently not clear from the docstrings how to create dimensionless numbers, as pointed out in the user experience issue #1.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.