out, _ := exec.Command("/bin/ls").CombinedOutput() // Compliant
+out, _ := exec.Command("/bin/ls").CombinedOutput()
From 2cf9a50047a0f93bccc1229c42b60bebf12efccd Mon Sep 17 00:00:00 2001 From: daniel-teuchert-sonarsource <141642369+daniel-teuchert-sonarsource@users.noreply.github.com> Date: Mon, 3 Feb 2025 11:14:51 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20=20@=20c1a6b?= =?UTF-8?q?0f5f5e1c17263aeeee975255b97c18970ed=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rules/S4036/go-description.html | 2 +- rules/S6728/default-description.html | 124 +++++++++++++++++++++++++++ rules/S6728/default-metadata.json | 1 + rules/S6728/python-description.html | 124 +++++++++++++++++++++++++++ rules/S6728/python-metadata.json | 1 + rules/rule-index-aggregates.json | 2 +- rules/rule-index-store.json | 2 +- rules/rule-index.json | 2 +- 8 files changed, 254 insertions(+), 4 deletions(-) create mode 100644 rules/S6728/default-description.html create mode 100644 rules/S6728/default-metadata.json create mode 100644 rules/S6728/python-description.html create mode 100644 rules/S6728/python-metadata.json diff --git a/rules/S4036/go-description.html b/rules/S4036/go-description.html index e074b9a2d9d..1cac078400a 100644 --- a/rules/S4036/go-description.html +++ b/rules/S4036/go-description.html @@ -44,7 +44,7 @@
out, _ := exec.Command("/bin/ls").CombinedOutput() // Compliant
+out, _ := exec.Command("/bin/ls").CombinedOutput()
This rule raises an issue when a NumPy function expecting a square matrix is called with a non-square matrix.
+Some matrix operations only make sense on square matrices. For example, a determinant can be computed only if a matrix is square.
+Therefore, NumPy functions performing these operations should be provided with a square matrix as an argument. If something other than a square matrix is provided, the computation does not make sense and an exception will be raised.
+The following functions will raise an exception when provided with a non-square matrix:
+np.linalg.det(a)
: computes the determinant of an matrix.
np.linalg.eig(a)
: computes the eigenvalues and right eigenvectors of a square matrix.
np.linalg.matrix_power(a, n)
: raises a square matrix to the (integer) power n.
np.linalg.solve(a, b)
: Solve a linear matrix equation, or system of linear scalar equations. a
should be square.
np.linalg.inv(a)
: computes the (multiplicative) inverse of a matrix.
Also requires a non-singular matrix (a matrix is singular if its determinant is 0).
+You can use numpy.shape()
function to check the dimensions of the matrix before performing the operation.
import numpy as np
+
+a = np.array([[1, 2], [3, 4], [5, 6]])
+b = np.linalg.inv(a) # Noncompliant: LinAlgError: Last 2 dimensions of the array must be square
+import numpy as np
+
+a = np.array([[1, 2], [3, 4]])
+b = np.linalg.inv(a) # Compliant
+NumPy Documentation - numpy.linalg.det
+NumPy Documentation - numpy.linalg.eig
+NumPy Documentation - numpy.linalg.inv
+NumPy Documentation - numpy.linalg.matrix_power
+NumPy Documentation - numpy.linalg.solve
+NumPy Documentation - numpy.shape
+(visible only on this page)
+(visible only on this page)
+This rule raises an issue when a NumPy function expecting a square matrix is called with a non-square matrix.
+Some matrix operations only make sense on square matrices. For example, a determinant can be computed only if a matrix is square.
+Therefore, NumPy functions performing these operations should be provided with a square matrix as an argument. If something other than a square matrix is provided, the computation does not make sense and an exception will be raised.
+The following functions will raise an exception when provided with a non-square matrix:
+np.linalg.det(a)
: computes the determinant of an matrix.
np.linalg.eig(a)
: computes the eigenvalues and right eigenvectors of a square matrix.
np.linalg.matrix_power(a, n)
: raises a square matrix to the (integer) power n.
np.linalg.solve(a, b)
: Solve a linear matrix equation, or system of linear scalar equations. a
should be square.
np.linalg.inv(a)
: computes the (multiplicative) inverse of a matrix.
Also requires a non-singular matrix (a matrix is singular if its determinant is 0).
+You can use numpy.shape()
function to check the dimensions of the matrix before performing the operation.
import numpy as np
+
+a = np.array([[1, 2], [3, 4], [5, 6]])
+b = np.linalg.inv(a) # Noncompliant: LinAlgError: Last 2 dimensions of the array must be square
+import numpy as np
+
+a = np.array([[1, 2], [3, 4]])
+b = np.linalg.inv(a) # Compliant
+NumPy Documentation - numpy.linalg.det
+NumPy Documentation - numpy.linalg.eig
+NumPy Documentation - numpy.linalg.inv
+NumPy Documentation - numpy.linalg.matrix_power
+NumPy Documentation - numpy.linalg.solve
+NumPy Documentation - numpy.shape
+(visible only on this page)
+(visible only on this page)
+