time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

repl.txt (2391B)


      1 
      2 {{alias}}( N, x, stride )
      3     Computes the sum of the absolute values.
      4 
      5     The sum of absolute values corresponds to the *L1* norm.
      6 
      7     The `N` and `stride` parameters determine which elements in `x` are used to
      8     compute the sum.
      9 
     10     Indexing is relative to the first index. To introduce an offset, use typed
     11     array views.
     12 
     13     If `N` or `stride` is less than or equal to `0`, the function returns `0`.
     14 
     15     Parameters
     16     ----------
     17     N: integer
     18         Number of elements to sum.
     19 
     20     x: Float32Array
     21         Input array.
     22 
     23     stride: integer
     24         Index increment.
     25 
     26     Returns
     27     -------
     28     sum: float
     29         Sum of absolute values.
     30 
     31     Examples
     32     --------
     33     // Standard usage:
     34     > var x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] );
     35     > var sum = {{alias}}( x.length, x, 1 )
     36     19.0
     37 
     38     // Sum every other value:
     39     > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
     40     > var stride = 2;
     41     > sum = {{alias}}( N, x, stride )
     42     10.0
     43 
     44     // Use view offset; e.g., starting at 2nd element:
     45     > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
     46     > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
     47     > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
     48     > sum = {{alias}}( N, x1, stride )
     49     12.0
     50 
     51 
     52 {{alias}}.ndarray( N, x, stride, offset )
     53     Computes the sum of absolute values using alternative indexing semantics.
     54 
     55     While typed array views mandate a view offset based on the underlying
     56     buffer, the `offset` parameter supports indexing semantics based on a
     57     starting index.
     58 
     59     Parameters
     60     ----------
     61     N: integer
     62         Number of elements to sum.
     63 
     64     x: Float32Array
     65         Input array.
     66 
     67     stride: integer
     68         Index increment.
     69 
     70     offset: integer
     71         Starting index.
     72 
     73     Returns
     74     -------
     75     sum: float
     76         Sum of absolute values.
     77 
     78     Examples
     79     --------
     80     // Standard usage:
     81     > var x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] );
     82     > var sum = {{alias}}.ndarray( x.length, x, 1, 0 )
     83     19.0
     84 
     85     // Sum the last three elements:
     86     > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
     87     > sum = {{alias}}.ndarray( 3, x, -1, x.length-1 )
     88     15.0
     89 
     90     See Also
     91     --------
     92