Skip to content

Commit

Permalink
Merge branch 'develop' into nearlyEqual2
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Apr 24, 2024
2 parents d848310 + 80a0ac1 commit a3e2925
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 2 additions & 0 deletions HISTORY.md
Expand Up @@ -2,6 +2,8 @@

# unpublished changes since 12.4.1

- Fix #3192: function `isNaN` returns `false` for `NaN` units in a matrix or
array (#3193). Thanks @lgerin.
- Fix: #3180 fix type definitions of functions `add` and `multiply` to allow
more than two arguments.
- Docs: correct the docs about `traverse` returning void (#3177).
Expand Down
6 changes: 3 additions & 3 deletions src/core/create.js
@@ -1,5 +1,5 @@
import typedFunction from 'typed-function'
import { deepFlatten, isLegacyFactory, values } from '../utils/object.js'
import { deepFlatten, isLegacyFactory } from '../utils/object.js'
import * as emitter from './../utils/emitter.js'
import { importFactory } from './function/import.js'
import { configFactory } from './function/config.js'
Expand Down Expand Up @@ -219,7 +219,7 @@ export function create (factories, config) {
// listen for changes in config, import all functions again when changed
// TODO: move this listener into the import function?
math.on('config', () => {
values(importedFactories).forEach(factory => {
Object.values(importedFactories).forEach(factory => {
if (factory && factory.meta && factory.meta.recreateOnConfigChange) {
// FIXME: only re-create when the current instance is the same as was initially created
// FIXME: delete the functions/constants before importing them again?
Expand All @@ -237,7 +237,7 @@ export function create (factories, config) {

// import the factory functions like createAdd as an array instead of object,
// else they will get a different naming (`createAdd` instead of `add`).
math.import(values(deepFlatten(factories)))
math.import(Object.values(deepFlatten(factories)))

math.ArgumentsError = ArgumentsError
math.DimensionError = DimensionError
Expand Down
4 changes: 1 addition & 3 deletions src/function/utils/isNaN.js
Expand Up @@ -54,8 +54,6 @@ export const createIsNaN = /* #__PURE__ */ factory(name, dependencies, ({ typed
return Number.isNaN(x.value)
},

'Array | Matrix': function (x) {
return deepMap(x, Number.isNaN)
}
'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
})
})
4 changes: 0 additions & 4 deletions src/utils/object.js
Expand Up @@ -390,10 +390,6 @@ export function pickShallow (object, properties) {
return copy
}

export function values (object) {
return Object.keys(object).map(key => object[key])
}

// helper function to test whether a string contains a path like 'user.name'
function isPath (str) {
return str.indexOf('.') !== -1
Expand Down
8 changes: 6 additions & 2 deletions test/unit-tests/function/utils/isNaN.test.js
Expand Up @@ -59,14 +59,18 @@ describe('isNegative', function () {
assert.strictEqual(isNaN(''), false)
})

it('should test isNegative element wise on an Array', function () {
it('should test isNaN element wise on an Array', function () {
assert.deepStrictEqual(isNaN([0, 5, -2, NaN]), [false, false, false, true])
})

it('should test isNegative element wise on a Matrix', function () {
it('should test isNaN element wise on a Matrix', function () {
assert.deepStrictEqual(isNaN(math.matrix([0, 5, -2, NaN])), math.matrix([false, false, false, true]))
})

it('should test isNaN element wise on a Matrix of units', function () {
assert.deepStrictEqual(isNaN(math.matrix([new Unit(3, 'ft'), new Unit(NaN, 'ft')])), math.matrix([false, true]))
})

it('should throw an error in case of unsupported data types', function () {
assert.throws(function () { isNaN(new Date()) }, /TypeError: Unexpected type of argument/)
assert.throws(function () { isNaN({}) }, /TypeError: Unexpected type of argument/)
Expand Down

0 comments on commit a3e2925

Please sign in to comment.