You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -27,8 +27,71 @@ var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' );
27
27
// MAIN //
28
28
29
29
/**
30
-
* Performs the rank 1 operation `A = α*x*y^T + A`, where `α` is a scalar, `x` is an `M` element vector, `y` is an `N` element vector and `A` is an `M` by `N` matrix.
30
+
* Performs the rank 1 operation `A = α*x*y^T + A`, where `α` is a scalar, `x` is an `M` element vector, `y` is an `N` element vector, and `A` is an `M` by `N` matrix.
31
31
*
32
+
* ## Notes
33
+
*
34
+
* - To help motivate the use of loop interchange below, we first recognize that a matrix stored in row-major order is equivalent to storing the matrix's transpose in column-major order. For example, consider the following 2-by-3 matrix `A`
35
+
*
36
+
* ```tex
37
+
* A = \begin{bmatrix}
38
+
* 1 & 2 & 3 \\
39
+
* 4 & 5 & 6
40
+
* \end{bmatrix}
41
+
* ```
42
+
*
43
+
* When stored in a linear buffer in column-major order, `A` becomes
44
+
*
45
+
* ```text
46
+
* [ 1 4 2 5 3 6]
47
+
* ```
48
+
*
49
+
* When stored in a linear buffer in row-major order, `A` becomes
50
+
*
51
+
* ```text
52
+
* [ 1 2 3 4 5 6]
53
+
* ```
54
+
*
55
+
* Now consider the transpose of `A`
56
+
*
57
+
* ```tex
58
+
* A^T = \begin{bmatrix}
59
+
* 1 & 4 \\
60
+
* 2 & 5 \\
61
+
* 3 & 6
62
+
* \end{bmatrix}
63
+
* ```
64
+
*
65
+
* When the transpose is stored in a linear buffer in column-major order, the transpose becomes
66
+
*
67
+
* ```text
68
+
* [ 1 2 3 4 5 6 ]
69
+
* ```
70
+
*
71
+
* Similarly, when stored in row-major order, the transpose becomes
72
+
*
73
+
* ```text
74
+
* [ 1 4 2 5 3 6 ]
75
+
* ```
76
+
*
77
+
* As may be observed, `A` stored in column-major order is equivalent to storing the transpose of `A` in row-major order, and storing `A` in row-major order is equivalent to storing the transpose of `A` in column-major order, and vice versa.
78
+
*
79
+
* Hence, we can interpret an `M` by `N` row-major matrix `B` as the matrix `A^T` stored in column-major order. In which case, we can derive an update equation for `B` as follows:
80
+
*
81
+
* ```tex
82
+
* \begin{align*}
83
+
* B &= A^T \\
84
+
* &= (\alpha \bar{x} \bar{y}^T + A)^T \\
85
+
* &= (\alpha \bar{x} \bar{y}^T)^T + A^T \\
86
+
* &= \alpha (\bar{x} \bar{y}^T)^T + A^T \\
87
+
* &= \alpha \bar{y} \bar{x}^T + A^T \\
88
+
* &= \alpha \bar{y} \bar{x}^T + B
89
+
* \end{align*}
90
+
* ```
91
+
*
92
+
* Accordingly, we can reuse the same loop logic for column-major and row-major `A` by simply swapping `x` and `y` and `M` and `N` when `A` is row-major order. That is the essence of loop interchange.
93
+
*
94
+
* @private
32
95
* @param {NonNegativeInteger} M - number of rows in the matrix `A`
33
96
* @param {NonNegativeInteger} N - number of columns in the matrix `A`
34
97
* @param {number} alpha - scalar constant
@@ -55,56 +118,68 @@ var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' );
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/blas/base/sger/lib/ndarray.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
/**
2
2
* @license Apache-2.0
3
3
*
4
-
* Copyright (c) 2025 The Stdlib Authors.
4
+
* Copyright (c) 2024 The Stdlib Authors.
5
5
*
6
6
* Licensed under the Apache License, Version 2.0 (the "License");
7
7
* you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@ var base = require( './base.js' );
27
27
// MAIN //
28
28
29
29
/**
30
-
* Performs the rank 1 operation `A = α*x*y^T + A`, where `α` is a scalar, `x` is an `M` element vector, `y` is an `N` element vector and `A` is an `M` by `N` matrix.
30
+
* Performs the rank 1 operation `A = α*x*y^T + A`, where `α` is a scalar, `x` is an `M` element vector, `y` is an `N` element vector, and `A` is an `M` by `N` matrix.
31
31
*
32
32
* @param {NonNegativeInteger} M - number of rows in the matrix `A`
33
33
* @param {NonNegativeInteger} N - number of columns in the matrix `A`
@@ -66,10 +66,10 @@ function sger( M, N, alpha, x, strideX, offsetX, y, strideY, offsetY, A, strideA
66
66
thrownewRangeError(format('invalid argument. Second argument must be a nonnegative integer. Value: `%d`.',N));
67
67
}
68
68
if(strideX===0){
69
-
thrownewRangeError(format('invalid argument. Fifth argument must be non-zero.'));
69
+
thrownewRangeError(format('invalid argument. Fifth argument must be non-zero. Value: `%d`.',strideX));
70
70
}
71
71
if(strideY===0){
72
-
thrownewRangeError(format('invalid argument. Eighth argument must be non-zero.'));
72
+
thrownewRangeError(format('invalid argument. Eighth argument must be non-zero. Value: `%d`.',strideY));
0 commit comments