-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Arguments to matrix operations appear to be modified by side effect #2990
Comments
Hmm, I am having trouble reproducing, @pramod-bls. In the version of your code where it is erroring, please just before you call
and just before the call to |
Oh, and can you also do a |
The version is: 11.8.2
Thanks,
Pramod
From: Glen Whitney ***@***.***>
Date: Tuesday, July 4, 2023 at 6:12 PM
To: josdejong/mathjs ***@***.***>
Cc: Pramod Butte ***@***.***>, Mention ***@***.***>
Subject: Re: [josdejong/mathjs] Evaluation/parsing problem in Electron (Issue #2990)
Oh, and can you also do a console.log(math.evaluate('version')) and let us know what that says just for certainty about what version you are running? Just to provide some color here, I am very confused as to how your evaluate that is erroring is getting into the guts of the (matrix) multiply function, when ostensibly the expression you're evaluating has no multiplications in it...
—
Reply to this email directly, view it on GitHub<#2990 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/A6G4I7L4XSS4JVID4QB2FETXOS5Q7ANCNFSM6AAAAAAZ6C76YA>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Great, thanks. Did you also see the request for |
Hmm, no output in that message, at least not that made it to github. Maybe you can use the web interface and put it in a comment? |
Yeah nothing there either. If you are emailing with attached images (for example), it appears the images are being stripped by the Github email processor. |
Yes, that's very helpful. The error is in a different place now that corresponds to the expression you are showing. I'll keep looking. |
Thank you! |
OK, I have reproduced the error without electron. The difficulty is that mathjs is modifying the numerator 2D array in a dotDivide, which is totally counterintuitive and frankly seems like a significant bug in mathjs; simply executing a dotDivide should not have any side effect on its arguments. It seems that it has come up for you because whatever the specifics are of how your 2D arrays are being created, they end up read-only, so the modification fails. Here is the minimal reproducing code I have come up with: import { parse } from 'mathjs'
const scope = {}
scope.Ch0 = {}
scope.Ch0.D40 = [[4,6,8,10],[3,6,9,12]]
Object.freeze(scope.Ch0.D40)
scope.Ch2 = {}
scope.Ch2.D40 = [[2,3,4,5],[3,3,3,3]]
const node = parse('Ch0.D40./Ch2.D40')
const code = node.compile()
console.log(code.evaluate(scope)) which in Node produces the output
I will be frank that it may take some time to track down/fix this apparently pretty deep-seated error. (I will rename this issue and escalate it to the extent possible.) I guess it's never come up before that people have tried to use mathjs on read-only inputs? That's a bit surprising, and also a bit surprising that nobody has noticed them modifying their inputs by side-effect. Apologies that there is this underlying issue, but thanks so much for surfacing it for us! We'll try to delve into it without undue delay. |
Thank you Glen, I did suspect that and hence I even changed to code to have a local modifiable scope like so, var localScope = { ...scope } but I guess it is still treated as read-only. Best, Pramod |
Thanks for bringing this up and debugging the issue guys. It looks like this const data = [[1, 2]]
Object.freeze(data)
const matrix = new DenseMatrix(data)
// TypeError: Cannot assign to read only property '0' of object '[object Array]' This function I'm halfway creating a fix for this. |
I've created a PR to address this issue, see #2991. @gwhitney or @pramod-bls can you have a look at it? |
apologies for late reply but i am unable to test the PR, when I try to install the PR using:
I get a error:
Any suggestions? |
@pramod-bls this may be because you cannot use the source code as-is: you have to run the build-step before it is usable. Can you clone the project, checkout the feature branch, run |
I can confirm that this resolves the issue. |
Thanks for verifying this @pramod-bls . We'll merge and publish the fix soon. |
* fix: #2990 DenseMatrix can mutate input arrays * chore: simplify internal function `preprocess` * chore: document ugly workaround of using `matrix.subset` to mutate a nested Array * chore: better solution for `assign` * chore: fix linting issue * chore: add a unit test for `multiply` testing whether the operation is immutable * chore: fix linting issue --------- Co-authored-by: Glen Whitney <glen@studioinfinity.org>
The fix is published now in |
step 1: I create a scope,
the scope looks like:
e.g Ch0.D10 is a 2D array of numbers
if I use the expression Ch0.D40./Ch2.D40 ....
the outpur is an Error
interestingly,
if i change the expression to:
the the output is fine:
hope this helps.
Originally posted by @pramod-bls in #2596 (comment)
The text was updated successfully, but these errors were encountered: