## Square-root operation with overlap import pyOcean_cpu as ocean a = ocean.asTensor([4, 9, 16, 25]) a1 = ocean.tensor(a.storage, 0, [3]) a2 = ocean.tensor(a.storage, 1, [3]) print(a1) print(a2) ocean.sqrt(a1, a2) print(a1) print(a2)
import pyOcean_cpu as ocean import pyOceanNumpy import numpy as np # 0 + 0j a = np.asarray([0 + 0j], np.complex64) a = a[0] print("Input: %s" % a) print(np.sqrt(a)) print(ocean.sqrt(a)) # 0 + NaNj a = np.asarray([0 + 0j], np.complex64) a.imag[0] = np.nan a = a[0] print("\nInput: %s" % a) print(np.sqrt(a)) print(ocean.sqrt(a)) # NaN + 2j a = np.asarray([0 + 2j], np.complex64) a.real[0] = np.nan a = a[0] print("\nInput: %s" % a) print(np.sqrt(a)) print(ocean.sqrt(a)) # 1 + inf*j a = np.asarray([1 + 0j]) a.imag[0] = np.inf a = a[0]
import pyOcean_cpu as ocean import sys a = ocean.double(2) print(ocean.sqrt(a)) a = ocean.half(2) print(ocean.sqrt(a)) a = ocean.cdouble(1 + 2j) print(ocean.sqrt(a)) print(ocean.sqrt(2.0)) print(ocean.sqrt(1 - 2j))
import pyOcean_cpu as ocean a = ocean.arange(10,ocean.double) a.byteswap() print(a) print(ocean.sqrt(a)) ocean.sqrt(a,a) print(a)
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() # Unsigned integer (8) a = ocean.arange(5,ocean.uint8) print(ocean.sqrt(a)) # Different types types = [ocean.int16, ocean.half, ocean.float, ocean.cdouble] for t in types : a = ocean.linspace(-5,5,11,t) print(ocean.sqrt(a)) # Result in unsigned integer a = ocean.arange(-5,5,ocean.int8) b = ocean.tensor(a.size, ocean.uint8) ocean.sqrt(a,b) print(b)