time-to-botec

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

README.md (3566B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2018 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 # Max View Buffer Index
     22 
     23 > Compute the maximum linear index in an underlying data buffer accessible to an array view.
     24 
     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 
     27 <section class="intro">
     28 
     29 </section>
     30 
     31 <!-- /.intro -->
     32 
     33 <!-- Package usage documentation. -->
     34 
     35 <section class="usage">
     36 
     37 ## Usage
     38 
     39 ```javascript
     40 var maxViewBufferIndex = require( '@stdlib/ndarray/base/max-view-buffer-index' );
     41 ```
     42 
     43 #### maxViewBufferIndex( shape, strides, offset )
     44 
     45 Computes the maximum linear index in an underlying data buffer accessible to an array view.
     46 
     47 ```javascript
     48 // Array shape:
     49 var shape = [ 2, 2 ];
     50 
     51 // Stride array:
     52 var strides = [ 2, 1 ];
     53 
     54 // Index offset which specifies the location of the first indexed value:
     55 var offset = 0;
     56 
     57 var idx = maxViewBufferIndex( shape, strides, offset );
     58 // returns 3
     59 ```
     60 
     61 </section>
     62 
     63 <!-- /.usage -->
     64 
     65 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
     66 
     67 <section class="notes">
     68 
     69 </section>
     70 
     71 <!-- /.notes -->
     72 
     73 <!-- Package usage examples. -->
     74 
     75 <section class="examples">
     76 
     77 ## Examples
     78 
     79 <!-- eslint no-undef: "error" -->
     80 
     81 ```javascript
     82 var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
     83 var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
     84 var strides2offset = require( '@stdlib/ndarray/base/strides2offset' );
     85 var randu = require( '@stdlib/random/base/randu' );
     86 var maxViewBufferIndex = require( '@stdlib/ndarray/base/max-view-buffer-index' );
     87 
     88 var strides;
     89 var offset;
     90 var shape;
     91 var idx;
     92 var i;
     93 var j;
     94 
     95 shape = [ 0, 0, 0 ];
     96 
     97 for ( i = 0; i < 100; i++ ) {
     98     // Generate a random array shape:
     99     shape[ 0 ] = discreteUniform( 1, 10 );
    100     shape[ 1 ] = discreteUniform( 1, 10 );
    101     shape[ 2 ] = discreteUniform( 1, 10 );
    102 
    103     // Generate strides:
    104     if ( randu() < 0.5 ) {
    105         strides = shape2strides( shape, 'row-major' );
    106     } else {
    107         strides = shape2strides( shape, 'column-major' );
    108     }
    109     j = discreteUniform( 0, shape.length-1 );
    110     strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1;
    111 
    112     // Compute the index offset:
    113     offset = strides2offset( shape, strides );
    114 
    115     // Compute the maximum linear index:
    116     idx = maxViewBufferIndex( shape, strides, offset );
    117     console.log( 'Shape: %s. Strides: %s. Offset: %d. Max idx: %d.', shape.join( 'x' ), strides.join( ',' ), offset, idx );
    118 }
    119 ```
    120 
    121 </section>
    122 
    123 <!-- /.examples -->
    124 
    125 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    126 
    127 <section class="references">
    128 
    129 </section>
    130 
    131 <!-- /.references -->
    132 
    133 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    134 
    135 <section class="links">
    136 
    137 </section>
    138 
    139 <!-- /.links -->