| 137 | |
| 138 | // Broadcast the data |
| 139 | const data = lhs_.data.map((v, i) => fn(v, rhs_.data[i])); |
| 140 | |
| 141 | // A result computed from a float tensor is a float tensor. |
| 142 | return makeTensor(lhs_.ce, { |
| 143 | dtype: lhs_.dtype, |
| 144 | holdsFloat: lhs_.holdsFloat || rhs_.holdsFloat, |
| 145 | shape: lhs_.shape, |
| 146 | data, |
| 147 | }); |
| 148 | } |
| 149 | |
| 150 | // The arithmetic operations that can be performed on the |
| 151 | // elements of the tensor, based on the datatype |
| 152 | readonly field: TensorField<DataTypeMap[DT]>; |
| 153 | |
| 154 | readonly shape: number[]; |
| 155 | readonly rank: number; |
| 156 | |
| 157 | /** |
| 158 | * Is this a float tensor (see `TensorData.holdsFloat`)? Then the field |
| 159 | * reads every cell back as a float, also a cell whose value is an |
| 160 | * integer. Every operation that computes a tensor from this one gives the |
| 161 | * new tensor the same flag: a result computed from a float tensor is a |
| 162 | * float tensor. |
| 163 | */ |
| 164 | readonly holdsFloat: boolean; |
| 165 | |
| 166 | private readonly _strides: number[]; |
| 167 | |
| 168 | constructor( |
| 169 | private ce: ComputeEngine, |
| 170 | tensorData: TensorData<DT> |
| 171 | ) { |
| 172 | this.shape = tensorData.shape; |
| 173 | this.rank = this.shape.length; |