github.com/gopherd/gonum@v0.0.4/lapack/gonum/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 gonum 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 switch { 13 case m < 0: 14 panic(mLT0) 15 case n < 0: 16 panic(nLT0) 17 case lda < max(1, n): 18 panic(badLdA) 19 } 20 21 if n == 0 || m == 0 { 22 return -1 23 } 24 25 if len(a) < (m-1)*lda+n { 26 panic(shortA) 27 } 28 29 // Check the common case where the corner is non-zero 30 if a[(m-1)*lda] != 0 || a[(m-1)*lda+n-1] != 0 { 31 return m - 1 32 } 33 for i := m - 1; i >= 0; i-- { 34 for j := 0; j < n; j++ { 35 if a[i*lda+j] != 0 { 36 return i 37 } 38 } 39 } 40 return -1 41 }