reminisce commented on a change in pull request #9306: Sequence Operator
Improvements
URL: https://github.com/apache/incubator-mxnet/pull/9306#discussion_r161588488
##########
File path: tests/python/unittest/test_operator.py
##########
@@ -2311,40 +2311,86 @@ def test_l2_normalization():
check_l2_normalization((nbatch, nchannel, height,
width), mode)
-def sequence_mask_numpy(array, lengths, value):
+# Numpy Implementation of Sequence Ops
+def sequence_last_numpy(array, lengths, axis):
+ # create new array of dims [batch, seqlen, ...]
+ array2 = np.moveaxis(array, axis, 1)
+ dims = array2.shape
+ if lengths is None:
+ return array2[:, -1]
+ lengths = list(lengths)
+ return np.array([array2[i, int(lengths[i]) - 1] for i in range(dims[0])])
+
Review comment:
nit: surround top-level function with 2 lines, otherwise, IDEs such as
PyCharm would issue a coding style warning.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services