convert a const numpy 1-dimensional vector to tvm tensor Parameters ---------- vector: numpy.ndarray Const input array name: str, optional The name of output op Returns ------- tensor: Tensor The created tensor
(vector, name="const_vector")
| 209 | |
| 210 | |
| 211 | def const_vector(vector, name="const_vector"): |
| 212 | """convert a const numpy 1-dimensional vector to tvm tensor |
| 213 | |
| 214 | Parameters |
| 215 | ---------- |
| 216 | vector: numpy.ndarray |
| 217 | Const input array |
| 218 | name: str, optional |
| 219 | The name of output op |
| 220 | |
| 221 | Returns |
| 222 | ------- |
| 223 | tensor: Tensor |
| 224 | The created tensor |
| 225 | """ |
| 226 | if not isinstance(vector, np.ndarray): |
| 227 | vector = np.array(vector) |
| 228 | row = vector.shape[0] |
| 229 | dtype = str(vector.dtype) |
| 230 | idxm = tvm.tirx.indexmod |
| 231 | |
| 232 | def select_array(i): |
| 233 | now = tvm.tirx.const(0.0, dtype) |
| 234 | for ii in range(row): |
| 235 | now = tvm.tirx.Select( |
| 236 | tvm.tirx.all(idxm(i, row) == ii), tvm.tirx.const(vector[ii], dtype), now |
| 237 | ) |
| 238 | return now |
| 239 | |
| 240 | return te.compute(vector.shape, select_array, name=name) |
| 241 | |
| 242 | |
| 243 | def get_float_tuple(in_tuple): |
no test coverage detected
searching dependent graphs…