forked from phreeza/cells
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcells_helpers.pyx
More file actions
31 lines (26 loc) · 756 Bytes
/
cells_helpers.pyx
File metadata and controls
31 lines (26 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
cimport numpy
def get_small_view_fast(self, int x, int y):
cdef numpy.ndarray[object, ndim=2] values = self.values
cdef int width = self.width
cdef int height = self.height
cdef int dr
cdef int dc
cdef int adj_x
cdef int adj_y
assert self.values.dtype == object
ret = []
get = self.get
for dr in xrange(-1,2):
for dc in xrange(-1,2):
if not dr and not dc:
continue
adj_x = x + dr
if not 0 <= adj_x < width:
continue
adj_y = y + dc
if not 0 <= adj_y < height:
continue
a = values[adj_x, adj_y]
if a is not None:
ret.append(a.get_view())
return ret