Skip to content

Commit 615a158

Browse files
authored
Kc/export blockindex (#17)
* export and test BlockIndex * hard code some sizes
1 parent b1db5ee commit 615a158

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/blockindices.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,23 @@ Converts from a block index to a tuple containing the global indices
7575
return $ex
7676
end
7777
end
78+
79+
# I hate having these function definitions but the generated function above sometimes(!) generates bad code and starts to allocate
80+
@inline function blockindex2global(block_sizes::BlockSizes{1}, block_index::BlockIndex{1})
81+
@inbounds v =(block_sizes[1, block_index.I[1]] + block_index.α[1] - 1)
82+
return v
83+
end
84+
85+
@inline function blockindex2global(block_sizes::BlockSizes{2}, block_index::BlockIndex{2})
86+
@inbounds v =(block_sizes[1, block_index.I[1]] + block_index.α[1] - 1,
87+
block_sizes[2, block_index.I[2]] + block_index.α[2] - 1)
88+
return v
89+
end
90+
91+
@inline function blockindex2global(block_sizes::BlockSizes{3}, block_index::BlockIndex{3})
92+
@inbounds v =(block_sizes[1, block_index.I[1]] + block_index.α[1] - 1,
93+
block_sizes[2, block_index.I[2]] + block_index.α[2] - 1,
94+
block_sizes[3, block_index.I[3]] + block_index.α[3] - 1)
95+
return v
96+
end
97+

0 commit comments

Comments
 (0)