diff options
author | A. Unique TensorFlower <gardener@tensorflow.org> | 2017-02-21 17:31:57 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2017-02-21 17:52:15 -0800 |
commit | 4891c01b1cadf085a915a3eac5dd1b8d8cdee203 (patch) | |
tree | 87ec00e1927877ba26a2ffb69bc4f74f25c36f6a /tensorflow/python/kernel_tests/slice_op_test.py | |
parent | 123c2bb0af532d5fdaa05358158da33497d4bfe6 (diff) |
Allow (safe) in-place computation in TensorFlow C++ ops. When at least one input tensor has the same size and type as the output, and the underlying buffer is owned by the op, i.e. when its refcount is 1 at the time the op's Compute method executes, the computation can be performed in place and allocation of the output buffer avoided.
I updated the following ops to perform in-place computation automatically when possible:
* All standard coefficient-wise unary and binary operators (including with broadcasting) inheriting from base classes in kernels/cwise_ops_common.h.
* unary and binary operators inheriting from base classes in framework/numeric_op.h. This is mostly old code for the Relu family and associated gradients.
* All linear algebra ops inheriting from linalg_common.
* Misc individual files/ops: softmax, select, bias, aggregate ops, batch_norm & fused_batch_norm, adjust_hue, constant, depthwise_conv_grad, fractional_avg_pool, misc. pooling ops, matrix_set_diag, xent & sparse_xent, unique_op.
Change: 148166936
Diffstat (limited to 'tensorflow/python/kernel_tests/slice_op_test.py')
-rw-r--r-- | tensorflow/python/kernel_tests/slice_op_test.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/tensorflow/python/kernel_tests/slice_op_test.py b/tensorflow/python/kernel_tests/slice_op_test.py index 29f76a2182..c11f78b77e 100644 --- a/tensorflow/python/kernel_tests/slice_op_test.py +++ b/tensorflow/python/kernel_tests/slice_op_test.py @@ -269,6 +269,15 @@ class SliceTest(test.TestCase): c = array_ops.slice(a, [begin, 0], [-1, 2]) self.assertEqual([None, 2], c.get_shape().as_list()) + def testSliceOfSlice(self): + with self.test_session(use_gpu=True): + a = constant_op.constant([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) + b = a[1:, :] + c = b[:-1, :] + d = c[1, :] + res = 2 * d - c[1, :] + a[2, :] - 2 * b[-2, :] + self.assertAllEqual([0, 0, 0], res.eval()) + if __name__ == "__main__": test.main() |