Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WindEnergyToolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
toolbox
WindEnergyToolbox
Commits
07595e1e
There was a problem fetching the pipeline summary.
Commit
07595e1e
authored
7 years ago
by
Mads M. Pedersen
Browse files
Options
Downloads
Patches
Plain Diff
fixed caching issue
parent
fda48e00
No related branches found
No related tags found
1 merge request
!44
Mmpe
Pipeline
#
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
wetb/utils/caching.py
+11
-18
11 additions, 18 deletions
wetb/utils/caching.py
wetb/utils/tests/test_caching.py
+19
-15
19 additions, 15 deletions
wetb/utils/tests/test_caching.py
wetb/utils/tests/test_files/test2.csv
+0
-5
0 additions, 5 deletions
wetb/utils/tests/test_files/test2.csv
with
30 additions
and
38 deletions
wetb/utils/caching.py
+
11
−
18
View file @
07595e1e
...
...
@@ -128,36 +128,29 @@ def cache_npsave(f):
return
loadsave
()
return
wrap
def
cache
_npsavez
(
f
):
def
_get
_npsavez
_wrap
(
f
,
compress
):
def
wrap
(
filename
,
*
args
,
**
kwargs
):
np_filename
=
os
.
path
.
splitext
(
filename
)[
0
]
+
"
.npy.npz
"
np_filename
=
os
.
path
.
splitext
(
filename
)[
0
]
+
"
.npy.npz
"
+
(
""
,
"
c
"
)[
compress
]
def
loadsave
():
res
=
f
(
filename
,
*
args
,
**
kwargs
)
np
.
savez
(
np_filename
,
*
res
)
if
compress
:
np
.
savez_compressed
(
np_filename
,
*
res
)
else
:
np
.
savez
(
np_filename
,
*
res
)
return
res
if
os
.
path
.
isfile
(
np_filename
)
and
(
not
os
.
path
.
isfile
(
filename
)
or
os
.
path
.
getmtime
(
np_filename
)
>
os
.
path
.
getmtime
(
filename
)):
try
:
npzfile
=
np
.
load
(
np_filename
)
return
[
npzfile
[
'
arr_%d
'
%
i
]
for
i
in
range
(
len
(
f
.
files
()
))]
return
[
npzfile
[
'
arr_%d
'
%
i
]
for
i
in
range
(
len
(
npzfile
.
files
))]
except
:
return
loadsave
()
else
:
return
loadsave
()
return
wrap
def
cache_npsavez
(
f
):
return
_get_npsavez_wrap
(
f
,
False
)
def
cache_npsavez_compressed
(
f
):
def
wrap
(
filename
,
*
args
,
**
kwargs
):
np_filename
=
os
.
path
.
splitext
(
filename
)[
0
]
+
"
.npy.npz
"
def
loadsave
():
res
=
f
(
filename
,
*
args
,
**
kwargs
)
np
.
savez_compressed
(
np_filename
,
*
res
)
return
res
if
os
.
path
.
isfile
(
np_filename
)
and
(
not
os
.
path
.
isfile
(
filename
)
or
os
.
path
.
getmtime
(
np_filename
)
>
os
.
path
.
getmtime
(
filename
)):
try
:
return
[
f
[
'
arr_%d
'
%
i
]
for
i
in
range
(
len
(
f
.
files
()))]
except
:
return
loadsave
()
else
:
return
loadsave
()
return
wrap
\ No newline at end of file
return
_get_npsavez_wrap
(
f
,
True
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
wetb/utils/tests/test_caching.py
+
19
−
15
View file @
07595e1e
...
...
@@ -136,28 +136,32 @@ class TestCacheProperty(unittest.TestCase):
os
.
remove
(
tfp
+
'
test.npy
'
)
def
test_cache_savez
(
self
):
if
os
.
path
.
isfile
(
tfp
+
"
test.npy.npy
"
):
os
.
remove
(
tfp
+
'
test.npy.npy
'
)
A
=
open_csv2
(
tfp
+
"
test.csv
"
)
self
.
assertTrue
(
os
.
path
.
isfile
(
tfp
+
"
test.npy.npz
"
))
npfilename
=
tfp
+
"
test.npy.npz
"
func
=
open_csv2
if
os
.
path
.
isfile
(
npfilename
):
os
.
remove
(
npfilename
)
A
=
func
(
tfp
+
"
test.csv
"
)
self
.
assertTrue
(
os
.
path
.
isfile
(
npfilename
))
np
.
testing
.
assert_array_equal
(
A
[
0
],
np
.
loadtxt
(
tfp
+
"
test.csv
"
))
A
[
0
][
0
]
=-
1
np
.
save
(
tfp
+
"
test.npy
"
,
A
)
B
=
open_csv
(
tfp
+
"
test.csv
"
)
np
.
save
z
(
npfilename
,
A
[
0
],
A
[
1
]
)
B
=
func
(
tfp
+
"
test.csv
"
)
np
.
testing
.
assert_array_equal
(
A
,
B
)
os
.
remove
(
tfp
+
'
test.npy
'
)
os
.
remove
(
npfilename
)
def
test_cache_savez_compressed
(
self
):
if
os
.
path
.
isfile
(
tfp
+
"
test2.npy.npy
"
):
os
.
remove
(
tfp
+
'
test2.npy.npy
'
)
A
=
open_csv2
(
tfp
+
"
test2.csv
"
)
self
.
assertTrue
(
os
.
path
.
isfile
(
tfp
+
"
test2.npy.npz
"
))
np
.
testing
.
assert_array_equal
(
A
[
0
],
np
.
loadtxt
(
tfp
+
"
test2.csv
"
))
npfilename
=
tfp
+
"
test.npy.npzc
"
func
=
open_csv3
if
os
.
path
.
isfile
(
npfilename
):
os
.
remove
(
npfilename
)
A
=
func
(
tfp
+
"
test.csv
"
)
self
.
assertTrue
(
os
.
path
.
isfile
(
npfilename
))
np
.
testing
.
assert_array_equal
(
A
[
0
],
np
.
loadtxt
(
tfp
+
"
test.csv
"
))
A
[
0
][
0
]
=-
1
np
.
save
(
tfp
+
"
test2.npy
"
,
A
)
B
=
open_csv
(
tfp
+
"
test
2
.csv
"
)
np
.
save
z
(
npfilename
,
A
[
0
],
A
[
1
]
)
B
=
func
(
tfp
+
"
test.csv
"
)
np
.
testing
.
assert_array_equal
(
A
,
B
)
os
.
remove
(
tfp
+
'
test2.npy
'
)
os
.
remove
(
npfilename
)
if
__name__
==
"
__main__
"
:
#import sys;sys.argv = ['', 'Test.testName']
...
...
This diff is collapsed.
Click to expand it.
wetb/utils/tests/test_files/test2.csv
deleted
100644 → 0
+
0
−
5
View file @
fda48e00
0.000000000000000000e+00 5.000000000000000000e+00
1.000000000000000000e+00 6.000000000000000000e+00
2.000000000000000000e+00 7.000000000000000000e+00
3.000000000000000000e+00 8.000000000000000000e+00
4.000000000000000000e+00 9.000000000000000000e+00
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