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()


# Create a scalar
s = ocean.int8(9)
print(s)
print(type(s))

# Casting with device gives tensor output
print(ocean.cpu(s))

# In-place casting with device gives an error
failTest("ocean.cpu(s,True)")
Exemple #2
0
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.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)
import pyOcean_cpu as ocean

print("Initialization: a = 17 (1001), b = 3 (011)")
b = ocean.int8(3)

print("\n------ a & b, ocean.bitwiseAnd(a,b), a &= b ------")
a = ocean.int8(17)
print(a & b)
print(ocean.bitwiseAnd(a, b))
a &= b
print(a)

print("\n------ a | b, ocean.bitwiseOr(a,b), a |= b ------")
a = ocean.int8(17)
print(a | b)
print(ocean.bitwiseOr(a, b))
a |= b
print(a)

print("\n------ a ^ b, ocean.bitwiseXor(a,b), a ^= b ------")
a = ocean.int8(17)
print(a ^ b)
print(ocean.bitwiseXor(a, b))
a ^= b
print(a)
Exemple #5
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([]))
Exemple #6
0
import sys


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


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)
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)
Exemple #8
0
import pyOcean_cpu as ocean

s = ocean.scalar([1])
print(s)

s = ocean.scalar(ocean.int8(3), ocean.double)
print(s)

s = ocean.scalar()