Skip to content

Instantly share code, notes, and snippets.

View AidanRocke's full-sized avatar

Aidan Rocke AidanRocke

View GitHub Profile
@rossant
rossant / raytracing.py
Last active December 24, 2023 12:50
Very simple ray tracing engine in (almost) pure Python. Depends on NumPy and Matplotlib. Diffuse and specular lighting, simple shadows, reflections, no refraction. Purely sequential algorithm, slow execution.
"""
MIT License
Copyright (c) 2017 Cyrille Rossant
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
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@danijar
danijar / blog_tensorflow_scope_decorator.py
Last active January 17, 2023 01:58
TensorFlow Scope Decorator
# Working example for my blog post at:
# https://danijar.github.io/structuring-your-tensorflow-models
import functools
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
def doublewrap(function):
"""
A decorator decorator, allowing to use the decorator to be used without
@higham
higham / complex_step_example.m
Last active November 2, 2021 15:45
Complex step example
% Complex step example. Requires Symbolic Math Toolbox.
format long
syms x; f = atan(x)/(1+exp(-x^2))
% Derivative at $a = 2$:
a = 2; fd = double(subs( diff(f), a))
% Convert symbolic function to MATLAB function.
f = matlabFunction(f);
@breuderink
breuderink / fx.c
Created November 30, 2019 20:19
SORF
#include "fx.h"
#include <stddef.h>
#include <stdint.h>
#include <math.h>
#include <assert.h>
void static inline wht_butterfly(float * const s, float * const d) {
float temp = *s;
*s += *d;
*d = temp - *d;
@higham
higham / complex_step.m
Created April 21, 2018 12:58
Complex step approximation to derivative.
function fd = complex_step(f,x,h)
%COMPLEX_STEP Complex step approximation to derivative.
% fd = COMPLEX_STEP(f,x,h) computes the complex step approximation
% fd to the derivative of f at x, using step h (default 1e-100).
if nargin < 3, h = 1e-100; end
fd = imag( f(x + sqrt(-1)*h) )/h;
@kingjr
kingjr / google_translate_challenge.py
Created June 8, 2018 21:41
Find simplest google translate request that generate the maximum number of unique words
from googletrans import Translator
from itertools import product
from pandas import DataFrame, read_csv
import numpy as np
import string
import time
import os
# Get google translator object
translator = Translator()