import pyOcean_cpu as ocean a = ocean.int8(0) print(a) a.imag = 3 print(a) a.real = -1 print(a) print(a.dtype) a = ocean.float(3) a.imag = ocean.float(2) print(a) print(a.dtype)
## 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)
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())
import pyOcean_cpu as ocean a = ocean.asTensor([[1, 2], [3, 4]], 'r', ocean.float) b = ocean.arange(6, ocean.float).reshape([2, 3]) print(a) print(b) print(ocean.gemm(ocean.float(3), a, b)) alpha = ocean.asTensor([1, 2, 3], ocean.float).reshape([1, 1, 3]) print(ocean.gemm(alpha, a, b)) print(ocean.gemm(ocean.float(1), a.T, b))
import pyOcean_cpu as ocean a = ocean.asTensor([[1 + 2j, 2 + 1j], [3 + 0j, 4 + 2j]], 'r', ocean.cfloat) b = ocean.asTensor([1 + 1j, 2 - 3j], ocean.cfloat) print(ocean.gemm(ocean.float(1), a, b))
import pyOcean_cpu as ocean # Type casting applied to storage objects s = ocean.asTensor([1, 2, 3]).storage print(s) t = ocean.int8(s) print(t) ocean.float(s, True) print(s)
import pyOcean_cpu as ocean a = ocean.float([1.0]) b = ocean.cdouble(1.0 + 0.01j) c = ocean.cdouble(1.0 - 0.01j) print([ocean.allLT(a, b), True]) print([ocean.allLT(a, c), False]) print([ocean.allGT(a, b), False]) print([ocean.allGE(a, c), True])
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))
import pyOcean_cpu as ocean a = [-20, 20, -20, 20] b = [3, 3, -3, -3] c = [1, 2, -2, -1] print(ocean.mod(ocean.int64(a), ocean.int64(b))) print(ocean.mod(ocean.float(a), ocean.float(b))) print(ocean.mod(ocean.double(a), ocean.double(b))) print(ocean.int64(c)) print("") c = [-2, 2, -2, 2] print(ocean.fmod(ocean.int64(a), ocean.int64(b))) print(ocean.fmod(ocean.float(a), ocean.float(b))) print(ocean.fmod(ocean.double(a), ocean.double(b))) print(ocean.int64(c))
import pyOcean_cpu as ocean a = ocean.asTensor([[0, 1], [2, 3]], 'r', ocean.float) b = ocean.asTensor([1, 2], ocean.float) c = ocean.tensor([2, 1, 3], ocean.float) ocean.gemm(ocean.float(1), a, b, 0, c) print(c)
import pyOcean_cpu as ocean # Type casting applied to tensor objects a = ocean.asTensor([1, 2, 3]) print(a) b = ocean.int8(a) print(b) ocean.float(a, True) print(a)