28#ifndef REMORA_DENSE_HPP
29#define REMORA_DENSE_HPP
32#include "detail/traits.hpp"
33#include "detail/proxy_optimizers_fwd.hpp"
44template<
class T,
class Device = cpu_tag>
60template<
class T,
class Orientation=row_major,
class Device = cpu_tag>
72template<
class T,
class Tag = dense_tag,
class Device = cpu_tag>
73class dense_vector_adaptor;
85template<
class T,
class Orientation = row_major,
class Tag = dense_tag,
class Device = cpu_tag>
86class dense_matrix_adaptor;
89template<
class T,
class Orientation,
class TriangularType,
class Device>
90class dense_triangular_proxy;
98dense_vector_adaptor<T, continuous_dense_tag, cpu_tag> adapt_vector(std::size_t size, T * v, std::size_t stride = 1){
99 return dense_vector_adaptor<T, continuous_dense_tag, cpu_tag>(v,size, stride);
103template <
class T, std::
size_t N>
104dense_vector_adaptor<T, continuous_dense_tag, cpu_tag> adapt_vector(T (&array)[N]){
105 return dense_vector_adaptor<T, continuous_dense_tag, cpu_tag>(array,N, 1);
110dense_matrix_adaptor<T, row_major, continuous_dense_tag, cpu_tag> adapt_matrix(std::size_t size1, std::size_t size2, T* data){
111 return dense_matrix_adaptor<T, row_major, continuous_dense_tag, cpu_tag>(data,size1, size2);
115template <
class T, std::
size_t M, std::
size_t N>
116dense_matrix_adaptor<T, row_major, continuous_dense_tag, cpu_tag> adapt_matrix(T (&array)[M][N]){
117 return dense_matrix_adaptor<T, row_major, continuous_dense_tag, cpu_tag>(&(array[0][0]),M,N);
124template<
class T,
class Device>
125struct vector_temporary_type<T,dense_tag, Device>{
126 typedef vector<T, Device> type;
129template<
class T,
class Device>
130struct vector_temporary_type<T,continuous_dense_tag, Device>{
131 typedef vector<T, Device> type;
134template<
class T,
class L,
class Device>
135struct matrix_temporary_type<T,L,dense_tag, Device>{
136 typedef matrix<T,L, Device> type;
138template<
class T,
class L,
class Device>
139struct matrix_temporary_type<T,L,continuous_dense_tag, Device>{
140 typedef matrix<T,L, Device> type;
143template<
class T,
class Device>
144struct matrix_temporary_type<T,unknown_orientation,dense_tag, Device>{
145 typedef matrix<T,row_major, Device> type;
148template<
class T,
class Device>
149struct matrix_temporary_type<T,unknown_orientation,continuous_dense_tag, Device>{
150 typedef matrix<T,row_major, Device> type;
166template<
class T,
class Tag,
class Device>
167struct vector_range_optimizer<dense_vector_adaptor<T, Tag, Device> >{
168 typedef dense_vector_adaptor<T, Tag, Device> type;
170 static type create(dense_vector_adaptor<T, Tag, Device>
const& m, std::size_t start, std::size_t end){
171 auto const& storage = m.raw_storage();
172 return type(storage.sub_region(start), m.queue(), end - start);
177template<
class T,
class Orientation,
class Tag,
class Device>
178struct matrix_transpose_optimizer<dense_matrix_adaptor<T,Orientation, Tag, Device> >{
179 typedef dense_matrix_adaptor<T,typename Orientation::transposed_orientation, Tag, Device> type;
181 static type create(dense_matrix_adaptor<T,Orientation, Tag, Device>
const& m){
182 return type(m.raw_storage(), m.queue(), m.size2(), m.size1());
186template<
class T,
class Orientation,
class Triangular,
class Device>
187struct matrix_transpose_optimizer<dense_triangular_proxy<T, Orientation, Triangular, Device> >{
188 typedef dense_triangular_proxy<T, typename Orientation::transposed_orientation, Triangular, Device> type;
190 static type create(dense_triangular_proxy<T, Orientation, Triangular, Device>
const& m){
191 return type(m.raw_storage(), m.queue(), m.size2(), m.size1());
196template<
class T,
class Orientation,
class Tag,
class Device>
197struct matrix_row_optimizer<dense_matrix_adaptor<T,Orientation, Tag, Device> >{
198 typedef typename std::conditional<std::is_same<Orientation, row_major>::value, Tag, dense_tag>::type proxy_tag;
199 typedef dense_vector_adaptor<T, proxy_tag, Device> type;
201 static type create(dense_matrix_adaptor<T,Orientation, Tag, Device>
const& m, std::size_t i){
202 auto const& storage = m.raw_storage();
203 return type(storage.row(i, Orientation()), m.queue(), m.size2());
209template<
class T,
class Orientation,
class Tag,
class Device>
210struct matrix_range_optimizer<dense_matrix_adaptor<T,Orientation, Tag, Device> >{
211 typedef dense_matrix_adaptor<T, Orientation, dense_tag, Device> type;
213 static type create(dense_matrix_adaptor<T,Orientation, Tag, Device>
const& m,
214 std::size_t start1, std::size_t end1,
215 std::size_t start2, std::size_t end2
217 auto const& storage = m.raw_storage();
218 return type(storage.sub_region(start1, start2, Orientation()), m.queue(), end1-start1, end2-start2);
222template<
class T,
class Orientation,
class Tag,
class Device>
223struct matrix_rows_optimizer<dense_matrix_adaptor<T,Orientation, Tag, Device> >{
224 typedef typename std::conditional<
225 std::is_same<Orientation, row_major>::value,
229 typedef dense_matrix_adaptor<T, Orientation, proxy_tag, Device> type;
231 static type create(dense_matrix_adaptor<T,Orientation, Tag, Device>
const& m,
232 std::size_t start, std::size_t end
234 auto const& storage = m.raw_storage();
235 return type(storage.sub_rows(start, Orientation()), m.queue(), end - start, m.size2());
240template<
class T,
class Orientation,
class Tag,
class Device>
241struct matrix_diagonal_optimizer<dense_matrix_adaptor<T,Orientation, Tag, Device> >{
242 typedef dense_vector_adaptor<T, dense_tag, Device> type;
244 static type create(dense_matrix_adaptor<T,Orientation, Tag, Device>
const& m){
245 return type(m.raw_storage().diag(), m.queue(), std::min(m.size1(), m.size2()));
251template<
class T,
class Orientation,
class Device>
252struct linearized_matrix_optimizer<dense_matrix_adaptor<T,Orientation, continuous_dense_tag, Device> >{
253 typedef dense_vector_adaptor<T, continuous_dense_tag, Device> type;
255 static type create(dense_matrix_adaptor<T,Orientation, continuous_dense_tag, Device>
const& m){
256 return type(m.raw_storage().linear(), m.queue(), m.size1() * m.size2());
263template<
class T,
class Orientation,
class Tag,
class Device,
class Triangular>
264struct triangular_proxy_optimizer<dense_matrix_adaptor<T,Orientation, Tag, Device>, Triangular >{
265 typedef dense_triangular_proxy<T, Orientation, Triangular, Device> type;
267 static type create(dense_matrix_adaptor<T,Orientation, Tag, Device>
const& m){
268 return type(m.raw_storage(), m.queue(), m.size1(), m.size2());