Check if an arg has all the core dims required by the signature. Slightly awkward design, of returning the error message. But we want to give a detailed error message, which requires inspecting the variable in the inner loop.
(signature, variable_args, name)
| 405 | |
| 406 | |
| 407 | def _check_core_dims(signature, variable_args, name): |
| 408 | """ |
| 409 | Check if an arg has all the core dims required by the signature. |
| 410 | |
| 411 | Slightly awkward design, of returning the error message. But we want to |
| 412 | give a detailed error message, which requires inspecting the variable in |
| 413 | the inner loop. |
| 414 | """ |
| 415 | missing = [] |
| 416 | for i, (core_dims, variable_arg) in enumerate( |
| 417 | zip(signature.input_core_dims, variable_args, strict=True) |
| 418 | ): |
| 419 | # Check whether all the dims are on the variable. Note that we need the |
| 420 | # `hasattr` to check for a dims property, to protect against the case where |
| 421 | # a numpy array is passed in. |
| 422 | if hasattr(variable_arg, "dims") and set(core_dims) - set(variable_arg.dims): |
| 423 | missing += [[i, variable_arg, core_dims]] |
| 424 | if missing: |
| 425 | message = "" |
| 426 | for i, variable_arg, core_dims in missing: |
| 427 | message += f"Missing core dims {set(core_dims) - set(variable_arg.dims)} from arg number {i + 1} on a variable named `{name}`:\n{variable_arg}\n\n" |
| 428 | message += "Either add the core dimension, or if passing a dataset alternatively pass `on_missing_core_dim` as `copy` or `drop`. " |
| 429 | return message |
| 430 | return True |
| 431 | |
| 432 | |
| 433 | def apply_dict_of_variables_vfunc( |
no outgoing calls
no test coverage detected
searching dependent graphs…