Skip to content

Instantly share code, notes, and snippets.

View bitonic's full-sized avatar
🍥
bottomless pit

Francesco Mazzoli bitonic

🍥
bottomless pit
View GitHub Profile
@bitonic
bitonic / readme.txt
Created December 13, 2018 21:30
Simple Block Pushing Game (PuzzleScript Script)
Play this game by pasting the script in http://www.puzzlescript.net/editor.html
@bitonic
bitonic / eigen-avx.c
Last active January 13, 2020 09:02
Repro for Eigen not using AVX operations
// Compiled with
//
// g++ -std=c++17 -march=native -O3 -I<path-to-eigen-master> eigen-avx.c -o eigen-avx
//
// Expected output:
//
// With size 8, normal_count: 0, packet4_count: 0, packet8_count: 1
// With size 9, normal_count: 1, packet4_count: 0, packet8_count: 1
//
// Actual output:
@bitonic
bitonic / TrigApprox.h
Last active November 25, 2021 11:04
Vectorized acos and atan2
// Vectorized (SSE and AVX, through Eigen) atan2 and acos.
//
// Care has been taken to ensure that the vectorized results are identical to the non-vectorized
// ones.
//
// Original functions from <https://developer.download.nvidia.com/cg/index_stdlib.html>, adapted
// to work in bulk. Both seem to be very accurate (only tested that error < 0.01
// degrees, which is what I need).
#include <Eigen/Core>
@bitonic
bitonic / poly.ts
Created June 5, 2020 13:22
polygon cube intersection in threejs
function signNonZero(x: number): number {
return x < 0 ? -1 : 1;
}
function inClosedInterval(a: number, x: number, b: number): boolean {
return (x-a) * (x-b) <= 0;
}
function segContainsPoint(a: number, b: number, x: number): number {
return (b > x ? 1 : 0) - (a > x ? 1 : 0);
#! /usr/bin/env bash
# Script to install NixOS from the Hetzner Cloud NixOS bootable ISO image.
# (tested with Hetzner's `NixOS 20.03 (amd64/minimal)` ISO image).
#
# This script wipes the disk of the server!
#
# Instructions:
#
# 1. Mount the above mentioned ISO image from the Hetzner Cloud GUI
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{ config, pkgs, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
@bitonic
bitonic / reverse.hs
Last active March 22, 2021 12:20
Simple reverse AD
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE BangPatterns #-}
{-# OPTIONS_GHC -Wall #-}
import Data.IORef
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RecordWildCards #-}
import Data.List (transpose)
data Forward a = Forward { _value :: !a, _grad :: !a }
deriving (Show, Eq)
lift :: Num a => a -> Forward a
lift a = Forward { _value = a, _grad = 0 }
// See <https://gist.github.com/pervognsen/b58108d134824e61caedffcc01004e03> for
// Per Vognsen gist on value speculation.
//
// I compile this on linux with
//
// $ clang --version
// clang version 12.0.0
// Target: x86_64-unknown-linux-gnu
// $ clang -static -Wall -O3 value-speculation-linux.c -o value-speculation-linux
//
@bitonic
bitonic / vectorized-atan2f.cpp
Last active December 11, 2025 07:33
Vectorized & branchless atan2f
// Copyright (c) 2021 Francesco Mazzoli <f@mazzo.li>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES