Time-Series-Library icon indicating copy to clipboard operation
Time-Series-Library copied to clipboard

fix: prevent in-place operations in TimesNet model to avoid potential side effects

Open Karesis opened this issue 9 months ago • 0 comments

Changes

This PR addresses potential side effects caused by in-place operations in the TimesNet model.

Modifications

  • Replaced in-place operators (e.g., /=, +=) with their non-in-place counterparts (e.g., = x / y, = x + y)
  • Ensured all tensor operations create new objects instead of modifying existing ones
  • Maintained the original mathematical operations while improving code safety

Rationale

  1. In-place operators (/=, +=, etc.) modify tensors directly, which can lead to unexpected side effects
  2. Using non-in-place operations creates new objects, making the code behavior more predictable
  3. This change prevents potential issues in model training and inference

Files Changed

  • models/TimesNet.py

Additional Notes

These modifications follow defensive programming practices by avoiding in-place operations, making the code more robust and easier to debug.

Karesis avatar Apr 09 '25 01:04 Karesis