Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
NIFTy
Commits
81910c01
Commit
81910c01
authored
Apr 20, 2017
by
Martin Reinecke
Browse files
avoid npz files
parent
27e8e9fe
Pipeline
#11563
failed with stage
in 21 minutes and 23 seconds
Changes
12
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ci/generate_test_data.sh
deleted
100755 → 0
View file @
27e8e9fe
#!/bin/bash
cd test
/data
for
filename
in
*
.py
;
do
./
$filename
done
cd
../..
nifty/spaces/rg_space/rg_space.py
View file @
81910c01
...
...
@@ -305,7 +305,7 @@ class RGSpace(Space):
for
ii
in
range
(
1
,
len
(
shape
)):
temp
=
((
cords
[
ii
]
-
shape
[
ii
]
//
2
)
*
dk
[
ii
])
**
2
if
not
self
.
zerocenter
[
ii
]:
temp
=
np
.
fft
.
fftshift
(
temp
)
temp
=
np
.
fft
.
i
fftshift
(
temp
)
dists
=
dists
+
temp
dists
=
np
.
sqrt
(
dists
)
return
dists
...
...
test/data/gl_space.npz
deleted
100644 → 0
View file @
27e8e9fe
File deleted
test/data/hp_space.npz
deleted
100644 → 0
View file @
27e8e9fe
File deleted
test/data/lm_space.npz
deleted
100644 → 0
View file @
27e8e9fe
File deleted
test/data/power_space.npz
deleted
100644 → 0
View file @
27e8e9fe
File deleted
test/data/rg_space.npz
deleted
100644 → 0
View file @
27e8e9fe
File deleted
test/test_spaces/test_gl_space.py
View file @
81910c01
...
...
@@ -18,6 +18,7 @@
import
unittest
import
numpy
as
np
import
itertools
from
numpy.testing
import
assert_
,
assert_equal
,
assert_raises
,
\
assert_almost_equal
...
...
@@ -43,17 +44,24 @@ CONSTRUCTOR_CONFIGS = [
]
def
get_distance_array_configs
():
npzfile
=
np
.
load
(
'test/data/gl_space.npz'
)
return
[[
2
,
None
,
None
,
npzfile
[
'da_0'
]]]
def
get_weight_configs
():
npzfile
=
np
.
load
(
'test/data/gl_space.npz'
)
np
.
random
.
seed
(
42
)
wgt
=
[
2.0943951
,
2.0943951
]
# for GLSpace(nlat=2, nlon=3)
weight_0
=
np
.
array
(
list
(
itertools
.
chain
.
from_iterable
(
itertools
.
repeat
(
x
,
3
)
for
x
in
wgt
)))
w_0_x
=
np
.
random
.
rand
(
6
)
w_0_res
=
w_0_x
*
weight_0
weight_1
=
np
.
array
(
list
(
itertools
.
chain
.
from_iterable
(
itertools
.
repeat
(
x
,
3
)
for
x
in
wgt
)))
weight_1
=
weight_1
.
reshape
([
1
,
1
,
6
])
w_1_x
=
np
.
random
.
rand
(
32
,
16
,
6
)
w_1_res
=
w_1_x
*
weight_1
return
[
[
npzfile
[
'
w_0_x
'
]
,
1
,
None
,
False
,
npzfile
[
'
w_0_res
'
]
],
[
npzfile
[
'w_0_x'
]
,
1
,
None
,
True
,
npzfile
[
'
w_0_res
'
]
],
[
npzfile
[
'w_1_x'
]
,
1
,
(
2
,),
True
,
npzfile
[
'
w_1_res
'
]
],
[
w_0_x
,
1
,
None
,
False
,
w_0_res
],
[
w_0_x
.
copy
()
,
1
,
None
,
True
,
w_0_res
],
[
w_1_x
.
copy
()
,
1
,
(
2
,),
True
,
w_1_res
],
]
...
...
@@ -92,11 +100,3 @@ class GLSpaceFunctionalityTests(unittest.TestCase):
assert_almost_equal
(
res
,
expected
)
if
inplace
:
assert_
(
x
is
res
)
@
expand
(
get_distance_array_configs
())
def
test_distance_array
(
self
,
nlat
,
nlon
,
dtype
,
expected
):
if
'libsharp_wrapper_gl'
not
in
di
:
raise
SkipTest
else
:
g
=
GLSpace
(
nlat
,
nlon
,
dtype
)
assert_almost_equal
(
g
.
get_distance_array
(
'not'
).
data
,
expected
)
test/test_spaces/test_hp_space.py
View file @
81910c01
...
...
@@ -45,17 +45,17 @@ CONSTRUCTOR_CONFIGS = [
]
def
get_distance_array_configs
():
npzfile
=
np
.
load
(
'test/data/hp_space.npz'
)
return
[[
2
,
None
,
npzfile
[
'da_0'
]]]
def
get_weight_configs
():
npzfile
=
np
.
load
(
'test/data/hp_space.npz'
)
np
.
random
.
seed
(
42
)
# for HPSpace(nside=2)
w_0_x
=
np
.
random
.
rand
(
48
)
w_0_res
=
w_0_x
*
((
4
*
np
.
pi
)
/
48
)
w_1_res
=
w_0_x
*
(((
4
*
np
.
pi
)
/
48
)
**
2
)
return
[
[
npzfile
[
'
w_0_x
'
]
,
1
,
None
,
False
,
npzfile
[
'
w_0_res
'
]
],
[
npzfile
[
'w_0_x'
]
,
1
,
None
,
True
,
npzfile
[
'
w_0_res
'
]
],
[
npzfile
[
'
w_
1
_x
'
]
,
2
,
None
,
False
,
npzfile
[
'
w_1_res
'
]
],
[
w_0_x
,
1
,
None
,
False
,
w_0_res
],
[
w_0_x
.
copy
()
,
1
,
None
,
True
,
w_0_res
],
[
w_
0
_x
,
2
,
None
,
False
,
w_1_res
],
]
...
...
@@ -93,11 +93,3 @@ class HPSpaceFunctionalityTests(unittest.TestCase):
assert_almost_equal
(
res
,
expected
)
if
inplace
:
assert_
(
x
is
res
)
@
expand
(
get_distance_array_configs
())
def
test_distance_array
(
self
,
nside
,
dtype
,
expected
):
if
'healpy'
not
in
di
:
raise
SkipTest
else
:
h
=
HPSpace
(
nside
,
dtype
)
assert_almost_equal
(
h
.
get_distance_array
(
'not'
).
data
,
expected
)
test/test_spaces/test_lm_space.py
View file @
81910c01
...
...
@@ -53,23 +53,44 @@ CONSTRUCTOR_CONFIGS = [
]
def
_distance_array_helper
(
index_arr
,
lmax
):
if
index_arr
<=
lmax
:
index_half
=
index_arr
else
:
if
(
index_arr
-
lmax
)
%
2
==
0
:
index_half
=
(
index_arr
+
lmax
)
/
2
else
:
index_half
=
(
index_arr
+
lmax
+
1
)
/
2
m
=
(
np
.
ceil
(((
2
*
lmax
+
1
)
-
np
.
sqrt
((
2
*
lmax
+
1
)
**
2
-
8
*
(
index_half
-
lmax
)))
/
2
)
).
astype
(
int
)
return
index_half
-
m
*
(
2
*
lmax
+
1
-
m
)
//
2
def
get_distance_array_configs
():
npzfile
=
np
.
load
(
'test/data/lm_space.npz'
)
return
[[
5
,
None
,
npzfile
[
'
da_0
'
]
]]
da_0
=
[
_distance_array_helper
(
idx
,
5
)
for
idx
in
np
.
arange
(
36
)]
return
[[
5
,
None
,
da_0
]]
def
get_weight_configs
():
npzfile
=
np
.
load
(
'test/data/lm_space.npz'
)
np
.
random
.
seed
(
42
)
w_0_x
=
np
.
random
.
rand
(
32
,
16
,
6
)
return
[
[
npzfile
[
'
w_0_x
'
]
,
1
,
None
,
False
,
npzfile
[
'w_0_res'
]
],
[
npzfile
[
'w_0_x'
]
,
1
,
None
,
True
,
npzfile
[
'w_0_res'
]
]
[
w_0_x
,
1
,
None
,
False
,
w_0_x
],
[
w_0_x
.
copy
()
,
1
,
None
,
True
,
w_0_x
]
]
def
get_hermitian_configs
():
npzfile
=
np
.
load
(
'test/data/lm_space.npz'
)
np
.
random
.
seed
(
42
)
h_0_res_real
=
np
.
random
.
rand
(
32
,
16
,
6
).
astype
(
np
.
complex128
)
h_0_res_imag
=
np
.
random
.
rand
(
32
,
16
,
6
).
astype
(
np
.
complex128
)
h_0_x
=
h_0_res_real
+
h_0_res_imag
*
1j
return
[
[
npzfile
[
'h_0_x'
],
npzfile
[
'h_0_res_real'
],
npzfile
[
'
h_0_res_imag
'
]
]
[
h_0_x
,
h_0_res_real
,
h_0_res_imag
]
]
...
...
test/test_spaces/test_power_space.py
View file @
81910c01
...
...
@@ -70,19 +70,27 @@ CONSTRUCTOR_CONFIGS = [
def
get_distance_array_configs
():
npzfile
=
np
.
load
(
'test/data/power_space.npz'
)
da_0
=
np
.
array
([
0
,
1.0
,
1.41421356
,
2.
,
2.23606798
,
2.82842712
]
)
return
[
[
RGSpace
((
4
,
4
),
harmonic
=
True
),
npzfile
[
'
da_0
'
]
],
[
RGSpace
((
4
,
4
),
harmonic
=
True
),
da_0
],
]
def
get_weight_configs
():
npzfile
=
np
.
load
(
'test/data/power_space.npz'
)
np
.
random
.
seed
(
42
)
# power 1
w_0_x
=
np
.
random
.
rand
(
32
,
16
,
6
)
# RGSpace((4, 4), harmonic=True)
# using rho directly
weight_0
=
np
.
array
([
1
,
4
,
4
,
2
,
4
,
1
])
weight_0
=
weight_0
.
reshape
([
1
,
1
,
6
])
w_0_res
=
w_0_x
*
weight_0
return
[
[
RGSpace
((
4
,
4
),
harmonic
=
True
),
npzfile
[
'
w_0_x
'
]
,
1
,
(
2
,),
False
,
npzfile
[
'
w_0_res
'
]
],
w_0_x
,
1
,
(
2
,),
False
,
w_0_res
],
[
RGSpace
((
4
,
4
),
harmonic
=
True
),
npzfile
[
'w_0_x'
]
,
1
,
(
2
,),
True
,
npzfile
[
'
w_0_res
'
]
],
w_0_x
.
copy
()
,
1
,
(
2
,),
True
,
w_0_res
],
]
...
...
test/test_spaces/test_rg_space.py
View file @
81910c01
...
...
@@ -92,46 +92,133 @@ CONSTRUCTOR_CONFIGS = [
def
get_distance_array_configs
():
npzfile
=
np
.
load
(
'test/data/rg_space.npz'
)
# for RGSpace(shape=(4, 4), distances=None, zerocenter=[False, False])
cords_0
=
np
.
ogrid
[
0
:
4
,
0
:
4
]
da_0
=
((
cords_0
[
0
]
-
4
//
2
)
*
0.25
)
**
2
da_0
=
np
.
fft
.
ifftshift
(
da_0
)
temp
=
((
cords_0
[
1
]
-
4
//
2
)
*
0.25
)
**
2
temp
=
np
.
fft
.
ifftshift
(
temp
)
da_0
=
da_0
+
temp
da_0
=
np
.
sqrt
(
da_0
)
# for RGSpace(shape=(4, 4), distances=None, zerocenter=[True, True])
da_1
=
((
cords_0
[
0
]
-
4
//
2
)
*
0.25
)
**
2
temp
=
((
cords_0
[
1
]
-
4
//
2
)
*
0.25
)
**
2
da_1
=
da_1
+
temp
da_1
=
np
.
sqrt
(
da_1
)
# for RGSpace(shape=(4, 4), distances=(12, 12), zerocenter=[True, True])
da_2
=
((
cords_0
[
0
]
-
4
//
2
)
*
12
)
**
2
temp
=
((
cords_0
[
1
]
-
4
//
2
)
*
12
)
**
2
da_2
=
da_2
+
temp
da_2
=
np
.
sqrt
(
da_2
)
return
[
[(
4
,
4
),
None
,
[
False
,
False
],
npzfile
[
'
da_0
'
]
],
[(
4
,
4
),
None
,
[
True
,
True
],
npzfile
[
'
da_1
'
]
],
[(
4
,
4
),
(
12
,
12
),
[
True
,
True
],
npzfile
[
'
da_2
'
]
]
[(
4
,
4
),
None
,
[
False
,
False
],
da_0
],
[(
4
,
4
),
None
,
[
True
,
True
],
da_1
],
[(
4
,
4
),
(
12
,
12
),
[
True
,
True
],
da_2
]
]
def
get_weight_configs
():
npzfile
=
np
.
load
(
'test/data/rg_space.npz'
)
np
.
random
.
seed
(
42
)
# power 1
w_0_x
=
np
.
random
.
rand
(
32
,
12
,
6
)
# for RGSpace(shape=(11,11), distances=None, harmonic=False)
w_0_res
=
w_0_x
*
(
1
/
11
*
1
/
11
)
# for RGSpace(shape=(11, 11), distances=(1.3,1.3), harmonic=False)
w_1_res
=
w_0_x
*
(
1.3
*
1.3
)
# for RGSpace(shape=(11,11), distances=None, harmonic=True)
w_2_res
=
w_0_x
*
(
1.0
*
1.0
)
# for RGSpace(shape=(11,11), distances=(1.3, 1,3), harmonic=True)
w_3_res
=
w_0_x
*
(
1.3
*
1.3
)
return
[
[(
11
,
11
),
None
,
False
,
npzfile
[
'w_0_x'
],
1
,
None
,
False
,
npzfile
[
'w_0_res'
]],
[(
11
,
11
),
None
,
False
,
npzfile
[
'w_0_x'
],
1
,
None
,
True
,
npzfile
[
'w_0_res'
]],
[(
11
,
11
),
(
1.3
,
1.3
),
False
,
npzfile
[
'w_0_x'
],
1
,
None
,
False
,
npzfile
[
'w_1_res'
]],
[(
11
,
11
),
(
1.3
,
1.3
),
False
,
npzfile
[
'w_0_x'
],
1
,
None
,
True
,
npzfile
[
'w_1_res'
]],
[(
11
,
11
),
None
,
True
,
npzfile
[
'w_0_x'
],
1
,
None
,
False
,
npzfile
[
'w_2_res'
]],
[(
11
,
11
),
None
,
True
,
npzfile
[
'w_0_x'
],
1
,
None
,
True
,
npzfile
[
'w_2_res'
]],
[(
11
,
11
),
(
1.3
,
1.3
),
True
,
npzfile
[
'w_0_x'
],
1
,
None
,
False
,
npzfile
[
'w_3_res'
]],
[(
11
,
11
),
(
1.3
,
1.3
),
True
,
npzfile
[
'w_0_x'
],
1
,
None
,
True
,
npzfile
[
'w_3_res'
]]
[(
11
,
11
),
None
,
False
,
w_0_x
,
1
,
None
,
False
,
w_0_res
],
[(
11
,
11
),
None
,
False
,
w_0_x
.
copy
(),
1
,
None
,
True
,
w_0_res
],
[(
11
,
11
),
(
1.3
,
1.3
),
False
,
w_0_x
,
1
,
None
,
False
,
w_1_res
],
[(
11
,
11
),
(
1.3
,
1.3
),
False
,
w_0_x
.
copy
(),
1
,
None
,
True
,
w_1_res
],
[(
11
,
11
),
None
,
True
,
w_0_x
,
1
,
None
,
False
,
w_2_res
],
[(
11
,
11
),
None
,
True
,
w_0_x
.
copy
(),
1
,
None
,
True
,
w_2_res
],
[(
11
,
11
),
(
1.3
,
1.3
),
True
,
w_0_x
,
1
,
None
,
False
,
w_3_res
],
[(
11
,
11
),
(
1.3
,
1.3
),
True
,
w_0_x
.
copy
(),
1
,
None
,
True
,
w_3_res
]
]
def
get_hermitian_configs
():
npzfile
=
np
.
load
(
'test/data/rg_space.npz'
)
h_0_x
=
np
.
array
([
[
0.88250339
+
0.12102381j
,
0.54293435
+
0.7345584j
,
0.87057998
+
0.20515315j
,
0.16602950
+
0.09396132j
],
[
0.83853902
+
0.17974696j
,
0.79735933
+
0.37104425j
,
0.22057732
+
0.9498977j
,
0.14329183
+
0.47899678j
],
[
0.96934284
+
0.3792878j
,
0.13118669
+
0.45643055j
,
0.16372149
+
0.48235714j
,
0.66141537
+
0.20383357j
],
[
0.49168197
+
0.77572178j
,
0.09570420
+
0.14219071j
,
0.69735595
+
0.33017333j
,
0.83692452
+
0.18544449j
]])
h_0_res_real
=
np
.
array
([
[
0.88250339
+
0.j
,
0.35448193
+
0.32029854j
,
0.87057998
+
0.j
,
0.35448193
-
0.32029854j
],
[
0.66511049
-
0.29798741j
,
0.81714193
+
0.09279988j
,
0.45896664
+
0.30986218j
,
0.11949801
+
0.16840303j
],
[
0.96934284
+
0.j
,
0.39630103
+
0.12629849j
,
0.16372149
+
0.j
,
0.39630103
-
0.12629849j
],
[
0.66511049
+
0.29798741j
,
0.11949801
-
0.16840303j
,
0.45896664
-
0.30986218j
,
0.81714193
-
0.09279988j
]])
h_0_res_imag
=
np
.
array
([
[
0.12102381
+
0.j
,
0.41425986
-
0.18845242j
,
0.20515315
+
0.j
,
0.41425986
+
0.18845242j
],
[
0.47773437
-
0.17342852j
,
0.27824437
+
0.0197826j
,
0.64003551
+
0.23838932j
,
0.31059374
-
0.02379381j
],
[
0.37928780
+
0.j
,
0.33013206
+
0.26511434j
,
0.48235714
+
0.j
,
0.33013206
-
0.26511434j
],
[
0.47773437
+
0.17342852j
,
0.31059374
+
0.02379381j
,
0.64003551
-
0.23838932j
,
0.27824437
-
0.0197826j
]])
h_1_x
=
np
.
array
([
[[
0.23987021
+
0.41617749j
,
0.34605012
+
0.55462234j
,
0.07947035
+
0.73360723j
,
0.22853748
+
0.39275304j
],
[
0.90254910
+
0.02107809j
,
0.28195470
+
0.56031588j
,
0.23004043
+
0.33873536j
,
0.56398377
+
0.68913034j
],
[
0.81897406
+
0.2050369j
,
0.88724852
+
0.8137488j
,
0.84645004
+
0.0059284j
,
0.14950377
+
0.50013099j
]],
[[
0.93491597
+
0.73251066j
,
0.74764790
+
0.11539037j
,
0.48090736
+
0.04352568j
,
0.49363732
+
0.97233093j
],
[
0.72761881
+
0.74636216j
,
0.46390134
+
0.4343401j
,
0.88436859
+
0.79415269j
,
0.67027606
+
0.85498234j
],
[
0.86318727
+
0.19076379j
,
0.36859448
+
0.89842333j
,
0.73407193
+
0.85091112j
,
0.44187657
+
0.08936409j
]]
])
h_1_res_real
=
np
.
array
([
[[
0.23987021
+
0.j
,
0.28729380
+
0.08093465j
,
0.07947035
+
0.j
,
0.28729380
-
0.08093465j
],
[
0.90254910
+
0.j
,
0.42296924
-
0.06440723j
,
0.23004043
+
0.j
,
0.42296924
+
0.06440723j
],
[
0.81897406
+
0.j
,
0.51837614
+
0.1568089j
,
0.84645004
+
0.j
,
0.51837614
-
0.1568089j
]],
[[
0.93491597
+
0.j
,
0.62064261
-
0.42847028j
,
0.48090736
+
0.j
,
0.62064261
+
0.42847028j
],
[
0.72761881
+
0.j
,
0.56708870
-
0.21032112j
,
0.88436859
+
0.j
,
0.56708870
+
0.21032112j
],
[
0.86318727
+
0.j
,
0.40523552
+
0.40452962j
,
0.73407193
+
0.j
,
0.40523552
-
0.40452962j
]]
])
h_1_res_imag
=
np
.
array
([
[[
0.41617749
+
0.j
,
0.47368769
-
0.05875632j
,
0.73360723
+
0.j
,
0.47368769
+
0.05875632j
],
[
0.02107809
+
0.j
,
0.62472311
+
0.14101454j
,
0.33873536
+
0.j
,
0.62472311
-
0.14101454j
],
[
0.20503690
+
0.j
,
0.65693990
-
0.36887238j
,
0.00592840
+
0.j
,
0.65693990
+
0.36887238j
]],
[[
0.73251066
+
0.j
,
0.54386065
-
0.12700529j
,
0.04352568
+
0.j
,
0.54386065
+
0.12700529j
],
[
0.74636216
+
0.j
,
0.64466122
+
0.10318736j
,
0.79415269
+
0.j
,
0.64466122
-
0.10318736j
],
[
0.19076379
+
0.j
,
0.49389371
+
0.03664104j
,
0.85091112
+
0.j
,
0.49389371
-
0.03664104j
]]
])
return
[
[
npzfile
[
'h_0_x'
],
None
,
npzfile
[
'h_0_res_real'
],
npzfile
[
'h_0_res_imag'
]],
[
npzfile
[
'h_1_x'
],
(
2
,),
npzfile
[
'h_1_res_real'
],
npzfile
[
'h_1_res_imag'
]]
[
h_0_x
,
None
,
h_0_res_real
,
h_0_res_imag
],
[
h_1_x
,
(
2
,),
h_1_res_real
,
h_1_res_imag
]
]
class
RGSpaceInterfaceTests
(
unittest
.
TestCase
):
@
expand
([[
'distances'
,
tuple
],
[
'zerocenter'
,
tuple
]])
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment