Skip to content

Conversation

@emekaokoli19
Copy link

Description

This PR adds a filter helper function to pytensor/scan/views.py, complementing the existing map, reduce, foldl, and foldr utilities.

The new filter function applies a user-defined condition (predicate) over a sequence using PyTensor’s scan operation and returns only the elements that satisfy the condition (i.e., the ones for which the predicate evaluates to True).

This addition restores functionality discussed in Theano/Theano#5365, now updated for PyTensor where boolean indexing is supported natively.

A corresponding unit test (test_filter) was added in tests/scan/test_views.py to ensure correct behavior.

Related Issue

Checklist

  • Checked that pre-commit linting/style checks pass
  • Included a test (test_filter) that verifies the correctness of the new function
  • Added necessary documentation (docstring for filter)
  • Each commit corresponds to a relevant logical change

Type of change

  • New feature / enhancement

@ricardoV94, please take a look when available

Copy link
Member

@ricardoV94 ricardoV94 left a comment

Choose a reason for hiding this comment

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

Looks great, just some small suggestions/request

@emekaokoli19
Copy link
Author

@ricardoV94 I have addressed the reviews. Also, is there a Discord or Slack community for Pytensor I can join? Thank you.

@ricardoV94
Copy link
Member

Thanks @emekaokoli19 looks great.

There's a discord but only available to recurring developers. If you contribute a while longer you'll be invited. Otherwise we prefer to keep discussion public and easy to find here on Github with issues/discussions.

@ricardoV94 ricardoV94 added the enhancement New feature or request label Nov 10, 2025
@ricardoV94 ricardoV94 changed the title added filter to scan Implement Scan based filter helper Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add filter to scan/views.py

2 participants