Skip to content

Commit 807f0e2

Browse files
committed
refactor: docs & examples
1 parent bd795d4 commit 807f0e2

12 files changed

Lines changed: 229 additions & 157 deletions

File tree

lib/node_modules/@stdlib/blas/ext/base/slast-index-of-row/README.md

Lines changed: 76 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,12 @@ limitations under the License.
2222

2323
> Return the index of the last row in a single-precision floating-point input matrix which has the same elements as a provided search vector.
2424
25-
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26-
2725
<section class="intro">
2826

2927
</section>
3028

3129
<!-- /.intro -->
3230

33-
<!-- Package usage documentation. -->
34-
3531
<section class="usage">
3632

3733
## Usage
@@ -50,17 +46,16 @@ var Uint8Array = require( '@stdlib/array/uint8' );
5046

5147
/*
5248
A = [
53-
[ 1.0, 3.0 ],
54-
[ 2.0, 4.0 ],
55-
[ 2.0, 4.0 ],
56-
[ 0.0, 0.0 ]
49+
[ 1.0, 2.0 ],
50+
[ 3.0, 4.0 ],
51+
[ 3.0, 4.0 ]
5752
]
5853
*/
59-
var A = new Float32Array( [ 1.0, 2.0, 2.0, 0.0, 3.0, 4.0, 4.0, 0.0 ] );
54+
var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ] );
6055

61-
var x = new Float32Array( [ 2.0, 4.0 ] );
62-
var workspace = new Uint8Array( 4 );
63-
var out = slastIndexOfRow( 'column-major', 4, 2, A, 4, x, 1, workspace, 1 );
56+
var x = new Float32Array( [ 3.0, 4.0 ] );
57+
var workspace = new Uint8Array( 3 );
58+
var out = slastIndexOfRow( 'row-major', 3, 2, A, 2, x, 1, workspace, 1 );
6459
// returns 2
6560
```
6661

@@ -70,11 +65,11 @@ The function has the following parameters:
7065
- **M**: number of rows in `A`.
7166
- **N**: number of columns in `A`.
7267
- **A**: input matrix stored as a [`Float32Array`][mdn-float32array].
73-
- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
68+
- **LDA**: stride length for the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
7469
- **x**: search vector stored as a [`Float32Array`][mdn-float32array].
75-
- **strideX**: stride length of `x`.
76-
- **workspace**: workspace array stored as a [`Uint8Array`][mdn-uint8array] for tracking row match candidates. This parameter is ignored if the function is provided an input matrix stored in row-major order.
77-
- **strideW**: stride length of `workspace`.
70+
- **strideX**: stride length for `x`.
71+
- **workspace**: workspace array stored as a [`Uint8Array`][mdn-uint8array] for tracking row match candidates. This parameter is ignored if the input matrix is stored in row-major order.
72+
- **strideW**: stride length for `workspace`.
7873

7974
When an input matrix is stored in row-major order, the workspace parameter is ignored, and, thus, one may provide an empty workspace array.
8075

@@ -86,15 +81,14 @@ var Uint8Array = require( '@stdlib/array/uint8' );
8681
A = [
8782
[ 1.0, 2.0 ],
8883
[ 3.0, 4.0 ],
89-
[ 3.0, 4.0 ],
90-
[ 0.0, 0.0 ]
84+
[ 3.0, 4.0 ]
9185
]
9286
*/
93-
var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0, 0.0, 0.0 ] );
87+
var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ] );
9488

9589
var x = new Float32Array( [ 3.0, 4.0 ] );
9690
var workspace = new Uint8Array( 0 );
97-
var out = slastIndexOfRow( 'row-major', 4, 2, A, 2, x, 1, workspace, 1 );
91+
var out = slastIndexOfRow( 'row-major', 3, 2, A, 2, x, 1, workspace, 1 );
9892
// returns 2
9993
```
10094

@@ -106,17 +100,16 @@ var Uint8Array = require( '@stdlib/array/uint8' );
106100

107101
/*
108102
A = [
109-
[ 1.0, 3.0 ],
110-
[ 2.0, 4.0 ],
111-
[ 2.0, 4.0 ],
112-
[ 0.0, 0.0 ]
103+
[ 1.0, 2.0 ],
104+
[ 3.0, 4.0 ],
105+
[ 3.0, 4.0 ]
113106
]
114107
*/
115-
var A = new Float32Array( [ 1.0, 2.0, 2.0, 0.0, 3.0, 4.0, 4.0, 0.0 ] );
108+
var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ] );
116109

117110
var x = new Float32Array( [ -3.0, -4.0 ] );
118-
var workspace = new Uint8Array( 4 );
119-
var out = slastIndexOfRow( 'column-major', 4, 2, A, 4, x, 1, workspace, 1 );
111+
var workspace = new Uint8Array( 3 );
112+
var out = slastIndexOfRow( 'row-major', 3, 2, A, 2, x, 1, workspace, 1 );
120113
// returns -1
121114
```
122115

@@ -129,16 +122,16 @@ var Float32Array = require( '@stdlib/array/float32' );
129122
var Uint8Array = require( '@stdlib/array/uint8' );
130123

131124
// Initial arrays:
132-
var A0 = new Float32Array( [ 0.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0, 0.0, 0.0 ] );
133-
var x0 = new Float32Array( [ 0.0, 3.0, 4.0 ] );
125+
var A0 = new Float32Array( [ 9999.0, 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ] );
126+
var x0 = new Float32Array( [ 9999.0, 3.0, 4.0 ] );
134127

135128
// Create offset views:
136129
var A1 = new Float32Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
137130
var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
138131

139-
var workspace = new Uint8Array( 0 );
140-
var out = slastIndexOfRow( 'row-major', 4, 2, A1, 2, x1, 1, workspace, 1 );
141-
// returns 2
132+
var workspace = new Uint8Array( 3 );
133+
var out = slastIndexOfRow( 'row-major', 3, 2, A1, 2, x1, 1, workspace, 1 );
134+
// returns 1
142135
```
143136

144137
<!-- lint disable maximum-heading-length -->
@@ -155,17 +148,16 @@ var Uint8Array = require( '@stdlib/array/uint8' );
155148

156149
/*
157150
A = [
158-
[ 1.0, 3.0 ],
159-
[ 2.0, 4.0 ],
160-
[ 2.0, 4.0 ],
161-
[ 0.0, 0.0 ]
151+
[ 1.0, 2.0 ],
152+
[ 3.0, 4.0 ],
153+
[ 3.0, 4.0 ]
162154
]
163155
*/
164-
var A = new Float32Array( [ 1.0, 2.0, 2.0, 0.0, 3.0, 4.0, 4.0, 0.0 ] );
156+
var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ] );
165157

166-
var x = new Float32Array( [ 2.0, 4.0 ] );
167-
var workspace = new Uint8Array( 4 );
168-
var out = slastIndexOfRow.ndarray( 4, 2, A, 1, 4, 0, x, 1, 0, workspace, 1, 0 );
158+
var x = new Float32Array( [ 3.0, 4.0 ] );
159+
var workspace = new Uint8Array( 3 );
160+
var out = slastIndexOfRow.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0, workspace, 1, 0 );
169161
// returns 2
170162
```
171163

@@ -174,14 +166,14 @@ The function has the following parameters:
174166
- **M**: number of rows in `A`.
175167
- **N**: number of columns in `A`.
176168
- **A**: input matrix stored as a [`Float32Array`][mdn-float32array].
177-
- **strideA1**: stride of the first dimension of `A`.
178-
- **strideA2**: stride of the second dimension of `A`.
169+
- **strideA1**: stride length for the first dimension of `A`.
170+
- **strideA2**: stride length for the second dimension of `A`.
179171
- **offsetA**: starting index for `A`.
180172
- **x**: search vector stored as a [`Float32Array`][mdn-float32array].
181-
- **strideX**: stride length of `x`.
173+
- **strideX**: stride length for `x`.
182174
- **offsetX**: starting index for `x`.
183-
- **workspace**: workspace array stored as a [`Uint8Array`][mdn-uint8array] for tracking row match candidates. This parameter is ignored if the function is provided an input matrix stored in row-major order.
184-
- **strideW**: stride length of `workspace`.
175+
- **workspace**: workspace array stored as a [`Uint8Array`][mdn-uint8array] for tracking row match candidates. This parameter is ignored if the input matrix is stored in row-major order.
176+
- **strideW**: stride length for `workspace`.
185177
- **offsetW**: starting index for `workspace`.
186178

187179
When an input matrix is stored in row-major order, the workspace parameter is ignored, and, thus, one may provide an empty workspace array.
@@ -190,32 +182,57 @@ When an input matrix is stored in row-major order, the workspace parameter is ig
190182
var Float32Array = require( '@stdlib/array/float32' );
191183
var Uint8Array = require( '@stdlib/array/uint8' );
192184

193-
var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0, 0.0, 0.0 ] );
185+
/*
186+
A = [
187+
[ 1.0, 2.0 ],
188+
[ 3.0, 4.0 ],
189+
[ 3.0, 4.0 ]
190+
]
191+
*/
192+
var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ] );
194193

195194
var x = new Float32Array( [ 3.0, 4.0 ] );
196195
var workspace = new Uint8Array( 0 );
197-
var out = slastIndexOfRow.ndarray( 4, 2, A, 2, 1, 0, x, 1, 0, workspace, 1, 0 );
196+
var out = slastIndexOfRow.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0, workspace, 1, 0 );
198197
// returns 2
199198
```
200199

200+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting indices. For example,
201+
202+
```javascript
203+
var Float32Array = require( '@stdlib/array/float32' );
204+
var Uint8Array = require( '@stdlib/array/uint8' );
205+
206+
/*
207+
A = [
208+
[ 1.0, 2.0 ],
209+
[ 3.0, 4.0 ],
210+
[ 0.0, 0.0 ]
211+
]
212+
*/
213+
var A = new Float32Array( [ 9999.0, 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ] );
214+
215+
var x = new Float32Array( [ 9999.0, 3.0, 4.0 ] );
216+
var workspace = new Uint8Array( 3 );
217+
var out = slastIndexOfRow.ndarray( 3, 2, A, 2, 1, 1, x, 1, 1, workspace, 1, 0 );
218+
// returns 1
219+
```
220+
201221
</section>
202222

203223
<!-- /.usage -->
204224

205-
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
206-
207225
<section class="notes">
208226

209227
## Notes
210228

229+
- If `M <= 0` or `N <= 0`, both functions return `-1`.
211230
- When searching for a matching row, the function checks for equality using the strict equality operator `===`. As a consequence, `NaN` values are considered distinct, and `-0` and `+0` are considered the same.
212231

213232
</section>
214233

215234
<!-- /.notes -->
216235

217-
<!-- Package usage examples. -->
218-
219236
<section class="examples">
220237

221238
## Examples
@@ -231,11 +248,11 @@ var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
231248
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
232249
var slastIndexOfRow = require( '@stdlib/blas/ext/base/slast-index-of-row' );
233250

234-
var shape = [ 4, 3 ];
251+
var shape = [ 3, 3 ];
235252
var order = 'row-major';
236253
var strides = shape2strides( shape, order );
237254

238-
var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 4.0, 5.0, 6.0, 0.0, 0.0, 0.0 ] );
255+
var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 4.0, 5.0, 6.0 ] );
239256
console.log( ndarray2array( A, shape, strides, 0, order ) );
240257

241258
var x = new Float32Array( [ 4.0, 5.0, 6.0 ] );
@@ -303,10 +320,10 @@ The function accepts the following arguments:
303320
- **M**: `[in] CBLAS_INT` number of rows in `A`.
304321
- **N**: `[in] CBLAS_INT` number of columns in `A`.
305322
- **A**: `[in] float*` input matrix.
306-
- **LDA**: `[in] CBLAS_INT` stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
323+
- **LDA**: `[in] CBLAS_INT` stride length for the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
307324
- **X**: `[in] float*` search vector.
308325
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
309-
- **workspace**: `[inout] uint8_t*` workspace array for tracking row match candidates. This parameter is ignored if the function is provided an input matrix stored in row-major order.
326+
- **workspace**: `[inout] uint8_t*` workspace array for tracking row match candidates. This parameter is ignored if the input matrix is stored in row-major order.
310327
- **strideW**: `[in] CBLAS_INT` stride length for `workspace`.
311328
312329
When an input matrix is stored in row-major order, the workspace parameter is ignored, and, thus, one may either provide an empty workspace array or a `NULL` pointer.
@@ -349,13 +366,13 @@ The function accepts the following arguments:
349366
- **M**: `[in] CBLAS_INT` number of rows in `A`.
350367
- **N**: `[in] CBLAS_INT` number of columns in `A`.
351368
- **A**: `[in] float*` input matrix.
352-
- **strideA1**: `[in] CBLAS_INT` stride of the first dimension of `A`.
353-
- **strideA2**: `[in] CBLAS_INT` stride of the second dimension of `A`.
354-
- **offsetA**: `[in] CBLAS_INT` index offset for `A`.
369+
- **strideA1**: `[in] CBLAS_INT` stride length for the first dimension of `A`.
370+
- **strideA2**: `[in] CBLAS_INT` stride length for the second dimension of `A`.
371+
- **offsetA**: `[in] CBLAS_INT` starting index for `A`.
355372
- **X**: `[in] float*` search vector.
356373
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
357374
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
358-
- **workspace**: `[inout] uint8_t*` workspace array for tracking row match candidates. This parameter is ignored if the function is provided an input matrix stored in row-major order.
375+
- **workspace**: `[inout] uint8_t*` workspace array for tracking row match candidates. This parameter is ignored if the input matrix is stored in row-major order.
359376
- **strideW**: `[in] CBLAS_INT` stride length for `workspace`.
360377
- **offsetW**: `[in] CBLAS_INT` starting index for `workspace`.
361378

lib/node_modules/@stdlib/blas/ext/base/slast-index-of-row/docs/repl.txt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
Input matrix `A`.
2626

2727
LDA: integer
28-
Stride of the first dimension of `A` (a.k.a., leading dimension of the
29-
matrix `A`).
28+
Stride length for the first dimension of `A` (a.k.a., leading dimension
29+
of the matrix `A`).
3030

3131
x: Float32Array
3232
Search vector.
@@ -35,8 +35,8 @@
3535
Stride length for `x`.
3636

3737
workspace: Uint8Array
38-
Workspace array for tracking row match candidates. This parameter
39-
is ignored if the input matrix is stored in row-major order.
38+
Workspace array for tracking row match candidates. This parameter is
39+
ignored if the input matrix is stored in row-major order.
4040

4141
strideW: integer
4242
Stride length for `workspace`.
@@ -48,11 +48,11 @@
4848

4949
Examples
5050
--------
51-
> var A = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 1.0, 2.0 ] );
52-
> var x = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0 ] );
53-
> var w = new {{alias:@stdlib/array/uint8}}( 2 );
54-
> {{alias}}( 'row-major', 2, 2, A, 2, x, 1, w, 1 )
55-
1
51+
> var A = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ] );
52+
> var x = new {{alias:@stdlib/array/float32}}( [ 3.0, 4.0 ] );
53+
> var w = new {{alias:@stdlib/array/uint8}}( 3 );
54+
> {{alias}}( 'row-major', 3, 2, A, 2, x, 1, w, 1 )
55+
2
5656

5757

5858
{{alias}}.ndarray( M, N, A, sa1, sa2, oa, x, sx, ox, w, sw, ow )
@@ -79,10 +79,10 @@
7979
Input matrix `A`.
8080

8181
sa1: integer
82-
Stride of the first dimension of `A`.
82+
Stride length for the first dimension of `A`.
8383

8484
sa2: integer
85-
Stride of the second dimension of `A`.
85+
Stride length for the second dimension of `A`.
8686

8787
oa: integer
8888
Starting index for `A`.
@@ -97,8 +97,8 @@
9797
Starting index for `x`.
9898

9999
w: Uint8Array
100-
Workspace array for tracking row match candidates. This parameter
101-
is ignored if the input matrix is stored in row-major order.
100+
Workspace array for tracking row match candidates. This parameter is
101+
ignored if the input matrix is stored in row-major order.
102102

103103
sw: integer
104104
Stride length for `w`.
@@ -113,11 +113,11 @@
113113

114114
Examples
115115
--------
116-
> var A = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 1.0, 2.0 ] );
117-
> var x = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0 ] );
118-
> var w = new {{alias:@stdlib/array/uint8}}( 2 );
119-
> {{alias}}.ndarray( 2, 2, A, 2, 1, 0, x, 1, 0, w, 1, 0 )
120-
1
116+
> var A = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ] );
117+
> var x = new {{alias:@stdlib/array/float32}}( [ 3.0, 4.0 ] );
118+
> var w = new {{alias:@stdlib/array/uint8}}( 3 );
119+
> {{alias}}.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0, w, 1, 0 )
120+
2
121121

122122
See Also
123123
--------

0 commit comments

Comments
 (0)