30 template<
typename elt_t>
31 Tensor<elt_t>::view::operator Tensor<elt_t>()
const
33 Tensor<elt_t> t(dims_);
34 typename Tensor<elt_t>::iterator it = t.begin();
36 for (index j; (j = ranges_->pop()) != ranges_->nomore(); it++) {
46 template<
typename elt_t>
const typename Tensor<elt_t>::view
50 assert(this->rank() == 1);
51 r->set_limit(dimension(0));
52 dims.at(0) = r->size();
53 return view(*
this, dims, r);
56 template<
typename elt_t>
const typename Tensor<elt_t>::view
60 assert(this->rank() == 2);
61 r1->set_limit(dimension(0));
62 r2->set_limit(dimension(1));
63 dims.at(0) = r1->size();
64 dims.at(1) = r2->size();
65 Range *r = product(r1, r2);
66 return view(*
this, dims, r);
69 template<
typename elt_t>
const typename Tensor<elt_t>::view
73 assert(this->rank() == 3);
74 r1->set_limit(dimension(0));
75 r2->set_limit(dimension(1));
76 r3->set_limit(dimension(2));
77 dims.at(0) = r1->size();
78 dims.at(1) = r2->size();
79 dims.at(2) = r3->size();
80 Range *r = product(r1, product(r2, r3));
81 return view(*
this, dims, r);
84 template<
typename elt_t>
const typename Tensor<elt_t>::view
88 assert(this->rank() == 4);
89 r1->set_limit(dimension(0));
90 r2->set_limit(dimension(1));
91 r3->set_limit(dimension(2));
92 r4->set_limit(dimension(3));
93 dims.at(0) = r1->size();
94 dims.at(1) = r2->size();
95 dims.at(2) = r3->size();
96 dims.at(3) = r4->size();
97 Range *r = product(r1, product(r2, product(r3, r4)));
98 return view(*
this, dims, r);
101 template<
typename elt_t>
const typename Tensor<elt_t>::view
105 assert(this->rank() == 5);
106 r1->set_limit(dimension(0));
107 r2->set_limit(dimension(1));
108 r3->set_limit(dimension(2));
109 r4->set_limit(dimension(3));
110 r5->set_limit(dimension(4));
111 dims.at(0) = r1->size();
112 dims.at(1) = r2->size();
113 dims.at(2) = r3->size();
114 dims.at(3) = r4->size();
115 dims.at(4) = r5->size();
116 PRange r = product(r1, product(r2, product(r3, product(r4, r5))));
117 return view(*
this, dims, r);
120 template<
typename elt_t>
const typename Tensor<elt_t>::view
122 PRange r4, PRange r5, PRange r6)
const
125 assert(this->rank() == 6);
126 r1->set_limit(dimension(0));
127 r2->set_limit(dimension(1));
128 r3->set_limit(dimension(2));
129 r4->set_limit(dimension(3));
130 r5->set_limit(dimension(4));
131 r6->set_limit(dimension(5));
132 dims.at(0) = r1->size();
133 dims.at(1) = r2->size();
134 dims.at(2) = r3->size();
135 dims.at(3) = r4->size();
136 dims.at(4) = r5->size();
137 dims.at(5) = r6->size();
138 Range *r = product(r1, product(r2, product(r3, product(r4, product(r5, r6)))));
139 return view(*
this, dims, r);
146 template<
typename elt_t>
typename Tensor<elt_t>::mutable_view
150 assert(this->rank() == 1);
151 r->set_limit(dimension(0));
152 dims.at(0) = r->size();
153 return mutable_view(*
this, dims, r);
156 template<
typename elt_t>
typename Tensor<elt_t>::mutable_view
160 assert(this->rank() == 2);
161 r1->set_limit(dimension(0));
162 r2->set_limit(dimension(1));
163 dims.at(0) = r1->size();
164 dims.at(1) = r2->size();
165 Range *r = product(r1, r2);
166 return mutable_view(*
this, dims, r);
169 template<
typename elt_t>
typename Tensor<elt_t>::mutable_view
173 assert(this->rank() == 3);
174 r1->set_limit(dimension(0));
175 r2->set_limit(dimension(1));
176 r3->set_limit(dimension(2));
177 dims.at(0) = r1->size();
178 dims.at(1) = r2->size();
179 dims.at(2) = r3->size();
180 Range *r = product(r1, product(r2, r3));
181 return mutable_view(*
this, dims, r);
184 template<
typename elt_t>
typename Tensor<elt_t>::mutable_view
188 assert(this->rank() == 4);
189 r1->set_limit(dimension(0));
190 r2->set_limit(dimension(1));
191 r3->set_limit(dimension(2));
192 r4->set_limit(dimension(3));
193 dims.at(0) = r1->size();
194 dims.at(1) = r2->size();
195 dims.at(2) = r3->size();
196 dims.at(3) = r4->size();
197 Range *r = product(r1, product(r2, product(r3, r4)));
198 return mutable_view(*
this, dims, r);
201 template<
typename elt_t>
typename Tensor<elt_t>::mutable_view
205 assert(this->rank() == 5);
206 r1->set_limit(dimension(0));
207 r2->set_limit(dimension(1));
208 r3->set_limit(dimension(2));
209 r4->set_limit(dimension(3));
210 r5->set_limit(dimension(4));
211 dims.at(0) = r1->size();
212 dims.at(1) = r2->size();
213 dims.at(2) = r3->size();
214 dims.at(3) = r4->size();
215 dims.at(4) = r5->size();
216 Range *r = product(r1, product(r2, product(r3, product(r4, r5))));
217 return mutable_view(*
this, dims, r);
220 template<
typename elt_t>
typename Tensor<elt_t>::mutable_view
222 PRange r4, PRange r5, PRange r6)
225 assert(this->rank() == 6);
226 r1->set_limit(dimension(0));
227 r2->set_limit(dimension(1));
228 r3->set_limit(dimension(2));
229 r4->set_limit(dimension(3));
230 r5->set_limit(dimension(4));
231 r6->set_limit(dimension(5));
232 dims.at(0) = r1->size();
233 dims.at(1) = r2->size();
234 dims.at(2) = r3->size();
235 dims.at(3) = r4->size();
236 dims.at(4) = r5->size();
237 dims.at(5) = r6->size();
238 Range *r = product(r1, product(r2, product(r3, product(r4, product(r5, r6)))));
239 return mutable_view(*
this, dims, r);
246 template<
typename elt_t>
void
247 Tensor<elt_t>::mutable_view::operator=
248 (
const typename Tensor<elt_t>::view &t)
251 assert(dims_.total_size() == t.dims_.total_size());
253 Range *r2 = t.ranges_;
257 (i = r1->pop(), j = r2->pop(), i != r1->nomore() && j != r2->nomore()); ) {
258 data_.at(i) = t.data_[j];
262 template<
typename elt_t>
void
263 Tensor<elt_t>::mutable_view::operator=(
const Tensor<elt_t> &t)
266 assert(dims_.total_size() == t.dims_.total_size());
268 for (index i = 0, j; (j = ranges_->pop()) != ranges_->nomore(); i++) {
273 template<
typename elt_t>
void
274 Tensor<elt_t>::mutable_view::operator=(elt_t v)
277 for (index i; (i = ranges_->pop()) != ranges_->nomore(); ) {
const elt_t & operator()(index i) const
Return an element of a 1D Tensor.
elt_t & at(index i)
Return a mutable reference to an element of a 1D Tensor.