braindecode 1.8.1.dev176562021__tar.gz → 1.8.1.dev176771289__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. {braindecode-1.8.1.dev176562021/braindecode.egg-info → braindecode-1.8.1.dev176771289}/PKG-INFO +1 -1
  2. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/augmentation/base.py +7 -1
  3. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/augmentation/functional.py +37 -10
  4. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/augmentation/transforms.py +11 -2
  5. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/base.py +8 -1
  6. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/mne.py +5 -0
  7. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/tuh.py +2 -1
  8. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datautil/serialization.py +11 -4
  9. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/atcnet.py +11 -8
  10. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/base.py +13 -1
  11. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/ctnet.py +9 -3
  12. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/guetschel2026.py +8 -8
  13. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/reve.py +5 -11
  14. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/modules/blocks.py +16 -83
  15. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/modules/quantization.py +5 -5
  16. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/preprocessing/eegprep_preprocess.py +6 -3
  17. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/preprocessing/preprocess.py +2 -0
  18. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/preprocessing/windowers.py +28 -17
  19. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/samplers/base.py +13 -2
  20. braindecode-1.8.1.dev176771289/braindecode/version.py +1 -0
  21. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289/braindecode.egg-info}/PKG-INFO +1 -1
  22. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/whats_new.rst +50 -22
  23. braindecode-1.8.1.dev176562021/braindecode/version.py +0 -1
  24. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/LICENSE.txt +0 -0
  25. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/MANIFEST.in +0 -0
  26. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/NOTICE.txt +0 -0
  27. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/README.rst +0 -0
  28. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/__init__.py +0 -0
  29. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/augmentation/__init__.py +0 -0
  30. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/classifier.py +0 -0
  31. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/__init__.py +0 -0
  32. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/_notebook_viewer.py +0 -0
  33. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/bbci.py +0 -0
  34. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/bcicomp.py +0 -0
  35. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/bids/__init__.py +0 -0
  36. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/bids/datasets.py +0 -0
  37. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/bids/format.py +0 -0
  38. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/bids/hub.py +0 -0
  39. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/bids/hub_format.py +0 -0
  40. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/bids/hub_io.py +0 -0
  41. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/bids/hub_validation.py +0 -0
  42. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/bids/iterable.py +0 -0
  43. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/chb_mit.py +0 -0
  44. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/collate.py +0 -0
  45. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/moabb.py +0 -0
  46. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/nmt.py +0 -0
  47. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/registry.py +0 -0
  48. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/siena.py +0 -0
  49. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/sleep_physio_challe_18.py +0 -0
  50. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/sleep_physionet.py +0 -0
  51. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/utils.py +0 -0
  52. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datasets/xy.py +0 -0
  53. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datautil/__init__.py +0 -0
  54. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datautil/channel_utils.py +0 -0
  55. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datautil/hub_formats.py +0 -0
  56. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/datautil/util.py +0 -0
  57. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/eegneuralnet.py +0 -0
  58. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/functional/__init__.py +0 -0
  59. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/functional/_real_dft.py +0 -0
  60. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/functional/functions.py +0 -0
  61. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/functional/initialization.py +0 -0
  62. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/__init__.py +0 -0
  63. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/attentionbasenet.py +0 -0
  64. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/attn_sleep.py +0 -0
  65. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/axon.py +0 -0
  66. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/barista.py +0 -0
  67. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/bendr.py +0 -0
  68. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/biot.py +0 -0
  69. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/brainbert.py +0 -0
  70. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/brainmodule.py +0 -0
  71. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/brainomni.py +0 -0
  72. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/brant.py +0 -0
  73. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/cbramod.py +0 -0
  74. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/codebrain.py +0 -0
  75. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/config.py +0 -0
  76. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/contrawr.py +0 -0
  77. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/csbrain.py +0 -0
  78. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/dance.py +0 -0
  79. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/deep4.py +0 -0
  80. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/deepsleepnet.py +0 -0
  81. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/dgcnn.py +0 -0
  82. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/diver1.py +0 -0
  83. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/duin.py +0 -0
  84. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/eeg_clip.py +0 -0
  85. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/eegconformer.py +0 -0
  86. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/eegdino.py +0 -0
  87. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/eeginception_erp.py +0 -0
  88. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/eeginception_mi.py +0 -0
  89. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/eegitnet.py +0 -0
  90. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/eegminer.py +0 -0
  91. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/eegnet.py +0 -0
  92. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/eegnex.py +0 -0
  93. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/eegpt.py +0 -0
  94. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/eegsimpleconv.py +0 -0
  95. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/eegsym.py +0 -0
  96. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/eegtcnet.py +0 -0
  97. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/emg2qwerty.py +0 -0
  98. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/epint.py +0 -0
  99. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/fbcnet.py +0 -0
  100. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/fblightconvnet.py +0 -0
  101. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/fbmsnet.py +0 -0
  102. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/gcnsnet.py +0 -0
  103. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/hybrid.py +0 -0
  104. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/ifnet.py +0 -0
  105. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/labram.py +0 -0
  106. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/luna.py +0 -0
  107. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/mapa.py +0 -0
  108. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/medformer.py +0 -0
  109. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/meta_neuromotor.py +0 -0
  110. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/mirepnet.py +0 -0
  111. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/mscformer.py +0 -0
  112. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/msvtnet.py +0 -0
  113. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/mvpformer.py +0 -0
  114. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/neuropose.py +0 -0
  115. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/neurorvq.py +0 -0
  116. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/neurorvq_tokenizer.py +0 -0
  117. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/patchedtransformer.py +0 -0
  118. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/popt.py +0 -0
  119. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/sccnet.py +0 -0
  120. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/seizure_transformer.py +0 -0
  121. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/sensingdynamics.py +0 -0
  122. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/shallow_fbcsp.py +0 -0
  123. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/signal_jepa.py +0 -0
  124. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/sinc_shallow.py +0 -0
  125. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/sleep_stager_blanco_2020.py +0 -0
  126. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/sleep_stager_chambon_2018.py +0 -0
  127. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/sleepfm.py +0 -0
  128. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/sparcnet.py +0 -0
  129. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/sstdpn.py +0 -0
  130. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/steegformer.py +0 -0
  131. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/summary.csv +0 -0
  132. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/syncnet.py +0 -0
  133. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/tcformer.py +0 -0
  134. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/tcn.py +0 -0
  135. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/tfm_tokenizer.py +0 -0
  136. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/tidnet.py +0 -0
  137. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/tmsanet.py +0 -0
  138. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/tsinception.py +0 -0
  139. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/usleep.py +0 -0
  140. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/util.py +0 -0
  141. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/vemg2pose.py +0 -0
  142. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/models/zuna.py +0 -0
  143. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/modules/__init__.py +0 -0
  144. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/modules/activation.py +0 -0
  145. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/modules/attention.py +0 -0
  146. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/modules/channels.py +0 -0
  147. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/modules/convolution.py +0 -0
  148. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/modules/dance_modules.py +0 -0
  149. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/modules/filter.py +0 -0
  150. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/modules/layers.py +0 -0
  151. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/modules/linear.py +0 -0
  152. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/modules/linear_attention.py +0 -0
  153. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/modules/parametrization.py +0 -0
  154. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/modules/popt_modules.py +0 -0
  155. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/modules/stats.py +0 -0
  156. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/modules/util.py +0 -0
  157. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/modules/wrapper.py +0 -0
  158. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/preprocessing/__init__.py +0 -0
  159. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/preprocessing/mne_preprocess.py +0 -0
  160. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/preprocessing/util.py +0 -0
  161. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/regressor.py +0 -0
  162. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/samplers/__init__.py +0 -0
  163. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/samplers/ssl.py +0 -0
  164. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/training/__init__.py +0 -0
  165. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/training/callbacks.py +0 -0
  166. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/training/losses.py +0 -0
  167. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/training/scoring.py +0 -0
  168. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/util.py +0 -0
  169. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/visualization/__init__.py +0 -0
  170. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/visualization/activations.py +0 -0
  171. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/visualization/attribution.py +0 -0
  172. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/visualization/confusion_matrices.py +0 -0
  173. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/visualization/frequency.py +0 -0
  174. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/visualization/metrics.py +0 -0
  175. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/visualization/sanity.py +0 -0
  176. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode/visualization/topology.py +0 -0
  177. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode.egg-info/SOURCES.txt +0 -0
  178. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode.egg-info/dependency_links.txt +0 -0
  179. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode.egg-info/requires.txt +0 -0
  180. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/braindecode.egg-info/top_level.txt +0 -0
  181. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/Makefile +0 -0
  182. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/_templates/autosummary/class.rst +0 -0
  183. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/_templates/autosummary/class_in_subdir.rst +0 -0
  184. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/_templates/autosummary/function.rst +0 -0
  185. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/_templates/autosummary/function_in_subdir.rst +0 -0
  186. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/agent_docs.rst +0 -0
  187. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/api.rst +0 -0
  188. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/cite.rst +0 -0
  189. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/conf.py +0 -0
  190. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/help.rst +0 -0
  191. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/index.rst +0 -0
  192. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/install/install.rst +0 -0
  193. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/install/install_pip.rst +0 -0
  194. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/install/install_source.rst +0 -0
  195. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/models/categorization/attention.rst +0 -0
  196. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/models/categorization/channel.rst +0 -0
  197. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/models/categorization/convolution.rst +0 -0
  198. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/models/categorization/filterbank.rst +0 -0
  199. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/models/categorization/gnn.rst +0 -0
  200. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/models/categorization/interpretable.rst +0 -0
  201. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/models/categorization/lbm.rst +0 -0
  202. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/models/categorization/recurrent.rst +0 -0
  203. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/models/categorization/spd.rst +0 -0
  204. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/models/models.rst +0 -0
  205. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/models/models_categorization.rst +0 -0
  206. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/models/models_table.rst +0 -0
  207. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/models/models_visualization.rst +0 -0
  208. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/sg_execution_times.rst +0 -0
  209. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/docs/user_guide/channel_strategies.rst +0 -0
  210. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/pyproject.toml +0 -0
  211. {braindecode-1.8.1.dev176562021 → braindecode-1.8.1.dev176771289}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: braindecode
3
- Version: 1.8.1.dev176562021
3
+ Version: 1.8.1.dev176771289
4
4
  Summary: Deep learning software to decode EEG, ECG or MEG signals
5
5
  Author-email: Robin Tibor Schirrmeister <robintibor@gmail.com>, Bruno Aristimunha Pinto <b.aristimunha@gmail.com>, Alexandre Gramfort <agramfort@meta.com>
6
6
  Maintainer-email: Alexandre Gramfort <agramfort@meta.com>, Bruno Aristimunha Pinto <b.aristimunha@gmail.com>, Robin Tibor Schirrmeister <robintibor@gmail.com>
@@ -171,7 +171,13 @@ class Compose(Transform):
171
171
  self.transforms = transforms
172
172
  super().__init__()
173
173
 
174
- def forward(self, X, y):
174
+ def forward(self, X, y=None):
175
+ # like Transform.forward, return only X when no target is given (each
176
+ # transform then returns a single tensor, not an (X, y) pair)
177
+ if y is None:
178
+ for transform in self.transforms:
179
+ X = transform(X)
180
+ return X
175
181
  for transform in self.transforms:
176
182
  X, y = transform(X, y)
177
183
  return X, y
@@ -22,6 +22,21 @@ from torch.fft import fft, ifft
22
22
  from torch.nn.functional import pad
23
23
 
24
24
 
25
+ def _max_float_dtype(device: torch.device | str) -> torch.dtype:
26
+ """float64, or float32 on Apple MPS, which has no float64."""
27
+ return torch.float32 if torch.device(device).type == "mps" else torch.float64
28
+
29
+
30
+ def _to_device(t: torch.Tensor, device: torch.device | str) -> torch.Tensor:
31
+ """Move ``t`` to ``device``, in single precision on MPS (no float64 there)."""
32
+ if torch.device(device).type == "mps":
33
+ if t.dtype == torch.float64:
34
+ return t.float().to(device)
35
+ if t.dtype == torch.complex128:
36
+ return t.to(torch.complex64).to(device)
37
+ return t.to(device)
38
+
39
+
25
40
  def identity(X: torch.Tensor, y: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
26
41
  """Identity operation.
27
42
 
@@ -92,10 +107,11 @@ def _new_random_fft_phase_odd(
92
107
  rng = check_random_state(random_state)
93
108
  random_phase = torch.from_numpy(
94
109
  2j * np.pi * rng.random((batch_size, c, (n - 1) // 2))
95
- ).to(device)
110
+ )
111
+ random_phase = _to_device(random_phase, device)
96
112
  return torch.cat(
97
113
  [
98
- torch.zeros((batch_size, c, 1), device=device),
114
+ torch.zeros((batch_size, c, 1), device=device, dtype=random_phase.dtype),
99
115
  random_phase,
100
116
  -torch.flip(random_phase, [-1]),
101
117
  ],
@@ -113,12 +129,13 @@ def _new_random_fft_phase_even(
113
129
  rng = check_random_state(random_state)
114
130
  random_phase = torch.from_numpy(
115
131
  2j * np.pi * rng.random((batch_size, c, n // 2 - 1))
116
- ).to(device)
132
+ )
133
+ random_phase = _to_device(random_phase, device)
117
134
  return torch.cat(
118
135
  [
119
- torch.zeros((batch_size, c, 1), device=device),
136
+ torch.zeros((batch_size, c, 1), device=device, dtype=random_phase.dtype),
120
137
  random_phase,
121
- torch.zeros((batch_size, c, 1), device=device),
138
+ torch.zeros((batch_size, c, 1), device=device, dtype=random_phase.dtype),
122
139
  -torch.flip(random_phase, [-1]),
123
140
  ],
124
141
  dim=-1,
@@ -178,7 +195,7 @@ def ft_surrogate(
178
195
  and 0 <= phase_noise_magnitude <= 1
179
196
  ), f"eps must be a float between 0 and 1. Got {phase_noise_magnitude}."
180
197
 
181
- f = fft(X.double(), dim=-1)
198
+ f = fft(X.to(_max_float_dtype(X.device)), dim=-1)
182
199
  device = X.device
183
200
 
184
201
  n = f.shape[-1]
@@ -580,6 +597,7 @@ def _frequency_shift(X: torch.Tensor, fs: float, f_shift: float) -> torch.Tensor
580
597
  _f_shift = torch.as_tensor(f_shift).float()
581
598
  else:
582
599
  raise ValueError(f"Invalid f_shift type: {type(f_shift)}")
600
+ _f_shift = _f_shift.to(X.device)
583
601
  f_shift_stack = _f_shift.repeat(N_padded, n_channels, 1)
584
602
  reshaped_f_shift = f_shift_stack.permute(
585
603
  *torch.arange(f_shift_stack.ndim - 1, -1, -1)
@@ -911,7 +929,15 @@ def _rotate_signals(
911
929
  sensors_positions_matrix: torch.Tensor,
912
930
  spherical: bool = True,
913
931
  ) -> torch.Tensor:
914
- sensors_positions_matrix = sensors_positions_matrix.to(X.device)
932
+ if X.device.type == "mps":
933
+ # MPS has no float64: compute the small (n_chans x n_chans) spherical
934
+ # spline matrices on CPU in double precision, only move the result
935
+ # (two separate steps: a combined device + dtype .to() from MPS
936
+ # returns zeros with some torch versions)
937
+ sensors_positions_matrix = sensors_positions_matrix.cpu().double()
938
+ rotations = [rotation.cpu().double() for rotation in rotations]
939
+ else:
940
+ sensors_positions_matrix = sensors_positions_matrix.to(X.device)
915
941
  rot_sensors_matrices = [
916
942
  rotation.matmul(sensors_positions_matrix) for rotation in rotations
917
943
  ]
@@ -921,9 +947,10 @@ def _rotate_signals(
921
947
  torch.as_tensor(
922
948
  _torch_make_interpolation_matrix(
923
949
  sensors_positions_matrix.T, rot_sensors_matrix.T
924
- ),
925
- device=X.device,
926
- ).float()
950
+ )
951
+ )
952
+ .float()
953
+ .to(X.device)
927
954
  for rot_sensors_matrix in rot_sensors_matrices
928
955
  ]
929
956
  )
@@ -18,6 +18,7 @@ from braindecode.util import resolve_montage_name
18
18
 
19
19
  from .base import Transform
20
20
  from .functional import (
21
+ _max_float_dtype,
21
22
  amplitude_scale,
22
23
  band_rotation,
23
24
  bandstop_filter,
@@ -494,6 +495,7 @@ class SmoothTimeMask(Transform):
494
495
  size=X.shape[0],
495
496
  ),
496
497
  device=X.device,
498
+ dtype=_max_float_dtype(X.device),
497
499
  ) * (seq_length - mask_len_samples)
498
500
  return {
499
501
  "mask_start_per_sample": mask_start,
@@ -675,7 +677,11 @@ class FrequencyShift(Transform):
675
677
  return super().get_augmentation_params(*batch)
676
678
  X = batch[0]
677
679
 
678
- u = torch.as_tensor(self.rng.uniform(size=X.shape[0]), device=X.device)
680
+ u = torch.as_tensor(
681
+ self.rng.uniform(size=X.shape[0]),
682
+ device=X.device,
683
+ dtype=_max_float_dtype(X.device),
684
+ )
679
685
  max_delta_freq = self.max_delta_freq
680
686
  if isinstance(max_delta_freq, torch.Tensor):
681
687
  max_delta_freq = max_delta_freq.to(X.device)
@@ -833,7 +839,10 @@ class SensorsRotation(Transform):
833
839
  if isinstance(max_degrees, torch.Tensor):
834
840
  max_degrees = max_degrees.to(X.device)
835
841
  random_angles = (
836
- torch.as_tensor(u, device=X.device) * 2 * max_degrees - max_degrees
842
+ torch.as_tensor(u, device=X.device, dtype=_max_float_dtype(X.device))
843
+ * 2
844
+ * max_degrees
845
+ - max_degrees
837
846
  )
838
847
  return {
839
848
  "sensors_positions_matrix": self.sensors_positions_matrix,
@@ -634,7 +634,9 @@ class RecordDataset(Dataset[tuple[np.ndarray, int | str, tuple[int, int, int]]])
634
634
  f"'{key}' already in description. Please "
635
635
  f"rename or set overwrite to True."
636
636
  )
637
- self._description.pop(key)
637
+ # drop on a copy: windows datasets share the description
638
+ # Series of the dataset they were created from
639
+ self._description = self._description.drop(key)
638
640
  self._description = pd.concat([self.description, description])
639
641
 
640
642
  @property
@@ -1900,6 +1902,11 @@ class BaseConcatDataset(ConcatDataset, HubDatasetMixin, Generic[T]):
1900
1902
  dataset description.
1901
1903
  """
1902
1904
  description = pd.DataFrame(description)
1905
+ if len(description.columns) and len(description) != len(self.datasets):
1906
+ raise ValueError(
1907
+ f"Length of values ({len(description)}) does not match "
1908
+ f"number of datasets ({len(self.datasets)})."
1909
+ )
1903
1910
  for key, value in description.items():
1904
1911
  for ds, value_ in zip(self.datasets, value):
1905
1912
  ds.set_description({key: value_}, overwrite=overwrite)
@@ -159,6 +159,11 @@ def create_from_mne_epochs(
159
159
 
160
160
  list_of_windows_ds = []
161
161
  for i, epochs in enumerate(list_of_epochs):
162
+ # drop rejected epochs first (on a copy) so that iterating over the
163
+ # epochs stays aligned with ``epochs.events``; preloaded epochs have
164
+ # already dropped them, so skip copying their data
165
+ if not epochs.preload:
166
+ epochs = epochs.copy().drop_bad()
162
167
  event_descriptions = epochs.events[:, 2]
163
168
  original_trial_starts = epochs.events[:, 0]
164
169
  stop = len(epochs.times) - window_size_samples
@@ -122,7 +122,8 @@ class TUH(BaseConcatDataset):
122
122
  # Assume it is an integer specifying number
123
123
  # of recordings to load
124
124
  recording_ids = range(recording_ids)
125
- descriptions = descriptions[recording_ids]
125
+ # select by chronological position, not by (file listing) label
126
+ descriptions = descriptions.iloc[:, list(recording_ids)]
126
127
 
127
128
  # workaround to ensure warnings are suppressed when running in parallel
128
129
  def create_dataset(*args, **kwargs):
@@ -140,15 +140,19 @@ def _load_signals(fif_file, preload, is_raw):
140
140
  with open(pkl_file, "rb") as f:
141
141
  signals = pickle.load(f)
142
142
 
143
- if all(Path(f).exists() for f in signals.filenames):
143
+ # The pickle stores absolute paths: check that they exist and point to
144
+ # this fif file, not to the folder the dataset was copied from.
145
+ if all(Path(f).exists() for f in signals.filenames) and (
146
+ Path(signals.filenames[0]).resolve() == fif_file.resolve()
147
+ ):
144
148
  if preload:
145
149
  signals.load_data()
146
150
  return _compact_fif_tags(signals)
147
151
  else: # This may happen if the file has been moved together with the pickle file.
148
152
  warnings.warn(
149
153
  f"Pickle file {pkl_file} exists, but the referenced fif "
150
- "file(s) do not exist. Will read the fif file(s) directly "
151
- "and re-create the pickle file.",
154
+ "file(s) do not exist or are not next to it. Will read the "
155
+ "fif file(s) directly and re-create the pickle file.",
152
156
  UserWarning,
153
157
  )
154
158
 
@@ -220,7 +224,10 @@ def load_concat_dataset(path, preload, ids_to_load=None, target_name=None, n_job
220
224
  # target_name.json, raw_preproc_kwargs.json, window_kwargs.json,
221
225
  # window_preproc_kwargs.json
222
226
  if ids_to_load is None:
223
- ids_to_load = [p.name for p in path.iterdir()]
227
+ # skip stray entries such as .DS_Store or a README next to the datasets
228
+ ids_to_load = [
229
+ p.name for p in path.iterdir() if p.is_dir() and p.name.isdigit()
230
+ ]
224
231
  ids_to_load = sorted(ids_to_load, key=lambda i: int(i))
225
232
  ids_to_load = [str(i) for i in ids_to_load]
226
233
  first_raw_fif_path = path / ids_to_load[0] / f"{ids_to_load[0]}-raw.fif"
@@ -444,8 +444,10 @@ class ATCNet(EEGModuleMixin, nn.Module):
444
444
  # ----- Sliding window -----
445
445
  sw_concat: list[torch.Tensor] = [] # to store sliding window outputs
446
446
  # for w in range(self.n_windows):
447
- for idx, (attention, tcn_module, final_layer) in enumerate(
448
- zip(self.attention_blocks, self.temporal_conv_nets, self.final_layer)
447
+ # (final_layer is not zipped in: with concat=True it holds a single
448
+ # layer, which would stop the loop after the first window)
449
+ for idx, (attention, tcn_module) in enumerate(
450
+ zip(self.attention_blocks, self.temporal_conv_nets)
449
451
  ):
450
452
  conv_feat_w = conv_feat[..., idx : idx + self.Tw]
451
453
  # Dimension: (batch_size, F2, Tw)
@@ -458,14 +460,15 @@ class ATCNet(EEGModuleMixin, nn.Module):
458
460
  tcn_feat = tcn_module(att_feat)[..., -1]
459
461
  # Dimension: (batch_size, F2)
460
462
 
461
- # Outputs of sliding window can be either averaged after being
462
- # mapped by dense layer or concatenated then mapped by a dense
463
- # layer
464
- if not self.concat:
465
- tcn_feat = final_layer(tcn_feat)
466
-
467
463
  sw_concat.append(tcn_feat)
468
464
 
465
+ # Outputs of sliding window can be either averaged after being
466
+ # mapped by dense layer or concatenated then mapped by a dense
467
+ # layer
468
+ if not self.concat:
469
+ for idx, final_layer in enumerate(self.final_layer):
470
+ sw_concat[idx] = final_layer(sw_concat[idx])
471
+
469
472
  # ----- Aggregation and prediction -----
470
473
  if self.concat:
471
474
  sw_concat_agg = torch.cat(sw_concat, dim=1)
@@ -521,6 +521,11 @@ class EEGModuleMixin(_BaseHubMixin, metaclass=_BraindecodeDocstringMeta):
521
521
  output_shape : tuple[int, ...]
522
522
  shape of the network output for `batch_size==1` (1, ...)
523
523
  """
524
+ # Run in eval mode, so that the probe input does not update BatchNorm
525
+ # running stats or draw dropout masks; restore each module's own mode
526
+ # afterwards (some may have been put in eval mode on purpose).
527
+ modes = {module: module.training for module in self.modules()}
528
+ self.eval()
524
529
  with torch.inference_mode():
525
530
  try:
526
531
  return tuple(
@@ -540,6 +545,9 @@ class EEGModuleMixin(_BaseHubMixin, metaclass=_BraindecodeDocstringMeta):
540
545
  if error is None:
541
546
  raise
542
547
  raise error from exc
548
+ finally:
549
+ for module, training in modes.items():
550
+ module.training = training
543
551
 
544
552
  def get_config(self) -> dict:
545
553
  """Return a JSON-serializable dict of all ``__init__`` parameters.
@@ -623,7 +631,11 @@ class EEGModuleMixin(_BaseHubMixin, metaclass=_BraindecodeDocstringMeta):
623
631
  ``"pad"``.
624
632
  """
625
633
  legacy = getattr(cls, "_legacy_on_non_divisible", None)
626
- if legacy is not None and "on_non_divisible" not in kwargs:
634
+ if legacy is None or "on_non_divisible" in kwargs:
635
+ return
636
+ # A subclass with its own signature may not take the argument.
637
+ params = inspect.signature(cls.__init__).parameters.values()
638
+ if any(p.name == "on_non_divisible" or p.kind is p.VAR_KEYWORD for p in params):
627
639
  kwargs["on_non_divisible"] = legacy
628
640
 
629
641
  def _set_n_outputs(self, n_outputs: int) -> None:
@@ -181,6 +181,7 @@ class CTNet(EEGModuleMixin, nn.Module, license="mit"):
181
181
  drop_prob=self.att_positional_drop_prob,
182
182
  n_times=self.n_times,
183
183
  pool_size=self.pool_size_1,
184
+ sequence_length=self.sequence_length,
184
185
  )
185
186
 
186
187
  self.trans = _TransformerEncoder(
@@ -220,7 +221,7 @@ class CTNet(EEGModuleMixin, nn.Module, license="mit"):
220
221
  cnn = self.position(cnn)
221
222
  trans = self.trans(cnn)
222
223
  features = cnn + trans
223
- flatten_feature = self.flatten(features)
224
+ flatten_feature = self.flatten_drop_layer(features)
224
225
  out = self.final_layer(flatten_feature)
225
226
  return out
226
227
 
@@ -516,18 +517,23 @@ class _PositionalEncoding(nn.Module):
516
517
  length: int = 100,
517
518
  drop_prob: float = 0.1,
518
519
  pool_size: int = 8,
520
+ sequence_length: int | None = None,
519
521
  ):
520
522
  super().__init__()
521
523
  self.pool_size = pool_size
522
524
  self.n_times = n_times
523
525
 
524
- if int(n_times / (pool_size * pool_size)) > length:
526
+ # n_times / pool_size**2 is the sequence length only when both pooling
527
+ # sizes are equal; also cover the actual length (e.g. pool_size_2 <
528
+ # pool_size_1), so that the encoding is never shorter than the input
529
+ needed = max(int(n_times / (pool_size * pool_size)), sequence_length or 0)
530
+ if needed > length:
525
531
  warn(
526
532
  "the temporal dimensional is too long for this default length. "
527
533
  "The length parameter will be automatically adjusted to "
528
534
  "avoid inference issues."
529
535
  )
530
- length = int(n_times / (pool_size * pool_size))
536
+ length = needed
531
537
 
532
538
  self.dropout = nn.Dropout(drop_prob)
533
539
  self.encoding = nn.Parameter(torch.randn(1, length, emb_size))
@@ -1,4 +1,5 @@
1
1
  # Authors: Pierre Guetschel <pierre.guetschel@gmail.com>
2
+ # Anton Soloviev <anton@praviel.com>
2
3
  #
3
4
  # License: MIT (see NOTICE.txt)
4
5
  #
@@ -72,6 +73,8 @@ class _GaussianRandomProjection(nn.Module):
72
73
  def __init__(self, n_features: int, n_components: int, seed: int = 0):
73
74
  super().__init__()
74
75
  self.n_features, self.n_components = n_features, n_components
76
+ # A factory also sees temporary device contexts on older torch versions.
77
+ device = torch.empty(0).device
75
78
  generator = torch.Generator(device="cpu").manual_seed(seed)
76
79
  projection = torch.empty(
77
80
  n_components, n_features, dtype=torch.float32, device="cpu"
@@ -81,9 +84,7 @@ class _GaussianRandomProjection(nn.Module):
81
84
  # the draw stays on the CPU, only the result follows the default device
82
85
  self.register_buffer(
83
86
  "projection",
84
- projection.to(
85
- device=torch.get_default_device(), dtype=torch.get_default_dtype()
86
- ),
87
+ projection.to(device=device, dtype=torch.get_default_dtype()),
87
88
  )
88
89
 
89
90
  def extra_repr(self) -> str:
@@ -107,12 +108,13 @@ class _LinearPatchEmbedding(nn.Module):
107
108
  class _PositionalEncoder(nn.Module):
108
109
  def __init__(self, ch_pos, embed_dim, pos_half_range, max_n_times):
109
110
  super().__init__()
111
+ device = torch.empty(0).device
110
112
  self.coord_dim = self.time_dim = embed_dim // 4
111
113
  self.pos_half_range, self.max_n_times = pos_half_range, max_n_times
112
114
  self.register_buffer("ch_pos", ch_pos, persistent=False)
113
115
  self.register_buffer(
114
116
  "div_term",
115
- _xyz_div_term(self.coord_dim).to(torch.get_default_device()),
117
+ _xyz_div_term(self.coord_dim).to(device),
116
118
  persistent=False,
117
119
  )
118
120
  self.register_buffer(
@@ -121,9 +123,7 @@ class _PositionalEncoder(nn.Module):
121
123
  # the same table, which overwrites them. Computed on the CPU, then moved
122
124
  # to the default device.
123
125
  # 33 = (6000 - 200) // 180 + 1 patches: the 30 s pre-training window
124
- _pos_encode_time(33, self.time_dim, max_n_times).to(
125
- torch.get_default_device()
126
- ),
126
+ _pos_encode_time(33, self.time_dim, max_n_times).to(device),
127
127
  )
128
128
 
129
129
  def forward(self, n_patches: int, batch_size: int):
@@ -559,7 +559,7 @@ class Guetschel2026(EEGModuleMixin, nn.Module, license="mit"):
559
559
  )
560
560
  # float32 BEFORE the encoding: float64 then cast gives a 4.2e-5 difference.
561
561
  ch_pos_np = ch_pos_f64.astype(np.float32)
562
- ch_pos = torch.from_numpy(ch_pos_np).to(torch.get_default_device())
562
+ ch_pos = torch.from_numpy(ch_pos_np).to(torch.empty(0).device)
563
563
  self.normalization: str = normalization
564
564
  self.input_scale: float = input_scale
565
565
  self.clip_sigma: float = clip_sigma
@@ -329,18 +329,12 @@ class REVE(EEGModuleMixin, nn.Module):
329
329
  step = patch_size - patch_overlap
330
330
  # Raises for "crop" below one patch and for "error" on an untiled window.
331
331
  _patch_count(known_n_times, patch_size, on_non_divisible, step)
332
- if on_non_divisible == "pad" and known_n_times < patch_size:
332
+ if on_non_divisible == "pad" and (
333
+ known_n_times < patch_size or (known_n_times - patch_size) % step
334
+ ):
333
335
  warnings.warn(
334
- f"Time dimension ({known_n_times}) is shorter than patch_size "
335
- f"({patch_size}). Input will be padded.",
336
- UserWarning,
337
- stacklevel=2,
338
- )
339
- elif on_non_divisible == "pad" and (known_n_times - patch_size) % step:
340
- warnings.warn(
341
- f"Time dimension ({known_n_times}) minus patch_size "
342
- f"({patch_size}) is not divisible by the patch step ({step}). "
343
- "Input will be padded.",
336
+ f"REVE's patches do not tile {known_n_times} samples: the input "
337
+ "will be padded.",
344
338
  UserWarning,
345
339
  stacklevel=2,
346
340
  )
@@ -20,33 +20,8 @@ def _check_on_non_divisible(on_non_divisible: str) -> None:
20
20
  def _patch_count(
21
21
  n_times: int, patch_size: int, on_non_divisible: str = "pad", step: int = 0
22
22
  ) -> int:
23
- """Number of patches a time axis of ``n_times`` samples is cut into.
24
-
25
- The single source of the patch count of the patch-based models: their
26
- positional tables, flatten heads and ``max_patches`` guards are sized
27
- with it, so they agree with what the tokenizer produces at ``forward``.
28
-
29
- Parameters
30
- ----------
31
- n_times : int
32
- Number of time samples.
33
- patch_size : int
34
- Number of samples per patch.
35
- on_non_divisible : {"pad", "crop", "error"}, default="pad"
36
- ``"pad"`` counts the right zero-padded last patch
37
- (``ceil``), ``"crop"`` only the complete patches (``floor``), and
38
- ``"error"`` raises when patches do not tile the axis exactly.
39
- step : int, default=0
40
- Hop between consecutive patch starts; ``0`` means ``patch_size``
41
- (non-overlapping patches). Overlapping patches (``step <
42
- patch_size``) tile the axis when ``(n_times - patch_size) % step ==
43
- 0``.
44
-
45
- Returns
46
- -------
47
- int
48
- The number of patches, at least 1.
49
- """
23
+ """Patches cut from ``n_times`` samples every ``step`` (``0``: ``patch_size``):
24
+ the last one zero-padded (``"pad"``), dropped (``"crop"``) or an error."""
50
25
  if step <= 0:
51
26
  step = patch_size
52
27
  if n_times < 1:
@@ -58,63 +33,26 @@ def _patch_count(
58
33
  raise ValueError(
59
34
  f"Need at least one full patch of {patch_size} samples, got {n_times}."
60
35
  )
61
- raise ValueError(
62
- f"Time dimension ({n_times}) is not divisible by patch_size "
63
- f"({patch_size}): it is shorter than one patch."
64
- )
65
- n_complete = (n_times - patch_size) // step + 1
66
- if (n_times - patch_size) % step == 0:
67
- return n_complete
68
- if on_non_divisible == "pad":
69
- return n_complete + 1
70
- if on_non_divisible == "crop":
71
- return n_complete
72
- if step == patch_size:
73
- raise ValueError(
74
- f"Time dimension ({n_times}) is not divisible by patch_size ({patch_size})."
75
- )
36
+ elif (n_times - patch_size) % step == 0:
37
+ return (n_times - patch_size) // step + 1
38
+ elif on_non_divisible != "error":
39
+ return (n_times - patch_size) // step + 1 + (on_non_divisible == "pad")
76
40
  raise ValueError(
77
- f"Time dimension ({n_times}) minus patch_size ({patch_size}) is not "
78
- f"divisible by the patch step ({step})."
41
+ f"Time dimension ({n_times}) is not divisible by patch_size ({patch_size})"
42
+ + ("." if step == patch_size else f" with patch step {step}.")
79
43
  )
80
44
 
81
45
 
82
46
  def _pad_or_crop_to_patches(
83
47
  x: torch.Tensor, patch_size: int, on_non_divisible: str = "pad", step: int = 0
84
48
  ) -> torch.Tensor:
85
- """Right zero-pad or crop the last axis of ``x`` so patches tile it.
86
-
87
- After this call, cutting patches of ``patch_size`` samples every ``step``
88
- samples (``0`` means ``patch_size``) covers the whole axis and yields
89
- :func:`_patch_count` patches. An axis that is already tiled is returned
90
- unchanged (the same tensor), so divisible inputs are bit-identical.
91
-
92
- Parameters
93
- ----------
94
- x : torch.Tensor
95
- Input of shape ``(..., n_times)``.
96
- patch_size : int
97
- Number of samples per patch.
98
- on_non_divisible : {"pad", "crop", "error"}, default="pad"
99
- See :func:`_patch_count`.
100
- step : int, default=0
101
- Hop between patch starts; ``0`` means ``patch_size``.
102
-
103
- Returns
104
- -------
105
- torch.Tensor
106
- ``x`` padded, cropped or unchanged.
107
- """
108
- n_times = x.shape[-1]
109
- n_patches = _patch_count(n_times, patch_size, on_non_divisible, step)
110
- if step <= 0:
111
- step = patch_size
112
- target = patch_size + (n_patches - 1) * step
113
- if target > n_times:
114
- return nn.functional.pad(x, (0, target - n_times))
115
- if target < n_times:
116
- return x[..., :target]
117
- return x
49
+ """Right zero-pad or crop the last axis so the patches tile it; a tiled axis
50
+ is returned as is."""
51
+ n_patches = _patch_count(x.shape[-1], patch_size, on_non_divisible, step)
52
+ target = patch_size + (n_patches - 1) * (step if step > 0 else patch_size)
53
+ if target > x.shape[-1]:
54
+ return nn.functional.pad(x, (0, target - x.shape[-1]))
55
+ return x[..., :target]
118
56
 
119
57
 
120
58
  class PatchTokenizer(nn.Module):
@@ -231,12 +169,7 @@ class PatchTokenizer(nn.Module):
231
169
  self.proj = nn.Linear(patch_size, self.emb_dim)
232
170
 
233
171
  def n_patches(self, n_times: int) -> int:
234
- """Number of patches ``forward`` returns for ``n_times`` samples.
235
-
236
- ``ceil(n_times / patch_size)`` for ``on_non_divisible="pad"``,
237
- ``n_times // patch_size`` for ``"crop"``; ``"error"`` raises for a
238
- non-divisible ``n_times``.
239
- """
172
+ """Number of patches ``forward`` returns for ``n_times`` samples."""
240
173
  return _patch_count(n_times, self.patch_size, self.on_non_divisible)
241
174
 
242
175
  def prepare_input(self, x):
@@ -217,11 +217,11 @@ class EMACodebook(nn.Module):
217
217
  work = torch.promote_types(x.dtype, torch.float32)
218
218
  x = x.to(work)
219
219
  embed = self.embed.t().to(work)
220
- dist = (
221
- x.pow(2).sum(1, keepdim=True)
222
- - 2 * x @ embed
223
- + embed.pow(2).sum(0, keepdim=True)
224
- )
220
+ # x2 - 2 x @ e + e2 written into the (N, codebook_size) product:
221
+ # same operations and rounding, no two more temporaries of that size.
222
+ dist = (2 * x @ embed).to(work)
223
+ dist = torch.sub(x.pow(2).sum(1, keepdim=True), dist, out=dist)
224
+ dist = dist.add_(embed.pow(2).sum(0, keepdim=True))
225
225
  indices = dist.argmin(dim=-1)
226
226
  return indices
227
227
 
@@ -163,7 +163,8 @@ class EEGPrepBasePreprocessor(Preprocessor):
163
163
  eeg_idx = mne.pick_types(raw.info, eeg=True, exclude=[])
164
164
  if len(eeg_idx) < len(chn_order):
165
165
  eeg = raw.copy().pick(eeg_idx)
166
- non_eeg = raw.drop_channels(eeg.ch_names)
166
+ # on a copy, so that a failure below leaves the caller's raw intact
167
+ non_eeg = raw.copy().drop_channels(eeg.ch_names)
167
168
  else:
168
169
  eeg = raw
169
170
  non_eeg = None
@@ -237,9 +238,11 @@ class EEGPrepBasePreprocessor(Preprocessor):
237
238
  )
238
239
  else:
239
240
  # re-insert non-EEG channels, and restore original channel order
241
+ # of the channels that remain (the operation may remove some)
240
242
  proc.add_channels([non_eeg], force_update_info=True)
241
- if proc.ch_names != chn_order:
242
- proc.reorder_channels(chn_order)
243
+ order = [ch for ch in chn_order if ch in proc.ch_names]
244
+ if proc.ch_names != order:
245
+ proc.reorder_channels(order)
243
246
 
244
247
  # write result back into raw, discard proc (_apply_op() is in-place)
245
248
  if not proc.preload:
@@ -7,6 +7,7 @@
7
7
  # Bruno Aristimunha <b.aristimunha@gmail.com>
8
8
  # Léo Burgund <leo.burgund@gmail.com>
9
9
  # Sarthak Tayal <sarthaktayal2@gmail.com>
10
+ # Anton Soloviev <anton@praviel.com>
10
11
  #
11
12
  # License: BSD (3-clause)
12
13
 
@@ -170,6 +171,7 @@ class Preprocessor(object):
170
171
  Preprocessor
171
172
  The deserialized Preprocessor object.
172
173
  """
174
+ data = data.copy()
173
175
  class_path = data.pop("__class_path__")
174
176
  cls_name = class_path.split(".")[-1]
175
177
  cls_module_name = ".".join(class_path.split(".")[:-1])