Skip to content

Conversation

@brandon-b-miller
Copy link
Contributor

Closes #580

@copy-pr-bot
Copy link

copy-pr-bot bot commented Nov 6, 2025

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@brandon-b-miller
Copy link
Contributor Author

/ok to test

@brandon-b-miller brandon-b-miller marked this pull request as ready for review November 6, 2025 15:23
@copy-pr-bot
Copy link

copy-pr-bot bot commented Nov 6, 2025

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

if ty is None:
raise ValueError(f"Cannot type list element type {type(val[0])}")
return types.List(ty, reflected=True)
return ty[::1]
Copy link
Contributor

Choose a reason for hiding this comment

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

This was a sketch of how things work for a 1D list only. A more robust implementation would:

  • Check that the purpose of the typeof operation is for a constant. We should not accept lists as arguments to kernels.
  • Convert the value to a NumPy array, then determine the Numba type of the NumPy array. This will allow handling of lists-of-lists, e.g. [[1, 2], [3, 4]]. It also prevents having to handle what happens if there are different element types (e.g. int and float), whereas the existing implementation assumes that all list elements have the same type, which need not be the case.
  • Not check for zero-length, because a zero-length NumPy array is possible and can be typed. The inability to handle a zero-length list is an issue of the reflected list implementation in Numba that doesn't present an issue for freezing global lists as arrays.

Copy link
Contributor

@gmarkall gmarkall left a comment

Choose a reason for hiding this comment

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

A couple of other additions that should be required:

  • Documentation. Not only is this a deviation from Python semantics (in terms of freezing the list as a constant), it even deviates from Numba list handling so could be surprising to a seasoned Numba user.
  • Additional testing: test with multiple data types in the list, an unfreezable list (e.g. one that won't convert to a NumPy array), test with a list of lists once the implementation of _typeof_list is modified according to comments.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the changes here are now superfluous?

@gmarkall gmarkall added the 4 - Waiting on author Waiting for author to respond to review label Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4 - Waiting on author Waiting for author to respond to review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEA] Constant lists currently not implemented

2 participants