foscat 2025.7.2__py3-none-any.whl → 2025.8.3__py3-none-any.whl

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.
foscat/BkTorch.py CHANGED
@@ -196,10 +196,41 @@ class BkTorch(BackendBase.BackendBase):
196
196
  y = y.reshape(*leading_dims, O_c, Nx, Ny)
197
197
 
198
198
  return y
199
-
199
+
200
200
  def conv1d(self, x, w, strides=[1, 1, 1], padding="SAME"):
201
- # to be written!!!
202
- return x
201
+ """
202
+ Performs 1D convolution along the last axis of a 2D tensor x[n, m] with kernel w[K].
203
+
204
+ Parameters:
205
+ - x: torch.Tensor of shape [n, m]
206
+ - w: torch.Tensor of shape [K]
207
+ - strides: list of 3 ints; only strides[1] (along axis -1) is used
208
+ - padding: "SAME" or "VALID"
209
+
210
+ Returns:
211
+ - torch.Tensor of shape [n, m] (if SAME) or smaller (if VALID)
212
+ """
213
+ assert x.ndim == 2, "Input x must be a 2D tensor [n, m]"
214
+ assert w.ndim == 1, "Kernel w must be a 1D tensor [K]"
215
+ stride = strides[1]
216
+
217
+ # Reshape for PyTorch conv1d: [batch, channels, width]
218
+ x_reshaped = x.unsqueeze(1) # [n, 1, m]
219
+ w_flipped = w.flip(0).view(1, 1, -1) # [out_channels=1, in_channels=1, kernel_size]
220
+
221
+ if padding.upper() == "SAME":
222
+ pad_total = w.shape[0] - 1
223
+ pad_left = pad_total // 2
224
+ pad_right = pad_total - pad_left
225
+ x_reshaped = F.pad(x_reshaped, (pad_left, pad_right), mode='constant', value=0)
226
+ padding_mode = 'valid'
227
+ elif padding.upper() == "VALID":
228
+ padding_mode = 'valid'
229
+ else:
230
+ raise ValueError("padding must be either 'SAME' or 'VALID'")
231
+
232
+ out = F.conv1d(x_reshaped, w_flipped, stride=stride, padding=0) # manual padding applied above
233
+ return out.squeeze(1) # [n, m_out]
203
234
 
204
235
  def bk_threshold(self, x, threshold, greater=True):
205
236
 
foscat/CNN.py CHANGED
@@ -91,6 +91,7 @@ class CNN:
91
91
  def get_weights(self):
92
92
  return self.x
93
93
 
94
+
94
95
  def eval(self, im, indices=None, weights=None):
95
96
 
96
97
  x = self.x