Skip to content

Conversation

@connoraird
Copy link
Contributor

@connoraird connoraird commented Jan 19, 2026

Description

Ports the functions left in fields.py which haven't yet been ported

Closes: #977

Changelog entry

Added: Full support for the array-api to fields.py

Checks

  • Is your code passing linting?
  • Is your code passing tests?
  • Have you added additional tests (if required)?
  • Have you modified/extended the documentation (if required)?
  • Have you added a one-liner changelog entry above (if required)?

@connoraird connoraird self-assigned this Jan 19, 2026
@connoraird connoraird added the array-api Work is related to the Array API label Jan 19, 2026
@connoraird connoraird force-pushed the connor/issue-977 branch 2 times, most recently from 6555d92 to d6c3cb6 Compare January 22, 2026 13:06
Base automatically changed from paddy/issue-902 to main January 26, 2026 17:24
@connoraird connoraird marked this pull request as ready for review January 27, 2026 14:44
@connoraird connoraird requested a review from paddyroddy January 27, 2026 14:50
@paddyroddy
Copy link
Member

Current regressions seem quite large

test_generate_grf[numpy-None-False] (0001_8fcf233) - Field 'mean' has failed PercentageRegressionCheck: 25.512178944 > 5.000000000
test_generate_grf[numpy-None-True] (0001_8fcf233) - Field 'mean' has failed PercentageRegressionCheck: 26.795189419 > 5.000000000
test_generate_grf[numpy-1-False] (0001_8fcf233) - Field 'mean' has failed PercentageRegressionCheck: 11.350133326 > 5.000000000
test_generate_grf[numpy-1-True] (0001_8fcf233) - Field 'mean' has failed PercentageRegressionCheck: 10.812015623 > 5.000000000
test_generate[numpy-None] (0001_8fcf233) - Field 'mean' has failed PercentageRegressionCheck: 42.996966146 > 5.000000000
test_generate[numpy-1] (0001_8fcf233) - Field 'mean' has failed PercentageRegressionCheck: 116.517332491 > 5.000000000

Copy link
Member

@paddyroddy paddyroddy left a comment

Choose a reason for hiding this comment

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

Please can you make a comment on the regressions?

@connoraird connoraird requested a review from paddyroddy January 28, 2026 14:40
@paddyroddy
Copy link
Member

This PR looks like it will have regressions to should have the needs-2-reviewers label

Copy link
Member

@paddyroddy paddyroddy left a comment

Choose a reason for hiding this comment

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

Okay, this looks in a good place now. Five things for me:

  • Need new line in docstring to match numpydoc
  • Move yield comment
  • Fill in checklist
  • Add need-2-reviewers label + Nicolas (if regressions)
  • Comment the regressions and check if okay

@connoraird connoraird added the needs-2-reviewers Could be considered "controversial" so worth a second pair of eyes label Jan 28, 2026
@connoraird
Copy link
Contributor Author

Current regressions appear to only be in generate. That may make sense as generate indirectly calls a lot of the functions which have been ported so the total regressions would accumulate.

--------------------------------------------------------------------------------
Performance has regressed:
	test_generate[numpy-None] (0001_20ea738) - Field 'mean' has failed PercentageRegressionCheck: 30.930359092 > 5.000000000
	test_generate[numpy-1] (0001_20ea738) - Field 'mean' has failed PercentageRegressionCheck: 68.876285110 > 5.000000000
--------------------------------------------------------------------------------

@connoraird connoraird requested a review from ntessore January 28, 2026 15:32
@paddyroddy
Copy link
Member

Current regressions appear to only be in generate

generate has been a consistent problem. Looks like it calls cltovar, getcl, _generate_grf. getcl, _generate_grf both have benchmark tests. Turns out cltovar is actually from transformcl. It appears to be array compatible in itself.

Does this mean the regression is actually coming from the for loop within generate?

@connoraird
Copy link
Contributor Author

connoraird commented Jan 29, 2026

Turns out cltovar is actually from transformcl. It appears to be array compatible in itself.

It looks like it has been ported but it actually doesn't work with array_api_strict due to this error TypeError: Only floating-point dtypes are allowed in __truediv__. This is because this is the code which produces an ell.dtype of array_api_strict.int64

xp = array_namespace(cl)
ell = xp.arange(cl.shape[-1])
return xp.sum((2 * ell + 1) / (4 * xp.pi) * cl, axis=-1)

A solution would be the following change.

   xp = array_namespace(cl)
- ell = xp.arange(cl.shape[-1])
+ ell = xp.arange(cl.shape[-1], dtype=xp.float64)
   return xp.sum((2 * ell + 1) / (4 * xp.pi) * cl, axis=-1)

Can we make this change? I've raised a PR to fix this - glass-dev/transformcl#6

Does this mean the regression is actually coming from the for loop within generate?

It could be, however, I think my point of the regressions from the other functions accumulating is still possibly true. Even if the other functions don't fail the regression tests, they could be regressing by 4%. then the total regression of all of them could add up to more than 5%. Or is that not how percentages work? 🤔

@paddyroddy
Copy link
Member

Can we make this change? I've raised a PR to fix this - glass-dev/transformcl#6

Yes, I don't see why not

It could be, however, I think my point of the regressions from the other functions accumulating is still possibly true. Even if the other functions don't fail the regression tests, they could be regressing by 4%. then the total regression of all of them could add up to more than 5%. Or is that not how percentages work? 🤔

I could buy that argument

@connoraird
Copy link
Contributor Author

Still seems to just be the known generate regression and a potential bit of noise.

--------------------------------------------------------------------------------
Performance has regressed:
	test_iternorm_k_0[numpy] (0001_4c89818) - Field 'mean' has failed PercentageRegressionCheck: 5.224544781 > 5.000000000
	test_generate[numpy-None] (0001_4c89818) - Field 'mean' has failed PercentageRegressionCheck: 33.989695641 > 5.000000000
	test_generate[numpy-1] (0001_4c89818) - Field 'mean' has failed PercentageRegressionCheck: 68.915726817 > 5.000000000
--------------------------------------------------------------------------------

@paddyroddy paddyroddy self-requested a review January 29, 2026 14:13
@paddyroddy
Copy link
Member

paddyroddy commented Jan 29, 2026

Making an executive decision to accept that this regression is inevitable for now. In the example notebook, the matter fields and created once using generate. They then are iterated over within a for loop. The net effect of generate is much smaller than functions like shear_from_convergence, uniform_positions, etc.

cc: @ntessore

@paddyroddy paddyroddy merged commit 4f659f6 into main Jan 29, 2026
21 of 22 checks passed
@paddyroddy paddyroddy deleted the connor/issue-977 branch January 29, 2026 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

array-api Work is related to the Array API needs-2-reviewers Could be considered "controversial" so worth a second pair of eyes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Port remaining functions in fields.py

3 participants