MCPcopy
hub / github.com/josdejong/mathjs / reshape

Function reshape

src/utils/array.js:248–282  ·  view source on GitHub ↗
(array, sizes)

Source from the content-addressed store, hash-verified

246 * not equal that of the old ones
247 */
248export 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.

Callers 4

array.test.jsFile · 0.90
DenseMatrix.jsFile · 0.90
orthogonalComplementFunction · 0.85
broadcastToFunction · 0.85

Calls 4

processSizesWildcardFunction · 0.85
_reshapeFunction · 0.85
flattenFunction · 0.70
productFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…