OSDN Git Service

new repo
[bytom/vapor.git] / vendor / gonum.org / v1 / gonum / lapack / gonum / iladlc.go
1 // Copyright ©2015 The Gonum Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package gonum
6
7 // Iladlc scans a matrix for its last non-zero column. Returns -1 if the matrix
8 // is all zeros.
9 //
10 // Iladlc is an internal routine. It is exported for testing purposes.
11 func (Implementation) Iladlc(m, n int, a []float64, lda int) int {
12         if n == 0 || m == 0 {
13                 return n - 1
14         }
15         checkMatrix(m, n, a, lda)
16
17         // Test common case where corner is non-zero.
18         if a[n-1] != 0 || a[(m-1)*lda+(n-1)] != 0 {
19                 return n - 1
20         }
21
22         // Scan each row tracking the highest column seen.
23         highest := -1
24         for i := 0; i < m; i++ {
25                 for j := n - 1; j >= 0; j-- {
26                         if a[i*lda+j] != 0 {
27                                 highest = max(highest, j)
28                                 break
29                         }
30                 }
31         }
32         return highest
33 }