code: def test_np_loss_ndarray():
      # Ported from test_loss.test_loss_ndarray
      output = np.array([1, 2, 3, 4])
      label = np.array([1, 3, 5, 7])
      weighting = np.array([0.5, 1, 0.5, 1])
  
      loss = gluon.loss.L1Loss()
      assert float(np.sum(loss(output, label))) == 6.0
      loss = gluon.loss.L1Loss(weight=0.5)
      assert float(np.sum(loss(output, label))) == 3.0
      loss = gluon.loss.L1Loss()
      assert float(np.sum(loss(output, label, weighting))) == 5.0
  
      loss = gluon.loss.L2Loss()
      assert float(np.sum(loss(output, label))) == 7.0
      loss = gluon.loss.L2Loss(weight=0.25)
      assert float(np.sum(loss(output, label))) == 1.75
      loss = gluon.loss.L2Loss()
      assert float(np.sum(loss(output, label, weighting))) == 6
  
      output = np.array([[0, 2], [1, 4]])
      label = np.array([0, 1])
      weighting = np.array([[0.5], [1.0]])
  
      loss = gluon.loss.SoftmaxCrossEntropyLoss()
      L = loss(output, label).asnumpy()
      assert_almost_equal(
          L,
          _np.array([2.12692809, 0.04858733]),
          use_broadcast=False,
          rtol=1e-3,
      )
  
      L = loss(output, label, weighting).asnumpy()
      assert_almost_equal(
          L,
          _np.array([1.06346405, 0.04858733]),
          use_broadcast=False,
          rtol=1e-3,
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  import os
  from uuid import uuid4
  import numpy
  import mxnet
  from mxnet import gluon, autograd, np, npx
  from mxnet.test_utils import use_np, assert_almost_equal, check_gluon_hybridize_consistency, assert_allclose
  from mxnet.gluon import nn
  from mxnet.base import MXNetError
  import random
  import pytest
label_desc: Use image node_id 4 for calling a global function with example usage: test_np_loss_ndarray() without return types