Skip to content
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

Expose assign methods #58

Merged
merged 10 commits into from
Dec 17, 2023
Merged

Expose assign methods #58

merged 10 commits into from
Dec 17, 2023

Conversation

michael-petersen
Copy link
Member

This small pull exposes the assign methods in CoefWrappers.cc for SphStruct, CylStruct, and TblStruct. It is not completely obvious to me that this is the end state, but for now, workflows such as this example:

import pyEXP

# we have some array of coefficients the we want to put in a SphCoefs instance
lmax,nmax = 2,5
tvals = np.arange(0.0,100.,1.)
coefs = np.random.rand(tvals.size,(lmax)*(lmax+1),nmax)
print(coefs[0]) # check

# assign the coefficients to a spherical basis holder (for later visualisation)
allcoefs = pyEXP.coefs.SphCoefs(False)

for t in range(0,tvals.size):
    # this must be reinitialised every step
    d = pyEXP.coefs.SphStruct()
    
    # give a time to the SphStruct
    d.time = float(tvals[t])
    
    # NEW FEATURE
    # assign to the SphStruct()
    # convert to complex to create phase information (or set up )
    d.assign(coefs[t].astype('complex128'),2,nmax)
    
    # add to the SphCoefs instance
    allcoefs.add(d)
    
print(allcoefs.getAllCoefs()[:,:,0]) # compare with above

with similar possibilities for CylStruct and TblStruct.

Tests:

  • Compiled
  • MWE for SphStruct

@michael-petersen
Copy link
Member Author

I also fixed a clang warning warning: non-void function does not return a value in all control paths [-Wreturn-type] by adding a throw. This works fine for me.

@The9Cat
Copy link
Contributor

The9Cat commented Dec 15, 2023

I believe that TblStruct::assign needs to set the cols dimension from the input array so that allocate correctly sets the storage array(s). Other assign methods in SphStruct and CylStruct already do this.

Reading the docstrings for Coefs, I'm thinking that my original intent was to make the dimensions (e.g. cols, nmax, lmax) settable attributes in pybind11. And then the create() methods would correctly allocate storage. We should probably change that (since it is not implemented) and replace it with the assign + add workflow example.

@The9Cat
Copy link
Contributor

The9Cat commented Dec 15, 2023

Does the example workflow above have the crazy-value bug in the quadrupole coefficient example that motivated this change?

@The9Cat
Copy link
Contributor

The9Cat commented Dec 16, 2023

The last commit adds the ascii file constructor so that the following works:

import numpy as np
import pyEXP

coefsread = pyEXP.coefs.TableData('coef1.txt', True)
C = coefsread1.getAllCoefs()
print(C)

where coef1.txt is an ascii table.

Copy link
Member Author

@michael-petersen michael-petersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified that the changes work as expected.

coefs/Coefficients.cc Show resolved Hide resolved
@The9Cat
Copy link
Contributor

The9Cat commented Dec 16, 2023

The last few commits were some polish. I suspect we are good to go for now.

@michael-petersen
Copy link
Member Author

I've verified that the constructors work as expected (and that compile works no problem). I'm merging now so we can start using the functionality!

@michael-petersen michael-petersen merged commit c0c3923 into main Dec 17, 2023
0 of 8 checks passed
@michael-petersen michael-petersen deleted the Issue57 branch December 17, 2023 16:17
@The9Cat
Copy link
Contributor

The9Cat commented Dec 17, 2023

Excellent, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants