code: def test_sparse_vs_dense_updates(
      tmpdir, learner, gpu_only, checkpoint, device_id
  ):
      if device_id == -1 and gpu_only:
          pytest.skip(
              "Test for adam, fsadagrad and rmspro currently only runs on GPU"
          )
  
      def session(is_sparse):
          x = C.input_variable((200,), is_sparse=is_sparse)
          w = C.parameter((200, 100))
          y = C.times(x, w)
  
          z = [0] * 100 + [1] * 100
          for i in range(200):
              j = (
                  3 * i * i + 5 * i + 1
              ) % 200  # just a random looking index
              z[i], z[j] = z[j], z[i]
  
          import scipy.sparse
  
          x11 = scipy.sparse.csr_matrix(np.array([1] * 200).astype("f"))
          x01 = scipy.sparse.csr_matrix(np.array(z).astype("f"))
  
          t = C.Trainer(y, y, learner(y.parameters))
  
          w.value = 0 * w.value
          t.train_minibatch({x: [x11]})
          t.train_minibatch({x: [x01]})
          t.train_minibatch({x: [x01]})
          if checkpoint:
              t.save_checkpoint(str(tmpdir.join("checkpoint")))
              t.train_minibatch({x: [x11]})
              t.train_minibatch({x: [x01]})
              t.train_minibatch({x: [x01]})
              t.restore_from_checkpoint(str(tmpdir.join("checkpoint")))
          t.train_minibatch({x: [x01]})
          t.train_minibatch({x: [x01]})
          t.train_minibatch({x: [x11]})
          return w.value
  
      s = session(is_sparse=False)
      d = session(is_sparse=True)
      assert np.allclose(s, d)
  
imports: from __future__ import division, print_function
  import numpy
  import cntk
  from cntk import parameter
  import pytest
  import sys
  import itertools
  from cntk.logging import ProgressPrinter
  from cntk.learners import sgd, learning_rate_schedule, learning_parameter_schedule, UnitType, universal
  from cntk.layers import Dense, Sequential
label_desc: Use image node_id 21 for calling a global function with example usage: test_sparse_vs_dense_updates(tmpdir, learner, gpu_only, checkpoint, device_id) and returns: w