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
FSL
fslpy
Commits
61e0ccd3
Commit
61e0ccd3
authored
Jul 29, 2017
by
Paul McCarthy
🚵
Browse files
Updated veclength/normalise tests
parent
47a0088a
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/test_transform.py
View file @
61e0ccd3
...
...
@@ -8,6 +8,7 @@
from
__future__
import
division
import
random
import
glob
import
os.path
as
op
import
itertools
as
it
...
...
@@ -400,7 +401,7 @@ def test_sformToFlirtMatrix():
def
test_normalise
(
seed
):
vectors
=
-
100
+
200
*
np
.
random
.
random
((
5
0
,
3
))
vectors
=
-
100
+
200
*
np
.
random
.
random
((
20
0
,
3
))
def
parallel
(
v1
,
v2
):
v1
=
v1
/
transform
.
veclength
(
v1
)
...
...
@@ -409,25 +410,55 @@ def test_normalise(seed):
return
np
.
isclose
(
np
.
dot
(
v1
,
v2
),
1
)
for
v
in
vectors
:
vn
=
transform
.
normalise
(
v
)
vl
=
transform
.
veclength
(
vn
)
vtype
=
random
.
choice
((
list
,
tuple
,
np
.
array
))
v
=
vtype
(
v
)
vn
=
transform
.
normalise
(
v
)
vl
=
transform
.
veclength
(
vn
)
assert
np
.
isclose
(
vl
,
1.0
)
assert
parallel
(
v
,
vn
)
# normalise should also be able
# to do multiple vectors at once
results
=
transform
.
normalise
(
vectors
)
lengths
=
transform
.
veclength
(
results
)
pars
=
np
.
zeros
(
200
)
for
i
in
range
(
200
):
v
=
vectors
[
i
]
r
=
results
[
i
]
pars
[
i
]
=
parallel
(
v
,
r
)
assert
np
.
all
(
np
.
isclose
(
lengths
,
1
))
assert
np
.
all
(
pars
)
def
test_veclength
(
seed
):
def
l
(
v
):
x
,
y
,
z
=
v
l
=
x
*
x
+
y
*
y
+
z
*
z
v
=
np
.
array
(
v
,
copy
=
False
).
reshape
((
-
1
,
3
))
x
=
v
[:,
0
]
y
=
v
[:,
1
]
z
=
v
[:,
2
]
l
=
x
*
x
+
y
*
y
+
z
*
z
return
np
.
sqrt
(
l
)
vectors
=
-
100
+
200
*
np
.
random
.
random
((
5
0
,
3
))
vectors
=
-
100
+
200
*
np
.
random
.
random
((
20
0
,
3
))
for
v
in
vectors
:
vtype
=
random
.
choice
((
list
,
tuple
,
np
.
array
))
v
=
vtype
(
v
)
assert
np
.
isclose
(
transform
.
veclength
(
v
),
l
(
v
))
# Multiple vectors in parallel
result
=
transform
.
veclength
(
vectors
)
expected
=
l
(
vectors
)
assert
np
.
all
(
np
.
isclose
(
result
,
expected
))
def
test_transformNormal
(
seed
):
...
...
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