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 FLENS_MATRIXTYPES_GENERAL_IMPL_GE_ELEMENTCLOSURE_TCC
34 #define FLENS_MATRIXTYPES_GENERAL_IMPL_GE_ELEMENTCLOSURE_TCC 1
35
36 #include <cxxblas/cxxblas.h>
37 #include <flens/typedefs.h>
38
39 namespace flens { namespace gematrix {
40
41 template <typename M>
42 ElementClosure<M>::ElementClosure(Matrix &matrix,
43 IndexVariable &row, IndexVariable &col)
44 : _matrix(matrix), _row(row), _col(col)
45 {
46 }
47
48 template <typename M>
49 void
50 ElementClosure<M>::operator=(const ElementType &rhs)
51 {
52 typename IndexVariable::ElementType &i = _row.value();
53 typename IndexVariable::ElementType &j = _col.value();
54
55 if (M::Engine::order==RowMajor) {
56 for (i=_matrix.firstRow(); i<=_matrix.lastRow(); ++i) {
57 for (j=_matrix.firstCol(); j<=_matrix.lastCol(); ++j) {
58 value() = rhs;
59 }
60 }
61 } else {
62 for (j=_matrix.firstCol(); j<=_matrix.lastCol(); ++j) {
63 for (i=_matrix.firstRow(); i<=_matrix.lastRow(); ++i) {
64 value() = rhs;
65 }
66 }
67 }
68 }
69
70 template <typename M>
71 template <typename S>
72 void
73 ElementClosure<M>::operator=(const Scalar<S> &rhs)
74 {
75 typename IndexVariable::ElementType &i = _row.value();
76 typename IndexVariable::ElementType &j = _col.value();
77
78 if (M::Engine::order==RowMajor) {
79 for (i=_matrix.firstRow(); i<=_matrix.lastRow(); ++i) {
80 for (j=_matrix.firstCol(); j<=_matrix.lastCol(); ++j) {
81 value() = rhs.impl().value();
82 }
83 }
84 } else {
85 for (j=_matrix.firstCol(); j<=_matrix.lastCol(); ++j) {
86 for (i=_matrix.firstRow(); i<=_matrix.lastRow(); ++i) {
87 value() = rhs.impl().value();
88 }
89 }
90 }
91 }
92
93 template <typename M>
94 void
95 ElementClosure<M>::operator=(const ElementClosure &rhs)
96 {
97 typename IndexVariable::ElementType &i = _row.value();
98 typename IndexVariable::ElementType &j = _col.value();
99
100 if (M::Engine::order==RowMajor) {
101 for (i=_matrix.firstRow(); i<=_matrix.lastRow(); ++i) {
102 for (j=_matrix.firstCol(); j<=_matrix.lastCol(); ++j) {
103 value() = rhs.impl().value();
104 }
105 }
106 } else {
107 for (j=_matrix.firstCol(); j<=_matrix.lastCol(); ++j) {
108 for (i=_matrix.firstRow(); i<=_matrix.lastRow(); ++i) {
109 value() = rhs.impl().value();
110 }
111 }
112 }
113 }
114
115 template <typename M>
116 const typename ElementClosure<M>::ElementType &
117 ElementClosure<M>::value() const
118 {
119 return _matrix(_row.value(), _col.value());
120 }
121
122 template <typename M>
123 typename ElementClosure<M>::ElementType &
124 ElementClosure<M>::value()
125 {
126 return _matrix(_row.value(), _col.value());
127 }
128
129 } } // namespace gematrix, flens
130
131 #endif // FLENS_MATRIXTYPES_GENERAL_IMPL_GE_ELEMENTCLOSURE_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 FLENS_MATRIXTYPES_GENERAL_IMPL_GE_ELEMENTCLOSURE_TCC
34 #define FLENS_MATRIXTYPES_GENERAL_IMPL_GE_ELEMENTCLOSURE_TCC 1
35
36 #include <cxxblas/cxxblas.h>
37 #include <flens/typedefs.h>
38
39 namespace flens { namespace gematrix {
40
41 template <typename M>
42 ElementClosure<M>::ElementClosure(Matrix &matrix,
43 IndexVariable &row, IndexVariable &col)
44 : _matrix(matrix), _row(row), _col(col)
45 {
46 }
47
48 template <typename M>
49 void
50 ElementClosure<M>::operator=(const ElementType &rhs)
51 {
52 typename IndexVariable::ElementType &i = _row.value();
53 typename IndexVariable::ElementType &j = _col.value();
54
55 if (M::Engine::order==RowMajor) {
56 for (i=_matrix.firstRow(); i<=_matrix.lastRow(); ++i) {
57 for (j=_matrix.firstCol(); j<=_matrix.lastCol(); ++j) {
58 value() = rhs;
59 }
60 }
61 } else {
62 for (j=_matrix.firstCol(); j<=_matrix.lastCol(); ++j) {
63 for (i=_matrix.firstRow(); i<=_matrix.lastRow(); ++i) {
64 value() = rhs;
65 }
66 }
67 }
68 }
69
70 template <typename M>
71 template <typename S>
72 void
73 ElementClosure<M>::operator=(const Scalar<S> &rhs)
74 {
75 typename IndexVariable::ElementType &i = _row.value();
76 typename IndexVariable::ElementType &j = _col.value();
77
78 if (M::Engine::order==RowMajor) {
79 for (i=_matrix.firstRow(); i<=_matrix.lastRow(); ++i) {
80 for (j=_matrix.firstCol(); j<=_matrix.lastCol(); ++j) {
81 value() = rhs.impl().value();
82 }
83 }
84 } else {
85 for (j=_matrix.firstCol(); j<=_matrix.lastCol(); ++j) {
86 for (i=_matrix.firstRow(); i<=_matrix.lastRow(); ++i) {
87 value() = rhs.impl().value();
88 }
89 }
90 }
91 }
92
93 template <typename M>
94 void
95 ElementClosure<M>::operator=(const ElementClosure &rhs)
96 {
97 typename IndexVariable::ElementType &i = _row.value();
98 typename IndexVariable::ElementType &j = _col.value();
99
100 if (M::Engine::order==RowMajor) {
101 for (i=_matrix.firstRow(); i<=_matrix.lastRow(); ++i) {
102 for (j=_matrix.firstCol(); j<=_matrix.lastCol(); ++j) {
103 value() = rhs.impl().value();
104 }
105 }
106 } else {
107 for (j=_matrix.firstCol(); j<=_matrix.lastCol(); ++j) {
108 for (i=_matrix.firstRow(); i<=_matrix.lastRow(); ++i) {
109 value() = rhs.impl().value();
110 }
111 }
112 }
113 }
114
115 template <typename M>
116 const typename ElementClosure<M>::ElementType &
117 ElementClosure<M>::value() const
118 {
119 return _matrix(_row.value(), _col.value());
120 }
121
122 template <typename M>
123 typename ElementClosure<M>::ElementType &
124 ElementClosure<M>::value()
125 {
126 return _matrix(_row.value(), _col.value());
127 }
128
129 } } // namespace gematrix, flens
130
131 #endif // FLENS_MATRIXTYPES_GENERAL_IMPL_GE_ELEMENTCLOSURE_TCC