Skip to content
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

[REVIEW] Trajectory pytests. Remove toy examples from tests. #26

Merged
merged 6 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cpp/include/cuspatial/trajectory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ gdf_size_type derive_trajectories(const gdf_column& x, const gdf_column& y,
* Trajectories are typically derived from coordinate data using
* derive_trajectories().
*
* @param[in] x: x coordinates relative to a camera origin and ordered by
* @param[in] x: x coordinates (km) relative to a camera origin and ordered by
* (id,timestamp)
* @param[in] y: y coordinates relative to a camera origin and ordered by
* @param[in] y: y coordinates (km) relative to a camera origin and ordered by
* (id,timestamp)
* @param[in] timestamp: timestamp column ordered by (id,timestamp)
* @param[in] timestamp: timestamp (ms) column ordered by (id,timestamp)
* @param[in] length: number of points column ordered by (id,timestamp)
* @param[in] offset: offsets of trajectories used to index x/y/oid/ts
* ordered by (id,timestamp)
Expand Down Expand Up @@ -140,4 +140,4 @@ gdf_size_type subset_trajectory_id(const gdf_column& id,
gdf_column& out_id,
gdf_column& out_timestamp);

} // namespace cuspatial
} // namespace cuspatial
36 changes: 19 additions & 17 deletions cpp/src/trajectory/trajectory_distance_speed.cu
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ template <typename T>
__global__ void distspeed_kernel(gdf_size_type num_traj,
const T* const __restrict__ x,
const T* const __restrict__ y,
const cuspatial::its_timestamp * const __restrict__ time,
const uint32_t * const __restrict__ len,
const uint32_t * const __restrict__ pos,
const cudf::timestamp * const __restrict__ time,
const int32_t * const __restrict__ length,
const int32_t * const __restrict__ pos,
T* const __restrict__ dis,
T* const __restrict__ sp)
{
Expand All @@ -45,29 +45,31 @@ __global__ void distspeed_kernel(gdf_size_type num_traj,
int bp=(pid==0)?0:pos[pid-1];
int ep=pos[pid]-1;

//assuming the same year --restriction to be removed
float td=(time[ep].yd-time[bp].yd)*86400;
td+=(time[ep].hh-time[bp].hh)*3600;
td+=(time[ep].mm-time[bp].mm)*60;
td+=(time[ep].ss-time[bp].ss);
td+=(time[ep].ms-time[bp].ms)/(float)1000;
cudf::timestamp b = time[bp];
cudf::timestamp e = time[ep];
cudf::timestamp td = e - b;

if((len[pid]<2)||(td==0)||(time[ep].y!=time[bp].y))
if(length[pid]<2)
{
dis[pid]=-1;
sp[pid]=-1;
dis[pid]=-2;
sp[pid]=-2;
}
else if(unwrap(td)==0)
{
dis[pid]=-3;
sp[pid]=-3;
}
else
{
float ds=0;
for(int i=0;i<len[pid]-1;i++)
for(int i=0;i<length[pid]-1;i++)
{
float dt=(x[bp+i+1]-x[bp+i])*(x[bp+i+1]-x[bp+i]);
dt+=(y[bp+i+1]-y[bp+i])*(y[bp+i+1]-y[bp+i]);
ds+=sqrt(dt);
}
dis[pid]=ds*1000; //km to m
sp[pid]=ds*1000/td; // m/s
sp[pid]=ds*1000000/unwrap(td); // m/s
}
}

Expand Down Expand Up @@ -104,9 +106,9 @@ struct distspeed_functor
cudf::util::cuda::grid_config_1d grid{x.size, block_size, 1};
distspeed_kernel<T><<<grid.num_blocks, block_size>>>(length.size,
static_cast<T*>(x.data), static_cast<T*>(y.data),
static_cast<cuspatial::its_timestamp*>(timestamp.data),
static_cast<uint32_t*>(length.data),
static_cast<uint32_t*>(offset.data),
static_cast<cudf::timestamp*>(timestamp.data),
static_cast<int32_t*>(length.data),
static_cast<int32_t*>(offset.data),
static_cast<T*>(dist.data), static_cast<T*>(speed.data) );
CUDA_TRY( cudaDeviceSynchronize() );

Expand Down
2 changes: 1 addition & 1 deletion python/cuspatial/cuspatial/bindings/soa_readers.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from cudf.core.column import Column
from cudf.core._lib import *
from cudf._lib.cudf import *
from libc.stdlib cimport calloc, malloc, free
from libcpp.pair cimport pair

Expand Down
64 changes: 45 additions & 19 deletions python/cuspatial/cuspatial/bindings/trajectory.pyx
Original file line number Diff line number Diff line change
@@ -1,68 +1,86 @@
from cudf import Series, DataFrame
from cudf.core.column import Column
from cudf._lib.cudf import *

from libc.stdlib cimport calloc, malloc, free
from libcpp.pair cimport pair

cpdef cpp_derive_trajectories(x, y, object_id, timestamp):
x = x.astype('float64')._column
y = y.astype('float64')._column
object_id = object_id.astype('int32')._column
timestamp = timestamp.astype('datetime64[ms]')._column
cdef gdf_column* c_x = column_view_from_column(x)
cdef gdf_column* c_y = column_view_from_column(y)
cdef gdf_column* c_object_id = column_view_from_column(object_id)
cdef gdf_column* c_timestamp = column_view_from_column(timestamp)
cdef gdf_column* c_trajectory_id = <gdf_column*>malloc(sizeof(gdf_column))
cdef gdf_column* c_len = <gdf_column*>malloc(sizeof(gdf_column))
cdef gdf_column* c_length = <gdf_column*>malloc(sizeof(gdf_column))
cdef gdf_column* c_pos = <gdf_column*>malloc(sizeof(gdf_column))

with nogil:
num_trajectories = derive_trajectories(c_x[0], c_y[0],
c_object_id[0],
c_timestamp[0],
c_trajectory_id[0],
c_len[0], c_pos[0])
c_length[0], c_pos[0])

traj_id_data, traj_id_mask = gdf_column_to_column_mem(c_trajectory_id)
len_data, len_mask = gdf_column_to_column_mem(c_len)
length_data, length_mask = gdf_column_to_column_mem(c_length)
pos_data, pos_mask = gdf_column_to_column_mem(c_pos)
trajectory_id = Column.from_mem_views(traj_id_data,
traj_id_mask)
len = Column.from_mem_views(len_data, len_mask)
length = Column.from_mem_views(length_data, length_mask)
pos = Column.from_mem_views(pos_data, pos_mask)

return num_trajectories, trajectory_id, len, pos
return (num_trajectories,
DataFrame({'trajectory_id': Series(trajectory_id),
'length': Series(length),
'position': Series(pos)}))

cpdef cpp_trajectory_distance_and_speed(x, y, timestamp, len, pos):

cpdef cpp_trajectory_distance_and_speed(x, y, timestamp, length, pos):
x = x.astype('float64')._column
y = y.astype('float64')._column
timestamp = timestamp.astype('datetime64[ms]')._column
length = length.astype('int32')._column
pos = pos.astype('int32')._column
cdef gdf_column* c_x = column_view_from_column(x)
cdef gdf_column* c_y = column_view_from_column(y)
cdef gdf_column* c_timestamp = column_view_from_column(timestamp)
cdef gdf_column* c_len = column_view_from_column(len)
cdef gdf_column* c_length = column_view_from_column(length)
cdef gdf_column* c_pos = column_view_from_column(pos)
cdef pair[gdf_column, gdf_column] c_distance_speed

with nogil:
c_distance_speed = trajectory_distance_and_speed(c_x[0], c_y[0],
c_timestamp[0],
c_len[0],c_pos[0])
c_length[0],c_pos[0])

dist_data, dist_mask = gdf_column_to_column_mem(&c_distance_speed.first)
speed_data, speed_mask = gdf_column_to_column_mem(&c_distance_speed.second)
dist=Column.from_mem_views(dist_data, dist_mask)
speed=Column.from_mem_views(speed_data, speed_mask)

return dist,speed
return Series(dist), Series(speed)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not make this a DataFrame?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No disagreement! I'm working in that direction as I get better bringing the two APIs together.


cpdef cpp_trajectory_spatial_bounds(coor_x,coor_y,len,pos):
cpdef cpp_trajectory_spatial_bounds(coor_x,coor_y,length,pos):
coor_x = coor_x.astype('float64')._column
coor_y = coor_y.astype('float64')._column
length = length.astype('int32')._column
pos = pos.astype('int32')._column
cdef gdf_column* c_coor_x = column_view_from_column(coor_x)
cdef gdf_column* c_coor_y = column_view_from_column(coor_y)
cdef gdf_column* c_len = column_view_from_column(len)
cdef gdf_column* c_length = column_view_from_column(length)
cdef gdf_column* c_pos = column_view_from_column(pos)
cdef gdf_column* c_x1 = <gdf_column*>malloc(sizeof(gdf_column))
cdef gdf_column* c_x2 = <gdf_column*>malloc(sizeof(gdf_column))
cdef gdf_column* c_y1 = <gdf_column*>malloc(sizeof(gdf_column))
cdef gdf_column* c_y2 = <gdf_column*>malloc(sizeof(gdf_column))

with nogil:
trajectory_spatial_bounds(c_coor_x[0], c_coor_y[0],
c_len[0], c_pos[0],
c_length[0], c_pos[0],
c_x1[0], c_y1[0], c_x2[0], c_y2[0])

x1_data, x1_mask = gdf_column_to_column_mem(c_x1)
Expand All @@ -74,10 +92,15 @@ cpdef cpp_trajectory_spatial_bounds(coor_x,coor_y,len,pos):
y2_data, y2_mask = gdf_column_to_column_mem(c_y2)
y2 = Column.from_mem_views(y2_data,y2_mask)

return x1, y1, x2, y2
return DataFrame({'x1': x1, 'y1': y1, 'x2': x2, 'y2': y2})

cpdef cpp_subset_trajectory_id(id, in_x, in_y, in_id, in_timestamp):
cdef gdf_column* c_id = column_view_from_column(id)
cpdef cpp_subset_trajectory_id(ids, in_x, in_y, in_id, in_timestamp):
ids = ids.astype('int32')._column
in_x = in_x.astype('float64')._column
in_y = in_y.astype('float64')._column
in_id = in_id.astype('int32')._column
in_timestamp = in_timestamp.astype('datetime64[ms]')._column
cdef gdf_column* c_id = column_view_from_column(ids)
cdef gdf_column* c_in_x = column_view_from_column(in_x)
cdef gdf_column* c_in_y = column_view_from_column(in_y)
cdef gdf_column* c_in_id = column_view_from_column(in_id)
Expand All @@ -92,14 +115,17 @@ cpdef cpp_subset_trajectory_id(id, in_x, in_y, in_id, in_timestamp):
count = subset_trajectory_id(c_id[0], c_in_x[0], c_in_y[0], c_in_id[0],
c_in_timestamp[0], c_out_x[0], c_out_y[0],
c_out_id[0], c_out_timestamp[0])

x_data, x_mask = gdf_column_to_column_mem(c_out_x)
x = Column.from_mem_views(x_data,x_mask)
y_data, y_mask = gdf_column_to_column_mem(c_out_y)
y = Column.from_mem_views(y_data,y_mask)
id_data, id_mask = gdf_column_to_column_mem(c_out_id)
id = Column.from_mem_views(id_data,id_mask)
ids = Column.from_mem_views(id_data,id_mask)
timestamp_data, timestamp_mask = gdf_column_to_column_mem(c_out_timestamp)
timestamp = Column.from_mem_views(timestamp_data, timestamp_mask)

return x, y, id, timestamp
return DataFrame({'x': Series(x),
'y': Series(y),
'ids': Series(ids),
'timestamp': Series(timestamp)})
6 changes: 6 additions & 0 deletions python/cuspatial/cuspatial/demos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Demo files

`cuspatial` demos typically depend on third party libraries and datasets. You
can see the performance difference between GPU spatial code and our competitors
by running these demos.

17 changes: 0 additions & 17 deletions python/cuspatial/cuspatial/tests/hausdorff_distance_test_toy.py

This file was deleted.

33 changes: 0 additions & 33 deletions python/cuspatial/cuspatial/tests/haversine_distance_test_toy.py

This file was deleted.

25 changes: 0 additions & 25 deletions python/cuspatial/cuspatial/tests/lonlat2coord_test_toy.py

This file was deleted.

23 changes: 0 additions & 23 deletions python/cuspatial/cuspatial/tests/pip_test_soa_toy.py

This file was deleted.

Loading