Skylark (Sketching Library)
0.1
|
00001 #ifndef SKYLARK_DENSE_TRANSFORM_ELEMENTAL_STAR_ROWDIST_CIRC_CIRC_HPP 00002 #define SKYLARK_DENSE_TRANSFORM_ELEMENTAL_STAR_ROWDIST_CIRC_CIRC_HPP 00003 00004 #include "../base/base.hpp" 00005 00006 #include "transforms.hpp" 00007 #include "dense_transform_data.hpp" 00008 #include "../utility/comm.hpp" 00009 #include "../utility/get_communicator.hpp" 00010 00011 #include "sketch_params.hpp" 00012 #include "dense_transform_Elemental_star_rowdist.hpp" 00013 00014 namespace skylark { namespace sketch { 00018 template <typename ValueType, 00019 elem::Distribution RowDist, 00020 template <typename> class ValueDistribution> 00021 struct dense_transform_t < 00022 elem::DistMatrix<ValueType, elem::STAR, RowDist>, 00023 elem::DistMatrix<ValueType, elem::CIRC, elem::CIRC>, 00024 ValueDistribution > : 00025 public dense_transform_data_t<ValueDistribution> { 00026 // Typedef matrix and distribution types so that we can use them regularly 00027 typedef ValueType value_type; 00028 typedef elem::DistMatrix<value_type, elem::STAR, RowDist> matrix_type; 00029 typedef elem::DistMatrix<value_type, elem::CIRC, elem::CIRC> 00030 output_matrix_type; 00031 typedef ValueDistribution<value_type> value_distribution_type; 00032 typedef dense_transform_data_t<ValueDistribution> data_type; 00033 00037 dense_transform_t (int N, int S, double scale, base::context_t& context) 00038 : data_type (N, S, scale, context) { 00039 00040 } 00041 00042 00046 dense_transform_t (dense_transform_t<matrix_type, 00047 output_matrix_type, 00048 ValueDistribution>& other) 00049 : data_type(other) {} 00050 00051 00055 dense_transform_t(const data_type& other_data) 00056 : data_type(other_data) {} 00057 00058 00062 template <typename Dimension> 00063 void apply (const matrix_type& A, 00064 output_matrix_type& sketch_of_A, 00065 Dimension dimension) const { 00066 00067 switch(RowDist) { 00068 case elem::VR: 00069 case elem::VC: 00070 try { 00071 apply_impl_vdist (A, sketch_of_A, dimension); 00072 } catch (std::logic_error e) { 00073 SKYLARK_THROW_EXCEPTION ( 00074 base::elemental_exception() 00075 << base::error_msg(e.what()) ); 00076 } catch(boost::mpi::exception e) { 00077 SKYLARK_THROW_EXCEPTION ( 00078 base::mpi_exception() 00079 << base::error_msg(e.what()) ); 00080 } 00081 00082 break; 00083 00084 default: 00085 SKYLARK_THROW_EXCEPTION ( 00086 base::unsupported_matrix_distribution() ); 00087 } 00088 } 00089 00090 int get_N() const { return this->_N; } 00091 int get_S() const { return this->_S; } 00093 const sketch_transform_data_t* get_data() const { return this; } 00094 00095 private: 00096 00101 void apply_impl_vdist(const matrix_type& A, 00102 output_matrix_type& sketch_of_A, 00103 skylark::sketch::rowwise_tag tag) const { 00104 00105 00106 matrix_type sketch_of_A_STAR_RD(A.Height(), 00107 data_type::_S); 00108 00109 dense_transform_t<matrix_type, matrix_type, ValueDistribution> 00110 transform(*this); 00111 00112 transform.apply(A, sketch_of_A_STAR_RD, tag); 00113 00114 sketch_of_A = sketch_of_A_STAR_RD; 00115 } 00116 00117 00118 void apply_impl_vdist(const matrix_type& A, 00119 output_matrix_type& sketch_of_A, 00120 skylark::sketch::columnwise_tag tag) const { 00121 00122 matrix_type sketch_of_A_STAR_RD(data_type::_S, 00123 A.Width()); 00124 00125 dense_transform_t<matrix_type, matrix_type, ValueDistribution> 00126 transform(*this); 00127 00128 transform.apply(A, sketch_of_A_STAR_RD, tag); 00129 00130 sketch_of_A = sketch_of_A_STAR_RD; 00131 } 00132 }; 00133 00134 } } 00136 #endif // SKYLARK_DENSE_TRANSFORM_ELEMENTAL_STAR_ROWDIST_CIRC_CIRC_HPP