Skip to content

Instantly share code, notes, and snippets.

View ToruNiina's full-sized avatar
🐧
turning into a penguin

Toru Niina ToruNiina

🐧
turning into a penguin
View GitHub Profile
@ToruNiina
ToruNiina / branchless_ReLU.c
Created July 9, 2018 12:35
branchless ReLU implementation (with bitwise operations)
// copyright Toru Niina 2018. distributed under the Boost Software License v1.0.
// it provides an implementation of ReLU without branching.
// the core idea of branchless-ReLU is the following.
// 1. first, bitwise-and with 0 bits everytime returns 0 bits. but bitwise-and
// with 1 bits returns the original argument kept intact.
// 0000 & 1010 == 0000, 1111 & 1010 == 1010
// 2. second, we can make 0 bits or 1 bits depending on the sign bit by applying
// right arithmetic shift 31 times.
// 1000 >> 31 == 1111, 0110 >> 31 == 0000
@ToruNiina
ToruNiina / zip_iterator.cpp
Created March 6, 2018 14:43
implementation of writable zip_iterator
// Copyright 2018 Toru Niina
// Distributed under the MIT license.
#include<type_traits>
#include<utility>
#include<iterator>
#include<tuple>
namespace detail
{
@ToruNiina
ToruNiina / constexpr-repressilator.cpp
Created March 9, 2017 06:31
compile time repressilator simulation depending on sprout
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/container/indexes.hpp>
#include <sprout/algorithm/fixed/unfold.hpp>
#include <sprout/utility/pair.hpp>
#include <sprout/array.hpp>
constexpr static double dt = 0.1;
@ToruNiina
ToruNiina / reverse.cpp
Created November 12, 2016 08:41
reverse type in variadic template
template<typename ... T_args>
struct pack{};
template<template<typename ...T>class target, typename ... T_args>
struct transfer;
template<template<typename ...T>class target, typename ... T_args>
struct transfer<target, pack<T_args...>>
{
typedef target<T_args...> type;
@ToruNiina
ToruNiina / stl_to_vmd.cpp
Last active August 8, 2016 06:41
generates vmd script (tcl) that draw polygon on vmd from STL binary format file.
/* Description: this program generates vmd script file (.tcl file) that draws *
* polygon structure on vmd from STL binary-format file. *
* *
* Licensing Terms : This code is licensed under the MIT License. *
* copyright (c) 2016 Toru Niina (niina.toru.68u@gmail.com) *
* all rights reserved.   *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy *
* of this software and associated documentation files (the "Software"), to deal *
* in the Software without restriction, including without limitation the rights *