Skip to content

Instantly share code, notes, and snippets.

View mdickinson's full-sized avatar

Mark Dickinson mdickinson

  • Enthought
  • Cambridge, UK
View GitHub Profile
@mdickinson
mdickinson / hilbert_curve.py
Last active October 30, 2015 08:38
Code to create the third-order approximation to a 3d space-filling Hilbert curve
import numpy
def hilbert():
"""
Return NumPy array of shape (512, 3) containing successive coordinates
for a third-order three-dimensional Hilbert curve.
"""
a,b,c=numpy.indices((8,)*3).reshape(3,-1)
d=c[:8];r=abs(d-3>>1);g=(d^d>>1)*73;f=g[abs(d-1)&6]
@mdickinson
mdickinson / sqrt_exact.c
Last active March 10, 2024 19:24
Fast square root of a 64-bit square number
// Exact square root of a known square integer
// ===========================================
// This snippet contains a function `isqrt64_exact` with signature
//
// uint32_t isqrt64_exact(uint64_t n);
//
// `isqrt64_exact` computes the 32-bit square root of its unsigned 64-bit
// integer input, under the assumption that that input is a perfect square.
//
// Compile under gcc or clang with: