Skip to content

Instantly share code, notes, and snippets.

View vbkaisetsu's full-sized avatar
♾️

Koichi Akabe vbkaisetsu

♾️
  • Edogawa, Tokyo, JP
View GitHub Profile
vim.cmd[[packadd packer.nvim]]
require'packer'.startup(function()
use'tpope/vim-fugitive'
use'tpope/vim-repeat'
use{'wbthomason/packer.nvim', opt = true}
use{'rhysd/git-messenger.vim', opt = true, cmd = {'GitMessenger'}}
@vbkaisetsu
vbkaisetsu / html5ever_edit.rs
Last active August 12, 2021 07:46
RustでHTMLをパースし,編集し,書き出す (html5ever)
use std::cell::RefCell;
use std::rc::Rc;
use html5ever::{Attribute, LocalName, QualName};
use html5ever::driver::ParseOpts;
use html5ever::{local_name, ns, namespace_url};
use html5ever::{parse_document, parse_fragment};
use html5ever::rcdom::{Handle, Node, NodeData, RcDom};
use html5ever::serialize;
use html5ever::serialize::SerializeOpts;
@vbkaisetsu
vbkaisetsu / col2im_gpu_caffe.cc
Last active July 31, 2018 11:32
col2im implementations
#include <algorithm>
#include <chrono>
#include <functional>
#include <iostream>
#include <random>
#define CL_HPP_ENABLE_EXCEPTIONS
#define CL_HPP_MINIMUM_OPENCL_VERSION 120
#define CL_HPP_TARGET_OPENCL_VERSION 120
#define CL_HPP_CL_1_2_DEFAULT_BUILD
#!/bin/bash -xe
ABSPATH=$(realpath $0)
DIRNAME=$(dirname ${ABSPATH})
ANDROID_NDK_PATH=/path/to/Android/Sdk/ndk-bundle
ANDROID_ABI=armeabi-v7a
ANDROID_PLATFORM=android-15
OPENCL_INCLUDE_DIR=${DIRNAME}/OpenCL/include
OPENCL_LIBRARY=${DIRNAME}/OpenCL/lib/libOpenCL.so
@vbkaisetsu
vbkaisetsu / core.clj
Created December 27, 2017 14:39
primitiv XOR example (Clojure)
(ns xor-example.core
(:import
[primitiv Device Graph Parameter Shape]
[primitiv functions functions$batch]
[primitiv.devices Naive]
[primitiv.initializers XavierUniform Constant]
[primitiv.optimizers SGD]))
(defn -main []
#define REDUCE(k, GROUP_SIZE) \
if (GROUP_SIZE >= k << 1) { \
if (tid < k) { \
if (max_val[tid + k] > max_val[tid]) { \
max_val[tid] = max_val[tid + k]; \
argmax_val[tid] = argmax_val[tid + k]; \
} \
} \
barrier(CLK_LOCAL_MEM_FENCE); \
}
@vbkaisetsu
vbkaisetsu / bwt.py
Last active November 9, 2021 06:15
Burrows Wheeler Transform implemented in Python (O(n log n))
#!/usr/bin/env python3
#
# Burrows Wheeler Transform implemented in Python
# Currently, list.sort() is not the radix sort, so the algorithm order is O(n log n log n).
# This algorithm replaces items of arr to integers, so we can use the radix sort instead.
# In that case, the algorithm order becomes O(n log n).
#
from operator import itemgetter
#!/usr/bin/env python3
from typing import TypeVar, Generic, Any, List
from abc import ABCMeta, abstractmethod
from itertools import dropwhile, zip_longest
def euclid_gcd(a, b):
x = a.zero()
y = a.identity()
@vbkaisetsu
vbkaisetsu / fobos_enr.py
Last active July 14, 2017 14:10
Elastic Net Regularizer using Forward Backward Splitting (FOBOS) implemented in Python
#!/usr/bin/env python3
# Efficient online and batch learning using forward backward splitting
# John Duchi and Yoram Singer
# Journal of Machine Learning Research 10 (2009) 2899-2934
# http://www.jmlr.org/papers/volume10/duchi09a/duchi09a.pdf
# Efficient Elastic Net Regularization for Sparse Linear Models
# Zachary C. Lipton and Charles Elkan (2015)
# https://arxiv.org/pdf/1505.06449.pdf
#!/usr/bin/env python3
from itertools import chain
def ranges_or(ranges):
result = []
depth = 0
for p, t in sorted(chain.from_iterable(((x, -1), (y, 1)) for x, y in ranges)):
if depth == 0 and t == -1: