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/lib/SGVector.h>
20 #include <shogun/io/SGIO.h>
21 
22 namespace shogun
23 {
25 template<class T> class SGNDArray : public SGReferencedData
26 {
27  public:
29  SGNDArray();
30 
38  SGNDArray(T* a, index_t* d, index_t nd, bool ref_counting=true);
39 
46  SGNDArray(index_t* d, index_t nd, bool ref_counting=true);
47 
53  SGNDArray(SGVector<index_t> d, bool ref_counting=true);
54 
59  SGNDArray(const SGNDArray &orig);
60 
62  virtual ~SGNDArray();
63 
65  SGNDArray<T> clone() const;
66 
72  T* get_matrix(index_t matIdx) const
73  {
74  ASSERT(array && dims && num_dims > 2 && dims[2] > matIdx)
75  return &array[int64_t(matIdx)*int64_t(dims[0])*dims[1]];
76  }
77 
82  void transpose_matrix(index_t matIdx) const;
83 
88  inline const T& operator[](index_t index) const
89  {
90  return array[index];
91  }
92 
97  inline T& operator[](index_t index)
98  {
99  return array[index];
100  }
101 
104 
109  void set_const(T const_elem);
110 
116  SGNDArray<T>& operator*=(T val);
117 
123  SGNDArray<T>& operator+=(SGNDArray& ndarray);
124 
130  SGNDArray<T>& operator-=(SGNDArray& ndarray);
131 
138  T max_element(index_t& max_at);
139 
145  void expand(SGNDArray& big_array, SGVector<index_t>& axes);
146 
152  T get_value(SGVector<index_t> index) const;
153 
158  void next_index(SGVector<index_t>& curr_index) const;
159 
160  protected:
161 
163  virtual void copy_data(const SGReferencedData &orig);
164 
166  virtual void init_data();
167 
169  virtual void free_data();
170 
171  public:
172 
174  T* array;
175 
178 
181 
184 };
185 }
186 #endif // __SGNDARRAY_H__

SHOGUN Machine Learning Toolbox - Documentation