code: def test_iter_allocate_output_subtype():
      # Make sure that the subtype with priority wins
      # 2018-04-29: moved here from core.tests.test_nditer, given the
      # matrix specific shape test.
  
      # matrix vs ndarray
      a = np.matrix([[1, 2], [3, 4]])
      b = np.arange(4).reshape(2, 2).T
      i = np.nditer(
          [a, b, None],
          [],
          [["readonly"], ["readonly"], ["writeonly", "allocate"]],
      )
      assert_(type(i.operands[2]) is np.matrix)
      assert_(type(i.operands[2]) is not np.ndarray)
      assert_equal(i.operands[2].shape, (2, 2))
  
      # matrix always wants things to be 2D
      b = np.arange(4).reshape(1, 2, 2)
      assert_raises(
          RuntimeError,
          np.nditer,
          [a, b, None],
          [],
          [["readonly"], ["readonly"], ["writeonly", "allocate"]],
      )
      # but if subtypes are disabled, the result can still work
      i = np.nditer(
          [a, b, None],
          [],
          [
              ["readonly"],
              ["readonly"],
              ["writeonly", "allocate", "no_subtype"],
          ],
      )
      assert_(type(i.operands[2]) is np.ndarray)
      assert_(type(i.operands[2]) is not np.matrix)
      assert_equal(i.operands[2].shape, (1, 2, 2))
  
imports: import pytest
  import textwrap
  import warnings
  import numpy
  from numpy.testing import assert_, assert_equal, assert_raises, assert_raises_regex, assert_array_equal, assert_almost_equal, assert_array_almost_equal
label_desc: Use image node_id 8 for calling a global function with example usage: test_iter_allocate_output_subtype() without return types