Skip to content

Instantly share code, notes, and snippets.

View speedcell4's full-sized avatar

Yiran Wang speedcell4

  • NICT
  • Nara, Japan
  • 20:47 (UTC +09:00)
  • X @nlp_yiran
View GitHub Profile
import torch
from torch import Tensor
from torch.testing import assert_close
def fft(tensor: Tensor, pi: Tensor = torch.acos(torch.tensor(-1.))) -> Tensor:
n = tensor.size()[-1]
index = torch.arange(n, dtype=torch.float32)
fourier = torch.exp(index[:, None] * index[None, :] * pi * -2j / n)
import math
import torch
from torch import Tensor
from torch import nn
from torch.nn import functional as F
from torch.nn import init
class ComplexLinear(nn.Module):
# CUDA
export CUDA_HOME=/usr/local/cuda-9.0
export CUDA_ROOT=/usr/local/cuda-9.0
export CUDA_PATH=/usr/local/cuda-9.0
export PATH=${CUDA_HOME}/bin:${PATH}
export LIBRARY_PATH=${CUDA_HOME}/lib64:${LIBRARY_PATH}
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64:${LD_LIBRARY_PATH}
# cuDNN
@speedcell4
speedcell4 / bibtex.png
Created September 2, 2018 03:39 — forked from max-mapper/bibtex.png
How to make a scientific looking PDF from markdown (with bibliography)
bibtex.png
@speedcell4
speedcell4 / requirements.txt
Last active April 11, 2018 03:26
basic python libraries
pip
wheel
setuptools
cython
numpy
scipy
matplotlib
pandas
gensim
sklearn
@speedcell4
speedcell4 / lstcoq.sty
Created November 29, 2017 12:15
listings coq style
% lstlisting coq style (inspired from https://github.com/cmc333333/forensics-thesis)
% lstlisting coq style (inspired from a file of Assia Mahboubi)
%
\lstdefinelanguage{coq}{
%
% Anything betweeen $ becomes LaTeX math mode
mathescape=true,
%
% Comments may or not include Latex commands
texcl=false,
import chainer.functions as F
import numpy as np
from chainer import Variable, Function
from chainer import cuda
class Scatter(Function):
def __init__(self, row: int, col: int):
self.row = row
self.col = col
@speedcell4
speedcell4 / binary_sort.cpp
Last active November 8, 2017 07:01
return the index of value
#include <iostream>
using namespace std;
int binary_search(int *a, int value, int left, int right) {
if (left >= right) return -1;
else {
int mid = (left + right) / 2;
if (a[mid] == value) return mid;
else if (a[mid] > value) return binary_search(a, value, left, mid);
import tensorflow as tf
class Summary(object):
def __init__(self, logdir: str):
self._placeholders = {}
self._observations = {}
self._session = tf.Session()
self._writer = tf.summary.FileWriter(logdir=logdir)
@speedcell4
speedcell4 / multi-task-classifier.py
Created August 11, 2017 05:09
multi-task classifier of chainer
from chainer import Chain, report
class MultiTaskClassifier(Chain):
def __init__(self, task1, task2, loss1, loss2, acc1, acc2, lambda_=1.0):
"""
:param task1: `Chain` of task 1
:param task2: `Chain` of task 2
:param loss1: loss function of task1
:param loss2: loss function of task2