{{ message }}

Instantly share code, notes, and snippets.

# Tim Clements tclements

• Harvard University
• Cambridge, MA, USA
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 end function strassen_mul!(C,A,B)
Created May 31, 2019
Hilbert transform on the GPU with Julia
View hilbert.jl
 using GPUArrays, FFTW """ hilbert(x) 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)
Created Mar 14, 2019
Create a Sliding Window function (with steps) using NumPy.
View sliding_window.py
 # 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 http://www.rigtorp.se/2011/01/01/rolling-statistics-numpy.html and # https://gist.github.com/codehacken/708f19ae746784cef6e68b037af65788 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)
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)) end function cos(A::GPUArray{ComplexF64}) return cos.(real(A)) .* cosh.(imag(A)) .- im .* sin.(real(A)) .* sinh.(imag(A))