code: def test_loss_np_ndarray(hybridize):
      output = mx.np.array([1, 2, 3, 4])
      label = mx.np.array([1, 3, 5, 7])
      weighting = mx.np.array([0.5, 1, 0.5, 1])
  
      loss = gluon.loss.L1Loss()
      if hybridize:
          loss.hybridize()
      assert mx.np.sum(loss(output, label)) == 6.0
      loss = gluon.loss.L1Loss(weight=0.5)
      if hybridize:
          loss.hybridize()
      assert mx.np.sum(loss(output, label)) == 3.0
      loss = gluon.loss.L1Loss()
      if hybridize:
          loss.hybridize()
      assert mx.np.sum(loss(output, label, weighting)) == 5.0
  
      loss = gluon.loss.L2Loss()
      if hybridize:
          loss.hybridize()
      assert mx.np.sum(loss(output, label)) == 7.0
      loss = gluon.loss.L2Loss(weight=0.25)
      if hybridize:
          loss.hybridize()
      assert mx.np.sum(loss(output, label)) == 1.75
      loss = gluon.loss.L2Loss()
      if hybridize:
          loss.hybridize()
      assert mx.np.sum(loss(output, label, weighting)) == 6
  
      loss = gluon.loss.HuberLoss()
      if hybridize:
          loss.hybridize()
      assert mx.np.sum(loss(output, label)) == 4.5
      loss = gluon.loss.HuberLoss(weight=0.25)
      if hybridize:
          loss.hybridize()
      assert mx.np.sum(loss(output, label)) == 1.125
      loss = gluon.loss.HuberLoss()
      if hybridize:
          loss.hybridize()
      assert mx.np.sum(loss(output, label, weighting)) == 3.75
  
      loss = gluon.loss.HingeLoss(margin=10)
      if hybridize:
          loss.hybridize()
      assert mx.np.sum(loss(output, label)) == 13.0
      loss = gluon.loss.HingeLoss(margin=8, weight=0.25)
      if hybridize:
          loss.hybridize()
      assert mx.np.sum(loss(output, label)) == 2.25
      loss = gluon.loss.HingeLoss(margin=7)
      if hybridize:
          loss.hybridize()
      assert mx.np.sum(loss(output, label, weighting)) == 4.0
  
      loss = gluon.loss.SquaredHingeLoss(margin=10)
      if hybridize:
          loss.hybridize()
      assert mx.np.sum(loss(output, label)) == 97.0
      loss = gluon.loss.SquaredHingeLoss(margin=8, weight=0.25)
      if hybridize:
          loss.hybridize()
      assert mx.np.sum(loss(output, label)) == 13.25
      loss = gluon.loss.SquaredHingeLoss(margin=7)
      if hybridize:
          loss.hybridize()
      assert mx.np.sum(loss(output, label, weighting)) == 19.0
  
      loss = gluon.loss.TripletLoss(margin=10)
      if hybridize:
          loss.hybridize()
      assert mx.np.sum(loss(output, label, -label)) == 6.0
      loss = gluon.loss.TripletLoss(margin=8, weight=0.25)
      if hybridize:
          loss.hybridize()
      assert mx.np.sum(loss(output, label, -label)) == 1.0
      loss = gluon.loss.TripletLoss(margin=7)
      if hybridize:
          loss.hybridize()
      assert mx.np.sum(loss(output, label, -label, weighting)) == 1.5
  
      output = mx.np.array([[0, 2], [1, 4]])
      label = mx.np.array([0, 1])
      weighting = mx.np.array([[0.5], [1.0]])
  
      loss = gluon.loss.SoftmaxCrossEntropyLoss()
      if hybridize:
          loss.hybridize()
      L = loss(output, label).asnumpy()
      assert_almost_equal(
          L, onp.array([2.12692809, 0.04858733]), rtol=1e-3, atol=1e-4
      )
  
      loss = gluon.loss.SoftmaxCrossEntropyLoss()
      if hybridize:
          loss.hybridize()
      L = loss(output, label, weighting).asnumpy()
      assert_almost_equal(
          L, onp.array([1.06346405, 0.04858733]), rtol=1e-3, atol=1e-4
      )
  
file_path: mxnet/tests/python/unittest/test_numpy_loss.py
imports: import mxnet
  import numpy
  from mxnet import gluon, autograd
  from mxnet.test_utils import assert_almost_equal, default_device, use_np
  from common import xfail_when_nonstandard_decimal_separator
  import pytest
label_desc: Use image node_id 1 for calling a global function with example usage: test_loss_np_ndarray(hybridize) without return types