## Automatic type case and broadcast
import pyOcean_cpu as ocean
import sys

def exceptionMsg() :
   print("Expected error: %s" % str(sys.exc_info()[1]))

def failTest(command) :
   try :
      eval(command)
   except :
      exceptionMsg()


a = ocean.int16([1,2,3])
b = ocean.float([1])

print(a+b)

ocean.setAutoTypecast(False)
print(a+3)

failTest("a+3.2")

print(b+3)
print(b+3.2)
failTest("a+b")


ocean.setAutoBroadcast(False)
print(a+3)
Esempio n. 2
0
import pyOcean_cpu as ocean

a = ocean.bool(0)
print(a.asPython())

a = ocean.int16(1)
print(a.asPython())

a = ocean.float(2)
print(a.asPython())

a = ocean.chalf(3 + 4j)
print(a.asPython())
Esempio n. 3
0
def failTest(command):
    try:
        eval(command)
    except:
        exceptionMsg()


a = ocean.int8(3)
print(a**2)
print(pow(a, 2))
a **= 2
print(a)

failTest("pow(a,2,3)")

print("\n------ Floating point ------")
a = ocean.float(4)
b = ocean.int16(3)
print(a**b)
print(pow(a, b))
a **= b
print(a)

print("\n------ Square root ------")
a = ocean.half(4)
b = a**ocean.half(0.5)
print([b, b.dtype.name])
print(a**0.5)
print(ocean.power(a, 0.5))
print(pow(a, 0.5))
Esempio n. 4
0
import pyOcean_cpu as ocean

# Type casting applied to ad-hoc values
print(ocean.int8(1))
print(ocean.int16([1, 2]))
print(ocean.chalf([[1, 2], [3, 4]]))
print(ocean.bool([]))
Esempio n. 5
0
import pyOcean_cpu as ocean

a = ocean.full([1, 2], 1)
print(a)

a = ocean.full([1, 2], [2.])
print(a)

a = ocean.full([1, 2], ocean.asTensor(3, ocean.double))
print(a)

a = ocean.full([1, 2], ocean.asTensor(4, ocean.double), ocean.int8)
print(a)

a = ocean.full([1, 2], ocean.int16(5), ocean.cpu)
print(a)

a = ocean.full([1, 2], ocean.int16(6), ocean.float, ocean.cpu)
print(a)