Skip to content

Instantly share code, notes, and snippets.

@Linux-cpp-lisp
Linux-cpp-lisp / spiral.md
Last active May 29, 2019 20:58
Flexible, configurable generation of natural numbers in a spiral

 Generate and print a spiral of natural numbers up to N with fully configurable shape and spacing.

Examples:

$ python3 spiral.py 50 square 2 
                                     
                                     
     32 31 30 29 28 27 26 25         
     33                   24         
@Linux-cpp-lisp
Linux-cpp-lisp / diffusion.pyx
Created May 13, 2020 16:11
Finite-difference method for evolution under the heat equation (diffusion) with periodic boundary conditions (Cython)
# Finite-difference method from http://www.cosy.sbg.ac.at/events/parnum05/book/horak1.pdf
# Parallel Numerical Solution of 2-D Heat Equation, Verena Horak & Peter Gruber (Parallel Numerics ’05, 47-56)
@cython.boundscheck(False)
def diffuse(initial_condition, int nstep, double c = 1.0, double delta_t_factor = 0.5):
"""Evolve `initial_condition` according to the 2D heat (diffusion) equation under periodic boundary conditions."""
# Short circut
if nstep == 0:
return initial_condition
@Linux-cpp-lisp
Linux-cpp-lisp / torch-neighbors.py
Created April 15, 2022 02:45
translating ASE periodic neighborlist into TorchScript compatible PyTorch (MOSTLY UNTESTED)
# Author: https://gist.github.com/Linux-cpp-lisp
from typing import Tuple, List
import numpy as np
import torch
@torch.jit.script
def torch_divmod(a, b) -> Tuple[torch.Tensor, torch.Tensor]: