code: def test_times_2d_sparse_operand(device_id):
      from .. import times
  
      dev = cntk_device(device_id)
  
      vocab_size = 6
      sample_shape = (2, vocab_size)
      input_sparse_indices = [[1, 3], [2, 4], [0, 2]]
      input_data = C.Value.one_hot(
          input_sparse_indices, sample_shape, device=dev
      )
  
      a = C.sequence.input_variable(
          shape=sample_shape,
          is_sparse=True,
          needs_gradient=True,
          name="a",
      )
      w_init = np.eye(vocab_size, dtype=np.float32)
      w = C.parameter(init=w_init, device=dev)
      a_dense = times(a, w)
  
      # TODO: Also test the results from grad
      grad = a_dense.grad(
          {a: input_data}, [w, a], as_numpy=False, device=dev
      )
  
      res = a_dense.eval({a: input_data}, device=dev)
      assert np.array_equal(
          res,
          [
              [w_init[input_sparse_indices[0]]],
              [w_init[input_sparse_indices[1]]],
              [w_init[input_sparse_indices[2]]],
          ],
      )
  
      a_no_sequence = C.input_variable(
          shape=sample_shape, is_sparse=True, name="a"
      )
      a_no_sequence_dense = times(a_no_sequence, w)
      res = a_no_sequence_dense.eval(
          {a_no_sequence: input_data}, device=dev
      )
      assert np.array_equal(
          res,
          [
              w_init[input_sparse_indices[0]],
              w_init[input_sparse_indices[1]],
              w_init[input_sparse_indices[2]],
          ],
      )
  
imports: import numpy
  import scipy
  import pytest
  import cntk
  from .ops_test_utils import cntk_device
  from cntk.axis import Axis
  from ..None import constant
  from cntk.tests.test_utils import _to_dense
label_desc: Use image node_id 1 for calling a global function with example usage: test_times_2d_sparse_operand(device_id) without return types