Skip to content

Instantly share code, notes, and snippets.

View avinashselvam's full-sized avatar
🏠
Working from home

avinashselvam

🏠
Working from home
View GitHub Profile
@avinashselvam
avinashselvam / Hungarian.py
Last active July 20, 2020 09:45
Hungarian Maximum Matching Algorithm
class Node:
"""
Vertex / Node in a bipartite graph
Attributes
----------
id : int
Unique identifier within a set
set: int
@avinashselvam
avinashselvam / autodiff.py
Created May 9, 2020 12:32
example of forward and backward automatic differentiation on a computational graph
class Constant():
def __init__(self, value):
self.value = value
self.gradient = None
def evaluate(self):
return self.value
def derivative(self, wrt_variable):
@avinashselvam
avinashselvam / filter.swift
Created June 19, 2019 11:15
A swift class that implements GPU based image processing
//
// filter.swift
// fltr
//
// Created by Avinash on 18/06/19.
// Copyright © 2019 eightyfive. All rights reserved.
//
import Metal
import MetalKit
@avinashselvam
avinashselvam / longest_increasing_subsequence.py
Created January 9, 2019 05:10
function to calculate Longest Increasing Subsequence given an array of unsorted integers
def find_k(arr_i, l ,r, ends):
# ends here is a sorted array.
# binary search
while r - l > 1:
m = (l+r)//2
if arr_i <= ends[m]: r = m
else: l = m
return r
@avinashselvam
avinashselvam / coin_change.py
Created December 30, 2018 18:09
function to calculate coin change recursively using dynamic programming
n = 10
c = [2, 3, 5, 6]
ways = [[0 if i < min(c) else - 1 for i in range(n + 1)] for j in c]
def num_ways(n, c):
row = len(c) - 1
# base case
if n < min(c): return 0