Skip to content

Inefficient Tensor Creation

Description

Using `torch.Tensor()` to directly create a tensor can lead to parsing issues and inefficiency. It is recommended to use the proper methods for tensor creation as outlined in the PyTorch documentation.

Examples

Insecure Code

python
x = torch.Tensor([1, 2, 3])

Secure Code

python
x = torch.tensor([1, 2, 3])

Remediation

Use the recommended methods for tensor creation, such as `torch.tensor()` or `torch.from_numpy()`

Rule Details

FieldValue
IDCODE-0103
CategoryPerformance
SeverityLOW
CWE
ConfidenceHIGH
ImpactLOW
LikelihoodMEDIUM
ExploitabilityCOMPLEX
Tagsperformance, parsing
OWASPN/A

References