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.
Why is this declaration needed if you define the class later?
There was a problem hiding this comment.
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.
I think it should be min + a.
Am I right?
Add tests for this func?
There was a problem hiding this comment.
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.
If a is negative, -a is positive.
There was a problem hiding this comment.
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.
Can you add a comment about this line?
There was a problem hiding this comment.
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 |
| 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.
I'll remove in next PR
This was for the POC, but I figured why not...