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
Neel Shah
NIFTy
Commits
b1f9d1a2
Commit
b1f9d1a2
authored
May 10, 2016
by
theos
Browse files
Reworked apply_scalar_function in order to avoid unnecessary array copying.
parent
03a8b938
Changes
1
Show whitespace changes
Inline
Side-by-side
d2o/distributed_data_object.py
View file @
b1f9d1a2
...
...
@@ -406,32 +406,26 @@ class distributed_data_object(object):
"""
remember_hermitianQ
=
self
.
hermitian
if
inplace
is
True
:
temp
=
self
if
dtype
is
not
None
and
self
.
dtype
!=
np
.
dtype
(
dtype
):
about
.
warnings
.
cprint
(
"WARNING: Inplace dtype conversion is not possible!"
)
else
:
temp
=
self
.
copy_empty
(
dtype
=
dtype
)
if
np
.
prod
(
self
.
local_shape
)
!=
0
:
local_data
=
self
.
get_local_data
(
copy
=
False
)
try
:
temp
.
data
[:]
=
function
(
self
.
data
)
result_
data
=
function
(
local_
data
)
except
:
about
.
warnings
.
cprint
(
"WARNING: Trying to use np.vectorize!"
)
temp
.
data
[:]
=
np
.
vectorize
(
function
)(
self
.
data
)
result_data
=
np
.
vectorize
(
function
)(
local_data
)
if
inplace
is
True
:
result_d2o
=
self
else
:
# Noting to do here. The value-empty array
# is also geometrically empty
pass
result_d2o
=
self
.
copy_empty
(
dtype
=
result_data
.
dtype
)
result_d2o
.
set_local_data
(
result_data
,
copy
=
False
)
if
function
in
(
np
.
exp
,
np
.
log
):
temp
.
hermitian
=
remember_hermitianQ
result_d2o
.
hermitian
=
remember_hermitianQ
else
:
temp
.
hermitian
=
False
return
temp
result_d2o
.
hermitian
=
False
return
result_d2o
def
apply_generator
(
self
,
generator
,
copy
=
False
):
""" Evaluates generator(local_shape) and stores the result locally.
...
...
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