Ejemplo n.º 1
0
## Indexing with a zero-dimensional Boolean array
import pyOcean_cpu as ocean

a = ocean.asTensor(True,ocean.bool);
b = ocean.zeros([3,3])
b[a] = 3
print(b)
Ejemplo n.º 2
0
import pyOcean_cpu as ocean

a = ocean.zeros([3, 4], ocean.float)
print(a)
a.dealloc()
print(a)
print(a.storage)
Ejemplo n.º 3
0
print("## Index binding")
idx = ocean.index[[1, 2, 3]]
idx.bind([5], True)
failTest("idx.bind([5,7],True)")
failTest("idx.bind([6],True)")
idx.bind([5], [8], True)
failTest("idx.bind([5],[4],True)")

idx = ocean.index[1, 3]
idx.bind([5, 5], True)
failTest("idx.bind([5,6,7])")

print("\n## Scalar")
idx = ocean.index[10]
failTest("idx.bind([5],True)")
idx = ocean.index[1, 2, 3]
failTest("idx.bind([5,5,2],True)")

print("\n## Indices")
idx = ocean.index[1, [1, 2, 10]]
failTest("idx.bind([5,5])")

print("\n## Mask")
idx = ocean.index[ocean.zeros([5, 6], ocean.bool)]
failTest("idx.bind([5,5])")

print("\n## Ellipsis")
idx = ocean.index[1, ..., 3, ..., 5]
failTest("idx.bind([5,5,5])")
Ejemplo n.º 4
0
import pyOcean_cpu as ocean

a = ocean.zeros([3,4,5])

a[1,2,3] = 4
a[-1,-1,-1] = 99
print(a)

Ejemplo n.º 5
0
import pyOcean_cpu as ocean

a = ocean.zeros([0, 5], ocean.float)
b = ocean.ones([5], ocean.float)
c = a * b
print(c)
Ejemplo n.º 6
0
import pyOcean_cpu as ocean

a = ocean.zeros([5, 0], ocean.float)
b = ocean.ones([0, 5], ocean.float)
c = a * b
print(c)
Ejemplo n.º 7
0
import pyOcean_cpu as ocean

a = ocean.zeros([5,5])
a[1,...,3] = 99
print(a)
Ejemplo n.º 8
0
## Set index with byteswapped data
import pyOcean_cpu as ocean
import sys


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


# Tensor is byteswapped
A = ocean.zeros([4, 5])
A.byteswap()

A[2:4, 1:3] = 3
print(A)

B = ocean.arange(2 * 2).reshape(2, 2) + 1
print(B)

A.fill(0)
A[1:3, 2:4] = B
print(A)

B.byteswap()
A.fill(0)
A[2:0:-1, 3:1:-1] = B
print(A)

A = ocean.zeros([4, 5])
A[[0, 3], [3, 0]] = B
print(A)
Ejemplo n.º 9
0
import pyOcean_cpu as ocean

a = ocean.zeros([3, 4])
print(a)

a = ocean.zeros([3, 4], ocean.int8)
print(a)

a = ocean.zeros([3, 4], ocean.cpu)
print(a)

a = ocean.zeros([3, 4], ocean.float, ocean.cpu)
print(a)