Skip to content

Instantly share code, notes, and snippets.


Tim Clements tclements

  • Harvard University
  • Cambridge, MA, USA
View GitHub Profile
tclements / mult.jl
Created Oct 7, 2020
Compare 2x2 matrix multiplication methods in Julia
View mult.jl
using BenchmarkTools. LinearAlgebra
function naive_mul!(C,A,B)
C[1,1] = A[1,1] * B[1,1] + A[1,2] * B[2,1]
C[1,2] = A[1,1] * B[1,2] + A[1,2] * B[2,2]
C[2,1] = A[2,1] * B[1,1] + A[2,2] * B[2,1]
C[2,2] = A[2,1] * B[1,2] + A[2,2] * B[2,2]
return nothing
function strassen_mul!(C,A,B)
tclements / hilbert.jl
Created May 31, 2019
Hilbert transform on the GPU with Julia
View hilbert.jl
using GPUArrays, FFTW
Computes the analytic representation of x, ``x_a = x + j
\\hat{x}``, where ``\\hat{x}`` is the Hilbert transform of x,
along the first dimension of x.
function hilbert(x::GPUArray{T}) where T<:Real
N = size(x, 1)
tclements /
Created Mar 14, 2019
Create a Sliding Window function (with steps) using NumPy.
# Create a function to reshape a 1d array using a sliding window with a step.
# NOTE: The function uses numpy's internat as_strided function because looping in python is slow in comparison.
# Adopted from and
import numpy as np
# Reshape a numpy array 'a' of shape (x) to form shape((n - window_size) // step + 1, window_size))
def rolling_window(a, window, step):
shape = a.shape[:-1] + ((a.shape[-1] - window + 1)//step, window)
tclements / GPUArray-complex-transcendental.jl
Created Feb 14, 2019
sin, cos, exp with complex numbers on GPU with Julia
View GPUArray-complex-transcendental.jl
using GPUArrays
using CuArrays
import Base.sin, Base.cos, Base.exp
function sin(A::GPUArray{ComplexF64})
return sin.(real(A)) .* cosh.(imag(A)) .+ im .* cos.(real(A)) .* sinh.(imag(A))
function cos(A::GPUArray{ComplexF64})
return cos.(real(A)) .* cosh.(imag(A)) .- im .* sin.(real(A)) .* sinh.(imag(A))