Skip to content

Commit 5d940dc

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: 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 b76249d commit 5d940dc

19 files changed

Lines changed: 674 additions & 159 deletions

File tree

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

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ limitations under the License.
3030
var dcartesianProduct = require( '@stdlib/blas/ext/base/dcartesian-product' );
3131
```
3232

33-
#### dcartesianProduct( M, N, x, strideX, y, strideY, out, LDO )
33+
#### dcartesianProduct( order, M, N, x, strideX, y, strideY, out, LDO )
3434

3535
Computes the Cartesian product for two double-precision floating-point strided arrays.
3636

@@ -42,12 +42,13 @@ var y = new Float64Array( [ 3.0, 4.0 ] );
4242
var out = new Float64Array( 8 );
4343

4444
// Compute the Cartesian product:
45-
dcartesianProduct( x.length, y.length, x, 1, y, 1, out, 2 );
45+
dcartesianProduct( 'row-major', x.length, y.length, x, 1, y, 1, out, 2 );
4646
// out => <Float64Array>[ 1.0, 3.0, 1.0, 4.0, 2.0, 3.0, 2.0, 4.0 ]
4747
```
4848

4949
The function has the following parameters:
5050

51+
- **order**: storage layout.
5152
- **M**: number of indexed elements of `x`.
5253
- **N**: number of indexed elements of `y`.
5354
- **x**: input [`Float64Array`][@stdlib/array/float64].
@@ -57,7 +58,7 @@ The function has the following parameters:
5758
- **out**: output [`Float64Array`][@stdlib/array/float64].
5859
- **LDO**: stride length for the leading dimension of `out`.
5960

60-
The `M`, `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the Cartesian square of every other element:
61+
The `M`, `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the Cartesian product of every other element:
6162

6263
```javascript
6364
var Float64Array = require( '@stdlib/array/float64' );
@@ -67,7 +68,7 @@ var y = new Float64Array( [ 3.0, 0.0, 4.0, 0.0 ] );
6768
var out = new Float64Array( 8 );
6869

6970
// Compute the Cartesian product:
70-
dcartesianProduct( 2, 2, x, 2, y, 2, out, 2 );
71+
dcartesianProduct( 'row-major', 2, 2, x, 2, y, 2, out, 2 );
7172
// out => <Float64Array>[ 1.0, 3.0, 1.0, 4.0, 2.0, 3.0, 2.0, 4.0 ]
7273
```
7374

@@ -87,7 +88,7 @@ var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd
8788
var out = new Float64Array( 8 );
8889

8990
// Compute the Cartesian product:
90-
dcartesianProduct( 2, 2, x1, 1, y1, 1, out, 2 );
91+
dcartesianProduct( 'row-major', 2, 2, x1, 1, y1, 1, out, 2 );
9192
// out => <Float64Array>[ 1.0, 3.0, 1.0, 4.0, 2.0, 3.0, 2.0, 4.0 ]
9293
```
9394

@@ -141,7 +142,7 @@ dcartesianProduct.ndarray( 2, 2, x, 1, 2, y, 1, 2, out, 2, 1, 0 );
141142

142143
## Notes
143144

144-
- For an input array `x` of length `M` and an input array `y` of length `N`, the output array `out` must contain at least `M*N*2` elements.
145+
- For an input array `x` of length `M` and an input array `y` of length `N`, the output array `out` must contain at least `M*N*LDO` elements.
145146
- If `N <= 0` or `M <= 0`, both functions return `out` unchanged.
146147

147148
</section>
@@ -160,7 +161,7 @@ var Float64Array = require( '@stdlib/array/float64' );
160161
var dcartesianProduct = require( '@stdlib/blas/ext/base/dcartesian-product' );
161162

162163
var M = 3;
163-
var N = 4;
164+
var N = 2;
164165
var x = discreteUniform( M, 1, 10, {
165166
'dtype': 'float64'
166167
});
@@ -174,7 +175,7 @@ console.log( y );
174175
var out = new Float64Array( M * N * 2 );
175176

176177
// Compute the Cartesian product:
177-
dcartesianProduct( M, N, x, 1, y, 1, out, 2 );
178+
dcartesianProduct( 'row-major', M, N, x, 1, y, 1, out, 2 );
178179
console.log( out );
179180
```
180181

@@ -208,20 +209,27 @@ console.log( out );
208209
#include "stdlib/blas/ext/base/dcartesianproduct.h"
209210
```
210211

211-
#### stdlib_strided_dcartesian_product( M, N, \*X, strideX, \*Y, strideY, \*Out, LDO )
212+
<!--lint disable maximum-heading-length-->
213+
214+
#### stdlib_strided_dcartesian_product( order, M, N, \*X, strideX, \*Y, strideY, \*Out, LDO )
215+
216+
<!--lint enable maximum-heading-length-->
212217

213218
Computes the Cartesian product for two double-precision floating-point strided arrays.
214219

215220
```c
221+
#include "stdlib/blas/base/shared.h"
222+
216223
const double x[] = { 1.0, 2.0 };
217224
const double y[] = { 3.0, 4.0 };
218225
double out[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
219226

220-
stdlib_strided_dcartesian_product( 2, 2, x, 1, y, 1, out, 2 );
227+
stdlib_strided_dcartesian_product( CblasRowMajor, 2, 2, x, 1, y, 1, out, 2 );
221228
```
222229
223230
The function accepts the following arguments:
224231
232+
- **order**: `[in] CBLAS_LAYOUT` storage layout.
225233
- **M**: `[in] CBLAS_INT` number of indexed elements of `X`.
226234
- **N**: `[in] CBLAS_INT` number of indexed elements of `Y`.
227235
- **X**: `[in] double*` input array.
@@ -232,7 +240,7 @@ The function accepts the following arguments:
232240
- **LDO**: `[in] CBLAS_INT` stride of the leading dimension of `Out`.
233241
234242
```c
235-
void stdlib_strided_dcartesian_product( const CBLAS_INT M, const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY, double *Out, const CBLAS_INT LDO );
243+
void stdlib_strided_dcartesian_product( const CBLAS_LAYOUT order, const CBLAS_INT M, const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY, double *Out, const CBLAS_INT LDO );
236244
```
237245

238246
<!--lint disable maximum-heading-length-->
@@ -290,6 +298,7 @@ void stdlib_strided_dcartesian_product_ndarray( const CBLAS_INT M, const CBLAS_I
290298

291299
```c
292300
#include "stdlib/blas/ext/base/dcartesianproduct.h"
301+
#include "stdlib/blas/base/shared.h"
293302
#include <stdio.h>
294303

295304
int main( void ) {
@@ -301,20 +310,20 @@ int main( void ) {
301310
const int M = 4;
302311
const int N = 4;
303312

304-
// Create an output array (M*N pairs, each pair has 2 elements):
305-
double out[ 32 ];
313+
// Create an output array (M*N pairs, each pair has LDO elements):
314+
double out[ 64 ];
306315

307316
// Specify strides:
308317
const int strideX = 1;
309318
const int strideY = 1;
310-
const int LDO = 2;
319+
const int LDO = 4;
311320

312321
// Compute the Cartesian product:
313-
stdlib_strided_dcartesian_product( M, N, X, strideX, Y, strideY, out, LDO );
322+
stdlib_strided_dcartesian_product( CblasRowMajor, M, N, X, strideX, Y, strideY, out, LDO );
314323

315324
// Print the result:
316325
for ( int i = 0; i < M*N; i++ ) {
317-
printf( "out[ %i ] = ( %lf, %lf )\n", i, out[ i*2 ], out[ i*2+1 ] );
326+
printf( "out[ %i ] = ( %lf, %lf )\n", i, out[ i*LDO ], out[ i*LDO+1 ] );
318327
}
319328
}
320329
```

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function createBenchmark( len ) {
5353

5454
x = uniform( len, -10.0, 10.0, options );
5555
y = uniform( len, -10.0, 10.0, options );
56-
out = new Float64Array( len * len * 2 );
56+
out = new Float64Array( len * len * len );
5757
return benchmark;
5858

5959
/**
@@ -68,7 +68,7 @@ function createBenchmark( len ) {
6868

6969
b.tic();
7070
for ( i = 0; i < b.iterations; i++ ) {
71-
z = dcartesianProduct( x.length, y.length, x, 1, y, 1, out, 2 );
71+
z = dcartesianProduct( 'row-major', x.length, y.length, x, 1, y, 1, out, len );
7272
if ( isnan( z[ 0 ] ) ) {
7373
b.fail( 'should not return NaN' );
7474
}
@@ -93,7 +93,7 @@ function main() {
9393
var i;
9494

9595
min = 1; // 10^min
96-
max = 3; // 10^max
96+
max = 2; // 10^max
9797

9898
for ( i = min; i <= max; i++ ) {
9999
len = pow( 10, i );

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function createBenchmark( len ) {
5858

5959
x = uniform( len, -10.0, 10.0, options );
6060
y = uniform( len, -10.0, 10.0, options );
61-
out = new Float64Array( len * len * 2 );
61+
out = new Float64Array( len * len * len );
6262
return benchmark;
6363

6464
/**
@@ -73,7 +73,7 @@ function createBenchmark( len ) {
7373

7474
b.tic();
7575
for ( i = 0; i < b.iterations; i++ ) {
76-
z = dcartesianProduct( x.length, y.length, x, 1, y, 1, out, 2 );
76+
z = dcartesianProduct( 'row-major', x.length, y.length, x, 1, y, 1, out, len );
7777
if ( isnan( z[ 0 ] ) ) {
7878
b.fail( 'should not return NaN' );
7979
}
@@ -98,7 +98,7 @@ function main() {
9898
var i;
9999

100100
min = 1; // 10^min
101-
max = 3; // 10^max
101+
max = 2; // 10^max
102102

103103
for ( i = min; i <= max; i++ ) {
104104
len = pow( 10, i );

lib/node_modules/@stdlib/blas/ext/base/dcartesian-product/benchmark/c/benchmark.length.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
#include "stdlib/blas/ext/base/dcartesianproduct.h"
20+
#include "stdlib/blas/base/shared.h"
2021
#include <stdlib.h>
2122
#include <stdio.h>
2223
#include <math.h>
@@ -27,7 +28,7 @@
2728
#define ITERATIONS 1000000
2829
#define REPEATS 3
2930
#define MIN 1
30-
#define MAX 3
31+
#define MAX 2
3132

3233
/**
3334
* Prints the TAP version.
@@ -104,14 +105,14 @@ static double benchmark1( int iterations, int len ) {
104105

105106
x = (double *) malloc( len * sizeof( double ) );
106107
y = (double *) malloc( len * sizeof( double ) );
107-
out = (double *) malloc( len * len * 2 * sizeof( double ) );
108+
out = (double *) malloc( len * len * len * sizeof( double ) );
108109
for ( i = 0; i < len; i++ ) {
109110
x[ i ] = ( rand_double()*200.0 ) - 100.0;
110111
y[ i ] = ( rand_double()*200.0 ) - 100.0;
111112
}
112113
t = tic();
113114
for ( i = 0; i < iterations; i++ ) {
114-
stdlib_strided_dcartesian_product( len, len, x, 1, y, 1, out, 2 );
115+
stdlib_strided_dcartesian_product( CblasRowMajor, len, len, x, 1, y, 1, out, len );
115116
if ( out[ 0 ] != out[ 0 ] ) {
116117
printf( "should not return NaN\n" );
117118
break;
@@ -188,14 +189,14 @@ int main( void ) {
188189
iter = ITERATIONS / (int) pow( 10, i-1 );
189190
for ( j = 0; j < REPEATS; j++ ) {
190191
count += 1;
191-
printf( "# c::%s:len=%d\n", NAME, len );
192+
printf( "# c::native::%s:len=%d\n", NAME, len );
192193
elapsed = benchmark1( iter, len );
193194
print_results( iter, elapsed );
194195
printf( "ok %d benchmark finished\n", count );
195196
}
196197
for ( j = 0; j < REPEATS; j++ ) {
197198
count += 1;
198-
printf( "# c::%s:ndarray:len=%d\n", NAME, len );
199+
printf( "# c::native::%s:ndarray:len=%d\n", NAME, len );
199200
elapsed = benchmark2( iter, len );
200201
print_results( iter, elapsed );
201202
printf( "ok %d benchmark finished\n", count );

lib/node_modules/@stdlib/blas/ext/base/dcartesian-product/binding.gyp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,39 @@
2929
# Target name should match the add-on export name:
3030
'addon_target_name%': 'addon',
3131

32+
# Fortran compiler (to override -Dfortran_compiler=<compiler>):
33+
'fortran_compiler%': 'gfortran',
34+
35+
# Fortran compiler flags:
36+
'fflags': [
37+
# Specify the Fortran standard to which a program is expected to conform:
38+
'-std=f95',
39+
40+
# Indicate that the layout is free-form source code:
41+
'-ffree-form',
42+
43+
# Aggressive optimization:
44+
'-O3',
45+
46+
# Enable commonly used warning options:
47+
'-Wall',
48+
49+
# Warn if source code contains problematic language features:
50+
'-Wextra',
51+
52+
# Warn if a procedure is called without an explicit interface:
53+
'-Wimplicit-interface',
54+
55+
# Do not transform names of entities specified in Fortran source files by appending underscores (i.e., don't mangle names, thus allowing easier usage in C wrappers):
56+
'-fno-underscoring',
57+
58+
# Warn if source code contains Fortran 95 extensions and C-language constructs:
59+
'-pedantic',
60+
61+
# Compile but do not link (output is an object file):
62+
'-c',
63+
],
64+
3265
# Set variables based on the host OS:
3366
'conditions': [
3467
[
@@ -128,6 +161,68 @@
128161
},
129162
], # end condition (OS!="win")
130163
], # end conditions
164+
165+
# Define custom build actions for particular inputs:
166+
'rules': [
167+
{
168+
# Define a rule for processing Fortran files:
169+
'extension': 'f',
170+
171+
# Define the pathnames to be used as inputs when performing processing:
172+
'inputs': [
173+
# Full path of the current input:
174+
'<(RULE_INPUT_PATH)'
175+
],
176+
177+
# Define the outputs produced during processing:
178+
'outputs': [
179+
# Store an output object file in a directory for placing intermediate results (only accessible within a single target):
180+
'<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).<(obj)'
181+
],
182+
183+
# Define the rule for compiling Fortran based on the host OS:
184+
'conditions': [
185+
[
186+
'OS=="win"',
187+
188+
# Rule to compile Fortran on Windows:
189+
{
190+
'rule_name': 'compile_fortran_windows',
191+
'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Windows...',
192+
193+
'process_outputs_as_sources': 0,
194+
195+
# Define the command-line invocation:
196+
'action': [
197+
'<(fortran_compiler)',
198+
'<@(fflags)',
199+
'<@(_inputs)',
200+
'-o',
201+
'<@(_outputs)',
202+
],
203+
},
204+
205+
# Rule to compile Fortran on non-Windows:
206+
{
207+
'rule_name': 'compile_fortran_linux',
208+
'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Linux...',
209+
210+
'process_outputs_as_sources': 1,
211+
212+
# Define the command-line invocation:
213+
'action': [
214+
'<(fortran_compiler)',
215+
'<@(fflags)',
216+
'-fPIC', # generate platform-independent code
217+
'<@(_inputs)',
218+
'-o',
219+
'<@(_outputs)',
220+
],
221+
}
222+
], # end condition (OS=="win")
223+
], # end conditions
224+
}, # end rule (extension=="f")
225+
], # end rules
131226
}, # end target <(addon_target_name)
132227

133228
# Target to copy a generated add-on to a standard location:

lib/node_modules/@stdlib/blas/ext/base/dcartesian-product/docs/repl.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
{{alias}}( M, N, x, strideX, y, strideY, out, LDO )
2+
{{alias}}( order, M, N, x, strideX, y, strideY, out, LDO )
33
Computes the Cartesian product for two double-precision floating-point
44
strided arrays.
55

@@ -10,6 +10,9 @@
1010

1111
Parameters
1212
----------
13+
order: string
14+
Storage layout.
15+
1316
M: integer
1417
Number of indexed elements of `x`.
1518

@@ -45,14 +48,14 @@
4548
> var x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] );
4649
> var y = new {{alias:@stdlib/array/float64}}( [ 3.0, 4.0 ] );
4750
> var out = new {{alias:@stdlib/array/float64}}( 8 );
48-
> {{alias}}( x.length, y.length, x, 1, y, 1, out, 2 )
51+
> {{alias}}( 'row-major', x.length, y.length, x, 1, y, 1, out, 2 )
4952
<Float64Array>[ 1.0, 3.0, 1.0, 4.0, 2.0, 3.0, 2.0, 4.0 ]
5053

5154
// Using `M`, `N`, and stride parameters:
5255
> x = new {{alias:@stdlib/array/float64}}( [ 1.0, 0.0, 2.0, 0.0 ] );
5356
> y = new {{alias:@stdlib/array/float64}}( [ 3.0, 4.0 ] );
5457
> out = new {{alias:@stdlib/array/float64}}( 8 );
55-
> {{alias}}( 2, y.length, x, 2, y, 1, out, 2 )
58+
> {{alias}}( 'row-major', 2, y.length, x, 2, y, 1, out, 2 )
5659
<Float64Array>[ 1.0, 3.0, 1.0, 4.0, 2.0, 3.0, 2.0, 4.0 ]
5760

5861

0 commit comments

Comments
 (0)