This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* File knn.h */ | |
#ifndef KNN_H | |
#define KNN_H | |
#include <stdio.h> | |
#include <vector> | |
#include <map> | |
/* Define function prototype */ | |
std::map<int,std::vector<int> > distance_knn(const double* array,int m, int n); | |
std::vector<int> argsort(double* input_list, int length); | |
double edist(double* arr1, double* arr2, int n); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm *.o myknn_wrap.cpp _myknn.so myknn.py | |
rm -rf __pycache__ | |
g++ -O3 -march=native -fPIC -c myknn.cpp | |
# Invoke SWIG on the interface file 'knn.i' to produce C/C++ wrapper | |
# code ('knn_wrap.cpp'): | |
swig -python -c++ -o myknn_wrap.cpp myknn.i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from myknn import distance_knn | |
%%time | |
c = distance_knn(arr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%capture | |
%matplotlib inline | |
from ipywidgets import interact, widgets | |
from IPython.display import display | |
import cv2 | |
from scipy import misc | |
import matplotlib.pyplot as plt | |
import numpy as np | |
def f(lower_H, lower_S, lower_V, upper_H, upper_S, upper_V, **kwargs): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
# https://stackoverflow.com/a/55176783/6660373 | |
# 20x20 image | |
img = im#np.random.randint(0,9,(512,512)) | |
# List of 4 5x20 image slices | |
sliced = np.split(img,4,axis=0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |