Skip to content

add rsutils::number::running_average<> - #11202

Merged
maloel merged 7 commits into
realsenseai:developmentfrom
maloel:avg
Dec 15, 2022
Merged

add rsutils::number::running_average<>#11202
maloel merged 7 commits into
realsenseai:developmentfrom
maloel:avg

Conversation

@maloel

@maloel maloel commented Dec 12, 2022

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
Contributor 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

Comment thread unit-tests/rsutils/number/running-average/test-double.py
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor 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 realsenseai: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