33#ifndef REMORA_MATRIX_PROXY_HPP
34#define REMORA_MATRIX_PROXY_HPP
36#include "detail/proxy_optimizers_fwd.hpp"
37#include "detail/vector_set.hpp"
39#include "detail/traits.hpp"
40#include "detail/check.hpp"
51template<
class V,
class Device>
52typename detail::vector_range_optimizer<typename V::closure_type >::type
53subrange(vector_expression<V, Device>& v, std::size_t start, std::size_t stop){
54 return detail::vector_range_optimizer<typename V::closure_type>::create(v(), start, stop);
57template<
class V,
class Device>
58typename detail::vector_range_optimizer<typename V::const_closure_type>::type
59subrange(vector_expression<V, Device>
const& v, std::size_t start, std::size_t stop){
60 return detail::vector_range_optimizer<typename V::const_closure_type>::create(v(), start, stop);
63template<
class V,
class Device>
64typename detail::vector_range_optimizer<typename V::closure_type>::type
65subrange(vector_expression<V,Device>&& v, std::size_t start, std::size_t stop){
66 static_assert(!std::is_base_of<vector_container<V, Device>,V>::value,
"It is unsafe to create a proxy from a temporary container");
67 return subrange(v(),start,stop);
86template<
class M,
class Device>
87typename detail::matrix_transpose_optimizer<typename M::closure_type>::type
88trans(matrix_expression<M, Device> & m){
89 return detail::matrix_transpose_optimizer<typename M::closure_type>::create(m());
91template<
class M,
class Device>
92typename detail::matrix_transpose_optimizer<typename M::const_closure_type>::type
93trans(matrix_expression<M, Device>
const& m){
94 return detail::matrix_transpose_optimizer<typename M::const_closure_type>::create(m());
97template<
class M,
class Device>
98typename detail::matrix_transpose_optimizer<typename M::closure_type>::type
99trans(matrix_expression<M, Device> && m){
100 static_assert(!std::is_base_of<matrix_container<M, Device>,M>::value,
"It is unsafe to create a proxy from a temporary container");
117template<
class M,
class Device>
118typename detail::matrix_row_optimizer<typename M::closure_type>::type
119row(matrix_expression<M, Device>& m,
typename M::size_type i){
120 return detail::matrix_row_optimizer<typename M::closure_type>::create(m(), i);
122template<
class M,
class Device>
123typename detail::matrix_row_optimizer<typename M::const_closure_type>::type
124row(matrix_expression<M, Device>
const& m,
typename M::size_type i){
125 return detail::matrix_row_optimizer<typename M::const_closure_type>::create(m(), i);
128template<
class M,
class Device>
129typename detail::matrix_row_optimizer<typename M::closure_type>::type
130row(matrix_expression<M, Device> && m,
typename M::size_type i){
131 static_assert(!std::is_base_of<matrix_container<M, Device>,M>::value,
"It is unsafe to create a proxy from a temporary container");
144template<
class M,
class Device>
145auto column(matrix_expression<M, Device>& m,
typename M::size_type j) ->
decltype(row(trans(m),j)){
146 return row(trans(m),j);
148template<
class M,
class Device>
149auto column(matrix_expression<M, Device>
const& m,
typename M::size_type j) ->
decltype(row(trans(m),j)){
150 return row(trans(m),j);
153template<
class M,
class Device>
154auto column(matrix_expression<M, Device> && m,
typename M::size_type j) ->
decltype(row(trans(m),j)){
155 static_assert(!std::is_base_of<matrix_container<M, Device>,M>::value,
"It is unsafe to create a proxy from a temporary container");
172template<
class M,
class Device>
173typename detail::matrix_diagonal_optimizer<typename M::closure_type>::type
174diag(matrix_expression<M, Device>& mat){
175 REMORA_SIZE_CHECK(mat().size1() == mat().size2());
176 return detail::matrix_diagonal_optimizer<typename M::closure_type>::create(mat());
179template<
class M,
class Device>
180typename detail::matrix_diagonal_optimizer<typename M::const_closure_type>::type
181diag(matrix_expression<M, Device>
const& mat){
182 REMORA_SIZE_CHECK(mat().size1() == mat().size2());
183 return detail::matrix_diagonal_optimizer<typename M::const_closure_type>::create(mat());
187template<
class M,
class Device>
188typename detail::matrix_diagonal_optimizer<typename M::closure_type>::type
189diag(matrix_expression<M, Device> && m){
190 static_assert(!std::is_base_of<matrix_container<M, Device>,M>::value,
"It is unsafe to create a proxy from a temporary container");
209template<
class M,
class Device>
210typename detail::matrix_range_optimizer<typename M::closure_type>::type subrange(
211 matrix_expression<M, Device>& m,
212 std::size_t start1, std::size_t stop1,
213 std::size_t start2, std::size_t stop2
215 REMORA_RANGE_CHECK(start1 <= stop1);
216 REMORA_RANGE_CHECK(start2 <= stop2);
217 REMORA_SIZE_CHECK(stop1 <= m().size1());
218 REMORA_SIZE_CHECK(stop2 <= m().size2());
219 return detail::matrix_range_optimizer<typename M::closure_type>::create(m(), start1, stop1, start2, stop2);
221template<
class M,
class Device>
222typename detail::matrix_range_optimizer<typename M::const_closure_type>::type subrange(
223 matrix_expression<M, Device>
const& m,
224 std::size_t start1, std::size_t stop1,
225 std::size_t start2, std::size_t stop2
227 REMORA_RANGE_CHECK(start1 <= stop1);
228 REMORA_RANGE_CHECK(start2 <= stop2);
229 REMORA_SIZE_CHECK(stop1 <= m().size1());
230 REMORA_SIZE_CHECK(stop2 <= m().size2());
231 return detail::matrix_range_optimizer<typename M::const_closure_type>::create(m(), start1, stop1, start2, stop2);
234template<
class M,
class Device>
235typename detail::matrix_range_optimizer<typename M::closure_type>::type subrange(
236 matrix_expression<M, Device> && m,
237 std::size_t start1, std::size_t stop1,
238 std::size_t start2, std::size_t stop2
240 static_assert(!std::is_base_of<matrix_container<M, Device>,M>::value,
"It is unsafe to create a proxy from a temporary container");
241 return subrange(m(),start1,stop1,start2,stop2);
244template<
class M,
class Device>
245typename detail::matrix_rows_optimizer<typename M::closure_type>::type rows(
246 matrix_expression<M, Device>& m,
247 std::size_t start, std::size_t stop
249 REMORA_RANGE_CHECK(start <= stop);
250 REMORA_SIZE_CHECK(stop <= m().size1());
251 return detail::matrix_rows_optimizer<typename M::closure_type>::create(m(),start,stop);
254template<
class M,
class Device>
255typename detail::matrix_rows_optimizer<typename M::const_closure_type >::type rows(
256 matrix_expression<M, Device>
const& m,
257 std::size_t start, std::size_t stop
259 REMORA_RANGE_CHECK(start <= stop);
260 REMORA_SIZE_CHECK(stop <= m().size1());
261 return detail::matrix_rows_optimizer<typename M::const_closure_type >::create(m(),start,stop);
264template<
class M,
class Device>
265typename detail::matrix_rows_optimizer<typename M::closure_type >::type rows(
266 matrix_expression<M, Device> && m,
267 std::size_t start, std::size_t stop
269 static_assert(!std::is_base_of<matrix_container<M, Device>,M>::value,
"It is unsafe to create a proxy from a temporary container");
270 return detail::matrix_rows_optimizer<typename M::closure_type>::create(m(),start,stop);
273template<
class M,
class Device>
275 matrix_expression<M, Device>& m,
276 typename M::size_type start,
typename M::size_type stop
277) ->
decltype(trans(rows(trans(m),start,stop))){
278 REMORA_RANGE_CHECK(start <= stop);
279 REMORA_SIZE_CHECK(stop <= m().size2());
280 return trans(rows(trans(m),start,stop));
283template<
class M,
class Device>
285 matrix_expression<M, Device>
const& m,
286 typename M::size_type start,
typename M::size_type stop
287) ->
decltype(trans(rows(trans(m),start,stop))){
288 REMORA_RANGE_CHECK(start <= stop);
289 REMORA_SIZE_CHECK(stop <= m().size2());
290 return trans(rows(trans(m),start,stop));
293template<
class M,
class Device>
295 matrix_expression<M, Device> && m,
296 std::size_t start, std::size_t stop
297) ->
decltype(trans(rows(trans(m),start,stop))){
298 static_assert(!std::is_base_of<matrix_container<M, Device>,M>::value,
"It is unsafe to create a proxy from a temporary container");
299 return columns(m(),start,stop);
310template<
class M,
class Device>
311typename detail::linearized_matrix_optimizer<typename M::closure_type>::type
312to_vector(matrix_expression<M, Device>& m){
313 return detail::linearized_matrix_optimizer<typename M::closure_type>::create(m());
316template<
class M,
class Device>
317typename detail::linearized_matrix_optimizer<typename M::const_closure_type>::type
318to_vector(matrix_expression<M, Device>
const& m){
319 return detail::linearized_matrix_optimizer<typename M::const_closure_type>::create(m());
322template<
class M,
class Device>
323typename detail::linearized_matrix_optimizer<typename M::closure_type>::type
324to_vector(matrix_expression<M, Device> && m){
325 static_assert(!std::is_base_of<vector_container<M, Device>,M>::value,
"It is unsafe to create a proxy from a temporary container");
326 return to_vector(m());
334template <
class M,
class Device,
class Tag>
335typename detail::triangular_proxy_optimizer<typename M::closure_type, Tag>::type
336to_triangular(matrix_expression<M, Device>& m, Tag){
337 return detail::triangular_proxy_optimizer<typename M::closure_type, Tag>::create(m());
340template <
class M,
class Device,
class Tag>
341typename detail::triangular_proxy_optimizer<typename M::const_closure_type, Tag>::type
342to_triangular(matrix_expression<M, Device>
const& m, Tag){
343 return detail::triangular_proxy_optimizer<typename M::const_closure_type, Tag>::create(m());
346template <
class M,
class Device,
class Tag>
347typename detail::triangular_proxy_optimizer<typename M::closure_type, Tag>::type
348to_triangular(matrix_expression<M, Device>&& m, Tag){
349 static_assert(!std::is_base_of<matrix_container<M, Device>,M>::value,
"It is unsafe to create a proxy from a temporary container");
350 return detail::triangular_proxy_optimizer<typename M::closure_type, Tag>::create(m());
358template <
class V,
class Device>
359typename detail::vector_to_matrix_optimizer<typename V::const_closure_type, row_major >::type to_matrix(
360 vector_expression<V, Device>
const& v,std::size_t size1, std::size_t size2
362 REMORA_SIZE_CHECK(size1 * size2 == v().size());
363 return detail::vector_to_matrix_optimizer<typename V::const_closure_type, row_major >::create(v(), size1, size2);
367template <
class V,
class Device>
368typename detail::vector_to_matrix_optimizer<typename V::closure_type, row_major >::type to_matrix(
369 vector_expression<V, Device>& v,std::size_t size1, std::size_t size2
371 REMORA_SIZE_CHECK(size1 * size2 == v().size());
372 return detail::vector_to_matrix_optimizer<typename V::closure_type, row_major >::create(v(), size1, size2);
375template <
class V,
class Device>
376typename detail::vector_to_matrix_optimizer<typename V::closure_type, row_major >::type to_matrix(
377 vector_expression<V,Device> && v,std::size_t size1, std::size_t size2
379 static_assert(!std::is_base_of<vector_container<V, Device>,V>::value,
"It is unsafe to create a proxy from a temporary container");
380 return to_matrix(v, size1, size2);
387template <
class O,
class M,
class Device>
388vector_set<typename M::const_closure_type, O >
389as_set(matrix_expression<M, Device>
const& m, O){
390 return vector_set<typename M::const_closure_type, O >(m());
393template <
class O,
class M,
class Device>
394vector_set<typename M::closure_type, O >
395as_set(matrix_expression<M, Device>& m, O){
396 return vector_set<typename M::closure_type, O >(m());
399template <
class O,
class M,
class Device>
400vector_set<typename M::closure_type, O >
401as_set(matrix_expression<M, Device>&& m, O){
402 static_assert(!std::is_base_of<matrix_container<M, Device>,M>::value,
"It is unsafe to create a proxy from a temporary container");
403 return vector_set<typename M::closure_type, O >(m());
408auto as_rows(M&& m)->
decltype(as_set(std::forward<M>(m), row_major())){
409 return as_set(std::forward<M>(m), row_major());
414auto as_columns(M&& m)->
decltype(as_set(std::forward<M>(m), column_major())){
415 return as_set(std::forward<M>(m), column_major());