Skip to content

Commit

Permalink
docs: update examples for blas/base/wasm/zswap
Browse files Browse the repository at this point in the history
PR-URL: #5770
Ref: #4833

Reviewed-by: Philipp Burckhardt <[email protected]>
  • Loading branch information
gururaj1512 authored Mar 4, 2025
1 parent c5f6ec6 commit bd9b313
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 391 deletions.
110 changes: 10 additions & 100 deletions lib/node_modules/@stdlib/blas/base/wasm/zswap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,13 @@ Interchanges two complex double-precision floating-point vectors.

```javascript
var Complex128Array = require( '@stdlib/array/complex128' );
var real = require( '@stdlib/complex/float64/real' );
var imag = require( '@stdlib/complex/float64/imag' );

var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

zswap.main( x.length, x, 1, y, 1 );

var z = y.get( 0 );
// returns <Complex128>

var re = real( z );
// returns 1.0

var im = imag( z );
// returns 2.0

z = x.get( 0 );
// returns <Complex128>

re = real( z );
// returns 0.0

im = imag( z );
// returns 0.0
// x => <Complex128Array>[ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]
// y => <Complex128Array>[ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]
```

The function has the following parameters:
Expand All @@ -75,31 +57,13 @@ The `N` and stride parameters determine how values from `x` are interchanged wit

```javascript
var Complex128Array = require( '@stdlib/array/complex128' );
var real = require( '@stdlib/complex/float64/real' );
var imag = require( '@stdlib/complex/float64/imag' );

var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

zswap.main( 2, x, -2, y, 1 );

var z = y.get( 0 );
// returns <Complex128>

var re = real( z );
// returns 5.0

var im = imag( z );
// returns 6.0

z = x.get( 0 );
// returns <Complex128>

re = real( z );
// returns 0.0

im = imag( z );
// returns 0.0
// x => <Complex128Array>[ 0.0, 0.0, 3.0, 4.0, 0.0, 0.0, 7.0, 8.0 ]
// y => <Complex128Array>[ 5.0, 6.0, 1.0, 2.0, 0.0, 0.0, 0.0, 0.0 ]
```

Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
Expand All @@ -108,8 +72,6 @@ Note that indexing is relative to the first index. To introduce an offset, use [

```javascript
var Complex128Array = require( '@stdlib/array/complex128' );
var real = require( '@stdlib/complex/float64/real' );
var imag = require( '@stdlib/complex/float64/imag' );

// Initial arrays...
var x0 = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
Expand All @@ -121,24 +83,8 @@ var y1 = new Complex128Array( y0.buffer, y0.BYTES_PER_ELEMENT*2 ); // start at 3

// Interchange every other value from `x1` into `y1` in reverse order...
zswap.main( 2, x1, -2, y1, 1 );

var z = y0.get( 2 );
// returns <Complex128>

var re = real( z );
// returns 7.0

var im = imag( z );
// returns 8.0

z = x0.get( 1 );
// returns <Complex128>

re = real( z );
// returns 0.0

im = imag( z );
// returns 0.0
// x0 => <Complex128Array>[ 1.0, 2.0, 0.0, 0.0, 5.0, 6.0, 0.0, 0.0 ]
// y0 => <Complex128Array>[ 0.0, 0.0, 0.0, 0.0, 7.0, 8.0, 3.0, 4.0 ]
```

#### zswap.ndarray( N, x, strideX, offsetX, y, strideY, offsetY )
Expand All @@ -147,31 +93,13 @@ Interchanges two complex double-precision floating-point vectors using alternati

```javascript
var Complex128Array = require( '@stdlib/array/complex128' );
var real = require( '@stdlib/complex/float64/real' );
var imag = require( '@stdlib/complex/float64/imag' );

var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

zswap.ndarray( x.length, x, 1, 0, y, 1, 0 );

var z = y.get( 0 );
// returns <Complex128>

var re = real( z );
// returns 1.0

var im = imag( z );
// returns 2.0

z = x.get( 0 );
// returns <Complex128>

re = real( z );
// returns 0.0

im = imag( z );
// returns 0.0
// x => <Complex128Array>[ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]
// y => <Complex128Array>[ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]
```

The function has the following additional parameters:
Expand All @@ -183,31 +111,13 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the

```javascript
var Complex128Array = require( '@stdlib/array/complex128' );
var real = require( '@stdlib/complex/float64/real' );
var imag = require( '@stdlib/complex/float64/imag' );

var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

zswap.ndarray( 2, x, 2, 1, y, -1, y.length-1 );

var z = y.get( y.length-1 );
// returns <Complex128>

var re = real( z );
// returns 3.0

var im = imag( z );
// returns 4.0

z = x.get( x.length-1 );
// returns <Complex128>

re = real( z );
// returns 0.0

im = imag( z );
// returns 0.0
// x => <Complex128Array>[ 1.0, 2.0, 0.0, 0.0, 5.0, 6.0, 0.0, 0.0 ]
// y => <Complex128Array>[ 0.0, 0.0, 0.0, 0.0, 7.0, 8.0, 3.0, 4.0 ]
```

* * *
Expand Down
70 changes: 20 additions & 50 deletions lib/node_modules/@stdlib/blas/base/wasm/zswap/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,48 +38,30 @@
> var x = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0 ] );
> var y = new {{alias:@stdlib/array/complex128}}( [ 6.0, 7.0, 8.0, 9.0 ] );
> {{alias}}.main( x.length, x, 1, y, 1 );
> var z = y.get( 0 );
> var re = {{alias:@stdlib/complex/float64/real}}( z )
1.0
> var im = {{alias:@stdlib/complex/float64/imag}}( z )
2.0
> z = x.get( 0 );
> re = {{alias:@stdlib/complex/float64/real}}( z )
6.0
> im = {{alias:@stdlib/complex/float64/imag}}( z )
7.0
> x
<Complex128Array>[ 6.0, 7.0, 8.0, 9.0 ]
> y
<Complex128Array>[ 1.0, 2.0, 3.0, 4.0 ]

// Advanced indexing:
> x = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
> y = new {{alias:@stdlib/array/complex128}}( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );
> {{alias}}.main( 2, x, -2, y, 1 );
> z = y.get( 0 );
> re = {{alias:@stdlib/complex/float64/real}}( z )
5.0
> im = {{alias:@stdlib/complex/float64/imag}}( z )
6.0
> z = x.get( 0 );
> re = {{alias:@stdlib/complex/float64/real}}( z )
0.0
> im = {{alias:@stdlib/complex/float64/imag}}( z )
0.0
> x
<Complex128Array>[ 0.0, 0.0, 3.0, 4.0, 0.0, 0.0, 7.0, 8.0 ]
> y
<Complex128Array>[ 5.0, 6.0, 1.0, 2.0, 0.0, 0.0, 0.0, 0.0 ]

// Using typed array views:
> var x0 = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
> var y0 = new {{alias:@stdlib/array/complex128}}( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );
> var x1 = new {{alias:@stdlib/array/complex128}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
> var y1 = new {{alias:@stdlib/array/complex128}}( y0.buffer, y0.BYTES_PER_ELEMENT*1 );
> {{alias}}.main( 2, x1, -1, y1, 1 );
> z = y0.get( 2 );
> re = {{alias:@stdlib/complex/float64/real}}( z )
3.0
> im = {{alias:@stdlib/complex/float64/imag}}( z )
4.0
> z = x0.get( 1 );
> re = {{alias:@stdlib/complex/float64/real}}( z )
0.0
> im = {{alias:@stdlib/complex/float64/imag}}( z )
0.0
> x0
<Complex128Array>[ 1.0, 2.0, 0.0, 0.0, 0.0, 0.0 ]
> y0
<Complex128Array>[ 0.0, 0.0, 5.0, 6.0, 3.0, 4.0 ]


{{alias}}.ndarray( N, x, strideX, offsetX, y, strideY, offsetY )
Expand Down Expand Up @@ -124,31 +106,19 @@
> var x = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0 ] );
> var y = new {{alias:@stdlib/array/complex128}}( [ 6.0, 7.0, 8.0, 9.0 ] );
> {{alias}}.ndarray( x.length, x, 1, 0, y, 1, 0 );
> var z = y.get( 0 );
> var re = {{alias:@stdlib/complex/float64/real}}( z )
1.0
> var im = {{alias:@stdlib/complex/float64/imag}}( z )
2.0
> z = x.get( 0 );
> re = {{alias:@stdlib/complex/float64/real}}( z )
6.0
> im = {{alias:@stdlib/complex/float64/imag}}( z )
7.0
> x
<Complex128Array>[ 6.0, 7.0, 8.0, 9.0 ]
> y
<Complex128Array>[ 1.0, 2.0, 3.0, 4.0 ]

// Advanced indexing:
> x = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
> y = new {{alias:@stdlib/array/complex128}}( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );
> {{alias}}.ndarray( 2, x, 2, 1, y, -1, y.length-1 );
> z = y.get( y.length-1 );
> re = {{alias:@stdlib/complex/float64/real}}( z )
3.0
> im = {{alias:@stdlib/complex/float64/imag}}( z )
4.0
> z = x.get( 1 );
> re = {{alias:@stdlib/complex/float64/real}}( z )
0.0
> im = {{alias:@stdlib/complex/float64/imag}}( z )
0.0
> x
<Complex128Array>[ 1.0, 2.0, 0.0, 0.0, 5.0, 6.0, 0.0, 0.0 ]
> y
<Complex128Array>[ 0.0, 0.0, 0.0, 0.0, 7.0, 8.0, 3.0, 4.0 ]


{{alias}}.Module( memory )
Expand Down
Loading

1 comment on commit bd9b313

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
blas/base/wasm/zswap $\color{green}699/699$
$\color{green}+100.00\%$
$\color{green}17/17$
$\color{green}+100.00\%$
$\color{green}6/6$
$\color{green}+100.00\%$
$\color{green}699/699$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.