Creates a Tensor from a Java object. A Tensor is a multi-dimensional array of elements of a limited set of types. Not all Java objects can be converted to a Tensor. In particular, the argument obj must be either a primitive (float, double, int, long, boolean, byte) or a m
(Object obj, Class<T> type)
| 102 | * system. |
| 103 | */ |
| 104 | @SuppressWarnings("unchecked") |
| 105 | public static <T> Tensor<T> create(Object obj, Class<T> type) { |
| 106 | DataType dtype = DataType.fromClass(type); |
| 107 | if (!objectCompatWithType(obj, dtype)) { |
| 108 | throw new IllegalArgumentException( |
| 109 | "DataType of object does not match T (expected " |
| 110 | + dtype |
| 111 | + ", got " |
| 112 | + dataTypeOf(obj) |
| 113 | + ")"); |
| 114 | } |
| 115 | return (Tensor<T>) create(obj, dtype); |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Creates a tensor from an object whose class is inspected to figure out what the underlying data |