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 assign action #287

Merged
merged 7 commits into from
Jan 14, 2024
Merged

Add assign action #287

merged 7 commits into from
Jan 14, 2024

Conversation

nahueespinosa
Copy link
Member

@nahueespinosa nahueespinosa commented Jan 12, 2024

Proposed changes

View-action composition in the range library is limited. This patch implements a new range adaptor object that can be appended to any view closure to evaluate it eagerly and assign the result to a given range, effectively converting any view into an action.

Related to #279.

The simple particle filter pipeline example becomes:

struct Particle {
  int state;
  double weight;
};

auto particles = std::vector<Particle>{};
auto motion_model = ...;
auto sensor_model = ...;

particles |= beluga::actions::propagate(motion_model) |
             beluga::actions::reweight(sensor_model) |
             beluga::views::sample |
             ranges::views::take_exactly(1000) |
             beluga::actions::assign;

Type of change

  • 🐛 Bugfix (change which fixes an issue)
  • 🚀 Feature (change which adds functionality)
  • 📚 Documentation (change which fixes or extends documentation)

Checklist

  • Lint and unit tests (if any) pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • All commits have been signed for DCO

View-action composition in the range library is limited (and often
produces the wrong result). This patch implements a new range adaptor
object that can be appended to any view closure to evaluate it
eagerly and assign the result to a given range, effectively converting
any view into an action.

It also adds an operator<<= overload to simplify syntax.

Signed-off-by: Nahuel Espinosa <nespinosa@ekumenlabs.com>
@nahueespinosa nahueespinosa added enhancement New feature or request cpp Related to C++ code labels Jan 12, 2024
@nahueespinosa nahueespinosa self-assigned this Jan 12, 2024
Copy link
Collaborator

@hidmic hidmic left a comment

Choose a reason for hiding this comment

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

Awesome!

beluga/include/beluga/actions/assign.hpp Show resolved Hide resolved
beluga/test/beluga/actions/test_assign.cpp Outdated Show resolved Hide resolved
Signed-off-by: Nahuel Espinosa <nespinosa@ekumenlabs.com>
Signed-off-by: Nahuel Espinosa <nespinosa@ekumenlabs.com>
Signed-off-by: Nahuel Espinosa <nespinosa@ekumenlabs.com>
Signed-off-by: Nahuel Espinosa <nespinosa@ekumenlabs.com>
Signed-off-by: Nahuel Espinosa <nespinosa@ekumenlabs.com>
Copy link
Collaborator

@hidmic hidmic left a comment

Choose a reason for hiding this comment

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

LGTM

beluga/include/beluga/actions/assign.hpp Show resolved Hide resolved
beluga/test/beluga/actions/test_assign.cpp Outdated Show resolved Hide resolved
Signed-off-by: Nahuel Espinosa <nespinosa@ekumenlabs.com>
@nahueespinosa nahueespinosa merged commit a177517 into main Jan 14, 2024
8 checks passed
@nahueespinosa nahueespinosa deleted the nahuel/self-assign-action branch January 14, 2024 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cpp Related to C++ code enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants