Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"add asnumpy interface" #5620

Merged
merged 6 commits into from
Nov 27, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Just for unittest
reyoung committed Nov 22, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 8d147121451ac501630092a756512f68ba66e7cc
11 changes: 6 additions & 5 deletions python/paddle/v2/fluid/executor.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ def __init__(self, places):
act_places.append(p)

self.executor = core.Executor(act_places)
self.places = act_places
self.places = places

def aslodtensor(self, data):
def accumulate(data):
@@ -38,8 +38,7 @@ def parselod(data):
if not isinstance(data, list):
# pure tensor case
tensor = core.LoDTensor()
numpy_data = np.array(data).reshape([len(data), 1])
tensor.set(numpy_data, self.places[0])
tensor.set(data, self.places[0])
return tensor
else:
# lodtensor case
@@ -121,8 +120,10 @@ def run(self,
inputs={'X': [feed_var]},
outputs={'Out': [out]},
attrs={'col': i})
# core.set_feed_variable(scope, self.aslodtensor(feed[name]), feed_var.name, i)
core.set_feed_variable(scope, feed[name], feed_var.name, i)
cur_feed = feed[name]
if not isinstance(cur_feed, core.LoDTensor):
cur_feed = self.aslodtensor(cur_feed)
core.set_feed_variable(scope, cur_feed, feed_var.name, i)

fetch_var = global_block.create_var(
name=fetch_var_name,
6 changes: 3 additions & 3 deletions python/paddle/v2/fluid/tests/test_executor_and_mul.py
Original file line number Diff line number Diff line change
@@ -41,15 +41,15 @@ class TestExecutor2(unittest.TestCase):
def test_asnumpy(self):
seq = data(name='seq', shape=[784], data_type='float32')
out = sequence_pool(seq, "sum")
x = np.ones(shape=(3, 5)).astype('float32')
x = numpy.ones(shape=(3, 5)).astype('float32')
lod = [[0, 2, 3]]
tensor = core.LoDTensor()
place = core.CPUPlace()
tensor.set(x, place)
tensor.set_lod(lod)
exe = Executor(place)
outs = exe.run(g_main_program, feed={"seq": tensor}, fetch_list=out)
self.assertTrue(np.allclose(outs[0], sequence_sum(lod, x)))
outs = exe.run(g_main_program, feed={"seq": tensor}, fetch_list=[out])
self.assertTrue(numpy.allclose(outs[0], sequence_sum(lod, x)))


if __name__ == '__main__':