Skip to content

Add big() and rationalize() for FixedPoint #186

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

Merged
merged 1 commit into from
Jul 12, 2020

Conversation

kimikage
Copy link
Collaborator

@kimikage kimikage commented Jun 22, 2020

Closes #184.

Perhaps, the users of big may need more accuracy than speed.(cf. #129 (comment))
I want to stop using the reciprocal technique below: (Edit: done.)

Base.BigFloat(x::Normed) = reinterpret(x)*(1/BigFloat(rawone(x)))

For large arrays, using the reciprocal technique seems to allocate more memory and slow.
In the first place, it seems that the constant folding is not applied. This seems to be essentially different from the following Float64's case.
# for Julia v1.0, which does not fold `div_float` before inlining
inv_rawone(x) = (@generated) ? (y = 1.0 / rawone(x); :($y)) : 1.0 / rawone(x)

@kimikage kimikage marked this pull request as draft June 22, 2020 11:57
@codecov
Copy link

codecov bot commented Jun 22, 2020

Codecov Report

Merging #186 into master will increase coverage by 0.09%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #186      +/-   ##
==========================================
+ Coverage   88.98%   89.08%   +0.09%     
==========================================
  Files           6        6              
  Lines         445      449       +4     
==========================================
+ Hits          396      400       +4     
  Misses         49       49              
Impacted Files Coverage Δ
src/FixedPointNumbers.jl 86.27% <100.00%> (+0.56%) ⬆️
src/normed.jl 89.00% <100.00%> (ø)

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 7c90fb6...f7d8f7c. Read the comment docs.

@kimikage kimikage marked this pull request as ready for review June 29, 2020 18:08
@kimikage kimikage mentioned this pull request Jul 10, 2020
4 tasks
This also stops using the reciprocal technique in `BigFloat(::Normed)`,
because the constant folding is not available.
@kimikage
Copy link
Collaborator Author

julia> versioninfo()
Julia Version 1.4.2
Commit 44fa15b150* (2020-05-23 18:35 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, skylake)

Before:

julia> @benchmark BigFloat.(x) setup=(x=collect(rand(N0f8, 1000, 1000)))
BenchmarkTools.Trial:
  memory estimate:  328.06 MiB
  allocs estimate:  6000002
  --------------
  minimum time:     508.701 ms (38.52% GC)
  median time:      589.345 ms (37.99% GC)
  mean time:        631.865 ms (34.44% GC)
  maximum time:     829.537 ms (43.97% GC)
  --------------
  samples:          9
  evals/sample:     1

julia> BigFloat(5N32f32)
5.000000000000000000000000000000000000000000000000000000000000000000000000000069

After:

julia> @benchmark BigFloat.(x) setup=(x=collect(rand(N0f8, 1000, 1000)))
BenchmarkTools.Trial:
  memory estimate:  221.25 MiB
  allocs estimate:  4000002
  --------------
  minimum time:     325.089 ms (28.13% GC)
  median time:      450.361 ms (29.96% GC)
  mean time:        442.812 ms (31.00% GC)
  maximum time:     536.980 ms (40.39% GC)
  --------------
  samples:          12
  evals/sample:     1

julia> big(5N32f32)
5.0

@kimikage
Copy link
Collaborator Author

I think there is room for improvement in the handling of BigFloat, but we should not need to improve it in this PR.

@kimikage kimikage merged commit 0446a89 into JuliaMath:master Jul 12, 2020
@kimikage kimikage deleted the big_rationalize branch July 12, 2020 11:55
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.

Adding big(::FixedPoint) and rationalize(::FixedPoint)
1 participant