added sumOfLog2s#2500
Conversation
|
So I see this just uses the formula - logarithm of products is a sum of logarithms to speed up the latter. |
std/numeric.d
Outdated
There was a problem hiding this comment.
ElementType!Range needs to be constrained
|
@DmitryOlshansky, accuracy like log2(r1...rn), but wihtout exponent overflow |
|
With native frexp (PR #2508) it is 4.5 times faster then sum of logs when compiled with LDC. |
|
Rebased |
std/numeric.d
Outdated
There was a problem hiding this comment.
While the new return type is an improvement, ElementType!Range still needs to be constrained. For example if(isInputRange!Range && isNumeric!(ElementType!Range)) (though by the looks of it, it won't work well with integers?).
There was a problem hiding this comment.
@JakobOvrum A have added isFloatingPoint!(ElementType!Range). It looks like all std.numeric without checks like isFloatingPoint. For example
ElementType!Range entropy(Range)(Range r) if (isInputRange!Range)
{
Unqual!(typeof(return)) result = 0.0;
foreach (e; r)
{
if (!e) continue;
result -= e * log2(e);
}
return result;
}|
LGTM |
|
Shouldn't this be |
|
All |
|
@9il: I don't think |
|
@klickverbot Yes ) I will change it =) |
|
Rebased |
std/numeric.d
Outdated
There was a problem hiding this comment.
You forgot to rename these calls. The autotester will probably report failure. :-)
renamed, and updated remove CustomFloat support remove blank line update comment update return type rename sumOfLogs -> sumOfLog2s update unittest
|
Rebased again) |
|
LGTM |
|
Auto-merge toggled on |
Computes accurate sum of binary logarithms of input range.