Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit f4eb31f

Browse files
author
Ehsan Totoni
committed
ros read for regular python, timers
1 parent fb820b0 commit f4eb31f

2 files changed

Lines changed: 24 additions & 11 deletions

File tree

‎examples/ros_example1.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import hpat
44
import hpat.ros
55
from hpat import prange, stencil
6+
import time
67

78
@stencil
89
def gaussian_blur(a):
@@ -14,6 +15,7 @@ def gaussian_blur(a):
1415

1516
@hpat.jit
1617
def read_example():
18+
t1 = time.time()
1719
A = hpat.ros.read_ros_images("image_test.bag")
1820
# crop out dashboard
1921
B = A[:,:-50,:,:]
@@ -47,6 +49,8 @@ def read_example():
4749
else:
4850
centroids[i] = np.random.randint(0, 255, (dh, dw, dc)).astype(np.uint8)
4951

52+
t2 = time.time()
53+
print("Exec time: ", t2-t1)
5054
return centroids
5155

5256
print(read_example().sum())

‎hpat/ros.py‎

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,31 @@
66
import hpat
77
import numpy as np
88

9-
def read_ros_images():
10-
return 0
9+
def read_ros_images(f_name):
10+
# implementation to enable regular python
11+
def f(file_name): # pragma: no cover
12+
bag = hpat.ros.open_bag(file_name)
13+
num_msgs = hpat.ros.get_msg_count(bag)
14+
m,n = hpat.ros.get_image_dims(bag)
15+
# hpat.cprint(num_msgs, m, n)
16+
A = np.empty((num_msgs, m, n, 3), dtype=np.uint8)
17+
s = hpat.ros.read_ros_images_inner(A, bag)
18+
return A
19+
20+
return hpat.jit(f)(f_name)
1121

1222
# inner functions
1323

14-
def open_bag():
24+
def open_bag(file_name):
1525
return 0
1626

17-
def get_msg_count():
27+
def get_msg_count(bag):
1828
return 0
1929

20-
def get_image_dims():
30+
def get_image_dims(bag):
2131
return 0
2232

23-
def read_ros_images_inner():
33+
def read_ros_images_inner(A, bag):
2434
return 0
2535

2636
def read_ros_images_inner_parallel():
@@ -31,11 +41,11 @@ def _handle_read_images(lhs, rhs):
3141
fname = rhs.args[0]
3242
def f(file_name): # pragma: no cover
3343
bag = hpat.ros.open_bag(file_name)
34-
num_msgs = hpat.ros.get_msg_count(bag)
35-
m,n = hpat.ros.get_image_dims(bag)
44+
_num_msgs = hpat.ros.get_msg_count(bag)
45+
_ros_m,_ros_n = hpat.ros.get_image_dims(bag)
3646
# hpat.cprint(num_msgs, m, n)
37-
A = np.empty((num_msgs, m, n, 3), dtype=np.uint8)
38-
s = hpat.ros.read_ros_images_inner(A, bag)
47+
_in_ros_arr = np.empty((_num_msgs, _ros_m, _ros_n, 3), dtype=np.uint8)
48+
_ret = hpat.ros.read_ros_images_inner(_in_ros_arr, bag)
3949

4050
f_block = compile_to_numba_ir(f, {'np': np, 'hpat': hpat}).blocks.popitem()[1]
4151
replace_arg_nodes(f_block, [fname])
@@ -155,4 +165,3 @@ def lower_read_images_inner(context, builder, sig, args):
155165
lir.IntType(64)])
156166
fn = builder.module.get_or_insert_function(fnty, name="read_images_parallel")
157167
return builder.call(fn, [ builder.bitcast(out.data, lir.IntType(8).as_pointer()), bag, args[2], args[3]])
158-

0 commit comments

Comments
 (0)