|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2026 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# gxmy |
| 22 | + |
| 23 | +> Multiply elements of a strided array `x` by the corresponding elements of a strided array `y` and assign the results to `y`. |
| 24 | +
|
| 25 | +<section class="intro"> |
| 26 | + |
| 27 | +This BLAS extension implements the operation |
| 28 | + |
| 29 | +<!-- <equation class="equation" label="eq:xmy" align="center" raw="\mathbf{y} = \mathbf{x} \odot \mathbf{y}" alt="Equation for xmy operation."> --> |
| 30 | + |
| 31 | +```math |
| 32 | +\mathbf{y} = \mathbf{x} \odot \mathbf{y} |
| 33 | +``` |
| 34 | + |
| 35 | +<!-- </equation> --> |
| 36 | + |
| 37 | +</section> |
| 38 | + |
| 39 | +<!-- /.intro --> |
| 40 | + |
| 41 | +<section class="usage"> |
| 42 | + |
| 43 | +## Usage |
| 44 | + |
| 45 | +```javascript |
| 46 | +var gxmy = require( '@stdlib/blas/ext/base/gxmy' ); |
| 47 | +``` |
| 48 | + |
| 49 | +#### gxmy( N, x, strideX, y, strideY ) |
| 50 | + |
| 51 | +Multiplies elements of a strided array `x` by the corresponding elements of a strided array `y` and assigns the results to `y`. |
| 52 | + |
| 53 | +```javascript |
| 54 | +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; |
| 55 | +var y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; |
| 56 | + |
| 57 | +gxmy( x.length, x, 1, y, 1 ); |
| 58 | +// y => [ 2.0, 6.0, 12.0, 20.0, 30.0 ] |
| 59 | +``` |
| 60 | + |
| 61 | +The function has the following parameters: |
| 62 | + |
| 63 | +- **N**: number of indexed elements. |
| 64 | +- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. |
| 65 | +- **strideX**: stride length for `x`. |
| 66 | +- **y**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. |
| 67 | +- **strideY**: stride length for `y`. |
| 68 | + |
| 69 | +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to multiply every other element of `x` by every other element of `y`: |
| 70 | + |
| 71 | +```javascript |
| 72 | +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; |
| 73 | +var y = [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ]; |
| 74 | + |
| 75 | +gxmy( 3, x, 2, y, 2 ); |
| 76 | +// y => [ 7.0, 8.0, 27.0, 10.0, 55.0, 12.0 ] |
| 77 | +``` |
| 78 | + |
| 79 | +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. |
| 80 | + |
| 81 | +```javascript |
| 82 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 83 | + |
| 84 | +// Initial arrays... |
| 85 | +var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 86 | +var y0 = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); |
| 87 | + |
| 88 | +// Create offset views... |
| 89 | +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 90 | +var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*2 ); // start at 3rd element |
| 91 | + |
| 92 | +gxmy( 3, x1, 1, y1, 1 ); |
| 93 | +// y0 => <Float64Array>[ 7.0, 8.0, 18.0, 30.0, 44.0, 12.0 ] |
| 94 | +``` |
| 95 | + |
| 96 | +#### gxmy.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) |
| 97 | + |
| 98 | +Multiplies elements of a strided array `x` by the corresponding elements of a strided array `y` and assigns the results to `y` using alternative indexing semantics. |
| 99 | + |
| 100 | +```javascript |
| 101 | +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; |
| 102 | +var y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; |
| 103 | + |
| 104 | +gxmy.ndarray( x.length, x, 1, 0, y, 1, 0 ); |
| 105 | +// y => [ 2.0, 6.0, 12.0, 20.0, 30.0 ] |
| 106 | +``` |
| 107 | + |
| 108 | +The function has the following additional parameters: |
| 109 | + |
| 110 | +- **offsetX**: starting index for `x`. |
| 111 | +- **offsetY**: starting index for `y`. |
| 112 | + |
| 113 | +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 multiply the last three elements of `x` by the last three elements of `y`: |
| 114 | + |
| 115 | +```javascript |
| 116 | +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; |
| 117 | +var y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; |
| 118 | + |
| 119 | +gxmy.ndarray( 3, x, 1, x.length-3, y, 1, y.length-3 ); |
| 120 | +// y => [ 6.0, 7.0, 24.0, 36.0, 50.0 ] |
| 121 | +``` |
| 122 | + |
| 123 | +</section> |
| 124 | + |
| 125 | +<!-- /.usage --> |
| 126 | + |
| 127 | +<section class="notes"> |
| 128 | + |
| 129 | +## Notes |
| 130 | + |
| 131 | +- If `N <= 0`, both functions return `y` unchanged. |
| 132 | +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). |
| 133 | + |
| 134 | +</section> |
| 135 | + |
| 136 | +<!-- /.notes --> |
| 137 | + |
| 138 | +<section class="examples"> |
| 139 | + |
| 140 | +## Examples |
| 141 | + |
| 142 | +<!-- eslint no-undef: "error" --> |
| 143 | + |
| 144 | +```javascript |
| 145 | +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
| 146 | +var gxmy = require( '@stdlib/blas/ext/base/gxmy' ); |
| 147 | + |
| 148 | +var x = discreteUniform( 10, -100, 100, { |
| 149 | + 'dtype': 'float64' |
| 150 | +}); |
| 151 | +console.log( x ); |
| 152 | + |
| 153 | +var y = discreteUniform( 10, -100, 100, { |
| 154 | + 'dtype': 'float64' |
| 155 | +}); |
| 156 | +console.log( y ); |
| 157 | + |
| 158 | +gxmy( x.length, x, 1, y, 1 ); |
| 159 | +console.log( y ); |
| 160 | +``` |
| 161 | + |
| 162 | +</section> |
| 163 | + |
| 164 | +<!-- /.examples --> |
| 165 | + |
| 166 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 167 | + |
| 168 | +<section class="related"> |
| 169 | + |
| 170 | +</section> |
| 171 | + |
| 172 | +<!-- /.related --> |
| 173 | + |
| 174 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 175 | + |
| 176 | +<section class="links"> |
| 177 | + |
| 178 | +[mdn-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array |
| 179 | + |
| 180 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 181 | + |
| 182 | +[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor |
| 183 | + |
| 184 | +<!-- <related-links> --> |
| 185 | + |
| 186 | +<!-- </related-links> --> |
| 187 | + |
| 188 | +</section> |
| 189 | + |
| 190 | +<!-- /.links --> |
0 commit comments