Skylark (Sketching Library)  0.1
/var/lib/jenkins/jobs/Skylark/workspace/sketch/dense_transform_Elemental_local.hpp
Go to the documentation of this file.
00001 #ifndef SKYLARK_DENSE_TRANSFORM_ELEMENTAL_LOCAL_HPP
00002 #define SKYLARK_DENSE_TRANSFORM_ELEMENTAL_LOCAL_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 
00013 namespace skylark { namespace sketch {
00014 
00019 template <typename ValueType,
00020           template <typename> class InputType,
00021           template <typename> class ValueDistribution>
00022 struct dense_transform_t <
00023     InputType<ValueType>,
00024     elem::Matrix<ValueType>,
00025     ValueDistribution> :
00026         public dense_transform_data_t<ValueDistribution> {
00027 
00028     typedef ValueType value_type;
00029     typedef InputType<value_type> matrix_type;
00030     typedef elem::Matrix<value_type> 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 
00045     dense_transform_t (const dense_transform_t<matrix_type,
00046                                          output_matrix_type,
00047                                          ValueDistribution>& other)
00048         : data_type(other) {}
00049 
00053     dense_transform_t(const data_type& other_data)
00054         : data_type(other_data) {}
00055 
00056 
00060     template <typename Dimension>
00061     void apply (const matrix_type& A,
00062                 output_matrix_type& sketch_of_A,
00063                 Dimension dimension) const {
00064         try {
00065             apply_impl_local(A, sketch_of_A, dimension);
00066         } catch (std::logic_error e) {
00067             SKYLARK_THROW_EXCEPTION (
00068                 base::elemental_exception()
00069                     << base::error_msg(e.what()) );
00070         }
00071     }
00072 
00073     int get_N() const { return this->_N; } 
00074     int get_S() const { return this->_S; } 
00076     const sketch_transform_data_t* get_data() const { return this; }
00077 
00078 private:
00079 
00080     // TODO: Block-by-block mode
00081     void apply_impl_local (const matrix_type& A,
00082                           output_matrix_type& sketch_of_A,
00083                           skylark::sketch::rowwise_tag tag) const {
00084 
00085         output_matrix_type R;
00086         data_type::realize_matrix_view(R);
00087 
00088         base::Gemm (elem::NORMAL,
00089                     elem::TRANSPOSE,
00090                     value_type(1),
00091                     A,
00092                     R,
00093                     value_type(0),
00094                     sketch_of_A);
00095     }
00096 
00097 
00098     // TODO: Block-by-block mode
00099     void apply_impl_local (const matrix_type& A,
00100                           output_matrix_type& sketch_of_A,
00101                           skylark::sketch::columnwise_tag tag) const {
00102 
00103         output_matrix_type R;
00104         data_type::realize_matrix_view(R);
00105 
00106         base::Gemm (elem::NORMAL,
00107                     elem::NORMAL,
00108                     value_type(1),
00109                     R,
00110                     A,
00111                     value_type(0),
00112                     sketch_of_A);
00113     }
00114 };
00115 
00116 } } 
00118 #endif // SKYLARK_DENSE_TRANSFORM_ELEMENTAL_LOCAL_HPP