expand_as return variable without shape
Created by: OleNet
mp, sp = fluid.Program(), fluid.Program()
with fluid.program_guard(mp, sp):
en_emb = fluid.layers.data(name='x', shape=[-1, 4], dtype='float32')
cn_emb = fluid.layers.data(name='y', shape=[-1, 4], dtype='float32')
en_emb_reshape = fluid.layers.reshape(en_emb, shape=[-1, 1, 4]) # -1(3) x 1 x 4
cn_emb_reshape = fluid.layers.reshape(cn_emb, shape=[1, -1, 4]) # 1 x 2(-1) x 4
en_emb_transpose = fluid.layers.transpose(en_emb_reshape, perm=[2, 0, 1]) # 4 x 3 x 1
cn_emb_transpose = fluid.layers.transpose(cn_emb_reshape, perm=[2, 0, 1]) # 4 x 1 x 2
output = fluid.layers.matmul(en_emb_transpose, cn_emb_transpose) # 4 x 3 x 2
en_cn_emb_elementwise = fluid.layers.transpose(output, perm=[1, 2, 0]) # 3 x 2 x 4
en_emb_expand = fluid.layers.expand_as(x=en_emb_reshape, target_tensor=en_cn_emb_elementwise)
cn_emb_expand = fluid.layers.expand_as(x=cn_emb_reshape, target_tensor=en_cn_emb_elementwise)
en_cn_inter = paddle.fluid.layers.stack([en_emb_expand, cn_emb_expand, en_cn_emb_elementwise], axis=2)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(sp)
en = np.array([[1,2,3, 0],[4,5,0,6],[0, 7,8,9]]).astype('float16')
cn = np.array([[3,2,1, 0], [6,5,0,4]]).astype('float16')
# print(">> en shape ", en.shape)
# print(">> cn shape ", cn.shape)
# print(o, o[0].shape)
# print('=========')
# print(b)
# print(exe.run(mp,
# feed={en_emb.name:en, cn_emb.name:cn},
# fetch_list=[en_emb_expand]))
# print(exe.run(mp,
# feed={en_emb.name:en, cn_emb.name:cn},
# fetch_list=[cn_emb_expand]))
# o = exe.run(mp,
# feed={en_emb.name:en, cn_emb.name:cn},
# fetch_list=[en_cn_emb_elementwise])
# print(o)
print(exe.run(mp,
feed={en_emb.name:en, cn_emb.name:cn},
fetch_list=[en_cn_inter]))