forked from tensorflow/tensorflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfast_tensor_util.pyx
More file actions
115 lines (90 loc) · 2.99 KB
/
fast_tensor_util.pyx
File metadata and controls
115 lines (90 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#cython: boundscheck=False
#cython: wraparound=False
#cython: infer_types=True
import numpy as np
cimport numpy as np
from tensorflow.python.util import compat
def AppendFloat32ArrayToTensorProto(
tensor_proto, np.ndarray[np.float32_t, ndim=1] nparray):
cdef long i, n
n = nparray.size
for i in range(n):
tensor_proto.float_val.append(nparray[i])
def AppendFloat64ArrayToTensorProto(
tensor_proto, np.ndarray[np.float64_t, ndim=1] nparray):
cdef long i, n
n = nparray.size
for i in range(n):
tensor_proto.double_val.append(nparray[i])
def AppendInt32ArrayToTensorProto(
tensor_proto, np.ndarray[np.int32_t, ndim=1] nparray):
cdef long i, n
n = nparray.size
for i in range(n):
tensor_proto.int_val.append(nparray[i])
def AppendUInt32ArrayToTensorProto(
tensor_proto, np.ndarray[np.uint32_t, ndim=1] nparray):
cdef long i, n
n = nparray.size
for i in range(n):
tensor_proto.uint32_val.append(nparray[i])
def AppendInt64ArrayToTensorProto(
tensor_proto, np.ndarray[np.int64_t, ndim=1] nparray):
cdef long i, n
n = nparray.size
for i in range(n):
tensor_proto.int64_val.append(nparray[i])
def AppendUInt64ArrayToTensorProto(
tensor_proto, np.ndarray[np.uint64_t, ndim=1] nparray):
cdef long i, n
n = nparray.size
for i in range(n):
tensor_proto.uint64_val.append(nparray[i])
def AppendUInt8ArrayToTensorProto(
tensor_proto, np.ndarray[np.uint8_t, ndim=1] nparray):
cdef long i, n
n = nparray.size
for i in range(n):
tensor_proto.int_val.append(nparray[i])
def AppendUInt16ArrayToTensorProto(
tensor_proto, np.ndarray[np.uint16_t, ndim=1] nparray):
cdef long i, n
n = nparray.size
for i in range(n):
tensor_proto.int_val.append(nparray[i])
def AppendInt16ArrayToTensorProto(
tensor_proto, np.ndarray[np.int16_t, ndim=1] nparray):
cdef long i, n
n = nparray.size
for i in range(n):
tensor_proto.int_val.append(nparray[i])
def AppendInt8ArrayToTensorProto(
tensor_proto, np.ndarray[np.int8_t, ndim=1] nparray):
cdef long i, n
n = nparray.size
for i in range(n):
tensor_proto.int_val.append(nparray[i])
def AppendComplex64ArrayToTensorProto(
tensor_proto, np.ndarray[np.complex64_t, ndim=1] nparray):
cdef long i, n
n = nparray.size
for i in range(n):
tensor_proto.scomplex_val.append(nparray[i].real)
tensor_proto.scomplex_val.append(nparray[i].imag)
def AppendComplex128ArrayToTensorProto(
tensor_proto, np.ndarray[np.complex128_t, ndim=1] nparray):
cdef long i, n
n = nparray.size
for i in range(n):
tensor_proto.dcomplex_val.append(nparray[i].real)
tensor_proto.dcomplex_val.append(nparray[i].imag)
def AppendObjectArrayToTensorProto(tensor_proto, np.ndarray nparray):
cdef long i, n
n = nparray.size
for i in range(n):
tensor_proto.string_val.append(compat.as_bytes(nparray[i]))
def AppendBoolArrayToTensorProto(tensor_proto, nparray):
cdef long i, n
n = nparray.size
for i in range(n):
tensor_proto.bool_val.append(np.asscalar(nparray[i]))