SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SGNDArray.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2012 Fernando José Iglesias García
8  * Written (W) 2010,2012 Soeren Sonnenburg
9  * Copyright (C) 2010 Berlin Institute of Technology
10  * Copyright (C) 2012 Soeren Sonnenburg
11  */
12 
13 #ifndef __SGNDARRAY_H__
14 #define __SGNDARRAY_H__
15 
16 #include <shogun/lib/config.h>
17 
19 #include <shogun/io/SGIO.h>
20 
21 namespace shogun
22 {
24 template<class T> class SGNDArray : public SGReferencedData
25 {
26  public:
28  SGNDArray();
29 
31  SGNDArray(T* a, index_t* d, index_t nd, bool ref_counting=true);
32 
34  SGNDArray(index_t* d, index_t nd, bool ref_counting=true);
35 
37  SGNDArray(const SGNDArray &orig);
38 
40  virtual ~SGNDArray();
41 
47  T* get_matrix(index_t matIdx) const
48  {
49  ASSERT(array && dims && num_dims > 2 && dims[2] > matIdx)
50  return &array[int64_t(matIdx)*int64_t(dims[0])*dims[1]];
51  }
52 
57  void transpose_matrix(index_t matIdx) const;
58 
63  inline const T& operator[](index_t index) const
64  {
65  return array[index];
66  }
67 
72  inline T& operator[](index_t index)
73  {
74  return array[index];
75  }
76 
77  protected:
78 
80  virtual void copy_data(const SGReferencedData &orig);
81 
83  virtual void init_data();
84 
86  virtual void free_data();
87 
88  public:
89 
91  T* array;
92 
95 
98 };
99 }
100 #endif // __SGNDARRAY_H__

SHOGUN Machine Learning Toolbox - Documentation