Skip to content

Instantly share code, notes, and snippets.

View hazdzz's full-sized avatar

Chieh Chang hazdzz

View GitHub Profile
@hazdzz
hazdzz / pscan.py
Last active November 9, 2025 22:39
Parallel Scan (Blelloch algorithm)
# Any copyright is dedicated to the Public Domain.
# https://creativecommons.org/publicdomain/zero/1.0/
# Written by Francois Fleuret <francois@fleuret.org>
import os
import random
import torch
class PScan(torch.autograd.Function):
@staticmethod
from torch import Tensor
from typing import Callable, List, Optional, Tuple
import math
import warnings
import torch
import torch.nn as nn
import torch.nn.functional as F
class CSigmoid(nn.Module):
def forward(self, input: Tensor) -> Tensor:
@hazdzz
hazdzz / casualconv.py
Created May 2, 2021 05:31
Dilated Causal Convolution
import torch
import torch.nn as nn
import torch.nn.functional as F
class CausalConv1d(nn.Conv1d):
def __init__(self, in_channels, out_channels, kernel_size, stride=1, enable_padding=False, dilation=1, groups=1, bias=True):
if enable_padding == True:
self.__padding = (kernel_size - 1) * dilation
else:
self.__padding = 0