Skip to content

Conversation

@mloubout
Copy link
Contributor

Fix two issues

  • Functions's rebuilt with new dimensions are broken when the function is staggerred
  • Tensor rebuild isn't defined properly.

@mloubout mloubout added the API api (symbolics, types, ...) label Apr 14, 2025
@codecov
Copy link

codecov bot commented Apr 14, 2025

Codecov Report

Attention: Patch coverage is 91.89189% with 18 lines in your changes missing coverage. Please review.

Project coverage is 92.00%. Comparing base (7a6b725) to head (9c9fe55).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
devito/types/basic.py 84.34% 15 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2583      +/-   ##
==========================================
+ Coverage   91.97%   92.00%   +0.02%     
==========================================
  Files         244      244              
  Lines       47826    47915      +89     
  Branches     4207     4222      +15     
==========================================
+ Hits        43989    44082      +93     
+ Misses       3164     3159       -5     
- Partials      673      674       +1     
Flag Coverage Δ
pytest-gpu-aomp-amdgpuX 72.56% <59.75%> (-0.01%) ⬇️
pytest-gpu-nvc-nvidiaX 73.62% <59.75%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

# compare staggering
if self.expr.staggered == func.staggered:
if self.expr.staggered == func.staggered and \
not (self.expr.is_Add or self.expr.is_Mul):
Copy link
Contributor

Choose a reason for hiding this comment

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

what if it were a Pow or a trascendental function or something else ? this check isn't very neat

# Extract the `indices`, as perhaps they're explicitly provided
dimensions, indices = cls.__indices_setup__(*args, **kwargs)
dim_args = cls.__indices_setup__(*args, **kwargs)
try:
Copy link
Contributor

Choose a reason for hiding this comment

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

why not letting __indices_setup__ do all this tinkering?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would require to add a bunch of it in all the Array/TempFunction/.... that don't need to know about staggered.

# when executing __init_finalize__
newobj._name = name
newobj._dimensions = dimensions
newobj._staggered = staggered
Copy link
Contributor

Choose a reason for hiding this comment

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

so Arrays now get this attribute too, which is not ideal. We may need a further AbstractFunction subclass instead, or something else

Copy link
Contributor

Choose a reason for hiding this comment

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

why did you lift it up here? as in, why not enough in DiscreteFunction?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because I need it to be in __new__, lifting it up requires a lot of messy tinkering with the init_finalize. But I will have another look.

return tuple()
elif stagg is CELL:
staggered = (sympy.S.One for d in dimensions)
elif stagg in [NODE]:
Copy link
Contributor

Choose a reason for hiding this comment

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

elif stagg is NODE ?

"""
stagg = kwargs.get('staggered')
if stagg is None:
return tuple()
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpicking -- return ()

if stagg is None:
return tuple()
elif stagg is CELL:
staggered = (sympy.S.One for d in dimensions)
Copy link
Contributor

Choose a reason for hiding this comment

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

could also be [sympy.S.One]*len(dimensions)

* 0 to non-staggered dimensions;
* 1 to staggered dimensions.
"""
stagg = kwargs.get('staggered')
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpicking: I'd call this value staggered, and the other one (the "lowered" staggered" processed instead, or perhaps just a letter, but I would avoid both stagg and staggered

@cached_property
def _fd_priority(self):
return 2.1 if self.staggered in [NODE, None] else 2.2
return 2.1 if not self.staggered or all(s == 0 for s in self.staggered) else 2.2
Copy link
Contributor

Choose a reason for hiding this comment

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

makes me think staggered should be of type class Staggering(tuple) rather just a tuple

@mloubout mloubout force-pushed the tens-rebuild branch 2 times, most recently from 255db5a to fb08901 Compare April 15, 2025 13:14
# in the matrix, so we ust return the class name
return self.__class__.__name__

def _rebuild(self, *args, **kwargs):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: This is the only addition

staggered_indices = mapper.values()

if not staggered:
staggered_indices = (d for d in dimensions)
Copy link
Contributor

Choose a reason for hiding this comment

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

= dimensions

if not staggered:
staggered_indices = (d for d in dimensions)
else:
# Staggered indices
Copy link
Contributor

Choose a reason for hiding this comment

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

useless comment

@property
def is_Staggered(self):
return self.staggered is not None
if not self.staggered:
Copy link
Contributor

Choose a reason for hiding this comment

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

just return self.staggered or bool(...) if you want it a bool

def _rebuild(self, *args, **kwargs):
# Plain `func` call (row, col, comps)
if not kwargs.keys() & self.__rkwargs__:
assert len(args) == 3
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of an assert I would use a ValueError, since this could easily be a user or developer programming attempted thing no? not entirely sure honetly, but in theory one can do mytensor._rebuild(a) where a is whatever. And that imho deserves a proper exception

if staggered in [CELL, NODE]:
staggered_indices = dimensions
staggered_indices = tuple(args)
else:
Copy link
Contributor

Choose a reason for hiding this comment

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

ultra-nitpicking , I'd just go with elif staggered: ... and then else (ie denesting everything)

Copy link
Contributor

@FabioLuporini FabioLuporini left a comment

Choose a reason for hiding this comment

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

GTG, thanks

@mloubout mloubout merged commit fefcfba into main Apr 17, 2025
34 checks passed
@mloubout mloubout deleted the tens-rebuild branch April 17, 2025 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API api (symbolics, types, ...)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants