Conversation
ahartikainen
left a comment
There was a problem hiding this comment.
Looks good. Added a few comments
cmdstanpy/utils.py
Outdated
| *_, vals, dim = rhs.replace('(', ' ').replace(')', ' ').split('c') | ||
| vals = [float(v) for v in vals.split(',')[:-1]] | ||
| dim = [int(v) for v in dim.split(',')] | ||
| val = np.array(vals).reshape(dim[::-1]).T |
There was a problem hiding this comment.
what is going on here?
Would this equal
np.array(vals).reshape(dim[::-1]).T
--> np.array(vals, order='F').reshape(dim, order='F')
or
--> np.array(vals).reshape(dim, order='F')
or
--> np.reshape(vals, dim, order='F')
There was a problem hiding this comment.
agreed, that's not very clear. I added a subroutine that processes the Rdump multi-dim structure - used an ugly regex with named groups for the essential bits - array values, array dimensions. I ran the Rdump file in R to see what R does, then added unit tests that verify that the array values end up in the right place. hope this helps.
cmdstanpy/utils.py
Outdated
| idx += 1 | ||
| next_var = idx | ||
| var_data = ''.join(lines[start_idx:next_var]).replace('\n', '') | ||
| lhs, rhs = [_.strip() for _ in var_data.split('<-')] |
There was a problem hiding this comment.
This is fine, just a small comment: using _ instead of item seems weird to me.
| """ | ||
| data_dict = {} | ||
| with open(fname, 'r') as fp: | ||
| lines = fp.readlines() |
There was a problem hiding this comment.
This is fine, larger than RAM files are not really that common.
|
I did a rewrite of the drump parsing logic and plugged it into the (this feature is as much of a PITA as everything else to do with R, but I can see its utility...) |
Submission Checklist
Summary
Add utility function
rload- see issue #89 for discussion.Test data for unit tests taken from Stan
src/test/test-models/good.Copyright and Licensing
Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company): Columbia University
By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses: