code: def optimize_layout(optimize=True):
      prev = ctypes.c_bool()
      check_call(_LIB.MXGetOptimizeLayout(ctypes.byref(prev)))
      check_call(_LIB.MXSetOptimizeLayout(ctypes.c_bool(optimize)))
      try:
          yield
      finally:
          check_call(_LIB.MXSetOptimizeLayout(prev))
  
imports: from contextlib import contextmanager
  import ctypes
  import numpy
  import pytest
  import mxnet
  from mxnet import amp
  from mxnet.base import check_call, _LIB
  from mxnet.gluon import nn
  from mxnet.test_utils import assert_allclose
label_desc: Use image node_id 3 for calling a global function with example usage: optimize_layout(optimize) without return types