github.com/gonum/lapack@v0.0.0-20181123203213-e4cdc5a0bff9/native/iladlr.go (about) 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 native 6 7 // Iladlr scans a matrix for its last non-zero row. Returns -1 if the matrix 8 // is all zeros. 9 // 10 // Iladlr is an internal routine. It is exported for testing purposes. 11 func (Implementation) Iladlr(m, n int, a []float64, lda int) int { 12 if m == 0 { 13 return m - 1 14 } 15 16 checkMatrix(m, n, a, lda) 17 18 // Check the common case where the corner is non-zero 19 if a[(m-1)*lda] != 0 || a[(m-1)*lda+n-1] != 0 { 20 return m - 1 21 } 22 for i := m - 1; i >= 0; i-- { 23 for j := 0; j < n; j++ { 24 if a[i*lda+j] != 0 { 25 return i 26 } 27 } 28 } 29 return -1 30 }