Skip to content

Instantly share code, notes, and snippets.

View angus-g's full-sized avatar

Angus Gibson angus-g

  • The Australian National University
View GitHub Profile
@angus-g
angus-g / dask.md
Created May 9, 2023 01:03
Dask tutorial notes

Dask

Tutorial

A brief example

Set up a synthetic example, loading some chunked data and exporting it into a Dask array. With this, we can see the task graph.

Terminology and how Dask works under the hood

@angus-g
angus-g / petsc_garbage.py
Created December 6, 2022 03:23
Demonstration of increasing KSP objects
from firedrake import *
from firedrake_adjoint import *
from firedrake.petsc import PETSc
from pyadjoint.tape import pause_annotation
mesh = UnitSquareMesh(10, 10)
x, y = SpatialCoordinate(mesh)
Q = FunctionSpace(mesh, "CG", 2)
Y = TestFunction(Q)
import vector
class V(vector.Vector):
def __init__(self):
super().__init__()
self.val = 0
def plus(self, x):
self.val += x.val
/*
* higher-up library:
*/
class Foo {
std::shared_ptr<Vector<double>> v;
template<class Archive>
void serialize(Archive &archive) {
// defer polymorphic serialisation of Vector
@angus-g
angus-g / day2.ijs
Last active December 2, 2020 05:44
input=: cutLF fread '~Projects/advent/2020-day2.in'
valid=: verb define
'con char word'=. ' ' splitstring y
'min max'=. ". each '-' splitstring con
(min&<: *. <:&max) +/ ({. char) = word
)
valid2=: verb define
@angus-g
angus-g / tosi-case2.py
Created June 18, 2020 23:44
Tosi et al., 2015 firedrake
from firedrake import *
from firedrake.petsc import PETSc
from mpi4py import MPI
import math, numpy
#########################################################################################################
################################## Some important constants etc...: #####################################
#########################################################################################################
mesh = UnitSquareMesh(40, 40) # This mesh is generated via a firedrake function
@angus-g
angus-g / carray.c
Created June 16, 2020 03:33
C/Fortran memory interop
#include <stdio.h>
#include <stdlib.h>
void allocate_from_c(double **arr, int *n) {
*arr = (double*)malloc(5 * sizeof(double));
*n = 5;
double *x = *arr;
for (int i = 0; i < *n; i++) {
#version 430
layout(local_size_x = 128, local_size_y = 1) in;
layout(std430, binding = 0) buffer input_data {
float domain[][128];
};
uniform bool transpose;
import glfw
import OpenGL.GL as gl
import imgui
from imgui.integrations.glfw import GlfwRenderer
import cv2
import numpy as np
from fluid import Fluid
@angus-g
angus-g / day15.rkt
Created December 15, 2019 05:36
advent of code day 15 (warning: ugly)
#lang racket
(define in (string-trim (file->string "day15.in")))
(define initial-memory
(list->vector
(map string->number
(string-split in ","))))
(define (step mem inputs ip base)
; indirect addressing (with optional offset)