Skip to content

Commit e569ea9

Browse files
committed
Replace hits of uint8_t -> uint32_t for cell indices
When allowing larger block sizes, we may easily overflow 8-bit counters. Note that this was *already* overflowing for nz > 6, but it appears it was never tested.
1 parent 283b0cf commit e569ea9

4 files changed

Lines changed: 17 additions & 17 deletions

File tree

yt/geometry/oct_container.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ cdef class OctreeContainer:
8686
self,
8787
const int level,
8888
const np.uint8_t[::1] level_inds,
89-
const np.uint8_t[::1] cell_inds,
89+
const np.uint32_t[::1] cell_inds,
9090
const np.int64_t[::1] file_inds,
9191
dict dest_fields,
9292
dict source_fields,
@@ -96,7 +96,7 @@ cdef class OctreeContainer:
9696
self,
9797
const int level,
9898
const np.uint8_t[::1] level_inds,
99-
const np.uint8_t[::1] cell_inds,
99+
const np.uint32_t[::1] cell_inds,
100100
const np.int64_t[::1] file_inds,
101101
const np.int32_t[::1] domain_inds,
102102
dict dest_fields,

yt/geometry/oct_container.pyx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ cdef class OctreeContainer:
754754
self,
755755
const int level,
756756
const np.uint8_t[::1] levels,
757-
const np.uint8_t[::1] cell_inds,
757+
const np.uint32_t[::1] cell_inds,
758758
const np.int64_t[::1] file_inds,
759759
dict dest_fields,
760760
dict source_fields,
@@ -807,7 +807,7 @@ cdef class OctreeContainer:
807807
-------
808808
oct_inds : int64 ndarray (nocts*8, )
809809
The on-domain index of the octs containing each cell
810-
cell_inds : uint8 ndarray (nocts*8, )
810+
cell_inds : uint32 ndarray (nocts*8, )
811811
The index of the cell in its parent oct
812812
813813
Note
@@ -819,10 +819,10 @@ cdef class OctreeContainer:
819819

820820
cdef NeighbourCellIndexVisitor visitor
821821

822-
cdef np.uint8_t[::1] cell_inds
822+
cdef np.uint32_t[::1] cell_inds
823823
cdef np.int64_t[::1] oct_inds
824824

825-
cell_inds = np.full(num_octs*4**3, self.nz[0] * self.nz[1] * self.nz[2], dtype=np.uint8)
825+
cell_inds = np.full(num_octs*4**3, self.nz[0] * self.nz[1] * self.nz[2], dtype=np.uint32)
826826
oct_inds = np.full(num_octs*4**3, -1, dtype=np.int64)
827827

828828
visitor = NeighbourCellIndexVisitor(self, -1, n_ghost_zones)
@@ -840,7 +840,7 @@ cdef class OctreeContainer:
840840
self,
841841
const int level,
842842
const np.uint8_t[::1] level_inds,
843-
const np.uint8_t[::1] cell_inds,
843+
const np.uint32_t[::1] cell_inds,
844844
const np.int64_t[::1] file_inds,
845845
const np.int32_t[::1] domain_inds,
846846
dict dest_fields,
@@ -896,7 +896,7 @@ cdef class OctreeContainer:
896896
-------
897897
levels : uint8, shape (num_cells,)
898898
The level of each cell of the super oct
899-
cell_inds : uint8, shape (num_cells, )
899+
cell_inds : uint32, shape (num_cells, )
900900
The index of each cell of the super oct within its own oct
901901
file_inds : int64, shape (num_cells, )
902902
The on-file position of the cell. See notes below.
@@ -933,12 +933,12 @@ cdef class OctreeContainer:
933933
cdef NeighbourCellVisitor visitor
934934

935935
cdef np.ndarray[np.uint8_t, ndim=1] levels
936-
cdef np.ndarray[np.uint8_t, ndim=1] cell_inds
936+
cdef np.ndarray[np.uint32_t, ndim=1] cell_inds
937937
cdef np.ndarray[np.int64_t, ndim=1] file_inds
938938
cdef np.ndarray[np.int32_t, ndim=1] domains
939939
levels = np.full(num_cells, 255, dtype="uint8")
940940
file_inds = np.full(num_cells, -1, dtype="int64")
941-
cell_inds = np.full(num_cells, self.nz[0] * self.nz[1] * self.nz[2], dtype="uint8")
941+
cell_inds = np.full(num_cells, self.nz[0] * self.nz[1] * self.nz[2], dtype="uint32")
942942
domains = np.full(num_cells, -1, dtype="int32")
943943

944944
visitor = NeighbourCellVisitor(self, -1, n_ghost_zones)

yt/geometry/oct_visitors.pxd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ cdef class StoreIndex(OctVisitor):
152152
cdef class BaseNeighbourVisitor(OctVisitor):
153153
cdef int idim # 0,1,2 for x,y,z
154154
cdef int direction # +1 for +x, -1 for -x
155-
cdef np.uint8_t neigh_ind[3]
155+
cdef np.uint32_t neigh_ind[3]
156156
cdef bint other_oct
157157
cdef Oct *neighbour
158158
cdef OctreeContainer octree
@@ -161,15 +161,15 @@ cdef class BaseNeighbourVisitor(OctVisitor):
161161

162162
cdef void set_neighbour_info(self, Oct *o, int ishift[3])
163163

164-
cdef inline np.uint8_t neighbour_rind(self):
164+
cdef inline np.uint32_t neighbour_rind(self):
165165
return (self.neigh_ind[2]*self.nz[1]+self.neigh_ind[1])*self.nz[0]+self.neigh_ind[0]
166166

167167
cdef class NeighbourCellIndexVisitor(BaseNeighbourVisitor):
168-
cdef np.uint8_t[::1] cell_inds
168+
cdef np.uint32_t[::1] cell_inds
169169
cdef np.int64_t[::1] domain_inds
170170

171171
cdef class NeighbourCellVisitor(BaseNeighbourVisitor):
172172
cdef np.uint8_t[::1] levels
173173
cdef np.int64_t[::1] file_inds
174-
cdef np.uint8_t[::1] cell_inds
174+
cdef np.uint32_t[::1] cell_inds
175175
cdef np.int32_t[::1] domains

yt/geometry/oct_visitors.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ cdef class BaseNeighbourVisitor(OctVisitor):
412412

413413
# Index of neighbouring cell within its oct
414414
for i in range(3):
415-
self.neigh_ind[i] = <np.uint8_t>(ishift[i]) % 2
415+
self.neigh_ind[i] = <np.uint32_t>(ishift[i]) % 2
416416

417417
self.other_oct = other_oct
418418
if other_oct:
@@ -452,7 +452,7 @@ cdef class NeighbourCellIndexVisitor(BaseNeighbourVisitor):
452452
cdef void visit(self, Oct* o, np.uint8_t selected):
453453
cdef int i, j, k
454454
cdef int ishift[3]
455-
cdef np.uint8_t neigh_cell_ind
455+
cdef np.uint32_t neigh_cell_ind
456456
cdef np.int64_t neigh_domain_ind
457457
if selected == 0: return
458458
# Work at oct level
@@ -497,7 +497,7 @@ cdef class NeighbourCellVisitor(BaseNeighbourVisitor):
497497
cdef int i, j, k
498498
cdef int ishift[3]
499499
cdef np.int64_t neigh_file_ind
500-
cdef np.uint8_t neigh_cell_ind
500+
cdef np.uint32_t neigh_cell_ind
501501
cdef np.int32_t neigh_domain
502502
cdef np.uint8_t neigh_level
503503
if selected == 0: return

0 commit comments

Comments
 (0)