HPMC User Guide v 1.00
© 2022 Bassem W. Jamaleddine


3-3

   Theano Programming

HPMC calculators have Theano already installed on them.

Theano is a Python library that allows you to define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays efficiently. Theano combines the convenience of NumPy's syntax.

■ Theano Example

You can program in python and run theano on your HPMC.



python exthea1.py

07:10 qn001: /appz/theano # python exthea1.py
Using gpu device 0: Graphics Device
[GpuElemwise{exp,no_inplace}(<CudaNdarrayType(float32, vector)>), HostFromGpu(GpuElemwise{exp,no_inplace}.0)]
Looping 1000 times took 0.429893016815 seconds
Result is [ 1.23178029  1.61879349  1.52278066 ...,  2.20771813  2.29967761
  1.62323296]
Used the gpu




python exthea2.py

07:11 qn001: /appz/theano # python exthea2.py
Using gpu device 0: Graphics Device
[GpuElemwise{exp,no_inplace}(<CudaNdarrayType(float32, vector)>)]
Looping 1000 times took 0.204324007034 seconds
Result is <CudaNdarray object at 0x6f05130>
Numpy result is [ 1.23178029  1.61879349  1.52278066 ...,  2.20771813  2.29967761
  1.62323296]
Used the gpu




python exthea3.py

07:11 qn001: /appz/theano # python exthea3.py
Using gpu device 0: Graphics Device
Used the gpu
target values for D
[ 1.  0.  1.  1.  0.  1.  1.  0.  0.  0.  0.  1.  0.  0.  1.  0.  0.  1.
  0.  0.  0.  1.  0.  0.  1.  0.  0.  0.  0.  0.  1.  1.  1.  1.  1.  0.
  0.  0.  0.  1.  1.  0.  1.  0.  0.  0.  1.  0.  0.  1.  1.  0.  0.  0.
  1.  0.  1.  1.  0.  1.  1.  1.  1.  0.  0.  1.  1.  1.  0.  1.  1.  0.
  1.  1.  1.  1.  0.  1.  0.  1.  1.  1.  1.  0.  0.  0.  1.  1.  1.  0.
  1.  0.  0.  0.  0.  1.  0.  0.  1.  1.  1.  1.  0.  1.  1.  1.  0.  0.
  0.  0.  1.  0.  0.  0.  1.  0.  0.  1.  1.  1.  1.  0.  0.  0.  1.  1.
  1.  0.  1.  0.  0.  0.  0.  0.  1.  0.  1.  0.  1.  1.  1.  0.  0.  0.
  1.  1.  0.  0.  0.  1.  1.  0.  0.  1.  1.  0.  1.  1.  0.  0.  0.  1.
  0.  1.  0.  1.  0.  0.  1.  0.  1.  0.  0.  1.  1.  1.  0.  1.  0.  0.
  1.  1.  0.  1.  0.  0.  0.  0.  1.  1.  1.  1.  0.  1.  1.  1.  0.  0.
  0.  1.  1.  1.  0.  0.  1.  1.  0.  1.  1.  0.  1.  1.  1.  1.  1.  0.
  0.  0.  0.  0.  0.  1.  0.  0.  1.  0.  0.  0.  0.  1.  0.  0.  0.  1.
  0.  1.  1.  0.  1.  1.  1.  1.  1.  1.  1.  1.  0.  1.  0.  0.  1.  1.
  1.  0.  1.  1.  0.  1.  0.  0.  0.  1.  0.  0.  1.  1.  0.  1.  0.  0.
  0.  1.  1.  1.  0.  1.  0.  0.  0.  1.  1.  1.  0.  0.  0.  1.  1.  1.
  0.  1.  0.  0.  0.  1.  1.  0.  0.  1.  1.  1.  0.  0.  1.  1.  1.  0.
  1.  0.  1.  1.  1.  1.  1.  0.  1.  0.  0.  1.  0.  0.  1.  1.  0.  1.
  1.  1.  1.  1.  1.  1.  0.  0.  0.  0.  0.  1.  1.  0.  1.  1.  1.  1.
  1.  1.  1.  1.  1.  1.  0.  1.  1.  0.  1.  1.  1.  1.  0.  0.  0.  0.
  0.  0.  0.  1.  0.  1.  1.  1.  0.  1.  1.  0.  1.  0.  1.  1.  1.  1.
  1.  0.  0.  1.  1.  1.  0.  0.  0.  1.  0.  1.  0.  1.  0.  1.  1.  1.
  1.  1.  0.  0.]
prediction on D
[1 0 1 1 0 1 1 0 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 1 1 1 1 1 0 0
 0 0 1 1 0 1 0 0 0 1 0 0 1 1 0 0 0 1 0 1 1 0 1 1 1 1 0 0 1 1 1 0 1 1 0 1 1
 1 1 0 1 0 1 1 1 1 0 0 0 1 1 1 0 1 0 0 0 0 1 0 0 1 1 1 1 0 1 1 1 0 0 0 0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