All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.py.rules.python.S6984.html Maven / Gradle / Ivy

There is a newer version: 4.23.0.17664
Show newest version

This rule raises an issue when an incorrect pattern is provided to an einops operation.

Why is this an issue?

The einops library provides a powerful and flexible way to manipulate tensors using the Einstein summation convention. The einops uses a different convention than the traditional one. In particular, the axis names can be more than one letter long and are separated by spaces.

How to fix it

Correct the syntax of the einops operation by balancing the parentheses and following the convention.

Code examples

Noncompliant code example

from einops import rearrange
import torch

x = torch.randn(2, 3, 4, 5)
x2 = rearrange(x, 'b c h w -> b (c h w') # Noncompliant : the parentheses are not balanced

Compliant solution

from einops import rearrange
import torch

x = torch.randn(2, 3, 4, 5)
x2 = rearrange(x, 'b c h w -> b (c h w)')

Resources

Documentation





© 2015 - 2024 Weber Informatics LLC | Privacy Policy