Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pycodegen
pystencils
Commits
b7a97729
Commit
b7a97729
authored
4 years ago
by
Markus Holzer
Browse files
Options
Downloads
Patches
Plain Diff
Generalised boolean_array_bounding_box
parent
24ef1d2f
No related branches found
No related tags found
1 merge request
!168
Extend testsuite
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pystencils/utils.py
+15
-9
15 additions, 9 deletions
pystencils/utils.py
with
15 additions
and
9 deletions
pystencils/utils.py
+
15
−
9
View file @
b7a97729
import
os
import
itertools
from
collections
import
Counter
from
contextlib
import
contextmanager
from
tempfile
import
NamedTemporaryFile
...
...
@@ -96,16 +97,21 @@ def fully_contains(l1, l2):
def
boolean_array_bounding_box
(
boolean_array
):
"""
Returns bounding box around
"
true
"
area of boolean array
"""
dim
=
len
(
boolean_array
.
shape
)
"""
Returns bounding box around
"
true
"
area of boolean array
>>>
a
=
np
.
zeros
((
4
,
4
),
dtype
=
bool
)
>>>
a
[
1
:
-
1
,
1
:
-
1
]
=
True
>>>
boolean_array_bounding_box
(
a
)
[(
1
,
3
),
(
1
,
3
)]
"""
dim
=
boolean_array
.
ndim
shape
=
boolean_array
.
shape
assert
0
not
in
shape
,
"
Shape must not contain zero
"
bounds
=
[]
for
i
in
range
(
dim
):
for
j
in
range
(
dim
):
if
i
!=
j
:
arr_1d
=
np
.
any
(
boolean_array
,
axis
=
j
)
begin
=
np
.
argmax
(
arr_1d
)
end
=
begin
+
np
.
argmin
(
arr_1d
[
begin
:])
bounds
.
append
((
begin
,
end
))
for
ax
in
itertools
.
combinations
(
reversed
(
range
(
dim
)),
dim
-
1
):
nonzero
=
np
.
any
(
boolean_array
,
axis
=
ax
)
t
=
np
.
where
(
nonzero
)[
0
][[
0
,
-
1
]]
bounds
.
append
((
t
[
0
],
t
[
1
]
+
1
))
return
bounds
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment