org.sonar.l10n.py.rules.python.S6984.html Maven / Gradle / Ivy
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
-
einops
documentation - Einops basics
© 2015 - 2024 Weber Informatics LLC | Privacy Policy