Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define AbstractQuantity #204

Merged
merged 1 commit into from
Feb 25, 2019
Merged

Conversation

giordano
Copy link
Collaborator

@giordano giordano commented Jan 27, 2019

Start addressing #186 by defining an AbstractQuantity type. I've marked this PR as work-in-progress because I'm not sure I've used the new abstract type wherever it's needed, at least tests pass locally.

@codecov
Copy link

codecov bot commented Jan 27, 2019

Codecov Report

Merging #204 into master will increase coverage by 1.01%.
The diff coverage is 90.69%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #204      +/-   ##
==========================================
+ Coverage   78.94%   79.95%   +1.01%     
==========================================
  Files          14       14              
  Lines         964      983      +19     
==========================================
+ Hits          761      786      +25     
+ Misses        203      197       -6
Impacted Files Coverage Δ
src/types.jl 94.28% <ø> (+0.34%) ⬆️
src/quantities.jl 91.56% <90.69%> (ø) ⬆️
src/conversion.jl 79.62% <0%> (-4.01%) ⬇️
src/Unitful.jl 100% <0%> (ø) ⬆️
src/logarithm.jl 69.66% <0%> (+0.29%) ⬆️
src/user.jl 88.8% <0%> (+1.3%) ⬆️
src/units.jl 92.5% <0%> (+4.16%) ⬆️
src/utils.jl 88% <0%> (+8%) ⬆️
src/pkgdefaults.jl 21.73% <0%> (+19.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 050f893...cffd842. Read the comment docs.

1 similar comment
@codecov
Copy link

codecov bot commented Jan 27, 2019

Codecov Report

Merging #204 into master will increase coverage by 1.01%.
The diff coverage is 90.69%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #204      +/-   ##
==========================================
+ Coverage   78.94%   79.95%   +1.01%     
==========================================
  Files          14       14              
  Lines         964      983      +19     
==========================================
+ Hits          761      786      +25     
+ Misses        203      197       -6
Impacted Files Coverage Δ
src/types.jl 94.28% <ø> (+0.34%) ⬆️
src/quantities.jl 91.56% <90.69%> (ø) ⬆️
src/conversion.jl 79.62% <0%> (-4.01%) ⬇️
src/Unitful.jl 100% <0%> (ø) ⬆️
src/logarithm.jl 69.66% <0%> (+0.29%) ⬆️
src/user.jl 88.8% <0%> (+1.3%) ⬆️
src/units.jl 92.5% <0%> (+4.16%) ⬆️
src/utils.jl 88% <0%> (+8%) ⬆️
src/pkgdefaults.jl 21.73% <0%> (+19.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 050f893...cffd842. Read the comment docs.

@giordano
Copy link
Collaborator Author

giordano commented Jan 27, 2019

I've played with this branch in PhysicalConstants.jl and it seems to be sufficient for my current needs: JuliaPhysics/PhysicalConstants.jl#2 (comment)

The only thing I would recommend doing is to define an API function (value?) to access the value of an AbstractQuantity, which for the concrete type Quantity could be value(x::Quantity) = x.val. In my tests for PhysicalConstants.jl I've implemented Base.getproperty(c::Constant, sym::Symbol). This function wouldn't need to be exported, just imported by packages implementing a subtype of AbstractQuantity.

@c42f
Copy link
Contributor

c42f commented Feb 8, 2019

The only thing I would recommend doing is to define an API function to access the value of an AbstractQuantity.

Just wondering - is this just ustrip, or does it mean something different?

@giordano
Copy link
Collaborator Author

giordano commented Feb 8, 2019

Ustrip is defined as

@inline ustrip(x::Quantity) = ustrip(x.val)

So strictly speaking it doesn't simply access to the val field. However, I'm having difficulties to find a case where the result would be different (maybe a quantity of quantity, whatever it is?)

@c42f
Copy link
Contributor

c42f commented Feb 8, 2019

Yes I haven't read enough of the internals to know why it's recursive, but it seems like it might have the meaning you want.

@giordano giordano changed the title [WIP] Define AbstractQuantity Define AbstractQuantity Feb 9, 2019
@giordano
Copy link
Collaborator Author

giordano commented Feb 9, 2019

Yeah, anyway I'm not too concerned about that, for me it's sufficient this PR is merged

@ajkeller34 ajkeller34 merged commit d4f17ab into PainterQubits:master Feb 25, 2019
@giordano giordano deleted the AbstractQuantity branch February 25, 2019 06:36
@ajkeller34
Copy link
Collaborator

I'm late on the explanation but ustrip is recursive because of types like Quantity{<:Level}, i.e. (20u"dBm/Hz").val == 20u"dBm", but presumably you want ustrip(20u"dBm/Hz") == 20. There is some special sauce needed to make logarithmic quantities work right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants