-
Notifications
You must be signed in to change notification settings - Fork 4
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
jsondecode should treat array-of-array as row or n-dimensional matrix #6
Comments
Yep, the condensation logic should do this. This will take a bit of work to fix. Since the dimensionality of numeric arrays is unlikely to get large (how often do you see a hundred-dimension array?), I think this can be done in a separate condensation step in the (I think? Or will we have to pay for expensive negative cases, where we have to search all the members of a cell array to determine whether it is in fact a condensable array-of-numeric-arrays? In that case, maybe the logic should live in the oct-file after all.) |
Yeah I think it would be a little wasteful, and probably slower, to return a cell only to examine its dimensions and types and see if it can be collapsed into a matrix. |
Wasteful, but easier to write: from what I can figure, doing the condensation means a recursive depth-first traversal through the object graph of the decoded JSON data, condensing as you go, and then doing a I've checked in an M-code implementation at 511404d. Please have a look and let me know what you think. After we've established correctness, then let's see about pushing this logic down into the oct-file for performance. |
Cool, works for me for most examples of full higher order arrays. Fails on some simpler and degenerate cases, for example
should return a row vector. And empty or null arrays evidently aren't condensed, for example
should return a cell array with an empty double array in it. Only gets condensed to a scalar if the innermost array consists of a scalar value. Same with arrays of objects, |
Argh, who designed the behavior for this stuff? Okay, I'll special-case these caes. |
Okay. I pulled the condensation logic up into M-code until we can get the algorithm fully sorted out. (Leaving just the array-of-numerics-to-numeric-vector case in C++ for speed.) de8ec86 This made things clearer: Every level of Tests are passing now, and I think I've got all the cases you covered here. Closing this as fixed, and leaving #10 as a reminder to optimize this in C++ once we're sure we know what we're doing. |
Cool! I'll try this in a little bit |
Works great for me! |
In Matlab, when decoding a JSON array-of-arrays where all values are numeric, it returns a numeric matrix of appropriate nested dimension.
Examples
I guess that this falls under the "condensation" logic. If any entries aren't numeric or are of inconsistent shape or size, then it falls back to returning cell arrays of cell arrays.
The text was updated successfully, but these errors were encountered: