Skip to content

_fill_dot support general vectors #229

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 17 commits into from
Mar 30, 2023

Conversation

putianyi889
Copy link
Contributor

@putianyi889 putianyi889 commented Mar 28, 2023

including Inf, NaN and nested arrays. Infinite cases should be implemented in InfiniteArrays.jl

Original PR:

including Fill(0,∞) and potentially 0.0:0.0:+∞ in the future

also fix a type issue:

julia> dot(fill(true, 5), fill(Int8(1), 5)) |> typeof
Int8

julia> dot(sum(fill(true, 5)), Int8(1)) |> typeof
Int64

@putianyi889 putianyi889 changed the title _fill_dot support more infinite zero vectors _fill_dot support general infinite zero vectors Mar 28, 2023
@codecov
Copy link

codecov bot commented Mar 28, 2023

Codecov Report

Merging #229 (4c630e0) into master (dc8aa6e) will increase coverage by 0.14%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #229      +/-   ##
==========================================
+ Coverage   99.04%   99.19%   +0.14%     
==========================================
  Files           4        4              
  Lines         630      622       -8     
==========================================
- Hits          624      617       -7     
+ Misses          6        5       -1     
Impacted Files Coverage Δ
src/fillalgebra.jl 99.42% <100.00%> (+0.52%) ⬆️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@putianyi889
Copy link
Contributor Author

putianyi889 commented Mar 29, 2023

Using sum(a)*value(b) can have rounding-off inconsistency as well as type instability. Somehow

julia> sum(fill(Int8(1),5)) |> typeof
Int64

julia> reduce(+, fill(Int8(1),5)) |> typeof
Int8

reduce doesn't work with ranges however.

@putianyi889
Copy link
Contributor Author

Julia intentionally let sum not always return the same type. The reason is for "type stability" according to them.

https://github.com/JuliaLang/julia/blob/38d24e574caab20529a61a6f7444c9e473724ccc/base/reduce.jl#L390-L412

@putianyi889
Copy link
Contributor Author

putianyi889 commented Mar 29, 2023

I'm accepting the rounding-off errors (See failed test) since I don't know how to work around. I tend to believe the default dot has larger errors.

@jishnub
Copy link
Member

jishnub commented Mar 29, 2023

Checking for iszero(b) in the short-circuiting branch is O(n), so we might as well compute the sum?

@putianyi889
Copy link
Contributor Author

putianyi889 commented Mar 29, 2023

I've found another problem...

For infinite vectors, if one of them is zero and another is well-defined, then the dot of them is zero.

However, if the other vector has Inf or NaN, we do want the dot to be NaN. This is a must-achieve for finite cases.

Most of the issues can be resolved by adding if-elses. The hard part is to tell whether an infinite vector with infinite sum actually contains Inf. I'm ignoring the last edge case for now.

The infinite case is also not type-stable, since the result could easily be ℵ₀. Maybe this should be done by InfiniteArrays.jl. @dlfivefifty any opinion?

@putianyi889 putianyi889 requested a review from dlfivefifty March 29, 2023 13:37
@putianyi889 putianyi889 changed the title _fill_dot support general infinite zero vectors _fill_dot support general vectors Mar 30, 2023
@putianyi889 putianyi889 requested a review from dlfivefifty March 30, 2023 15:38
@putianyi889
Copy link
Contributor Author

sorry for the ping, inferred 😅

@dlfivefifty
Copy link
Member

Is this Ready to merge?

@putianyi889
Copy link
Contributor Author

yes

@dlfivefifty dlfivefifty changed the base branch from master to release-1.0 March 30, 2023 19:56
@dlfivefifty dlfivefifty merged commit d8e1f9a into JuliaArrays:release-1.0 Mar 30, 2023
dlfivefifty added a commit that referenced this pull request Mar 30, 2023
* StepRangeLen to support 0 step size in cumsum #226 (#230)

* use StepRangeLen to support 0 step size

* v0.13.11

* allow special casing on ∞ length

* Restore ± special cases

* Update runtests.jl

* fix more tests

* Update runtests.jl

* Structured Broadcasting (#228)

* Structured Broadcasting

* add jishnubs tests

* Update runtests.jl

* Fix #97 by adding promote_rules (#234)

* Move OneElement from Zygote and overload setindex (#161) (#235)

* Add Zeros(T, n...) and Ones(T, n...) constructors (#94( (#233)

* Add Zeros(T, n...) and Ones(T, n...) constructors (#94(

* increase coverage

* Update README.md

* Move over OneElement from Zygote

* Add tests

* Update oneelement.jl

* add tests

* Update runtests.jl

* add docs

* ensure type in array convert (#237)

* increase coverage

* add convert tests

* v1.0

* `_fill_dot` support general vectors (#229)

* Update fillalgebra.jl

* promote_op

* add breaking test

* add breaking test

* fix

* accept round-off errors

* Update test/runtests.jl

Co-authored-by: Sheehan Olver <solver@mac.com>

* update

* support inf and nan

* fix 1.6

* Update fillalgebra.jl

* Update fillalgebra.jl

* trying to fix Julia 1.6

* comments

* Update runtests.jl

* add @inferred

---------

Co-authored-by: Sheehan Olver <solver@mac.com>

---------

Co-authored-by: Jishnu Bhattacharya <jishnub.github@gmail.com>
Co-authored-by: Tianyi Pu <44583944+putianyi889@users.noreply.github.com>
@putianyi889 putianyi889 mentioned this pull request Mar 30, 2023
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