Skip to content

Conversation

@mmatera
Copy link
Contributor

@mmatera mmatera commented Nov 12, 2025

Now we have the is_uniform attribute, this PR uses it to make faster the match test with SequenceBlank and SequenceNullBlank. Also, ensure that this property be computed and stored in list/expression creation operations (Table, Sum, Product).

  • using is_uniform property in matching SequenceBlank and SequenceNullBlank patterns
  • get_result now accepts an optional attribute is_uniform to set this property in its result.
  • Table, Sum and Product now set the element_property is_uniform to provide a faster evaluation of large lists.
  • convert_expression_elements now handles is_uniform

…lBlank patterns

* `get_result` now accepts an optional attribute `is_uniform` to set this property in its result.

* `Table`, `Sum` and `Product` now set the element_property `is_uniform` to provide a faster evaluation of large lists.

* convert_expression_elements now handles is_uniform
@rocky
Copy link
Member

rocky commented Nov 12, 2025

LGTM, although I confess I don't see how this is going to help. If you want to give a specific example, I'd be grateful.

@mmatera
Copy link
Contributor Author

mmatera commented Nov 12, 2025

@rocky, suppose that you define a function
F[vals__Real]=Sum[x,{x,vals}]
and a list of values A=Table[BesselJ[3,x],{x,0,10,1000}]. Now, to evaluate

F[A]

first you need to check if the result of Table[BesselJ[3,x],{x,0,10,1000}] has all real entries. So, the match function (as is in master) has to check the head of each element in A. But, by construction, A has all their elements of the same type. So check the first is enough.
Same happens with the evaluation: since A is uniform, when you evaluate it, it is not necesary to check for upvalues on each element, you need just to look at the first one.

In this way,
Table[A=Table[1.*i^2,{i,0,n}]; {n, Timing[MatchQ[A, {__Real}]]},{n,{2,10,100,10000}}]
should show that the time required by MatchQ should be constant instead of linear in the size of A.

However, for some reason, it seems we are missing the element_properties after the assigment, so the improvement is not shown.

@rocky
Copy link
Member

rocky commented Nov 12, 2025

@mmatera Thanks for the explanaition.

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.

3 participants