code: def test_matrix(self):
      x = tensor.matrix()
      np_x = np.arange(77).reshape(7, 11).astype(theano.config.floatX)
      fn = theano.function([x], GpuExtractDiag()(x), mode=mode_with_gpu)
      assert np.allclose(fn(np_x), np_x.diagonal())
      fn = theano.function(
          [x], GpuExtractDiag(2)(x), mode=mode_with_gpu
      )
      assert np.allclose(fn(np_x), np_x.diagonal(2))
      fn = theano.function(
          [x], GpuExtractDiag(-3)(x), mode=mode_with_gpu
      )
      assert np.allclose(fn(np_x), np_x.diagonal(-3))
  
imports: from __future__ import absolute_import, print_function, division
  import numpy
  import unittest
  import theano
  from theano import tensor
  from theano.compile import DeepCopyOp
  from theano.tensor.tests import test_subtensor, test_basic
  from theano.tests import unittest_tools
  from ..basic_ops import HostFromGpu, GpuFromHost, GpuContiguous
  from ..elemwise import GpuDimShuffle
  from ..subtensor import GpuIncSubtensor, GpuSubtensor, GpuAdvancedSubtensor1, GpuAdvancedSubtensor, GpuAdvancedBooleanSubtensor, GpuAdvancedIncSubtensor, GpuAdvancedIncSubtensor1, GpuAdvancedIncSubtensor1_dev20, GpuExtractDiag, GpuAllocDiag
  from ..type import gpuarray_shared_constructor
  from .config import mode_with_gpu, test_ctx_name
label_desc: Use image node_id 2 for calling the test_gpuextractdiag obj's underlying member method code with example usage: obj.test_matrix() without return types