Comments (6)
Looks like both of those errors stem from isapprox
implementation of rtol
and atol
settings here, I.e.
atol::Real=0, rtol::Real=rtoldefault(x,y,atol)
where rtoldefault
here calls real(T)
.
Edit: I went back and forked this into its own Issue with a MWE.
from dynamicquantities.jl.
It doesn't necessarily have to be type unstable. For example, you could have a boolean valid
bit in a Dimensions object, with valid = 0
in this case. I did something like this in StochasticAD.jl: https://github.com/gaurav-arya/StochasticAD.jl/blob/e13ee20616ec8cc053dab181ef9bccd160b0d12a/src/backends/pruned_aggressive.jl#L50-L53
In theory, the type approach + union splitting could also work. This could in theory be superior to the valid
bit approach in that the branch will only be created in the case where one of the units could feasibly be invalid, as opposed to all the time for every addition of quantities. So this seems promising -- I just don't personally have a good mental model for when union splitting runs, its performance, etc.
Am I understanding correctly that we'd want to make the units of this zero a "wildcard", i.e willing to assume the units of any other type? It would make code such as zero(typeof(1u"m")) + 1u"s"
work, but perhaps that's OK / a worthwhile tradeoff. [Edit: re-reading, yes I am pretty sure this is what you mean:)]
from dynamicquantities.jl.
Pasted from #77
I think one alternative is to allow a user to temporarily disable dimensional analysis in a particular scope, so that the first call of a Base.:+(::Quantity, ::Number)
would simply take the first dimensions it sees. Maybe like
using DynamicQuantities
@dimension_globbing begin
u"km/s" + one(typeof(u"km/s"))
end
which would result as 1001 m/s
. The one(u"km/s") == 1.0
but since you turned on dimension globbing, the 1.0 would automatically take the units m/s
from the u"km/s"
part.
from dynamicquantities.jl.
Just came over to mention this occurs when trying to compose DynamicQuantities.jl with the geometric representations from Meshes.jl.
using DynamicQuantities
using Meshes
Meshes.Point(1.0m, 2.0m)
Example error stack trace:
ERROR: Cannot create an additive identity for a `UnionAbstractQuantity` type, as the dimensions are unknown. Please use `zero(::UnionAbstractQuantity)` instead.
Stacktrace:
[1] error(s::String)
@ Base .\error.jl:35
[2] zero(::Type{DynamicQuantities.Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}})
@ DynamicQuantities C:\Users\x\.julia\packages\DynamicQuantities\HYcKp\src\utils.jl:280
[3] float(::Type{DynamicQuantities.Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}})
@ Base .\float.jl:311
[4] Vec(coords::Tuple{DynamicQuantities.Quantity{…}, DynamicQuantities.Quantity{…}})
@ Meshes C:\Users\x\.julia\packages\Meshes\Lb9po\src\vectors.jl:46
[5] Vec(::DynamicQuantities.Quantity{Float64, Dimensions{…}}, ::Vararg{DynamicQuantities.Quantity{…}})
@ Meshes C:\Users\x\.julia\packages\Meshes\Lb9po\src\vectors.jl:58
[6] Point(::DynamicQuantities.Quantity{Float64, Dimensions{…}}, ::Vararg{DynamicQuantities.Quantity{…}})
@ Meshes C:\Users\x\.julia\packages\Meshes\Lb9po\src\primitives\point.jl:48
[7] top-level scope
@ REPL[15]:1
Some type information was truncated. Use `show(err)` to see complete types.
from dynamicquantities.jl.
Thanks, I posted a comment there as well.
I'd be open to the idea #76 (comment) if someone wants to try it. It's not really a robust approach to this, but it is a temporary workaround in case there are issues like this in a downstream package.
from dynamicquantities.jl.
Thanks again for the quick fix to float(T)
, @MilesCranmer !
I just updated my LineIntegrals.jl package to enable tests with DynamicQuantities.jl and have run into a new hurdle. I don't time to dig in more at the moment, but it looks like Julia's isapprox
also runs into issues with zero(T)
and something about Quantity<:Real
, e.g.:
Scalar-Valued Functions: Error During Test at C:\Users\mikei\.julia\packages\LineIntegrals\Y8iYI\test\runtests.jl:159
Test threw exception
Expression: isapprox(integral(f, unit_circle), (2π) * Ω; atol = 0.15Ω)
TypeError: in keyword argument atol, expected Real, got a value of type DynamicQuantities.Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}
Stacktrace:
[1] isapprox(l::DynamicQuantities.Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}, r::DynamicQuantities.Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}; kws::@Kwargs{atol::DynamicQuantities.Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}})
@ DynamicQuantities C:\Users\mikei\.julia\packages\DynamicQuantities\jkfTz\src\utils.jl:227
[2] eval_test(evaluated::Expr, quoted::Expr, source::LineNumberNode, negate::Bool)
@ Test C:\Users\mikei\.julia\juliaup\julia-1.10.0+0.x64.w64.mingw32\share\julia\stdlib\v1.10\Test\src\Test.jl:367
[3] macro expansion
@ C:\Users\mikei\.julia\juliaup\julia-1.10.0+0.x64.w64.mingw32\share\julia\stdlib\v1.10\Test\src\Test.jl:669 [inlined]
[4] macro expansion
@ C:\Users\mikei\.julia\packages\LineIntegrals\Y8iYI\test\runtests.jl:159 [inlined]
[5] macro expansion
@ C:\Users\mikei\.julia\juliaup\julia-1.10.0+0.x64.w64.mingw32\share\julia\stdlib\v1.10\Test\src\Test.jl:1577 [inlined]
[6] macro expansion
@ C:\Users\mikei\.julia\packages\LineIntegrals\Y8iYI\test\runtests.jl:154 [inlined]
[7] macro expansion
@ C:\Users\mikei\.julia\juliaup\julia-1.10.0+0.x64.w64.mingw32\share\julia\stdlib\v1.10\Test\src\Test.jl:1577 [inlined]
[8] top-level scope
@ C:\Users\mikei\.julia\packages\LineIntegrals\Y8iYI\test\runtests.jl:128
Vector-Valued Functions: Error During Test at C:\Users\mikei\.julia\packages\LineIntegrals\Y8iYI\test\runtests.jl:164
Test threw exception
Expression: integral(f, seg_ne) ≈ [sqrt(2), sqrt(2), sqrt(2)] .* Ω
Cannot create an additive identity for a `UnionAbstractQuantity` type, as the dimensions are unknown. Please use `zero(::UnionAbstractQuantity)` instead.
Stacktrace:
[1] error(s::String)
@ Base .\error.jl:35
[2] zero(::Type{DynamicQuantities.Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}})
@ DynamicQuantities C:\Users\mikei\.julia\packages\DynamicQuantities\jkfTz\src\utils.jl:280
[3] real(T::Type)
@ Base .\complex.jl:120
[4] rtoldefault(x::Type{DynamicQuantities.Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}}, y::Type{DynamicQuantities.Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}}, atol::Int64)
@ Base .\floatfuncs.jl:347
[5] isapprox(x::Vector{DynamicQuantities.Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}}, y::Vector{DynamicQuantities.Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}})
@ LinearAlgebra C:\Users\mikei\.julia\juliaup\julia-1.10.0+0.x64.w64.mingw32\share\julia\stdlib\v1.10\LinearAlgebra\src\generic.jl:1785
[6] eval_test(evaluated::Expr, quoted::Expr, source::LineNumberNode, negate::Bool)
@ Test C:\Users\mikei\.julia\juliaup\julia-1.10.0+0.x64.w64.mingw32\share\julia\stdlib\v1.10\Test\src\Test.jl:355
[7] macro expansion
@ C:\Users\mikei\.julia\juliaup\julia-1.10.0+0.x64.w64.mingw32\share\julia\stdlib\v1.10\Test\src\Test.jl:669 [inlined]
[8] macro expansion
@ C:\Users\mikei\.julia\packages\LineIntegrals\Y8iYI\test\runtests.jl:164 [inlined]
[9] macro expansion
@ C:\Users\mikei\.julia\juliaup\julia-1.10.0+0.x64.w64.mingw32\share\julia\stdlib\v1.10\Test\src\Test.jl:1577 [inlined]
[10] macro expansion
@ C:\Users\mikei\.julia\packages\LineIntegrals\Y8iYI\test\runtests.jl:163 [inlined]
[11] macro expansion
@ C:\Users\mikei\.julia\juliaup\julia-1.10.0+0.x64.w64.mingw32\share\julia\stdlib\v1.10\Test\src\Test.jl:1577 [inlined]
[12] top-level scope
@ C:\Users\mikei\.julia\packages\LineIntegrals\Y8iYI\test\runtests.jl:128
from dynamicquantities.jl.
Related Issues (20)
- u"Ω" errors in precompilation HOT 6
- Base.isapprox fails for Vector{Quantity} HOT 14
- Meshes.jl test failure HOT 10
- Round tripping Quantities through String HOT 3
- `bionomial` and `factorial` functions not defined? HOT 5
- Molar units not supported HOT 7
- Why `one(1u"kg")` no dimension? HOT 2
- Pretty print element types of `QuantityArray` HOT 2
- Logo HOT 7
- Immutable constants for symbolic dimensions
- Registering custom unit propagation rules
- Choosing type of quantity value based on type used in construction HOT 1
- Further improvements to startup time HOT 1
- Behavior with `missing` HOT 6
- Adding "missing" units HOT 4
- Unitful conversion fails for symbolic units HOT 7
- Sweep: Define `NoDims` for indicating something is not a quantity HOT 2
- `reduce(vcat` returns corrupted result HOT 1
- `map` fails with `QuantityArray` HOT 3
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 dynamicquantities.jl.