code: def test_keepdims(self):
      x = tensor.dtensor3()
      a = np.random.rand(3, 2, 4)
      # We don't need to test all opt and C code, as this is tested
      # by the ops tests.
      mode = theano.compile.Mode(optimizer="fast_compile", linker="py")
  
      # 'max_and_argmax' has two outputs and can be specified with either
      # a single or every axis:
      for axis in [
          0,
          1,
          2,
          [0],
          [1],
          [2],
          None,
          [0, 1, 2],
          [-1],
          [-2],
          [-3],
          [-1, -2, -3],
          [0, -1, -2],
          [-2, -3, 2],
      ]:
          op = tensor.max_and_argmax
          f = function(
              [x],
              [
                  op(x, axis=axis, keepdims=True)[0],
                  self.makeKeepDims_local(
                      x, op(x, axis=axis, keepdims=False)[0], axis
                  ),
              ],
              mode=mode,
          )
          ans1, ans2 = f(a)
          assert np.allclose(ans1, ans2)
          assert ans1.shape == ans2.shape
  
          f = function(
              [x],
              [
                  op(x, axis=axis, keepdims=True)[1],
                  self.makeKeepDims_local(
                      x, op(x, axis=axis, keepdims=False)[1], axis
                  ),
              ],
              mode=mode,
          )
          ans1, ans2 = f(a)
          assert np.allclose(ans1, ans2)
          assert ans1.shape == ans2.shape
  
      # the following ops can be specified with either a single axis or every
      # axis:
      for op in [tensor.argmax, tensor.argmin]:
          for axis in [
              0,
              1,
              2,
              [0],
              [1],
              [2],
              None,
              [0, 1, 2],
              [-1],
              [-2],
              [-3],
              [-1, -2, -3],
              [0, -2, 2],
          ]:
              f = function(
                  [x],
                  [
                      op(x, axis=axis, keepdims=True),
                      self.makeKeepDims_local(
                          x, op(x, axis=axis, keepdims=False), axis
                      ),
                  ],
                  mode=mode,
              )
              ans1, ans2 = f(a)
              assert np.allclose(ans1, ans2)
              assert ans1.shape == ans2.shape
  
      # the following ops can be specified with a freely specified axis
      # parameter
      for op in [
          tensor.sum,
          tensor.prod,
          tensor.mean,
          tensor.var,
          tensor.std,
          tensor.all,
          tensor.any,
          tensor.max,
          tensor.min,
      ]:
          for axis in [
              0,
              1,
              2,
              [0],
              [1],
              [2],
              None,
              [0, 1],
              [1, 2],
              [0, 1, 2],
              [-1],
              [-2],
              [-3],
              [-1, -2],
              [-1, -2, -3],
              [0, -2, 2],
          ]:
              f = function(
                  [x],
                  [
                      op(x, axis=axis, keepdims=True),
                      self.makeKeepDims_local(
                          x, op(x, axis=axis, keepdims=False), axis
                      ),
                  ],
                  mode=mode,
              )
  
              ans1, ans2 = f(a)
              assert np.allclose(ans1, ans2)
              assert ans1.shape == ans2.shape
  
file_path: Theano/theano/tensor/tests/test_keepdims.py
imports: from __future__ import absolute_import, print_function, division
  import unittest
  import numpy
  from six import integer_types
  import theano
  from theano import tensor, function
  from theano.tests.unittest_tools import attr
label_desc: Use image node_id 2 for calling the TestKeepDims obj's underlying member method code with example usage: obj.test_keepdims() without return types