Skip to content

Instantly share code, notes, and snippets.

View thautwarm's full-sized avatar
🧐

Taine Zhao thautwarm

🧐
View GitHub Profile
@Z-Shang
Z-Shang / tco.py
Created September 6, 2018 11:44
Working yet naive Tail Call Optimisation (Trampoline) in Python
from collections import namedtuple
TailCall = namedtuple("TailCall", ['fn', 'args', 'kargs'])
class tco:
def __init__(self, f):
self.fn = f
def __call__(self, *a, **k):
retval = self.fn(*a, **k)
@arctangent
arctangent / hmazed.hs
Created December 29, 2011 10:00
Maze generator in Haskell
-- Simple maze generator in Haskell
-- Jacob Conrad Martin
-- http://jacobconradmartin.com
import System.Random
import Debug.Trace
import Control.Monad.State
data Location = Location { x::Int, y::Int } deriving (Eq)
data Path = Path { from::Location, to::Location } deriving (Eq)
@inkydragon
inkydragon / testset.jl
Last active May 1, 2019 10:39
patch for `MLStyle.jl`
# test driven development
# TestSet for `@when` + `@otherwise`
using MLStyle
using Test
using Random
#=
Test help macro/functions
=#
@delimitry
delimitry / python_hashes.py
Last active September 24, 2020 11:47
Python hash algorithms
#!/usr/bin/evn python
# -*- coding: utf-8 -*-
import sys
import math
import struct
if sys.version_info > (3, 0):
basestring_type = str
else:
@delimitry
delimitry / uint_7bit.py
Last active November 7, 2022 16:09
Python version of unsigned integer 7-bit encoder and decoder
#!/usr/bin/evn python
# -*- coding: utf8 -*-
def encode_to_7bit(value):
"""
Encode unsigned int to 7-bit str data
"""
data = []
number = abs(value)
while number >= 0x80:
@svaksha
svaksha / pythontojulia.md
Created May 12, 2017 12:27 — forked from cuckookernel/pythontojulia.md
Python to Julia Quick translation / conversion reference Guide

A quick and dirty syntax translation / conversion reference guide to ease the transition between Python and Julia. This is not meant as a reference to the language. For that you should read the manual.

Some important differences

  • Arrays in Julia are indexed starting from 1.
  • In Julia classes (i.e. types) don't own methods. Methods are implementations of generic functions and are invoked in a "static style", i.e. instead of Python's str1.rstrip(), we will have rstrip( str1 ), instead of file1.close(), close( file1 ).

Some important similarities.

@ChrisRackauckas
ChrisRackauckas / diffeqflux_differentialequations_vs_torchdiffeq_results.md
Last active December 20, 2023 13:10
torchdiffeq (Python) vs DifferentialEquations.jl (Julia) ODE Benchmarks (Neural ODE Solvers)

Torchdiffeq vs DifferentialEquations.jl (/ DiffEqFlux.jl) Neural ODE Compatible Solver Benchmarks

Only non-stiff ODE solvers are tested since torchdiffeq does not have methods for stiff ODEs. The ODEs are chosen to be representative of models seen in physics and model-informed drug development (MIDD) studies (quantiative systems pharmacology) in order to capture the performance on realistic scenarios.

Summary

Below are the timings relative to the fastest method (lower is better). For approximately 1 million ODEs and less, torchdiffeq was more than an order of magnitude slower than DifferentialEquations.jl

@mewmew
mewmew / ll.bnf
Last active January 16, 2024 15:38
A BNF grammar for LLVM IR assembly
// ### [ Lexical part ] ########################################################
_ascii_letter_upper
: 'A' - 'Z'
;
_ascii_letter_lower
: 'a' - 'z'
;
@JamesPHoughton
JamesPHoughton / make_python_identifier.py
Last active February 28, 2024 01:40
Converts an arbitrary string into something that can be used as a python identifier. Checks for namespace conflicts and conflicts with python and specified reserved words.
def make_python_identifier(string, namespace=None, reserved_words=None,
convert='drop', handle='force'):
"""
Takes an arbitrary string and creates a valid Python identifier.
If the python identifier created is already in the namespace,
or if the identifier is a reserved word in the reserved_words
list, or is a python default reserved word,
adds _1, or if _1 is in the namespace, _2, etc.
Parameters
@eevee
eevee / perlin.py
Last active March 2, 2024 08:48
Perlin noise in Python
"""Perlin noise implementation."""
# Licensed under ISC
from itertools import product
import math
import random
def smoothstep(t):
"""Smooth curve with a zero derivative at 0 and 1, making it useful for
interpolating.