Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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()
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
You can’t perform that action at this time.