* Like expression(), but return a nested JS array instead * of a Expression
()
| 174 | this._strides = getStrides(this.shape); |
| 175 | this.holdsFloat = tensorData.holdsFloat === true; |
| 176 | this.field = makeTensorField<DT>(ce, tensorData.dtype, this.holdsFloat); |
| 177 | } |
| 178 | |
| 179 | abstract get dtype(): DT; |
| 180 | abstract get data(): DataTypeMap[DT][]; |
| 181 | |
| 182 | // A Boxed Expression that represents the tensor |
| 183 | get expression(): Expression { |
| 184 | // Recursively fill the tensor with expressions |
| 185 | // according to the shape |
| 186 | |
| 187 | // Base case: scalar |
| 188 | // if (this.rank === 0) return ce.number(this.data[0]); |
| 189 | |
| 190 | // Recursive case: tensor |
| 191 | const shape = this.shape; |
| 192 | const rank = this.rank; |
| 193 | const data = this.data; |
| 194 | const index = this._index.bind(this); |
| 195 | const expression = this.field.expression.bind(this.field); |
| 196 | const fill = (indices: number[]): Expression => { |
| 197 | if (indices.length === rank - 1) { |
| 198 | // Base case: vector |
| 199 | const idx = index(indices); |
| 200 | return this.ce._fn( |
| 201 | 'List', |
| 202 | data.slice(idx, idx + shape[rank - 1]).map((x) => expression(x)) |
| 203 | ); |
| 204 | } else { |
| 205 | // Recursive case: tensor |
| 206 | const list: Expression[] = []; |
| 207 | for (let i = 1; i <= shape[indices.length]; i++) |
| 208 | list.push(fill([...indices, i])); |