Skip to content

Instantly share code, notes, and snippets.

View philtomson's full-sized avatar

Phil Tomson philtomson

View GitHub Profile

20 million digits of pi in under a minute with Julia

I recently discovered a relatively obscure algorithm for calculating the digits of pi: https://en.wikipedia.org/wiki/Gauss–Legendre_algorithm. Well, at least obscure compared to Chudnovsky's. Wikipedia notes that it is "memory-intensive" but is it really? Let's compare to the MPFR pi function:

function gauss_legendre(prec)
    setprecision(BigFloat, prec, base=10)
    GC.enable(false)
@Hirrolot
Hirrolot / CoC.ml
Last active July 17, 2024 13:27
How to implement dependent types in 80 lines of code
type term =
| Lam of (term -> term)
| Pi of term * (term -> term)
| Appl of term * term
| Ann of term * term
| FreeVar of int
| Star
| Box
let unfurl lvl f = f (FreeVar lvl)
@nicebyte
nicebyte / dyn_arr.h
Last active July 1, 2024 10:44
dyn_arr
#pragma once
#define DYN_ARR_OF(type) struct { \
type *data; \
type *endptr; \
uint32_t capacity; \
}
#if !defined(__cplusplus)
#define decltype(x) void*

Neural Style Transfer

Neural Style Transfer is the process of using Deep Neural Networks to migrate the semantic content of one image to different styles.

Usage

This gist implements NST in Owl, and provides a simple interfaces to use. Here is an example:

#zoo "6f28d54e69d1a19c1819f52c5b16c1a1"

This document has moved!

It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.

@akabe
akabe / maze_solver.ml
Last active October 13, 2019 16:34
A maze solver by A* algorithm on OCaml
(* ========================================================================== *
* General implementation of A-star algorithm
* ========================================================================== *)
module Astar :
sig
type 'a t =
{
cost : 'a -> 'a -> int;
goal : 'a;
@PhDP
PhDP / harr1.jl
Last active August 29, 2015 14:16
First example of Harrison's "Handbook of Practical Logic and Automated Reasoning" in Julia.
abstract Expr
type Const <: Expr; value::Int end
type Var <: Expr; name::String end
type Add <: Expr; left::Expr; right::Expr end
type Mult <: Expr; left::Expr; right::Expr end
add(x::Const, y::Const) = Const(x.value + y.value)
add(x::Const, y::Expr) = x.value == 0? y : Add(x, y)
add(x::Expr, y::Const) = add(y, x)
@rmcgibbo
rmcgibbo / Install Intel-CPU OpenCL on Ubuntu.md
Last active November 6, 2021 10:00
Installing Intel CPU OpenCL on Ubuntu 12.04

Open Computing Language (OpenCL) is a language and framework for writing computationally intensive kernels that run accross heterogenious platforms, including GPUs, CPUs, and perhaps other more esoteric devices.

Intel provides an OpenCL implementation for Intel CPUs, but there's not a lot of instructions on how to get it set up. Here's what I did.

Installing Intel CPU OpenCL on Ubuntu (12.04)

  1. Download the Intel® SDK for OpenCL* Applications XE 2013 from the Intel website, here http://software.intel.com/en-us/vcsource/tools/opencl-sdk-xe. The download is a tarball -- the one I got is called intel_sdk_for_ocl_applications_2013_xe_sdk_3.0.67279_x64.tgz
  2. Unpack the tarball and cd into the new directory
@NicolasT
NicolasT / binsec.ml
Created June 21, 2011 18:45
Monadic binary (de)serialization API for OCaml
type 'a writer = Buffer.t -> 'a -> unit;;
type 'a reader = string -> int -> ('a * int);;
let ($) a b = a b;;
let id x = x;;
let lift_llio_writer (l: Buffer.t -> 'b -> unit): ('a -> 'b) -> 'a writer =
fun f -> fun b a ->
let v = f a in
l b v;;
@joelreymont
joelreymont / 0001-fast-track-the-case-where-executable-name-matches-ma.patch
Created May 27, 2011 07:09
Avoid copying and invoke ocamlbuild once for all targets where executable name matches MainIs
From 618b4efb183fcd49256b43e04ef9e07fa67dcce6 Mon Sep 17 00:00:00 2001
From: Joel Reymont <joelr1@gmail.com>
Date: Fri, 27 May 2011 09:07:29 +0200
Subject: [PATCH] fast-track the case where executable name matches main, avoid copying
---
src/base/BaseBuilt.ml | 9 ++++++++-
src/plugins/ocamlbuild/OCamlbuildPlugin.ml | 2 +-
2 files changed, 9 insertions(+), 2 deletions(-)