运行和验证

操作步骤

  1. 使用PuTTY工具,以root用户登录服务器。
  2. 执行以下命令创建测试文件test.py。

    1. 新建“test.py”文件。
      vim test.py
    2. 按“i”进入编辑模式,在文件中输入以下内容。
      import theano
      from theano import tensor
      ##declare two symbolic floating-point scalars
      a = tensor.dscalar()
      b = tensor.dscalar()
      ##create a simple expression
      c = a + b
      ##convert the expression into a callable object that takes (a,b)
      ##values as input and computes a value for c
      f = theano.function([a,b], c)
      ##bind 1.5 to ‘a’, 2.5 to ‘b’, and evaluate ‘c’
      assert 4.0 == f(1.5, 2.5)
    3. 按“Esc”键,输入:wq!,按“Enter”保存并退出编辑。

  3. 执行以下命令测试。

    python3 test.py

    运行的示例不提供任何输出,则证明结论1.5+2.5=4.0是真实的。

  4. 执行以下命令创建测试文件test2.py。

    1. 新建“test2.py”文件。
      vim test2.py
    2. 按“i”进入编辑模式,在文件中输入以下内容。
      import theano
      from theano import tensor
      ##declare two symbolic floating-point scalars
      a = tensor.dscalar()
      b = tensor.dscalar()
      ##create a simple expression
      c = a + b
      ##convert the expression into a callable object that takes (a,b)
      ##values as input and computes a value for c
      f = theano.function([a,b], c)
      ##bind 1.5 to ‘a’, 2.5 to ‘b’, and evaluate ‘c’
      assert 4.5== f(1.5, 2.5)
    3. 按“Esc”键,输入:wq!,按“Enter”保存并退出编辑。

  5. 执行以下命令再次测试。

    python3 test2.py

    运行的示例将会报错,证明结论1.5+2.5=4.5是错误的。