Skip to content

Instantly share code, notes, and snippets.

jshahbazi /
Last active Jan 16, 2021
Async Token Bucket implementation
class AsyncTokenBucket(object):
"""Implementation of an awaitable token bucket that defaults to a single token at a time.
Based on"""
def __init__(self, max_tokens, fill_rate):
self.max_tokens = float(max_tokens)
self.current_tokens = float(max_tokens)
self.fill_rate = float(fill_rate)
self.wait_time = (1.0 / self.fill_rate)
self.timestamp = time.time()
jshahbazi / mkl_matrix_multiply.f90
Last active Jan 17, 2017
Wrapper routine for using the Intel MKL xGEMM matrix multiplication routines
View mkl_matrix_multiply.f90
subroutine matrix_multiply(first_matrix, first_transposed, second_matrix, second_transposed, result_matrix)
!This subroutine multiplies two matrices using the Intel MKL xGEMM multiplication routines
!The routines can be a little tricky, so I've made it a little easier to use them consistently
!first_matrix and second_matrix are the input matrices
!first_transposed and second_transposed are integers indicating (with a 1 or 0) whether or not
!the respective matrix is transposed
!The resulting matrix is stored in result_matrix, but you'll have to allocate that outside the routine
!The sGEMM below can be changed to dGEMM for double precision without any other changes to the
!subroutine call. You'll then have to change the 'real' variables to 'double precision'.
jshahbazi / fmincg.f90
Created May 31, 2014
fmincg minimization function ported to Fortran
View fmincg.f90
real function fmincg(length, nn_params, input_layer_size, hidden_layer_size, num_labels, inputdata, y, lambda)
implicit none
! Copyright (C) 2001 and 2002 by Carl Edward Rasmussen. Date 2002-02-13
! (C) Copyright 1999, 2000 & 2001, Carl Edward Rasmussen
! Permission is granted for anyone to copy, use, or modify these
! programs and accompanying documents for purposes of research or
! education, provided this copyright notice is retained, and note is
! made of any changes that have been made.
jshahbazi / djb_hash.f90
Last active Apr 3, 2020
Daniel J. Bernstein's hash algorithm written in Fortran
View djb_hash.f90
integer function djb_hash(str) result(hash)
implicit none
character(len=*),intent(in) :: str
integer :: hash
integer :: i
hash = 5381
do i=1,len(str)
jshahbazi / fortran_convolution.f90
Last active Dec 15, 2015
A simple convolution of two 1D vectors (signals) done in Fortran
View fortran_convolution.f90
function convolve(x, h)
implicit none
!x is the signal array
!h is the noise/impulse array
real, dimension(:), allocatable :: convolve, y
real, dimension(:) :: x, h
integer :: kernelsize, datasize
integer :: i,j,k