code: def test001_jacobian_vector():
      x = tensor.vector()
      y = x * 2
      rng = np.random.RandomState(seed=utt.fetch_seed())
  
      # test when the jacobian is called with a tensor as wrt
      Jx = tensor.jacobian(y, x)
      f = theano.function([x], Jx)
      vx = rng.uniform(size=(10,)).astype(theano.config.floatX)
      assert np.allclose(f(vx), np.eye(10) * 2)
  
      # test when the jacobian is called with a tuple as wrt
      Jx = tensor.jacobian(y, (x,))
      assert isinstance(Jx, tuple)
      f = theano.function([x], Jx[0])
      vx = rng.uniform(size=(10,)).astype(theano.config.floatX)
      assert np.allclose(f(vx), np.eye(10) * 2)
  
      # test when the jacobian is called with a list as wrt
      Jx = tensor.jacobian(y, [x])
      assert isinstance(Jx, list)
      f = theano.function([x], Jx[0])
      vx = rng.uniform(size=(10,)).astype(theano.config.floatX)
      assert np.allclose(f(vx), np.eye(10) * 2)
  
      # test when the jacobian is called with a list of two elements
      z = tensor.vector()
      y = x * z
      Js = tensor.jacobian(y, [x, z])
      f = theano.function([x, z], Js)
      vx = rng.uniform(size=(10,)).astype(theano.config.floatX)
      vz = rng.uniform(size=(10,)).astype(theano.config.floatX)
      vJs = f(vx, vz)
      evx = np.zeros((10, 10))
      evz = np.zeros((10, 10))
      np.fill_diagonal(evx, vx)
      np.fill_diagonal(evz, vz)
      assert np.allclose(vJs[0], evz)
      assert np.allclose(vJs[1], evx)
  
file_path: Theano/theano/tests/test_2nd_order_grads.py
imports: from __future__ import absolute_import, print_function, division
  from six.moves import xrange
  from theano.tests import unittest_tools
  import theano
  from theano import tensor
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: test001_jacobian_vector() without return types