@@ -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
5347The 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
6357The ` 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
7569Note 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
8072var 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:
8778var 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
9993Computes 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
121120var 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 ] );
124123var 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' );
153154var Float64Array = require ( ' @stdlib/array/float64' );
155+ var pow = require ( ' @stdlib/math/base/special/pow' );
154156var 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+ });
157163console .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 );
162167console .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-
201202Computes 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
212213The 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
223224void 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
232233Computes 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
241242The 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
280282int 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">
0 commit comments