-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Feature/89 rload fn #90
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, just a small comment: using _
instead of item
seems weird to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, fixed.
""" | ||
data_dict = {} | ||
with open(fname, 'r') as fp: | ||
lines = fp.readlines() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: