1 /*
2 * Copyright (c) 2010, 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 #ifndef CXXBLAS_LEVEL1EXTENSIONS_TRCOPY_TCC
34 #define CXXBLAS_LEVEL1EXTENSIONS_TRCOPY_TCC 1
35
36 #include <algorithm>
37 #include <cassert>
38
39 namespace cxxblas {
40
41 //
42 // B = A or B = A^T
43 //
44 template <typename IndexType, typename MA, typename MB>
45 void
46 trcopy(StorageOrder order, StorageUpLo upLo, Transpose trans, Diag diag,
47 IndexType m, IndexType n, const MA *A, IndexType ldA,
48 MB *B, IndexType ldB)
49 {
50 CXXBLAS_DEBUG_OUT("trcopy_generic");
51 using std::min;
52
53 // TODO: implement complex cases B = conj(A) and B = A^H
54 ASSERT(trans==NoTrans || trans==Trans);
55
56 if (order==RowMajor) {
57 ASSERT(0);
58 }
59 if (diag==NonUnit) {
60 if (trans==NoTrans) {
61 if (upLo==Upper) {
62 for (IndexType j=0; j<n; ++j) {
63 copy(min(j+1,m), A+j*ldA, IndexType(1),
64 B+j*ldB, IndexType(1));
65 }
66 } else {
67 for (IndexType j=0; j<min(m,n); ++j) {
68 copy(m-j, A+j*(ldA+1), IndexType(1),
69 B+j*(ldB+1), IndexType(1));
70 }
71 }
72 } else if (trans==Trans) {
73 if (upLo==Upper) {
74 for (IndexType j=0; j<n; ++j) {
75 copy(min(j+1,m), A+j, ldA,
76 B+j*ldB, IndexType(1));
77 }
78 } else {
79 for (IndexType j=0; j<min(m,n); ++j) {
80 copy(m-j, A+j*(ldA+1), ldA,
81 B+j*(ldB+1), IndexType(1));
82 }
83 }
84 } else {
85 // TODO: implement this case
86 ASSERT(0);
87 }
88 } else {
89 if (trans==NoTrans) {
90 if (upLo==Upper) {
91 for (IndexType j=0; j<n; ++j) {
92 copy(min(j,m), A+j*ldA, IndexType(1),
93 B+j*ldB, IndexType(1));
94 }
95 } else {
96 for (IndexType j=0; j<min(m,n); ++j) {
97 copy(m-j-1, A+j*(ldA+1)+1, IndexType(1),
98 B+j*(ldB+1)+1, IndexType(1));
99 }
100 }
101 } else {
102 // TODO: implement this case
103 ASSERT(0);
104 }
105 }
106 }
107
108 } // namespace cxxblas
109
110 #endif // CXXBLAS_LEVEL1EXTENSIONS_TRCOPY_TCC
2 * Copyright (c) 2010, 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 #ifndef CXXBLAS_LEVEL1EXTENSIONS_TRCOPY_TCC
34 #define CXXBLAS_LEVEL1EXTENSIONS_TRCOPY_TCC 1
35
36 #include <algorithm>
37 #include <cassert>
38
39 namespace cxxblas {
40
41 //
42 // B = A or B = A^T
43 //
44 template <typename IndexType, typename MA, typename MB>
45 void
46 trcopy(StorageOrder order, StorageUpLo upLo, Transpose trans, Diag diag,
47 IndexType m, IndexType n, const MA *A, IndexType ldA,
48 MB *B, IndexType ldB)
49 {
50 CXXBLAS_DEBUG_OUT("trcopy_generic");
51 using std::min;
52
53 // TODO: implement complex cases B = conj(A) and B = A^H
54 ASSERT(trans==NoTrans || trans==Trans);
55
56 if (order==RowMajor) {
57 ASSERT(0);
58 }
59 if (diag==NonUnit) {
60 if (trans==NoTrans) {
61 if (upLo==Upper) {
62 for (IndexType j=0; j<n; ++j) {
63 copy(min(j+1,m), A+j*ldA, IndexType(1),
64 B+j*ldB, IndexType(1));
65 }
66 } else {
67 for (IndexType j=0; j<min(m,n); ++j) {
68 copy(m-j, A+j*(ldA+1), IndexType(1),
69 B+j*(ldB+1), IndexType(1));
70 }
71 }
72 } else if (trans==Trans) {
73 if (upLo==Upper) {
74 for (IndexType j=0; j<n; ++j) {
75 copy(min(j+1,m), A+j, ldA,
76 B+j*ldB, IndexType(1));
77 }
78 } else {
79 for (IndexType j=0; j<min(m,n); ++j) {
80 copy(m-j, A+j*(ldA+1), ldA,
81 B+j*(ldB+1), IndexType(1));
82 }
83 }
84 } else {
85 // TODO: implement this case
86 ASSERT(0);
87 }
88 } else {
89 if (trans==NoTrans) {
90 if (upLo==Upper) {
91 for (IndexType j=0; j<n; ++j) {
92 copy(min(j,m), A+j*ldA, IndexType(1),
93 B+j*ldB, IndexType(1));
94 }
95 } else {
96 for (IndexType j=0; j<min(m,n); ++j) {
97 copy(m-j-1, A+j*(ldA+1)+1, IndexType(1),
98 B+j*(ldB+1)+1, IndexType(1));
99 }
100 }
101 } else {
102 // TODO: implement this case
103 ASSERT(0);
104 }
105 }
106 }
107
108 } // namespace cxxblas
109
110 #endif // CXXBLAS_LEVEL1EXTENSIONS_TRCOPY_TCC