Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
hypertiling
hypertiling
Commits
d2930a68
Commit
d2930a68
authored
Nov 03, 2021
by
Manuel Schrauth
Browse files
find routine offers direct conversion to filtered list
parent
b0ec3365
Changes
1
Hide whitespace changes
Inline
Side-by-side
hypertiling/neighbours.py
View file @
d2930a68
...
...
@@ -2,7 +2,7 @@ import numpy as np
from
.distance
import
weierstrass_distance
# wrapper to provide a nicer interface
def
find
(
tiling
,
nn_dist
=
None
,
which
=
"optimized_slice"
,
verbose
=
False
):
def
find
(
tiling
,
nn_dist
=
None
,
which
=
"optimized_slice"
,
output_type
=
"array"
,
verbose
=
False
):
if
nn_dist
==
None
:
if
verbose
:
...
...
@@ -10,17 +10,34 @@ def find(tiling, nn_dist=None, which="optimized_slice", verbose=False):
nn_dist
=
weierstrass_distance
(
tiling
[
0
].
centerW
,
tiling
[
1
].
centerW
)
if
which
==
"optimized_slice"
:
ret
urn
find_nn_optimized_slice
(
tiling
,
nn_dist
)
# fastest
ret
val
=
find_nn_optimized_slice
(
tiling
,
nn_dist
)
# fastest
elif
which
==
"optimized"
:
ret
urn
find_nn_optimized
(
tiling
,
nn_dist
)
ret
val
=
find_nn_optimized
(
tiling
,
nn_dist
)
elif
which
==
"brute_force"
:
ret
urn
find_nn_brute_force
(
tiling
,
nn_dist
)
# use for debug
ret
val
=
find_nn_brute_force
(
tiling
,
nn_dist
)
# use for debug
elif
which
==
"slice"
:
ret
urn
find_nn_slice
(
tiling
,
nn_dist
)
ret
val
=
find_nn_slice
(
tiling
,
nn_dist
)
else
:
print
(
"[Hypertiling] Error:"
,
which
,
" is not a valid algorithm!"
)
# raw output; includes the search point
if
output_type
==
"array"
:
return
retval
# nicer output as a list; search point is removed; also indices start from 0
elif
output_type
==
"list"
:
nbrs
=
[]
for
i
,
nb
in
enumerate
(
retval
):
arr
=
np
.
array
(
nb
)
arr
=
list
(
arr
[(
arr
>
0
)]
-
1
)
arr
.
remove
(
i
)
nbrs
.
append
(
arr
)
return
nbrs
else
:
print
(
"[hypertiling] Error: Invalid output format specified."
)
# find nearest neighbours by brute force comparison of all-to-all distances
# scales quadratically in the number of vertices and may thus become prohibitively expensive
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment