MCPcopy Index your code
hub / github.com/josdejong/mathjs / processSizesWildcard

Function processSizesWildcard

src/utils/array.js:291–313  ·  view source on GitHub ↗
(sizes, currentLength)

Source from the content-addressed store, hash-verified

289 * @returns {number[]} The sizes array with wildcard replaced.
290 */
291export function processSizesWildcard (sizes, currentLength) {
292 const newLength = product(sizes)
293 const processedSizes = sizes.slice()
294 const WILDCARD = -1
295 const wildCardIndex = sizes.indexOf(WILDCARD)
296
297 const isMoreThanOneWildcard = sizes.indexOf(WILDCARD, wildCardIndex + 1) >= 0
298 if (isMoreThanOneWildcard) {
299 throw new Error('More than one wildcard in sizes')
300 }
301
302 const hasWildcard = wildCardIndex >= 0
303 const canReplaceWildcard = currentLength % newLength === 0
304
305 if (hasWildcard) {
306 if (canReplaceWildcard) {
307 processedSizes[wildCardIndex] = -currentLength / newLength
308 } else {
309 throw new Error('Could not replace wildcard, since ' + currentLength + ' is no multiple of ' + (-newLength))
310 }
311 }
312 return processedSizes
313}
314
315/**
316 * Computes the product of all array elements.

Callers 3

SparseMatrix.jsFile · 0.90
DenseMatrix.jsFile · 0.90
reshapeFunction · 0.85

Calls 1

productFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…