-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Python Initial Unit Testing and Bindings #18
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7d22c31
Tests all appearing to pass. Demos have some issues still.
thomcom e222cec
First pass of python refactorings to create unit tests.
thomcom df2c178
Add more tests and Series processing to pip
thomcom 0744545
Return Series from lonlat2coord and create more lonlat2 tests.
thomcom ced7157
All bindings from spatial.pyx now return Series
thomcom 8092988
Merge branch 'branch-0.10' into python-initial-code
thomcom 06eb7fe
Fix accidental renaming in query.hpp
thomcom 25f8fdd
Whitespace
thomcom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,94 +16,101 @@ | |
import cuspatial.bindings.spatial as gis | ||
import cuspatial.bindings.soa_readers as readers | ||
|
||
data_dir="/home/jianting/trajcode/" | ||
data_set="locust256" | ||
data_dir = "/home/jianting/trajcode/" | ||
data_set = "locust256" | ||
|
||
#scipy_res='scipyres.mat' | ||
#cuspatial_res='cuspatialres.mat' | ||
#if(len(sys.argv)>=2): | ||
# scipy_res='scipyres.mat' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete commented out code? |
||
# cuspatial_res='cuspatialres.mat' | ||
# if(len(sys.argv)>=2): | ||
# scipy_res=sys.argv[1] | ||
#if(len(sys.argv)>=3): | ||
# if(len(sys.argv)>=3): | ||
# cuspatial_res=sys.argv[2] | ||
|
||
if(len(sys.argv)>=2): | ||
data_set=sys.argv[1] | ||
if len(sys.argv) >= 2: | ||
data_set = sys.argv[1] | ||
|
||
#reading poing xy coordinate data (relative to a camera origin) | ||
pnt_x,pnt_y=readers.cpp_read_pnt_xy_soa(data_dir+data_set+".coor"); | ||
#reading numbers of points in trajectories | ||
cnt=readers.cpp_read_uint_soa(data_dir+data_set+".objcnt") | ||
#reading object(vehicle) id | ||
id=readers.cpp_read_uint_soa(data_dir+data_set+".objectid") | ||
# reading poing xy coordinate data (relative to a camera origin) | ||
pnt_x, pnt_y = readers.cpp_read_pnt_xy_soa(data_dir + data_set + ".coor") | ||
# reading numbers of points in trajectories | ||
cnt = readers.cpp_read_uint_soa(data_dir + data_set + ".objcnt") | ||
# reading object(vehicle) id | ||
id = readers.cpp_read_uint_soa(data_dir + data_set + ".objectid") | ||
|
||
num_traj=cnt.data.size | ||
dist0=gis.cpp_directed_hausdorff_distance(pnt_x,pnt_y,cnt) | ||
cuspatial_dist0=dist0.data.to_array().reshape((num_traj,num_traj)) | ||
num_traj = cnt.data.size | ||
dist0 = gis.cpp_directed_hausdorff_distance(pnt_x, pnt_y, cnt) | ||
cuspatial_dist0 = dist0.data.to_array().reshape((num_traj, num_traj)) | ||
|
||
start = time.time() | ||
dist=gis.cpp_directed_hausdorff_distance(pnt_x,pnt_y,cnt) | ||
print("dis.size={} num_traj*num_traj={}".format(dist.data.size,num_traj*num_traj)) | ||
dist = gis.cpp_directed_hausdorff_distance(pnt_x, pnt_y, cnt) | ||
print("dis.size={} num_traj*num_traj={}".format(dist.data.size, num_traj * num_traj)) | ||
end = time.time() | ||
print(end - start) | ||
print("python Directed Hausdorff distance GPU end-to-end time in ms (end-to-end)={}".format((end - start)*1000)) | ||
print(end - start) | ||
print( | ||
"python Directed Hausdorff distance GPU end-to-end time in ms (end-to-end)={}".format( | ||
(end - start) * 1000 | ||
) | ||
) | ||
|
||
start = time.time() | ||
cuspatial_dist=dist.data.to_array().reshape((num_traj,num_traj)) | ||
cuspatial_dist = dist.data.to_array().reshape((num_traj, num_traj)) | ||
print("num_traj={}".format(num_traj)) | ||
print("cuspatial_dist[0[1]={}".format(cuspatial_dist[0][1])) | ||
|
||
#with open(cuspatial_res, 'wb') as f: | ||
# with open(cuspatial_res, 'wb') as f: | ||
# pickle.dump(cuspatial_dist, f) | ||
|
||
mis_match=0 | ||
mis_match = 0 | ||
for i in range(num_traj): | ||
for j in range(num_traj): | ||
if(abs(cuspatial_dist0[i][j]-cuspatial_dist[i][j])>0.00001): | ||
mis_match=mis_match+1 | ||
print('mis_match between two rounds ={}'.format(mis_match)) | ||
for j in range(num_traj): | ||
if abs(cuspatial_dist0[i][j] - cuspatial_dist[i][j]) > 0.00001: | ||
mis_match = mis_match + 1 | ||
print("mis_match between two rounds ={}".format(mis_match)) | ||
|
||
|
||
x=pnt_x.data.to_array() | ||
y=pnt_y.data.to_array() | ||
n=cnt.data.to_array() | ||
end = time.time() | ||
print("data conversion time={}".format((end - start)*1000)) | ||
x = pnt_x.data.to_array() | ||
y = pnt_y.data.to_array() | ||
n = cnt.data.to_array() | ||
end = time.time() | ||
print("data conversion time={}".format((end - start) * 1000)) | ||
|
||
start = time.time() | ||
trajs=[] | ||
c=0 | ||
trajs = [] | ||
c = 0 | ||
for i in range(num_traj): | ||
traj=np.zeros((n[i],2),dtype=np.float64) | ||
for j in range(n[i]): | ||
traj[j][0]=x[c+j] | ||
traj[j][1]=y[c+j] | ||
trajs.append(traj.reshape(-1,2)) | ||
c=c+n[i] | ||
#print('c={}'.format(c)) | ||
end=time.time() | ||
print("CPU traj prep time={}".format((end - start)*1000)) | ||
#print("trajs[0]") | ||
#print(trajs[0]) | ||
|
||
mis_match=0 | ||
d=np.zeros((num_traj,num_traj), dtype=np.float64) | ||
traj = np.zeros((n[i], 2), dtype=np.float64) | ||
for j in range(n[i]): | ||
traj[j][0] = x[c + j] | ||
traj[j][1] = y[c + j] | ||
trajs.append(traj.reshape(-1, 2)) | ||
c = c + n[i] | ||
# print('c={}'.format(c)) | ||
end = time.time() | ||
print("CPU traj prep time={}".format((end - start) * 1000)) | ||
# print("trajs[0]") | ||
# print(trajs[0]) | ||
|
||
mis_match = 0 | ||
d = np.zeros((num_traj, num_traj), dtype=np.float64) | ||
for i in range(num_traj): | ||
if(i%100==99): | ||
print("i={}".format(i)) | ||
for j in range(num_traj): | ||
dij=directed_hausdorff(trajs[i],trajs[j]) | ||
d[i][j]=dij[0] | ||
if(abs(d[i][j]-cuspatial_dist[i][j])>0.00001): | ||
print('{} {} {} {}'.format(i,j,d[i][j],cuspatial_dist[i][j])) | ||
mis_match=mis_match+1 | ||
print('mis_match={}'.format(mis_match)) | ||
end = time.time() | ||
print("python Directed Hausdorff distance cpu end-to-end time in ms (end-to-end)={}".format((end - start)*1000)) | ||
|
||
#for val in d[0]: | ||
if i % 100 == 99: | ||
print("i={}".format(i)) | ||
for j in range(num_traj): | ||
dij = directed_hausdorff(trajs[i], trajs[j]) | ||
d[i][j] = dij[0] | ||
if abs(d[i][j] - cuspatial_dist[i][j]) > 0.00001: | ||
print("{} {} {} {}".format(i, j, d[i][j], cuspatial_dist[i][j])) | ||
mis_match = mis_match + 1 | ||
print("mis_match={}".format(mis_match)) | ||
end = time.time() | ||
print( | ||
"python Directed Hausdorff distance cpu end-to-end time in ms (end-to-end)={}".format( | ||
(end - start) * 1000 | ||
) | ||
) | ||
|
||
# for val in d[0]: | ||
# print('{}'.format(val)) | ||
|
||
#with open(scipy_res, 'wb') as f: | ||
# with open(scipy_res, 'wb') as f: | ||
# pickle.dump(d, f) | ||
|
22 changes: 11 additions & 11 deletions
22
python/cuspatial/cuspatial/demos/haversine_distance_test_nyctaxi.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
import time | ||
import cudf | ||
from cudf.dataframe import columnops | ||
from cudf.core import column | ||
import cuspatial.bindings.spatial as gis | ||
|
||
start = time.time() | ||
#data dowloaded from https://s3.amazonaws.com/nyc-tlc/trip+data/yellow_tripdata_2009-01.csv | ||
# data dowloaded from https://s3.amazonaws.com/nyc-tlc/trip+data/yellow_tripdata_2009-01.csv | ||
df = cudf.read_csv("/home/jianting/hardbd19/data/nyctaxi/yellow_tripdata_2009-01.csv") | ||
end = time.time() | ||
print("data ingesting time (from SSD) in ms={}".format((end - start)*1000)) | ||
print("data ingesting time (from SSD) in ms={}".format((end - start) * 1000)) | ||
df.head().to_pandas().columns | ||
|
||
start = time.time() | ||
x1=columnops.as_column(df['Start_Lon']) | ||
y1=columnops.as_column(df['Start_Lat']) | ||
x2=columnops.as_column(df['End_Lon']) | ||
y2=columnops.as_column(df['End_Lat']) | ||
x1 = column.as_column(df["Start_Lon"]) | ||
y1 = column.as_column(df["Start_Lat"]) | ||
x2 = column.as_column(df["End_Lon"]) | ||
y2 = column.as_column(df["End_Lat"]) | ||
end = time.time() | ||
print("data frame to gdf column conversion time in ms={}".format((end - start)*1000)) | ||
print("data frame to gdf column conversion time in ms={}".format((end - start) * 1000)) | ||
|
||
start = time.time() | ||
h_dist=gis.cpp_haversine_distance(x1,y1,x2,y1) | ||
h_dist = gis.cpp_haversine_distance(x1, y1, x2, y1) | ||
end = time.time() | ||
print("python computing distance time in ms={}".format((end - start)*1000)) | ||
#h_dist.data.to_array() | ||
print("python computing distance time in ms={}".format((end - start) * 1000)) | ||
# h_dist.data.to_array() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove personal home directories from our released code. We need to figure out a dataset that's small enough (a few kb) to ship with cuspatial for testing.