Make matrix dependency optional for now in subset (WIP)

This commit is contained in:
jos 2019-05-15 21:25:44 +02:00
parent bd2e68e3ab
commit c8b02fb9f2
3 changed files with 8 additions and 4 deletions

View File

@ -5,7 +5,7 @@ import { errorTransform } from './utils/errorTransform'
import { createSubset } from '../../function/matrix/subset'
const name = 'subset'
const dependencies = ['typed', 'matrix']
const dependencies = ['typed', '?matrix']
export const createSubsetTransform = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix }) => {
const subset = createSubset({ typed, matrix })

View File

@ -72,7 +72,7 @@ import {
} from './plain/number'
import { factory } from './utils/factory'
import { noMatrix, noSubset } from './utils/noop'
import { noSubset } from './utils/noop'
// ----------------------------------------------------------------------------
// classes and functions
@ -171,7 +171,6 @@ export { createNumber } from './type/number'
export { createString } from './type/string'
export { createBoolean } from './type/boolean'
export { createParser } from './expression/function/parser'
export const createMatrix = /* #__PURE__ */ factory('matrix', [], () => noMatrix) // FIXME: needed now because subset transform needs it. Remove the need for it in subset
// expression
export { createNode } from './expression/node/Node'

View File

@ -6,9 +6,10 @@ import { validateIndex } from '../../utils/array'
import { getSafeProperty, setSafeProperty } from '../../utils/customs'
import { DimensionError } from '../../error/DimensionError'
import { factory } from '../../utils/factory'
import { noMatrix } from '../../utils/noop'
const name = 'subset'
const dependencies = ['typed', 'matrix']
const dependencies = ['typed', '?matrix']
export const createSubset = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix }) => {
/**
@ -48,6 +49,10 @@ export const createSubset = /* #__PURE__ */ factory(name, dependencies, ({ typed
return typed(name, {
// get subset
'Array, Index': function (value, index) {
if (!matrix) {
noMatrix()
}
const m = matrix(value)
const subset = m.subset(index) // returns a Matrix
return index.isScalar()