code: def test_constant_output(self):
      # Test that if the output is a constant, we respect the theano memory interface
      f = theano.function([], theano.tensor.constant([4]))
      # print f.maker.fgraph.toposort()
      out = f()
      assert (out == 4).all()
      out[0] = 3
      out2 = f()
      # If the following 2 asserts fail it mean Theano broke it's memory contract.
      assert out2 is not out
      assert (out2 == 4).all()
  
      # Test that if the output is a constant and borrow, we respect the theano memory interface
      f = theano.function(
          [], Out(theano.tensor.constant([4]), borrow=True)
      )
      # print f.maker.fgraph.toposort()
      out = f()
      assert (out == 4).all()
      out[0] = 3
      out2 = f()
  
      if isinstance(
          theano.compile.mode.get_default_mode(),
          theano.compile.DebugMode,
      ):
          # In DebugMode, we don't implement optimization based on borrow on the output.
          assert (out2 == 4).all()
      else:
          assert out2 is out
          assert (out2 == 3).all()
  
imports: from __future__ import absolute_import, print_function, division
  import copy
  import six.moves.cPickle
  import numpy
  import unittest
  import time
  from theano import config, gof
  from six import iteritems
  from theano.compile.io import In, Out
  from theano.compile import function
  from theano.compile import UnusedInputError
  from theano.gof import MissingInputError
  from theano.compat import exc_message
  from theano.tests.unittest_tools import SkipTest
  from theano import tensor
  from theano import tensor
  import theano
label_desc: Use image node_id 24 for calling the T_function obj's underlying member method code with example usage: obj.test_constant_output() without return types