|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2024 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 | +# scasum |
| 22 | + |
| 23 | +> Compute the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var scasum = require( '@stdlib/blas/base/scasum' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### scasum( N, cx, strideX ) |
| 34 | + |
| 35 | +Computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 39 | + |
| 40 | +var cx = new Complex64Array( [ 0.3, 0.1, 0.5, 0.0, 0.0, 0.5, 0.0, 0.2 ] ); |
| 41 | + |
| 42 | +var out = scasum( 4, cx, 1 ); |
| 43 | +// returns ~1.6 |
| 44 | +``` |
| 45 | + |
| 46 | +The function has the following parameters: |
| 47 | + |
| 48 | +- **N**: number of indexed elements. |
| 49 | +- **cx**: input [`Complex64Array`][@stdlib/array/complex64]. |
| 50 | +- **strideX**: index increment for `cx`. |
| 51 | + |
| 52 | +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to traverse every other value, |
| 53 | + |
| 54 | +```javascript |
| 55 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 56 | + |
| 57 | +var cx = new Complex64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); |
| 58 | + |
| 59 | +var out = scasum( 2, cx, 2 ); |
| 60 | +// returns 7.0 |
| 61 | +``` |
| 62 | + |
| 63 | +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. |
| 64 | + |
| 65 | +```javascript |
| 66 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 67 | + |
| 68 | +// Initial array: |
| 69 | +var cx0 = new Complex64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); |
| 70 | + |
| 71 | +// Create an offset view: |
| 72 | +var cx1 = new Complex64Array( cx0.buffer, cx0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 73 | + |
| 74 | +// Compute the L2-out: |
| 75 | +var out = scasum( 2, cx1, 1 ); |
| 76 | +// returns 18.0 |
| 77 | +``` |
| 78 | + |
| 79 | +#### scasum.ndarray( N, cx, strideX, offset ) |
| 80 | + |
| 81 | +Computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector using alternative indexing semantics. |
| 82 | + |
| 83 | +```javascript |
| 84 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 85 | + |
| 86 | +var cx = new Complex64Array( [ 0.3, 0.1, 0.5, 0.0, 0.0, 0.5, 0.0, 0.2 ] ); |
| 87 | + |
| 88 | +var out = scasum.ndarray( 4, cx, 1, 0 ); |
| 89 | +// returns ~1.6 |
| 90 | +``` |
| 91 | + |
| 92 | +The function has the following additional parameters: |
| 93 | + |
| 94 | +- **offsetX**: starting index. |
| 95 | + |
| 96 | +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to start from the second index, |
| 97 | + |
| 98 | +```javascript |
| 99 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 100 | + |
| 101 | +var cx = new Complex64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); |
| 102 | + |
| 103 | +var out = scasum.ndarray( 2, cx, 1, 1 ); |
| 104 | +// returns 18.0 |
| 105 | +``` |
| 106 | + |
| 107 | +</section> |
| 108 | + |
| 109 | +<!-- /.usage --> |
| 110 | + |
| 111 | +<section class="notes"> |
| 112 | + |
| 113 | +## Notes |
| 114 | + |
| 115 | +- If `N <= 0`, both functions return `0.0`. |
| 116 | +- `scasum()` corresponds to the [BLAS][blas] level 1 function [`scasum`][scasum]. |
| 117 | + |
| 118 | +</section> |
| 119 | + |
| 120 | +<!-- /.notes --> |
| 121 | + |
| 122 | +<section class="examples"> |
| 123 | + |
| 124 | +## Examples |
| 125 | + |
| 126 | +<!-- eslint no-undef: "error" --> |
| 127 | + |
| 128 | +```javascript |
| 129 | +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); |
| 130 | +var filledarrayBy = require( '@stdlib/array/filled-by' ); |
| 131 | +var Complex64 = require( '@stdlib/complex/float32/ctor' ); |
| 132 | +var scasum = require( '@stdlib/blas/base/scasum' ); |
| 133 | + |
| 134 | +function rand() { |
| 135 | + return new Complex64( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); |
| 136 | +} |
| 137 | + |
| 138 | +var cx = filledarrayBy( 10, 'complex64', rand ); |
| 139 | +console.log( cx.toString() ); |
| 140 | + |
| 141 | +// Compute the sum of the absolute values of real and imaginary components: |
| 142 | +var out = scasum( cx.length, cx, 1 ); |
| 143 | +console.log( out ); |
| 144 | +``` |
| 145 | + |
| 146 | +</section> |
| 147 | + |
| 148 | +<!-- /.examples --> |
| 149 | + |
| 150 | +<!-- C interface documentation. --> |
| 151 | + |
| 152 | +* * * |
| 153 | + |
| 154 | +<section class="c"> |
| 155 | + |
| 156 | +## C APIs |
| 157 | + |
| 158 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 159 | + |
| 160 | +<section class="intro"> |
| 161 | + |
| 162 | +</section> |
| 163 | + |
| 164 | +<!-- /.intro --> |
| 165 | + |
| 166 | +<!-- C usage documentation. --> |
| 167 | + |
| 168 | +<section class="usage"> |
| 169 | + |
| 170 | +### Usage |
| 171 | + |
| 172 | +```c |
| 173 | +#include "stdlib/blas/base/scasum.h" |
| 174 | +``` |
| 175 | + |
| 176 | +#### c_scasum( N, \*CX, strideX ) |
| 177 | + |
| 178 | +Computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector. |
| 179 | + |
| 180 | +```c |
| 181 | +const float cx[] = { 0.3f, 0.1f, 0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.2f }; |
| 182 | + |
| 183 | +float out = c_scasum( 4, (void *)cx, 1 ); |
| 184 | +// returns 1.6f |
| 185 | +``` |
| 186 | +
|
| 187 | +The function accepts the following arguments: |
| 188 | +
|
| 189 | +- **N**: `[in] CBLAS_INT` number of indexed elements. |
| 190 | +- **CX**: `[in] void*` input array. |
| 191 | +- **strideX**: `[in] CBLAS_INT` index increment for `CX`. |
| 192 | +
|
| 193 | +```c |
| 194 | +float c_scasum( const CBLAS_INT N, const void *CX, const CBLAS_INT strideX ); |
| 195 | +``` |
| 196 | + |
| 197 | +</section> |
| 198 | + |
| 199 | +<!-- /.usage --> |
| 200 | + |
| 201 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 202 | + |
| 203 | +<section class="notes"> |
| 204 | + |
| 205 | +</section> |
| 206 | + |
| 207 | +<!-- /.notes --> |
| 208 | + |
| 209 | +<!-- C API usage examples. --> |
| 210 | + |
| 211 | +<section class="examples"> |
| 212 | + |
| 213 | +### Examples |
| 214 | + |
| 215 | +```c |
| 216 | +#include "stdlib/blas/base/scasum.h" |
| 217 | +#include <stdio.h> |
| 218 | + |
| 219 | +int main( void ) { |
| 220 | + // Create a strided array of interleaved real and imaginary components: |
| 221 | + const float cx[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; |
| 222 | + |
| 223 | + // Specify the number of elements: |
| 224 | + const int N = 4; |
| 225 | + |
| 226 | + // Specify stride length: |
| 227 | + const int strideX = 1; |
| 228 | + |
| 229 | + // Compute the sum of the absolute values of real and imaginary components: |
| 230 | + float out = c_scasum( N, (void *)cx, strideX ); |
| 231 | + |
| 232 | + // Print the result: |
| 233 | + printf( "out: %f\n", out ); |
| 234 | +} |
| 235 | +``` |
| 236 | +
|
| 237 | +</section> |
| 238 | +
|
| 239 | +<!-- /.examples --> |
| 240 | +
|
| 241 | +</section> |
| 242 | +
|
| 243 | +<!-- /.c --> |
| 244 | +
|
| 245 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 246 | +
|
| 247 | +<section class="related"> |
| 248 | +
|
| 249 | +</section> |
| 250 | +
|
| 251 | +<!-- /.related --> |
| 252 | +
|
| 253 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 254 | +
|
| 255 | +<section class="links"> |
| 256 | +
|
| 257 | +[blas]: http://www.netlib.org/blas |
| 258 | +
|
| 259 | +[scasum]: https://www.netlib.org/lapack/explore-html/d5/d72/group__asum_ga89c76eef329f84ba9ed106b34fedab16.html#ga89c76eef329f84ba9ed106b34fedab16 |
| 260 | +
|
| 261 | +[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex64 |
| 262 | +
|
| 263 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 264 | +
|
| 265 | +</section> |
| 266 | +
|
| 267 | +<!-- /.links --> |
0 commit comments