Skip to content

TODO:sample_discrete_maps updated to handle torch tensors natively #2213

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

DarshanCode2005
Copy link
Contributor

Implement PyTorch tensor support in sample_discrete_maps (previously TODO)

This PR addresses the outstanding TODO in pgmpy/utils/mathext.py by enabling the sample_discrete_maps function to natively handle PyTorch tensors, alongside existing support for NumPy arrays.

By avoiding conversions between tensors and arrays, this enhancement:

  • Improves performance and memory efficiency,
  • Preserves GPU residency of tensors without forcing CPU transfers,
  • Facilitates smoother integration with PyTorch-based deep learning workflows.

Backward compatibility with NumPy inputs is fully maintained.

This completes the planned extension and makes sample_discrete_maps more versatile and efficient for hybrid ML and PGMs applications.

@ankurankan
Copy link
Member

@DarshanCode2005 How is this any better than what we were already doing? This still has to test whether the array is torch tensor or a numpy array.

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.

3 participants