Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pulse_lib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
QuTech QDLabs
pulse_lib
Commits
5dba23d9
Commit
5dba23d9
authored
2 years ago
by
Sander de Snoo
Browse files
Options
Downloads
Patches
Plain Diff
Improved performance of loop_controller and find_common_dimension using shortcut for shape = (1,)
parent
6797a173
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pulse_lib/segments/utility/data_handling_functions.py
+36
-28
36 additions, 28 deletions
pulse_lib/segments/utility/data_handling_functions.py
with
36 additions
and
28 deletions
pulse_lib/segments/utility/data_handling_functions.py
+
36
−
28
View file @
5dba23d9
...
...
@@ -17,6 +17,8 @@ def find_common_dimension(dim_1, dim_2):
Will raise error is dimensions are not compatible
'''
if
dim_2
==
(
1
,):
return
dim_1
dim_1
=
list
(
dim_1
)[::
-
1
]
dim_2
=
list
(
dim_2
)[::
-
1
]
dim_comb
=
[]
...
...
@@ -178,38 +180,44 @@ def loop_controller(func):
if
isinstance
(
kwarg
,
loop_obj
):
loop_info_kwargs
.
append
(
_get_loop_info
(
kwarg
,
key
))
orig_data
=
obj
.
data
for
lp
in
loop_info_args
:
for
i
in
range
(
len
(
lp
[
'
axis
'
])
-
1
,
-
1
,
-
1
):
data_shape
=
obj
.
data
.
shape
lp_axis
=
lp
[
'
axis
'
][
i
]
lp_length
=
lp
[
'
shape
'
][
i
]
new_dim
,
axis
=
get_new_dim_loop
(
data_shape
,
lp_axis
,
lp_length
)
lp
[
'
axis
'
][
i
]
=
axis
obj
.
data
=
update_dimension
(
obj
.
data
,
new_dim
)
if
lp
[
'
setpnt
'
]
is
not
None
:
lp
[
'
setpnt
'
][
i
].
axis
=
axis
obj
.
_setpoints
+=
lp
[
'
setpnt
'
][
i
]
for
lp
in
loop_info_kwargs
:
for
i
in
range
(
len
(
lp
[
'
axis
'
])
-
1
,
-
1
,
-
1
):
new_dim
,
axis
=
get_new_dim_loop
(
obj
.
data
.
shape
,
lp
[
'
axis
'
][
i
],
lp
[
'
shape
'
][
i
])
lp
[
'
axis
'
][
i
]
=
axis
obj
.
data
=
update_dimension
(
obj
.
data
,
new_dim
)
if
len
(
loop_info_args
)
==
0
and
len
(
loop_info_kwargs
)
==
0
:
data
=
obj
.
data
if
data
.
shape
!=
(
1
,):
loop_over_data
(
func
,
data
,
args
,
kwargs
)
else
:
obj
.
data_tmp
=
data
[
0
]
data
[
0
]
=
func
(
*
args
,
**
kwargs
)
if
lp
[
'
setpnt
'
]
is
not
None
:
lp
[
'
setpnt
'
][
i
].
axis
=
axis
obj
.
_setpoints
+=
lp
[
'
setpnt
'
][
i
]
else
:
if
orig_data
is
not
obj
.
data
:
print
(
f
'
data
{
obj
.
name
}
change
{
orig_data
.
shape
}
->
{
obj
.
data
.
shape
}
'
)
orig_data
=
obj
.
data
for
lp
in
loop_info_args
:
for
i
in
range
(
len
(
lp
[
'
axis
'
])
-
1
,
-
1
,
-
1
):
data_shape
=
obj
.
data
.
shape
lp_axis
=
lp
[
'
axis
'
][
i
]
lp_length
=
lp
[
'
shape
'
][
i
]
new_dim
,
axis
=
get_new_dim_loop
(
data_shape
,
lp_axis
,
lp_length
)
lp
[
'
axis
'
][
i
]
=
axis
obj
.
data
=
update_dimension
(
obj
.
data
,
new_dim
)
if
lp
[
'
setpnt
'
]
is
not
None
:
lp
[
'
setpnt
'
][
i
].
axis
=
axis
obj
.
_setpoints
+=
lp
[
'
setpnt
'
][
i
]
for
lp
in
loop_info_kwargs
:
for
i
in
range
(
len
(
lp
[
'
axis
'
])
-
1
,
-
1
,
-
1
):
new_dim
,
axis
=
get_new_dim_loop
(
obj
.
data
.
shape
,
lp
[
'
axis
'
][
i
],
lp
[
'
shape
'
][
i
])
lp
[
'
axis
'
][
i
]
=
axis
obj
.
data
=
update_dimension
(
obj
.
data
,
new_dim
)
if
lp
[
'
setpnt
'
]
is
not
None
:
lp
[
'
setpnt
'
][
i
].
axis
=
axis
obj
.
_setpoints
+=
lp
[
'
setpnt
'
][
i
]
if
orig_data
is
not
obj
.
data
:
print
(
f
'
data
{
obj
.
name
}
change
{
orig_data
.
shape
}
->
{
obj
.
data
.
shape
}
'
)
obj_data
=
obj
.
data
if
len
(
loop_info_args
)
>
0
or
len
(
loop_info_kwargs
)
>
0
:
loop_over_data_lp
(
func
,
obj_data
,
args
,
loop_info_args
,
kwargs
,
loop_info_kwargs
)
else
:
loop_over_data
(
func
,
obj_data
,
args
,
kwargs
)
return
wrapper
...
...
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