Skip to content

Commit

Permalink
included config.predictable
Browse files Browse the repository at this point in the history
  • Loading branch information
dvd101x committed Jul 12, 2023
1 parent 436e566 commit 5b07776
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/type/matrix/MatrixIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { isInteger } from '../../utils/number.js'
import { factory } from '../../utils/factory.js'

const name = 'Index'
const dependencies = ['ImmutableDenseMatrix']
const dependencies = ['config', 'ImmutableDenseMatrix']

export const createIndexClass = /* #__PURE__ */ factory(name, dependencies, ({ ImmutableDenseMatrix }) => {
export const createIndexClass = /* #__PURE__ */ factory(name, dependencies, ({ config, ImmutableDenseMatrix }) => {
/**
* Create an index. An Index can store ranges and sets for multiple dimensions.
* Matrix.get, Matrix.set, and math.subset accept an Index as input.
Expand Down Expand Up @@ -48,7 +48,7 @@ export const createIndexClass = /* #__PURE__ */ factory(name, dependencies, ({ I
// size
const size = m.size()
// scalar
if (size.length !== 1 || size[0] !== 1) {
if (config.predictable || (size.length !== 1 || size[0] !== 1)) {
this._isScalar = false
}
} else if (typeof arg === 'number') {
Expand Down
2 changes: 2 additions & 0 deletions test/unit-tests/function/matrix/subset.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const subset = math.subset
const matrix = math.matrix
const Range = math.Range
const index = math.index
const mathPredictable = math.create({ predictable: true })

describe('subset', function () {
const a = [[1, 2], [3, 4]]
Expand All @@ -19,6 +20,7 @@ describe('subset', function () {
assert.deepStrictEqual(subset(a, index([true, true], 1)), [[2], [4]])
assert.deepStrictEqual(subset(a, index([false, true], [true, false])), 3)
assert.deepStrictEqual(subset([math.bignumber(2)], index([true])), math.bignumber(2))
assert.deepStrictEqual(subset(a, mathPredictable.index([false, true], [true, false])), [[3]])
})

it('should return an empty value with an empty index', function () {
Expand Down

0 comments on commit 5b07776

Please sign in to comment.