1 /*
2 * Copyright (c) 2011, Michael Lehn
3 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1) Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * 3) Neither the name of the FLENS development group nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /* Based on
34 *
35 * INTEGER FUNCTION ILA?LC( M, N, A, LDA )
36 *
37 * -- LAPACK auxiliary routine (version 3.2.2) --
38 *
39 * -- June 2010 --
40 *
41 * -- LAPACK is a software package provided by Univ. of Tennessee, --
42 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
43 */
44
45 #ifndef FLENS_LAPACK_AUX_ILALC_TCC
46 #define FLENS_LAPACK_AUX_ILALC_TCC 1
47
48 #include <flens/blas/blas.h>
49 #include <flens/lapack/lapack.h>
50
51 namespace flens { namespace lapack {
52
53 //== generic lapack implementation =============================================
54
55 template <typename MA>
56 typename GeMatrix<MA>::IndexType
57 ilalc_generic(const GeMatrix<MA> &A)
58 {
59 typedef typename GeMatrix<MA>::IndexType IndexType;
60 typedef typename GeMatrix<MA>::ElementType T;
61
62 const IndexType m = A.numRows();
63 const IndexType n = A.numCols();
64
65 //
66 // Quick test for the common case where one corner is non-zero.
67 //
68 if (n==0) {
69 return n;
70 } else if ((A(1,n)!=T(0)) || A(m,n)!=T(0)) {
71 return n;
72 } else {
73 //
74 // Now scan each column from the end, returning with the first non-zero.
75 //
76 for (IndexType j=n; j>=1; --j) {
77 for (IndexType i=1; i<=m; ++i) {
78 if (A(i,j)!=T(0)) {
79 return j;
80 }
81 }
82 }
83 }
84 return 0;
85 }
86
87 //== interface for native lapack ===============================================
88
89
90 //== public interface ==========================================================
91
92 template <typename MA>
93 typename GeMatrix<MA>::IndexType
94 ilalc(const GeMatrix<MA> &A)
95 {
96 LAPACK_DEBUG_OUT("ilalc");
97
98 ASSERT(A.firstRow()==1);
99 ASSERT(A.firstCol()==1);
100
101 return ilalc_generic(A);
102 }
103
104 } } // namespace lapack, flens
105
106 #endif // FLENS_LAPACK_AUX_ILALC_TCC
2 * Copyright (c) 2011, Michael Lehn
3 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1) Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * 3) Neither the name of the FLENS development group nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /* Based on
34 *
35 * INTEGER FUNCTION ILA?LC( M, N, A, LDA )
36 *
37 * -- LAPACK auxiliary routine (version 3.2.2) --
38 *
39 * -- June 2010 --
40 *
41 * -- LAPACK is a software package provided by Univ. of Tennessee, --
42 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
43 */
44
45 #ifndef FLENS_LAPACK_AUX_ILALC_TCC
46 #define FLENS_LAPACK_AUX_ILALC_TCC 1
47
48 #include <flens/blas/blas.h>
49 #include <flens/lapack/lapack.h>
50
51 namespace flens { namespace lapack {
52
53 //== generic lapack implementation =============================================
54
55 template <typename MA>
56 typename GeMatrix<MA>::IndexType
57 ilalc_generic(const GeMatrix<MA> &A)
58 {
59 typedef typename GeMatrix<MA>::IndexType IndexType;
60 typedef typename GeMatrix<MA>::ElementType T;
61
62 const IndexType m = A.numRows();
63 const IndexType n = A.numCols();
64
65 //
66 // Quick test for the common case where one corner is non-zero.
67 //
68 if (n==0) {
69 return n;
70 } else if ((A(1,n)!=T(0)) || A(m,n)!=T(0)) {
71 return n;
72 } else {
73 //
74 // Now scan each column from the end, returning with the first non-zero.
75 //
76 for (IndexType j=n; j>=1; --j) {
77 for (IndexType i=1; i<=m; ++i) {
78 if (A(i,j)!=T(0)) {
79 return j;
80 }
81 }
82 }
83 }
84 return 0;
85 }
86
87 //== interface for native lapack ===============================================
88
89
90 //== public interface ==========================================================
91
92 template <typename MA>
93 typename GeMatrix<MA>::IndexType
94 ilalc(const GeMatrix<MA> &A)
95 {
96 LAPACK_DEBUG_OUT("ilalc");
97
98 ASSERT(A.firstRow()==1);
99 ASSERT(A.firstCol()==1);
100
101 return ilalc_generic(A);
102 }
103
104 } } // namespace lapack, flens
105
106 #endif // FLENS_LAPACK_AUX_ILALC_TCC