Created
September 30, 2019 18:45
-
-
Save namakshenas/30f300c26a9fa27901c60dc49aba7998 to your computer and use it in GitHub Desktop.
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 | |
from timeit import default_timer as timer | |
from numba import vectorize | |
import pandas as pd | |
@vectorize(['float32(float32, float32,float32, float32)'], target='cuda') | |
def get_length(x1, y1, x2, y2): | |
return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** (1 / 2) | |
def build_graph(data): | |
graph = {} | |
for this in range(len(data)): | |
for another_point in range(len(data)): | |
if this != another_point: | |
if this not in graph: | |
graph[this] = {} | |
graph[this][another_point] = get_length(data[this][0], data[this][1], data[another_point][0], | |
data[another_point][1]) | |
return graph | |
def main(): | |
data = pd.read_csv("mona.csv",header=None).values.tolist() | |
start = timer() | |
graph = build_graph(data) | |
duration = timer() - start | |
print(duration) | |
if __name__ == '__main__': | |
main() |
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 | |
from timeit import default_timer as timer | |
def get_length(x1, y1, x2, y2): | |
return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** (1 / 2) | |
def build_graph(data): | |
graph = {} | |
for this in range(len(data)): | |
for another_point in range(len(data)): | |
if this != another_point: | |
if this not in graph: | |
graph[this] = {} | |
graph[this][another_point] = get_length(data[this][0], data[this][1], data[another_point][0], | |
data[another_point][1]) | |
def main(): | |
data = pd.read_csv("mona.csv",header=None).values.tolist() | |
start = timer() | |
graph = build_graph(data) | |
duration = timer() - start | |
print(duration) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment