Skip to content

Instantly share code, notes, and snippets.

@coderforlife
coderforlife / _arraytools.py
Last active February 28, 2023 04:46
Implementation of scipy.signal.lfilter and scipy.signal.filtfilt with cupy
import cupy
def axis_replace(shape, axis, value):
if axis < 0:
axis += len(shape)
return shape[:axis] + (value,) + shape[axis+1:]
def axis_seq(axis, ndim, value, default):
@coderforlife
coderforlife / generic_filter_test.py
Created July 15, 2020 08:27
Testing `cupyx.scipy.ndimage.generic_filter()`
import numpy, cupy
import scipy.ndimage as ndi
import cupyx.scipy.ndimage as cp_ndi
from scipy import LowLevelCallable
from numba import cfunc, types, carray
##### Root Mean Squared #####
# Actually these are just the mean-squared
rms_raw = cupy.RawKernel('''extern "C" __global__
@coderforlife
coderforlife / filters.py
Last active March 12, 2020 21:25
Rough draft of new cupy/cupyx/scipy/ndimage/filters.py
# pylint: disable=redefined-builtin
import cupy
# ######## Convolutions and Correlations ##########
def correlate(input, weights, output=None, mode='reflect', cval=0.0, origin=0):
"""Multi-dimensional correlate.
The array is correlated with the given kernel.
Args:
@coderforlife
coderforlife / gkeep_completions
Last active September 2, 2019 16:00
bash tab completions for gkeep
#!/usr/bin/env python3
# To install (assuming you have the bash-completions package)
# python3 -c 'import gkeep_completions; gkeep_completions.install()'
# or if you don't (this doesn't work as well, for example you have to restart your terminal and it edits your .bashrc file)
# python3 -c 'import gkeep_completions; gkeep_completions.install_rc()'
import os, sys, shlex, subprocess
def __get_files(path):
#include <stdio.h> // for FILE, fread, fwrite, feof
#include <assert.h> // for assertion checks
#include <lznt1.h> // mscomp LZNT1 header
#define BUF_SIZE 65536
/* TODO: probably use a return value for error handling or something */
void inflate(FILE *source, FILE *dest)
{
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@coderforlife
coderforlife / delayed.py
Last active August 29, 2015 14:25
Simple delay-loaded objects
"""
Simple delay-loaded objects. Essentially this calls a function to generate the object the first time
any attribute of the object is accesssed.
This supports many object types. Some types it does not support are (at least not fully):
* objects with a modified __getattribute__
* objects with __slots__
* objects with __value__
* descriptor objects will not work as descriptors
* buffer-able objects will not work with buffer
@coderforlife
coderforlife / Flags-Test.cpp
Last active August 29, 2015 14:02
C++Flags
#include "Flags.hpp"
#include <iostream>
BOOST_FLAGS_WITH_VALUES(MyFlags, std::uint8_t, A, 1, B, 2, AB, 3, C, 4);
BOOST_FLAGS(MyDefaultFlags, AX, BX, CX, DX, EX, FX, GX, HX);
namespace MyNS
{
BOOST_FLAGS(MyFlags, M, N, O, P, Q);
}
@coderforlife
coderforlife / hodgkin-huxley.ipynb
Created September 7, 2013 08:53
Hodgkin-Huxley Neuron Model
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@coderforlife
coderforlife / python-tutorial.ipynb
Created September 7, 2013 08:31
Introduction to Scientific Python by using the IPython Notebook
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.