Skip to content

Commit b98fb7f

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: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent a0db025 commit b98fb7f

24 files changed

Lines changed: 530 additions & 321 deletions

lib/node_modules/@stdlib/blas/ext/base/dcartesian-power/README.md

Lines changed: 54 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ limitations under the License.
2222

2323
> Compute the Cartesian power for a double-precision floating-point strided array.
2424
25-
<section class="intro">
26-
27-
</section>
28-
29-
<!-- /.intro -->
30-
3125
<section class="usage">
3226

3327
## Usage
@@ -52,13 +46,13 @@ dcartesianPower( 'row-major', x.length, 2, x, 1, out, 2 );
5246

5347
The function has the following parameters:
5448

55-
- **order**: storage layout.
49+
- **order**: storage layout. Must be either `'row-major'` or `'column-major'`.
5650
- **N**: number of indexed elements.
5751
- **k**: power.
5852
- **x**: input [`Float64Array`][@stdlib/array/float64].
5953
- **strideX**: stride length for `x`.
6054
- **out**: output [`Float64Array`][@stdlib/array/float64].
61-
- **LDO**: stride length for the leading dimension of `out`.
55+
- **LDO**: stride length between successive contiguous vectors of the matrix `out` (a.k.a., leading dimension of `out`).
6256

6357
The `N`, `k`, and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the Cartesian power of every other element:
6458

@@ -74,27 +68,27 @@ dcartesianPower( 'row-major', 2, 2, x, 2, out, 2 );
7468

7569
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
7670

77-
<!-- eslint-disable stdlib/capitalized-comments -->
78-
7971
```javascript
8072
var Float64Array = require( '@stdlib/array/float64' );
8173

82-
// Initial arrays...
83-
var x0 = new Float64Array( [ 0.0, 1.0, 2.0 ] );
84-
var out0 = new Float64Array( 8 );
74+
// Initial array:
75+
var x0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] );
8576

86-
// Create offset views...
77+
// Create an offset view:
8778
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
8879

89-
dcartesianPower( 'row-major', 2, 2, x1, 1, out0, 2 );
90-
// out0 => <Float64Array>[ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]
80+
// Output array:
81+
var out = new Float64Array( 8 );
82+
83+
dcartesianPower( 'row-major', 2, 2, x1, 1, out, 2 );
84+
// out => <Float64Array>[ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]
9185
```
9286

93-
<!--lint disable maximum-heading-length-->
87+
<!-- lint disable maximum-heading-length -->
9488

9589
#### dcartesianPower.ndarray( N, k, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut )
9690

97-
<!--lint enable maximum-heading-length-->
91+
<!-- lint enable maximum-heading-length -->
9892

9993
Computes the Cartesian power for a double-precision floating-point strided array using alternative indexing semantics.
10094

@@ -108,22 +102,27 @@ dcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, 1, 0 );
108102
// out => <Float64Array>[ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]
109103
```
110104

111-
The function has the following additional parameters:
105+
The function has the following parameters:
112106

107+
- **N**: number of indexed elements.
108+
- **k**: power.
109+
- **x**: input [`Float64Array`][@stdlib/array/float64].
110+
- **strideX**: stride length for `x`.
113111
- **offsetX**: starting index for `x`.
114-
- **strideOut1**: stride length for the first dimension of `out`.
115-
- **strideOut2**: stride length for the second dimension of `out`.
112+
- **out**: output [`Float64Array`][@stdlib/array/float64].
113+
- **strideOut1**: stride length of the first dimension of `out`.
114+
- **strideOut2**: stride length of the second dimension of `out`.
116115
- **offsetOut**: starting index for `out`.
117116

118-
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to compute the Cartesian power of every other value in the strided input array starting from the second value:
117+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to access only the last two elements:
119118

120119
```javascript
121120
var Float64Array = require( '@stdlib/array/float64' );
122121

123-
var x = new Float64Array( [ 0.0, 1.0, 2.0 ] );
122+
var x = new Float64Array( [ 0.0, 0.0, 1.0, 2.0 ] );
124123
var out = new Float64Array( 8 );
125124

126-
dcartesianPower.ndarray( 2, 2, x, 1, 1, out, 2, 1, 0 );
125+
dcartesianPower.ndarray( 2, 2, x, 1, 2, out, 2, 1, 0 );
127126
// out => <Float64Array>[ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]
128127
```
129128

@@ -135,9 +134,10 @@ dcartesianPower.ndarray( 2, 2, x, 1, 1, out, 2, 1, 0 );
135134

136135
## Notes
137136

137+
- `k`-tuples are stored as rows in the output matrix, where the `j`-th column contains the `j`-th element of each tuple.
138+
- For an input array of length `N`, the output array must contain at least `N^k * k` indexed elements.
139+
- For row-major order, the `LDO` parameter must be greater than or equal to `max(1,k)`. For column-major order, the `LDO` parameter must be greater than or equal to `max(1,N^k)`.
138140
- If `N <= 0` or `k <= 0`, both functions return `out` unchanged.
139-
- The output array must contain at least `N^k * k` elements.
140-
- The `LDO` parameter must be greater than or equal to `max(1, k)`.
141141

142142
</section>
143143

@@ -150,15 +150,20 @@ dcartesianPower.ndarray( 2, 2, x, 1, 1, out, 2, 1, 0 );
150150
<!-- eslint no-undef: "error" -->
151151

152152
```javascript
153+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
153154
var Float64Array = require( '@stdlib/array/float64' );
155+
var pow = require( '@stdlib/math/base/special/pow' );
154156
var dcartesianPower = require( '@stdlib/blas/ext/base/dcartesian-power' );
155157

156-
var x = new Float64Array( [ 1.0, 2.0 ] );
158+
var N = 2;
159+
var k = 3;
160+
var x = discreteUniform( N, 1, 10, {
161+
'dtype': 'float64'
162+
});
157163
console.log( x );
158164

159-
var out = new Float64Array( 24 );
160-
161-
dcartesianPower( 'row-major', x.length, 3, x, 1, out, 3 );
165+
var out = new Float64Array( pow( N, k ) * k );
166+
dcartesianPower( 'row-major', N, k, x, 1, out, k );
162167
console.log( out );
163168
```
164169

@@ -192,21 +197,17 @@ console.log( out );
192197
#include "stdlib/blas/ext/base/dcartesianpower.h"
193198
```
194199

195-
<!--lint disable maximum-heading-length-->
196-
197200
#### stdlib_strided_dcartesian_power( order, N, k, \*X, strideX, \*Out, LDO )
198201

199-
<!--lint enable maximum-heading-length-->
200-
201202
Computes the Cartesian power for a double-precision floating-point strided array.
202203

203204
```c
204205
#include "stdlib/blas/base/shared.h"
205206

206-
const double X[] = { 1.0, 2.0 };
207-
double Out[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
207+
const double x[] = { 1.0, 2.0 };
208+
double out[ 8 ];
208209

209-
stdlib_strided_dcartesian_power( CblasRowMajor, 2, 2, X, 1, Out, 2 );
210+
stdlib_strided_dcartesian_power( CblasRowMajor, 2, 2, x, 1, out, 2 );
210211
```
211212
212213
The function accepts the following arguments:
@@ -217,25 +218,25 @@ The function accepts the following arguments:
217218
- **X**: `[in] double*` input array.
218219
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
219220
- **Out**: `[out] double*` output array.
220-
- **LDO**: `[in] CBLAS_INT` stride length for the leading dimension of `Out`.
221+
- **LDO**: `[in] CBLAS_INT` stride length between successive contiguous vectors of the matrix `Out` (a.k.a., leading dimension of `Out`). For row-major order, must be greater than or equal to `max(1,k)`. For column-major order, must be greater than or equal to `max(1,N^k)`.
221222
222223
```c
223224
void stdlib_strided_dcartesian_power( const CBLAS_LAYOUT order, const CBLAS_INT N, const CBLAS_INT k, const double *X, const CBLAS_INT strideX, double *Out, const CBLAS_INT LDO );
224225
```
225226

226-
<!--lint disable maximum-heading-length-->
227+
<!-- lint disable maximum-heading-length -->
227228

228229
#### stdlib_strided_dcartesian_power_ndarray( N, k, \*X, strideX, offsetX, \*Out, strideOut1, strideOut2, offsetOut )
229230

230-
<!--lint enable maximum-heading-length-->
231+
<!-- lint enable maximum-heading-length -->
231232

232233
Computes the Cartesian power for a double-precision floating-point strided array using alternative indexing semantics.
233234

234235
```c
235-
const double X[] = { 1.0, 2.0 };
236-
double Out[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
236+
const double x[] = { 1.0, 2.0 };
237+
double out[ 8 ];
237238

238-
stdlib_strided_dcartesian_power_ndarray( 2, 2, X, 1, 0, Out, 2, 1, 0 );
239+
stdlib_strided_dcartesian_power_ndarray( 2, 2, x, 1, 0, out, 2, 1, 0 );
239240
```
240241
241242
The function accepts the following arguments:
@@ -246,8 +247,8 @@ The function accepts the following arguments:
246247
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
247248
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
248249
- **Out**: `[out] double*` output array.
249-
- **strideOut1**: `[in] CBLAS_INT` stride length for the first dimension of `Out`.
250-
- **strideOut2**: `[in] CBLAS_INT` stride length for the second dimension of `Out`.
250+
- **strideOut1**: `[in] CBLAS_INT` stride length of the first dimension of `Out`.
251+
- **strideOut2**: `[in] CBLAS_INT` stride length of the second dimension of `Out`.
251252
- **offsetOut**: `[in] CBLAS_INT` starting index for `Out`.
252253
253254
```c
@@ -276,28 +277,30 @@ void stdlib_strided_dcartesian_power_ndarray( const CBLAS_INT N, const CBLAS_INT
276277
#include "stdlib/blas/ext/base/dcartesianpower.h"
277278
#include "stdlib/blas/base/shared.h"
278279
#include <stdio.h>
280+
#include <math.h>
279281

280282
int main( void ) {
281283
// Create a strided input array:
282-
const double X[] = { 1.0, 2.0 };
284+
const double x[] = { 1.0, 2.0 };
283285

284286
// Specify the number of indexed elements and power:
285287
const int N = 2;
286288
const int k = 2;
287289

288-
// Create an output array:
289-
double out[ 8 ] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
290+
// Create an output array (N^k tuples, each tuple has k elements):
291+
double out[ 8 ];
290292

291293
// Specify strides:
292294
const int strideX = 1;
293295
const int LDO = 2;
294296

295297
// Compute the Cartesian power:
296-
stdlib_strided_dcartesian_power( CblasRowMajor, N, k, X, strideX, out, LDO );
298+
stdlib_strided_dcartesian_power( CblasRowMajor, N, k, x, strideX, out, LDO );
297299

298300
// Print the result:
299-
for ( int i = 0; i < N*N; i++ ) {
300-
printf( "out[ %i ] = ( %lf, %lf )\n", i, out[ i*2 ], out[ i*2+1 ] );
301+
const int len = (int)pow( N, k );
302+
for ( int i = 0; i < len; i++ ) {
303+
printf( "out[ %i ] = ( %lf, %lf )\n", i, out[ i*2 ], out[ (i*2)+1 ] );
301304
}
302305
}
303306
```
@@ -310,12 +313,6 @@ int main( void ) {
310313
311314
<!-- /.c -->
312315
313-
<section class="references">
314-
315-
</section>
316-
317-
<!-- /.references -->
318-
319316
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
320317
321318
<section class="related">

lib/node_modules/@stdlib/blas/ext/base/dcartesian-power/benchmark/benchmark.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ var dcartesianPower = require( './../lib/dcartesianpower.js' );
3232

3333
// VARIABLES //
3434

35-
var K = 2;
3635
var options = {
3736
'dtype': 'float64'
3837
};
38+
var K = 2;
3939

4040

4141
// FUNCTIONS //
4242

4343
/**
44-
* Creates a benchmark function.
44+
* Create a benchmark function.
4545
*
4646
* @private
4747
* @param {PositiveInteger} len - array length
@@ -62,18 +62,18 @@ function createBenchmark( len ) {
6262
* @param {Benchmark} b - benchmark instance
6363
*/
6464
function benchmark( b ) {
65-
var z;
65+
var y;
6666
var i;
6767

6868
b.tic();
6969
for ( i = 0; i < b.iterations; i++ ) {
70-
z = dcartesianPower( 'row-major', x.length, K, x, 1, out, K );
71-
if ( isnan( z[ 0 ] ) ) {
70+
y = dcartesianPower( 'row-major', x.length, K, x, 1, out, K );
71+
if ( isnan( y[ 0 ] ) ) {
7272
b.fail( 'should not return NaN' );
7373
}
7474
}
7575
b.toc();
76-
if ( isnan( z[ 0 ] ) ) {
76+
if ( isnan( y[ 0 ] ) ) {
7777
b.fail( 'should not return NaN' );
7878
}
7979
b.pass( 'benchmark finished' );
@@ -84,6 +84,11 @@ function createBenchmark( len ) {
8484

8585
// MAIN //
8686

87+
/**
88+
* Main execution sequence.
89+
*
90+
* @private
91+
*/
8792
function main() {
8893
var len;
8994
var min;

lib/node_modules/@stdlib/blas/ext/base/dcartesian-power/benchmark/benchmark.native.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ var dcartesianPower = tryRequire( resolve( __dirname, './../lib/dcartesianpower.
3737
var opts = {
3838
'skip': ( dcartesianPower instanceof Error )
3939
};
40-
var K = 2;
4140
var options = {
4241
'dtype': 'float64'
4342
};
43+
var K = 2;
4444

4545

4646
// FUNCTIONS //
4747

4848
/**
49-
* Creates a benchmark function.
49+
* Create a benchmark function.
5050
*
5151
* @private
5252
* @param {PositiveInteger} len - array length
@@ -67,18 +67,18 @@ function createBenchmark( len ) {
6767
* @param {Benchmark} b - benchmark instance
6868
*/
6969
function benchmark( b ) {
70-
var z;
70+
var y;
7171
var i;
7272

7373
b.tic();
7474
for ( i = 0; i < b.iterations; i++ ) {
75-
z = dcartesianPower( 'row-major', x.length, K, x, 1, out, K );
76-
if ( isnan( z[ 0 ] ) ) {
75+
y = dcartesianPower( 'row-major', x.length, K, x, 1, out, K );
76+
if ( isnan( y[ 0 ] ) ) {
7777
b.fail( 'should not return NaN' );
7878
}
7979
}
8080
b.toc();
81-
if ( isnan( z[ 0 ] ) ) {
81+
if ( isnan( y[ 0 ] ) ) {
8282
b.fail( 'should not return NaN' );
8383
}
8484
b.pass( 'benchmark finished' );
@@ -89,6 +89,11 @@ function createBenchmark( len ) {
8989

9090
// MAIN //
9191

92+
/**
93+
* Main execution sequence.
94+
*
95+
* @private
96+
*/
9297
function main() {
9398
var len;
9499
var min;

0 commit comments

Comments
 (0)