Allow passing 0-length vectors to cor#70
Conversation
Codecov Report
@@ Coverage Diff @@
## master #70 +/- ##
==========================================
- Coverage 97.41% 96.41% -1.00%
==========================================
Files 1 1
Lines 387 391 +4
==========================================
Hits 377 377
- Misses 10 14 +4
Continue to review full report at Codecov.
|
| length(y) == n || throw(DimensionMismatch("inconsistent lengths")) | ||
| n > 0 || throw(ArgumentError("correlation only defined for non-empty vectors")) | ||
| if n == 0 | ||
| T = promote_type(typeof(mx), typeof(my)) |
There was a problem hiding this comment.
How about using an equation closer to the actual computation of the correlation, like the one used below with zero?
EDIT: though it's true that at JuliaLang/julia#29033 we used oftype(..., NaN).
There was a problem hiding this comment.
I did this this way as x and y can have abstract eltype (e.g. Any), in which case you cannot use zero on it.
This code assumes that type of mx and my is somehow "derived" from x and y. As corm is unexported I thought it should be safe.
But we might use something like: sqrt(zero(mx)*zero(my)/(abs2(one(mx)*abs2(one(my)))
There was a problem hiding this comment.
Yeah, that formula looks good (with zero at the denominator)!
|
Also probably |
|
+1 Relevant previous discussions:
|
I have not added the tests yet. Let us first decide if we like the design of what I propose and then I will finalize the PR.
The proposed change is non-breaking.