code: def test_argsort():
      # Set up
      rng = np.random.RandomState(seed=utt.fetch_seed())
      m_val = rng.rand(3, 2)
      v_val = rng.rand(4)
  
      # Example 1
      a = tensor.dmatrix()
      w = argsort(a)
      f = theano.function([a], w)
      gv = f(m_val)
      gt = np.argsort(m_val)
      utt.assert_allclose(gv, gt)
  
      # Example 2
      a = tensor.dmatrix()
      axis = tensor.lscalar()
      w = argsort(a, axis)
      f = theano.function([a, axis], w)
      for axis_val in 0, 1:
          gv = f(m_val, axis_val)
          gt = np.argsort(m_val, axis_val)
          utt.assert_allclose(gv, gt)
  
      # Example 3
      a = tensor.dvector()
      w2 = argsort(a)
      f = theano.function([a], w2)
      gv = f(v_val)
      gt = np.argsort(v_val)
      utt.assert_allclose(gv, gt)
  
      # Example 4
      a = tensor.dmatrix()
      axis = tensor.lscalar()
      l = argsort(a, axis, "mergesort")
      f = theano.function([a, axis], l)
      for axis_val in 0, 1:
          gv = f(m_val, axis_val)
          gt = np.argsort(m_val, axis_val)
          utt.assert_allclose(gv, gt)
  
      # Example 5
      a = tensor.dmatrix()
      axis = tensor.lscalar()
      a1 = ArgSortOp("mergesort", [])
      a2 = ArgSortOp("quicksort", [])
      # All the below should give true
      assert a1 != a2
      assert a1 == ArgSortOp("mergesort", [])
      assert a2 == ArgSortOp("quicksort", [])
  
      # Example 6: Testing axis=None
      a = tensor.dmatrix()
      w2 = argsort(a, None)
      f = theano.function([a], w2)
      gv = f(m_val)
      gt = np.argsort(m_val, None)
      utt.assert_allclose(gv, gt)
  
imports: from __future__ import absolute_import, print_function, division
  from itertools import product, chain
  from functools import reduce
  import unittest
  from theano.tests import unittest_tools
  import numpy
  import theano
  from theano import tensor
  from theano.tensor.sort import sort, SortOp
  from theano.tensor.sort import argsort, ArgSortOp
  from theano.tensor.sort import topk, argtopk, topk_and_argtopk, TopKOp
label_desc: Use image node_id 2 for calling a global function with example usage: test_argsort() without return types