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
#include <iostream> | |
#include <vector> | |
#include<map> | |
#include<queue> | |
#include<math.h> | |
#include<vector> | |
#include <cassert> | |
#include <algorithm> | |
using namespace std; |
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
%%time | |
a = nearest_ngbr_raw(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
%%time | |
a = nearest_ngbr_raw(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
import numpy as np | |
%load_ext line_profiler |
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
%%writefile simulation.py | |
import numpy as np | |
def comp_inner_raw(i, x): | |
res = np.zeros(x.shape[0], dtype=np.float64) | |
for j in range(x.shape[0]): | |
res[j] = np.sqrt(np.sum((i-x[j])**2)) | |
return res | |
def nearest_ngbr_raw(x): | |
dist = {} |
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 simulation import nearest_ngbr_raw | |
arr = np.random.rand(1000,800) | |
%lprun -T sim_result -f nearest_ngbr_raw nearest_ngbr_raw(arr) | |
print(open('sim_result', 'r').read()) |
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 numba import jit, njit | |
@jit('float64[:](float64[:], float64[:, :])') | |
def comp_inner_numba(i, x): | |
res = np.zeros(x.shape[0], dtype=np.float64) | |
for j in range(x.shape[0]): | |
res[j] = np.sqrt(np.sum((i-x[j])**2)) | |
return res | |
def nearest_ngbr_numba(x): | |
dist = {} |
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
%%time | |
b = nearest_ngbr_numba(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
#include <cstdlib> | |
#include <algorithm> | |
#include <numeric> | |
#include <vector> | |
#include <stdio.h> | |
#include <iostream> | |
#include <map> | |
#include <cmath> | |
#include <math.h> |
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
%module myknn | |
#define SWIGPYTHON_BUILTIN | |
%{ | |
#include "numpy/arrayobject.h" | |
#define SWIG_FILE_WITH_INIT /* To import_array() below */ | |
#include "myknn.h" | |
%} | |
%include "std_map.i" |
OlderNewer