-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
add rsutils::number::running_average<> #11202
Conversation
e4c9863
to
01fea25
Compare
// We adapt this to a signed integral T type, where we must start counting leftovers. | ||
// We also add some rounding. | ||
// | ||
template< class T, typename Enable = void > |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this declaration needed if you define the class later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This defines a generic template, mapping to nothing.
The later declarations specialize the template with specific arguments.
} | ||
else if( a < 0 ) | ||
{ | ||
if( b < std::numeric_limits< T >::min() - a ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be min + a
.
Am I right?
Add tests for this func?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh a is negative, It will add it, forget about the previous comment.
Except the missing test part maybe..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a is negative, -a is positive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little hard to add tests without exposing the function itself... I'll leave alone for now.
from pyrsutils import running_average | ||
import random | ||
|
||
random.seed() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment about this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seeds the random number generator... if it's not clear, I'll add
using int_avg = rsutils::number::running_average< int64_t >; | ||
py::class_< int_avg >( m, "running_average_i" ) | ||
.def( py::init<>() ) | ||
.def( "__nonzero__", &int_avg::size ) // Called to implement truth value testing in Python 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python 2?
using double_avg = rsutils::number::running_average< double >; | ||
py::class_< double_avg >( m, "running_average" ) | ||
.def( py::init<>() ) | ||
.def( "__nonzero__", &double_avg::size ) // Called to implement truth value testing in Python 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python 2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove in next PR
This was for the POC, but I figured why not...