Skip to content

Commit d34dc87

Browse files
committed
fix: apply suggestions from code review
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 245c9b1 commit d34dc87

4 files changed

Lines changed: 51 additions & 110 deletions

File tree

lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/docs/repl.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
contains the first element of each pair and the second column contains
77
the second element.
88

9-
The `N` and stride parameters determine which elements in the strided
10-
arrays are accessed at runtime.
9+
The `N` and stride parameters determine which elements in the strided arrays
10+
are accessed at runtime.
1111

1212
If `N <= 0`, the function returns `out` unchanged.
1313

@@ -63,8 +63,8 @@
6363

6464

6565
{{alias}}.ndarray( N, x, sx, ox, out, so1, so2, oo )
66-
Computes the Cartesian square for a strided array using alternative
67-
indexing semantics.
66+
Computes the Cartesian square for a strided array using alternative indexing
67+
semantics.
6868

6969
Pairs are stored as rows in the output matrix, where the first column
7070
contains the first element of each pair and the second column contains

lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/lib/base.js

Lines changed: 0 additions & 99 deletions
This file was deleted.

lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/lib/main.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string
2525
var stride2offset = require( '@stdlib/strided/base/stride2offset' );
2626
var max = require( '@stdlib/math/base/special/fast/max' );
2727
var format = require( '@stdlib/string/format' );
28-
var base = require( './base.js' );
28+
var ndarray = require( './ndarray.js' );
2929

3030

3131
// MAIN //
@@ -70,10 +70,7 @@ function gcartesianSquare( order, N, x, strideX, out, LDO ) {
7070
sa1 = LDO;
7171
sa2 = 1;
7272
}
73-
if ( N <= 0 ) {
74-
return out;
75-
}
76-
return base( N, x, strideX, stride2offset( N, strideX ), out, sa1, sa2, 0 );
73+
return ndarray( N, x, strideX, stride2offset( N, strideX ), out, sa1, sa2, 0 );
7774
}
7875

7976

lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/lib/ndarray.js

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020

2121
// MODULES //
2222

23-
var base = require( './base.js' );
23+
var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
24+
var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' );
25+
var gfill = require( '@stdlib/blas/ext/base/gfill' ).ndarray;
26+
var gcopy = require( '@stdlib/blas/base/gcopy' ).ndarray;
27+
var accessors = require( './accessors.js' );
2428

2529

2630
// MAIN //
@@ -50,10 +54,49 @@ var base = require( './base.js' );
5054
* // out => [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]
5155
*/
5256
function gcartesianSquare( N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) { // eslint-disable-line max-len
57+
var xobj;
58+
var oobj;
59+
var ix;
60+
var jx;
61+
var io;
62+
var i;
63+
var j;
64+
5365
if ( N <= 0 ) {
5466
return out;
5567
}
56-
return base( N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut );
68+
xobj = arraylike2object( x );
69+
oobj = arraylike2object( out );
70+
if ( xobj.accessorProtocol || oobj.accessorProtocol ) {
71+
return accessors( N, xobj, strideX, offsetX, oobj, strideOut1, strideOut2, offsetOut ); // eslint-disable-line max-len
72+
}
73+
ix = offsetX;
74+
io = offsetOut;
75+
if ( isRowMajor( [ strideOut1, strideOut2 ] ) ) {
76+
for ( i = 0; i < N; i++ ) {
77+
jx = offsetX;
78+
for ( j = 0; j < N; j++ ) {
79+
out[ io ] = x[ ix ];
80+
out[ io + strideOut2 ] = x[ jx ];
81+
jx += strideX;
82+
io += strideOut1;
83+
}
84+
ix += strideX;
85+
}
86+
return out;
87+
}
88+
// Column-major...
89+
for ( i = 0; i < N; i++ ) {
90+
gfill( N, x[ ix ], out, strideOut1, io );
91+
ix += strideX;
92+
io += N * strideOut1;
93+
}
94+
io = offsetOut + strideOut2;
95+
for ( i = 0; i < N; i++ ) {
96+
gcopy( N, x, strideX, offsetX, out, strideOut1, io );
97+
io += N * strideOut1;
98+
}
99+
return out;
57100
}
58101

59102

0 commit comments

Comments
 (0)