Skip to content
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

Merged
merged 7 commits into from
Dec 15, 2022
Merged

Conversation

maloel
Copy link
Collaborator

@maloel maloel commented Dec 12, 2022

This was for the POC, but I figured why not...

@maloel maloel force-pushed the avg branch 2 times, most recently from e4c9863 to 01fea25 Compare December 14, 2022 07:09
@maloel maloel requested a review from Nir-Az December 14, 2022 07:10
@maloel maloel marked this pull request as ready for review December 14, 2022 07:11
// 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 >
Copy link
Collaborator

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?

Copy link
Collaborator Author

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 )
Copy link
Collaborator

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?

Copy link
Collaborator

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..

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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()
Copy link
Collaborator

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?

Copy link
Collaborator Author

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
Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python 2?

Copy link
Collaborator Author

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

@maloel maloel merged commit b761504 into IntelRealSense:development Dec 15, 2022
@maloel maloel deleted the avg branch December 15, 2022 06:11
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.

2 participants