(array, sizes)
| 246 | * not equal that of the old ones |
| 247 | */ |
| 248 | export function reshape (array, sizes) { |
| 249 | const flatArray = flatten(array, true) // since it has rectangular |
| 250 | const currentLength = flatArray.length |
| 251 | |
| 252 | if (!Array.isArray(array) || !Array.isArray(sizes)) { |
| 253 | throw new TypeError('Array expected') |
| 254 | } |
| 255 | |
| 256 | if (sizes.length === 0) { |
| 257 | throw new DimensionError(0, currentLength, '!=') |
| 258 | } |
| 259 | |
| 260 | sizes = processSizesWildcard(sizes, currentLength) |
| 261 | const newLength = product(sizes) |
| 262 | if (currentLength !== newLength) { |
| 263 | throw new DimensionError( |
| 264 | newLength, |
| 265 | currentLength, |
| 266 | '!=' |
| 267 | ) |
| 268 | } |
| 269 | |
| 270 | try { |
| 271 | return _reshape(flatArray, sizes) |
| 272 | } catch (e) { |
| 273 | if (e instanceof DimensionError) { |
| 274 | throw new DimensionError( |
| 275 | newLength, |
| 276 | currentLength, |
| 277 | '!=' |
| 278 | ) |
| 279 | } |
| 280 | throw e |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Replaces the wildcard -1 in the sizes array. |
no test coverage detected
searching dependent graphs…