SHOGUN  6.0.0
LinalgBackendBase.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Shogun-Toolbox e.V. <shogun-team@shogun-toolbox.org>
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  * Authors: 2016 Pan Deng, Soumyajit De, Heiko Strathmann, Viktor Gal
31  */
32 
33 #ifndef LINALG_BACKEND_BASE_H__
34 #define LINALG_BACKEND_BASE_H__
35 
36 #include <shogun/lib/config.h>
37 #include <shogun/lib/common.h>
38 #include <shogun/lib/SGVector.h>
39 #include <shogun/lib/SGMatrix.h>
40 #include <shogun/io/SGIO.h>
43 #include <memory>
44 
45 namespace shogun
46 {
47 
52 {
53 public:
54  #define DEFINE_FOR_ALL_PTYPE(METHODNAME, Container) \
55  METHODNAME(bool, Container); \
56  METHODNAME(char, Container); \
57  METHODNAME(int8_t, Container); \
58  METHODNAME(uint8_t, Container); \
59  METHODNAME(int16_t, Container); \
60  METHODNAME(uint16_t, Container); \
61  METHODNAME(int32_t, Container); \
62  METHODNAME(uint32_t, Container); \
63  METHODNAME(int64_t, Container); \
64  METHODNAME(uint64_t, Container); \
65  METHODNAME(float32_t, Container); \
66  METHODNAME(float64_t, Container); \
67  METHODNAME(floatmax_t, Container); \
68  METHODNAME(complex128_t, Container); \
69 
70  #define DEFINE_FOR_REAL_PTYPE(METHODNAME, Container) \
71  METHODNAME(bool, Container); \
72  METHODNAME(char, Container); \
73  METHODNAME(int8_t, Container); \
74  METHODNAME(uint8_t, Container); \
75  METHODNAME(int16_t, Container); \
76  METHODNAME(uint16_t, Container); \
77  METHODNAME(int32_t, Container); \
78  METHODNAME(uint32_t, Container); \
79  METHODNAME(int64_t, Container); \
80  METHODNAME(uint64_t, Container); \
81  METHODNAME(float32_t, Container); \
82  METHODNAME(float64_t, Container); \
83  METHODNAME(floatmax_t, Container);
84 
85  #define DEFINE_FOR_NON_INTEGER_PTYPE(METHODNAME, Container) \
86  METHODNAME(float32_t, Container); \
87  METHODNAME(float64_t, Container); \
88  METHODNAME(floatmax_t, Container); \
89  METHODNAME(complex128_t, Container);
90 
96  #define BACKEND_GENERIC_IN_PLACE_ADD(Type, Container) \
97  virtual void add(Container<Type>& a, Container<Type>& b, Type alpha, Type beta, Container<Type>& result) const \
98  { \
99  SG_SNOTIMPLEMENTED; \
100  }
103  #undef BACKEND_GENERIC_IN_PLACE_ADD
104 
110  #define BACKEND_GENERIC_CHOLESKY_FACTOR(Type, Container) \
111  virtual Container<Type> cholesky_factor(const Container<Type>& A, \
112  const bool lower) const \
113  { \
114  SG_SNOTIMPLEMENTED; \
115  return 0; \
116  }
118  #undef BACKEND_GENERIC_CHOLESKY_FACTOR
119 
125  #define BACKEND_GENERIC_CHOLESKY_SOLVER(Type, Container) \
126  virtual SGVector<Type> cholesky_solver(const Container<Type>& L, \
127  const SGVector<Type>& b, const bool lower) const \
128  { \
129  SG_SNOTIMPLEMENTED; \
130  return 0; \
131  }
133  #undef BACKEND_GENERIC_CHOLESKY_SOLVER
134 
140  #define BACKEND_GENERIC_DOT(Type, Container) \
141  virtual Type dot(const Container<Type>& a, const Container<Type>& b) const \
142  { \
143  SG_SNOTIMPLEMENTED; \
144  return 0; \
145  }
147  #undef BACKEND_GENERIC_DOT
148 
154  #define BACKEND_GENERIC_IN_PLACE_ELEMENT_PROD(Type, Container) \
155  virtual void element_prod(Container<Type>& a, Container<Type>& b,\
156  Container<Type>& result) const \
157  { \
158  SG_SNOTIMPLEMENTED; \
159  }
161  #undef BACKEND_GENERIC_IN_PLACE_ELEMENT_PROD
162 
168  #define BACKEND_GENERIC_IN_PLACE_BLOCK_ELEMENT_PROD(Type, Container) \
169  virtual void element_prod(linalg::Block<Container<Type>>& a, \
170  linalg::Block<Container<Type>>& b, Container<Type>& result) const \
171  { \
172  SG_SNOTIMPLEMENTED; \
173  }
175  #undef BACKEND_GENERIC_IN_PLACE_BLOCK_ELEMENT_PROD
176 
182  #define BACKEND_GENERIC_LOGISTIC(Type, Container) \
183  virtual void logistic(Container<Type>& a, Container<Type>& result) const \
184  { \
185  SG_SNOTIMPLEMENTED; \
186  }
188  #undef BACKEND_GENERIC_LOGISTIC
189 
195  #define BACKEND_GENERIC_IN_PLACE_MATRIX_PROD(Type, Container) \
196  virtual void matrix_prod(SGMatrix<Type>& a, Container<Type>& b,\
197  Container<Type>& result, bool transpose_A, bool transpose_B) const \
198  { \
199  SG_SNOTIMPLEMENTED; \
200  }
203  #undef BACKEND_GENERIC_IN_PLACE_MATRIX_PROD
204 
210  #define BACKEND_GENERIC_MAX(Type, Container) \
211  virtual Type max(const Container<Type>& a) const \
212  { \
213  SG_SNOTIMPLEMENTED; \
214  return 0; \
215  }
218  #undef BACKEND_GENERIC_MAX
219 
226  #define BACKEND_GENERIC_REAL_MEAN(Type, Container) \
227  virtual float64_t mean(const Container<Type>& a) const \
228  { \
229  SG_SNOTIMPLEMENTED; \
230  return 0; \
231  }
234  #undef BACKEND_GENERIC_REAL_MEAN
235 
242  #define BACKEND_GENERIC_COMPLEX_MEAN(Container) \
243  virtual complex128_t mean(const Container<complex128_t>& a) const \
244  { \
245  SG_SNOTIMPLEMENTED; \
246  return 0; \
247  }
250  #undef BACKEND_GENERIC_COMPLEX_MEAN
251 
257  #define BACKEND_GENERIC_RANGE_FILL(Type, Container) \
258  virtual void range_fill(Container<Type>& a, const Type start) const \
259  { \
260  SG_SNOTIMPLEMENTED; \
261  }
264  #undef BACKEND_GENERIC_RANGE_FILL
265 
271  #define BACKEND_GENERIC_IN_PLACE_SCALE(Type, Container) \
272  virtual void scale(Container<Type>& a, Type alpha, Container<Type>& result) const \
273  { \
274  SG_SNOTIMPLEMENTED; \
275  }
278  #undef BACKEND_GENERIC_IN_PLACE_SCALE
279 
285  #define BACKEND_GENERIC_SET_CONST(Type, Container) \
286  virtual void set_const(Container<Type>& a, const Type value) const \
287  { \
288  SG_SNOTIMPLEMENTED; \
289  }
292  #undef BACKEND_GENERIC_SET_CONST
293 
299  #define BACKEND_GENERIC_SUM(Type, Container) \
300  virtual Type sum(const Container<Type>& a, bool no_diag) const \
301  { \
302  SG_SNOTIMPLEMENTED; \
303  return 0; \
304  }
307  #undef BACKEND_GENERIC_SUM
308 
314  #define BACKEND_GENERIC_BLOCK_SUM(Type, Container) \
315  virtual Type sum(const linalg::Block<Container<Type>>& a, bool no_diag) const \
316  { \
317  SG_SNOTIMPLEMENTED; \
318  return 0; \
319  }
321  #undef BACKEND_GENERIC_BLOCK_SUM
322 
328  #define BACKEND_GENERIC_SYMMETRIC_SUM(Type, Container) \
329  virtual Type sum_symmetric(const Container<Type>& a, bool no_diag) const \
330  { \
331  SG_SNOTIMPLEMENTED; \
332  return 0; \
333  }
335  #undef BACKEND_GENERIC_SYMMETRIC_SUM
336 
342  #define BACKEND_GENERIC_SYMMETRIC_BLOCK_SUM(Type, Container) \
343  virtual Type sum_symmetric(const linalg::Block<Container<Type>>& a, bool no_diag) const \
344  { \
345  SG_SNOTIMPLEMENTED; \
346  return 0; \
347  }
349  #undef BACKEND_GENERIC_SYMMETRIC_BLOCK_SUM
350 
356  #define BACKEND_GENERIC_COLWISE_SUM(Type, Container) \
357  virtual SGVector<Type> colwise_sum(const Container<Type>& a, bool no_diag) const \
358  { \
359  SG_SNOTIMPLEMENTED; \
360  return 0; \
361  }
363  #undef BACKEND_GENERIC_COLWISE_SUM
364 
370  #define BACKEND_GENERIC_BLOCK_COLWISE_SUM(Type, Container) \
371  virtual SGVector<Type> colwise_sum(const linalg::Block<Container<Type>>& a, bool no_diag) const \
372  { \
373  SG_SNOTIMPLEMENTED; \
374  return 0; \
375  }
377  #undef BACKEND_GENERIC_BLOCK_COLWISE_SUM
378 
384  #define BACKEND_GENERIC_ROWWISE_SUM(Type, Container) \
385  virtual SGVector<Type> rowwise_sum(const Container<Type>& a, bool no_diag) const \
386  { \
387  SG_SNOTIMPLEMENTED; \
388  return 0; \
389  }
391  #undef BACKEND_GENERIC_ROWWISE_SUM
392 
398  #define BACKEND_GENERIC_BLOCK_ROWWISE_SUM(Type, Container) \
399  virtual SGVector<Type> rowwise_sum(const linalg::Block<Container<Type>>& a, bool no_diag) const \
400  { \
401  SG_SNOTIMPLEMENTED; \
402  return 0; \
403  }
405  #undef BACKEND_GENERIC_BLOCK_ROWWISE_SUM
406 
413  #define BACKEND_GENERIC_TO_GPU(Type, Container) \
414  virtual GPUMemoryBase<Type>* to_gpu(const Container<Type>&) const \
415  { \
416  SG_SNOTIMPLEMENTED; \
417  return 0; \
418  }
421  #undef BACKEND_GENERIC_TO_GPU
422 
428  #define BACKEND_GENERIC_FROM_GPU(Type, Container) \
429  virtual void from_gpu(const Container<Type>&, Type* data) const \
430  { \
431  SG_SNOTIMPLEMENTED; \
432  }
435  #undef BACKEND_GENERIC_FROM_GPU
436 
437 #undef DEFINE_FOR_ALL_PTYPE
438 #undef DEFINE_FOR_REAL_PTYPE
439 #undef DEFINE_FOR_NON_INTEGER_PTYPE
440 };
441 
442 }
443 
444 #endif //LINALG_BACKEND_BASE_H__
#define BACKEND_GENERIC_MAX(Type, Container)
#define BACKEND_GENERIC_IN_PLACE_ADD(Type, Container)
#define BACKEND_GENERIC_ROWWISE_SUM(Type, Container)
#define BACKEND_GENERIC_RANGE_FILL(Type, Container)
#define DEFINE_FOR_NON_INTEGER_PTYPE(METHODNAME, Container)
#define DEFINE_FOR_ALL_PTYPE(METHODNAME, Container)
#define BACKEND_GENERIC_IN_PLACE_SCALE(Type, Container)
#define BACKEND_GENERIC_SET_CONST(Type, Container)
#define BACKEND_GENERIC_REAL_MEAN(Type, Container)
#define BACKEND_GENERIC_CHOLESKY_SOLVER(Type, Container)
#define BACKEND_GENERIC_DOT(Type, Container)
#define BACKEND_GENERIC_LOGISTIC(Type, Container)
#define BACKEND_GENERIC_SYMMETRIC_SUM(Type, Container)
#define BACKEND_GENERIC_SUM(Type, Container)
#define DEFINE_FOR_REAL_PTYPE(METHODNAME, Container)
#define BACKEND_GENERIC_COMPLEX_MEAN(Container)
#define BACKEND_GENERIC_SYMMETRIC_BLOCK_SUM(Type, Container)
#define BACKEND_GENERIC_FROM_GPU(Type, Container)
#define BACKEND_GENERIC_IN_PLACE_MATRIX_PROD(Type, Container)
#define BACKEND_GENERIC_BLOCK_COLWISE_SUM(Type, Container)
#define BACKEND_GENERIC_CHOLESKY_FACTOR(Type, Container)
#define BACKEND_GENERIC_IN_PLACE_ELEMENT_PROD(Type, Container)
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
Base interface of generic linalg methods and generic memory transfer methods.
#define BACKEND_GENERIC_TO_GPU(Type, Container)
#define BACKEND_GENERIC_BLOCK_SUM(Type, Container)
#define BACKEND_GENERIC_COLWISE_SUM(Type, Container)
#define BACKEND_GENERIC_BLOCK_ROWWISE_SUM(Type, Container)
#define BACKEND_GENERIC_IN_PLACE_BLOCK_ELEMENT_PROD(Type, Container)

SHOGUN Machine Learning Toolbox - Documentation