MCPcopy Create free account
hub / github.com/apache/singa / numpy2tensors

Function numpy2tensors

examples/rnn/char_rnn.py:124–143  ·  view source on GitHub ↗

batch, seq, dim -- > seq, batch, dim

(npx, npy, dev, inputs=None, labels=None)

Source from the content-addressed store, hash-verified

122
123
124def numpy2tensors(npx, npy, dev, inputs=None, labels=None):
125 '''batch, seq, dim -- > seq, batch, dim'''
126 tmpy = np.swapaxes(npy, 0, 1).reshape((-1, 1))
127 if labels:
128 labels.copy_from_numpy(tmpy)
129 else:
130 labels = tensor.from_numpy(tmpy)
131 labels.to_device(dev)
132 tmpx = np.swapaxes(npx, 0, 1)
133 inputs_ = []
134 for t in range(tmpx.shape[0]):
135 if inputs:
136 inputs[t].copy_from_numpy(tmpx[t])
137 else:
138 x = tensor.from_numpy(tmpx[t])
139 x.to_device(dev)
140 inputs_.append(x)
141 if not inputs:
142 inputs = inputs_
143 return inputs, labels
144
145
146def convert(batch,

Callers 1

convertFunction · 0.70

Calls 4

appendMethod · 0.80
reshapeMethod · 0.45
copy_from_numpyMethod · 0.45
to_deviceMethod · 0.45

Tested by

no test coverage detected