Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSL
fslpy
Commits
61e0ccd3
Commit
61e0ccd3
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Updated veclength/normalise tests
parent
47a0088a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_transform.py
+37
-6
37 additions, 6 deletions
tests/test_transform.py
with
37 additions
and
6 deletions
tests/test_transform.py
+
37
−
6
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
):
...
...
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