Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

compute-io / argmax / 9

9 Jun 2015 - 5:16 coverage: 97.059% (-2.9%) from 100.0%
9

Pull #1

travis-ci

88cba5f6ee044b057480fe2cff63825b?size=18&default=identiconkgryte
[UPDATE] dependencies
Pull Request #1: Update according to TODO

98 of 101 new or added lines in 5 files covered. (97.03%)

99 of 102 relevant lines covered (97.06%)

36.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.55
/lib/matrix.js
1
'use strict';
2

3
/**
4
* FUNCTION: argmax( out, mat[, dim] )
5
*        Computes the maximum value along a matrix dimension and return the corresponding indices.
6
*
7
* @param {Array} idx - output array
8
* @param {Matrix} mat - input matrix
9
* @param {Number} [dim=2] - matrix dimension along which to compute the arg max. If `dim=1`, compute along matrix rows. If `dim=2`, compute along matrix columns.
10
* @returns {Array|Null} arrays of maximum value indices or null
11
*/
12
function argmax( idx, mat, dim ) {
3×
13
        var max,
33×
14
                v,
15
                M, N,
16
                s0, s1,
17
                o,
18
                i, j, k;
19

20
        if ( dim === 1 ) {
33×
21
                // Compute along the rows...
22
                M = mat.shape[ 1 ];
9×
23
                N = mat.shape[ 0 ];
9×
24
                s0 = mat.strides[ 1 ];
9×
25
                s1 = mat.strides[ 0 ];
9×
26
        } else {
27
                // Compute along the columns...
28
                M = mat.shape[ 0 ];
24×
29
                N = mat.shape[ 1 ];
24×
30
                s0 = mat.strides[ 0 ];
24×
31
                s1 = mat.strides[ 1 ];
24×
32
        }
33
        if ( M === 0 || N === 0 ) {
33×
34
                return null;
9×
35
        }
36
        o = mat.offset;
24×
37
        idx = new Array( M );
24×
38
        for ( i = 0; i < M; i++ ) {
24×
39
                k = o + i*s0;
90×
40
                max = mat.data[ k ];
90×
41
                idx[ i ] = [ 0 ];
90×
42
                for ( j = 1; j < N; j++ ) {
90×
43
                        v = mat.data[ k + j*s1 ];
270×
44
                        if ( v > max ) {
270×
45
                                max = v;
243×
46
                                idx[ i ].length = 0;
243×
47
                                idx[ i ].push( j );
243×
48
                        }
49
                        else if ( v === max ) {
27×
NEW
50
                                idx[ i ].push( j );
!
51
                        }
52
                }
53
        }
54
        return idx;
24×
55
} // end FUNCTION argmax()
56

57

58
// EXPORTS //
59

60
module.exports = argmax;
3×
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc