|
| 1 | +import assert from 'assert' |
| 2 | +import math from '../../../../src/defaultInstance.js' |
| 3 | + |
| 4 | +describe('broadcastSizes', function () { |
| 5 | + it('should broadcast sizes', function () { |
| 6 | + assert.deepStrictEqual(math.broadcastSizes([2, 3]), [2, 3]) |
| 7 | + assert.deepStrictEqual(math.broadcastSizes([3, 3], [3, 1]), [3, 3]) |
| 8 | + assert.deepStrictEqual(math.broadcastSizes([2, 1], [1, 3]), [2, 3]) |
| 9 | + assert.deepStrictEqual(math.broadcastSizes([5, 4, 3], [1, 4, 1]), [5, 4, 3]) |
| 10 | + assert.deepStrictEqual(math.broadcastSizes([3], [2, 3]), [2, 3]) |
| 11 | + assert.deepStrictEqual(math.broadcastSizes([1, 3], [2, 1]), [2, 3]) |
| 12 | + }) |
| 13 | + |
| 14 | + it('should throw an error if sizes are not compatible', function () { |
| 15 | + assert.throws(function () { math.broadcastSizes([2, 3], [3, 2]) }, /Error: shape mismatch: /) |
| 16 | + assert.throws(function () { math.broadcastSizes([2, 3], [2, 3, 4]) }, /Error: shape mismatch: /) |
| 17 | + }) |
| 18 | + |
| 19 | + it('should broadcast sizes of mixed arrays and matrices', function () { |
| 20 | + assert.deepStrictEqual(math.broadcastSizes([3, 3], math.matrix([3, 1])), [3, 3]) |
| 21 | + assert.deepStrictEqual(math.broadcastSizes(math.matrix([2, 1]), [1, 3]), [2, 3]) |
| 22 | + assert.deepStrictEqual(math.broadcastSizes(math.matrix([5, 4, 3]), math.matrix([1, 4, 1])), [5, 4, 3]) |
| 23 | + }) |
| 24 | +}) |
0 commit comments