Skip to content

Commit 11bf0c8

Browse files
committed
refactor: 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: passed - task: lint_package_json status: na - task: lint_repl_help status: na - 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: missing_dependencies - 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 105d199 commit 11bf0c8

4 files changed

Lines changed: 31 additions & 54 deletions

File tree

lib/node_modules/@stdlib/blas/ext/base/ddiff/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ The `N` and stride parameters determine which elements in the strided array are
7474
var Float64Array = require( '@stdlib/array/float64' );
7575

7676
var x = new Float64Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] );
77-
var p = new Float64Array( [ 1.0 ] )
77+
var p = new Float64Array( [ 1.0 ] );
7878
var a = new Float64Array( [ 11.0 ] );
7979
var out = new Float64Array( 4 );
8080
var w = new Float64Array( 4 );
@@ -96,15 +96,15 @@ var x0 = new Float64Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] );
9696
// Create an offset view...
9797
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
9898

99-
var p = new Float64Array( [ 1.0 ] )
99+
var p = new Float64Array( [ 1.0 ] );
100100
var a = new Float64Array( [ 11.0 ] );
101101
var out = new Float64Array( 5 );
102102
var w = new Float64Array( 5 );
103103

104104
ddiff( x1.length, 1, x1, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 );
105105

106106
console.log( out );
107-
// out => <Float64Array>[ 3.0, 2.0, 2.0, 2.0, 11.0 ]
107+
// out => <Float64Array>[ 3.0, 2.0, 2.0, 2.0, 1.0 ]
108108
```
109109

110110
<!-- lint disable maximum-heading-length -->
@@ -122,7 +122,7 @@ var a = new Float64Array( [ 11.0 ] );
122122
var out = new Float64Array( 6 );
123123
var w = new Float64Array( 6 );
124124

125-
ddiff( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 );
125+
ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 );
126126

127127
console.log( out );
128128
// out => <Float64Array>[ 1.0, 2.0, 2.0, 2.0, 2.0, 1.0 ]
@@ -142,12 +142,12 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the
142142
var Float64Array = require( '@stdlib/array/float64' );
143143

144144
var x = new Float64Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] );
145-
var p = new Float64Array( [ 1.0 ] )
145+
var p = new Float64Array( [ 1.0 ] );
146146
var a = new Float64Array( [ 11.0 ] );
147147
var out = new Float64Array( 4 );
148148
var w = new Float64Array( 4 );
149149

150-
ddiff( 3, 1, x, 1, x.length-3, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 );
150+
ddiff.ndarray( 3, 1, x, 1, x.length-3, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 );
151151

152152
console.log( out );
153153
// out => <Float64Array>[ 5.0, 2.0, 2.0, 1.0 ]

lib/node_modules/@stdlib/blas/ext/base/ddiff/lib/ndarray.js

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020

2121
'use strict';
2222

23+
// MODULES //
24+
25+
var dcopy = require( '@stdlib/blas/base/dcopy' );
26+
27+
2328
// FUNCTIONS //
2429

2530
/**
@@ -189,10 +194,6 @@ function base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append
189194
*/
190195
function ddiff( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut, workspace, strideW, offsetW ) {
191196
var total;
192-
var ix;
193-
var ip;
194-
var ia;
195-
var io;
196197
var n;
197198
var i;
198199

@@ -207,27 +208,14 @@ function ddiff( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, ap
207208
}
208209

209210
if ( k === 0 ) {
210-
io = offsetOut;
211-
ip = offsetP;
212-
for ( i = 0; i < N1; i++ ) {
213-
out[ io ] = prepend[ ip ];
214-
io += strideOut;
215-
ip += strideP;
216-
}
211+
// Copy `prepend` into output array:
212+
dcopy.ndarray( N1, prepend, strideP, offsetP, out, strideOut, offsetOut );
217213

218-
ix = offsetX;
219-
for ( i = 0; i < N; i++ ) {
220-
out[ io ] = x[ ix ];
221-
io += strideOut;
222-
ix += strideX;
223-
}
214+
// Copy `x` into output array:
215+
dcopy.ndarray( N, x, strideX, offsetX, out, strideOut, offsetOut );
224216

225-
ia = offsetA;
226-
for ( i = 0; i < N2; i++ ) {
227-
out[ io ] = append[ ia ];
228-
io += strideOut;
229-
ia += strideA;
230-
}
217+
// Copy `append` into output array:
218+
dcopy.ndarray( N2, append, strideA, offsetA, out, strideOut, offsetOut );
231219
}
232220

233221
if ( k === 1 ) {

lib/node_modules/@stdlib/blas/ext/base/ddiff/manifest.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"dependencies": [
3939
"@stdlib/blas/base/shared",
4040
"@stdlib/strided/base/stride2offset",
41+
"@stdlib/blas/base/dcopy",
4142
"@stdlib/napi/export",
4243
"@stdlib/napi/argv",
4344
"@stdlib/napi/argv-int64",
@@ -56,7 +57,8 @@
5657
"libpath": [],
5758
"dependencies": [
5859
"@stdlib/blas/base/shared",
59-
"@stdlib/strided/base/stride2offset"
60+
"@stdlib/strided/base/stride2offset",
61+
"@stdlib/blas/base/dcopy"
6062
]
6163
},
6264
{
@@ -71,7 +73,8 @@
7173
"libpath": [],
7274
"dependencies": [
7375
"@stdlib/blas/base/shared",
74-
"@stdlib/strided/base/stride2offset"
76+
"@stdlib/strided/base/stride2offset",
77+
"@stdlib/blas/base/dcopy"
7578
]
7679
}
7780
]

lib/node_modules/@stdlib/blas/ext/base/ddiff/src/main.c

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "stdlib/blas/ext/base/ddiff.h"
2020
#include "stdlib/strided/base/stride2offset.h"
21+
#include "stdlib/blas/base/dcopy.h"
2122
#include "stdlib/blas/base/shared.h"
2223

2324
/**
@@ -196,10 +197,6 @@ static void stdlib_strided_base_ddiff_ndarray( const CBLAS_INT N, const double *
196197
*/
197198
void API_SUFFIX(stdlib_strided_ddiff_ndarray)( const CBLAS_INT N, const CBLAS_INT k, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const double *prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const double *append, const CBLAS_INT strideA, const CBLAS_INT offsetA, double *out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut, double *workspace, const CBLAS_INT strideW, const CBLAS_INT offsetW ) {
198199
CBLAS_INT total;
199-
CBLAS_INT ix;
200-
CBLAS_INT ip;
201-
CBLAS_INT ia;
202-
CBLAS_INT io;
203200
CBLAS_INT n;
204201
CBLAS_INT i;
205202

@@ -209,25 +206,14 @@ void API_SUFFIX(stdlib_strided_ddiff_ndarray)( const CBLAS_INT N, const CBLAS_IN
209206
}
210207

211208
if ( k == 0 ) {
212-
io = offsetOut;
213-
ip = offsetP;
214-
for ( i = 0; i < N1; i++ ) {
215-
out[ io ] = prepend[ ip ];
216-
io += strideOut;
217-
ip += strideP;
218-
}
219-
ix = offsetX;
220-
for ( i = 0; i < N; i++ ) {
221-
out[ io ] = X[ ix ];
222-
io += strideOut;
223-
ix += strideX;
224-
}
225-
ia = offsetA;
226-
for ( i = 0; i < N2; i++ ) {
227-
out[ io ] = append[ ia ];
228-
io += strideOut;
229-
ia += strideA;
230-
}
209+
// Copy `prepend` into output array:
210+
c_dcopy_ndarray( N1, prepend, strideP, offsetP, out, strideOut, offsetOut );
211+
212+
// Copy `x` into output array:
213+
c_dcopy_ndarray( N, X, strideX, offsetX, out, strideOut, offsetOut );
214+
215+
// Copy `append` into output array:
216+
c_dcopy_ndarray( N, append, strideA, offsetA, out, strideOut, offsetOut );
231217
}
232218

233219
if ( k == 1 ) {

0 commit comments

Comments
 (0)