CUV  0.9.201304091348
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
densedense_to_sparse.hpp
1 //*LB*
2 // Copyright (c) 2010, University of Bonn, Institute for Computer Science VI
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 // * Neither the name of the University of Bonn
14 // nor the names of its contributors may be used to endorse or promote
15 // products derived from this software without specific prior written
16 // permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //*LE*
29 
30 
31 
32 
33 
34 #ifndef __DENSEDENSE_TO_SPARSE_HPP__
35 #define __DENSEDENSE_TO_SPARSE_HPP__
36 
37 
39 
40 #define SPARSE_DIA_BLOCK_SIZE 16
41 #define SPARSE_DIA_BLOCK_SIZE_LEN (2*SPARSE_DIA_BLOCK_SIZE+2)
42 
43 namespace cuv{
44 
52  template<class __value_type, class __index_type=unsigned int>
54  public:
55  typedef __value_type value_type;
56  typedef __index_type index_type;
58 
62  };
63 
72  template<class __value_type, class __index_type=unsigned int>
74  public:
75  typedef __value_type value_type;
76  typedef __index_type index_type;
78  protected:
82  struct block{
83  int startx;
84  int starty;
85  int diag[2*SPARSE_DIA_BLOCK_SIZE];
86  };
87  struct block_array{
88  int* ptr;
89  int len;
90  } m_blocks;
91  public:
99 
101  const block_array& blocks()const{return m_blocks;}
102 
104  inline int len()const{ return m_blocks.len; }
105  };
106 
122  // dev_block_descriptor and host_block_descriptor explicit... UGLY...
123  template<class __value_type, class __memory_layout_type, class __index_type >
124  void densedense_to_dia(
125  dia_matrix<__value_type,dev_memory_space,__index_type>& C,
126  const dev_block_descriptor<__value_type, __index_type>& Cbd,
127  const tensor<__value_type, dev_memory_space, __memory_layout_type>& A,
128  const tensor<__value_type, dev_memory_space, __memory_layout_type>& B,
129  const __value_type& factAB=1.f,
130  const __value_type& factC =0.f);
131 
132  template<class __value_type, class __memory_layout_type, class __index_type >
133  void densedense_to_dia(
134  dia_matrix<__value_type,host_memory_space,__index_type>& C,
135  const host_block_descriptor<__value_type, __index_type>& Cbd,
136  const tensor<__value_type, host_memory_space, __memory_layout_type>& A,
137  const tensor<__value_type, host_memory_space, __memory_layout_type>& B,
138  const __value_type& factAB=1.f,
139  const __value_type& factC =0.f);
140 
141 
142 } // cuv
143 
144 
145 #endif