SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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__
SGNDArray< T > & operator*=(T val)
Definition: SGNDArray.cpp:153
void transpose_matrix(index_t matIdx) const
Definition: SGNDArray.cpp:122
SGNDArray< T > & operator+=(SGNDArray &ndarray)
Definition: SGNDArray.cpp:176
virtual void init_data()
Definition: SGNDArray.cpp:86
T & operator[](index_t index)
Definition: SGNDArray.h:97
int32_t index_t
Definition: common.h:62
SGNDArray< T > clone() const
Definition: SGNDArray.cpp:105
virtual ~SGNDArray()
Definition: SGNDArray.cpp:73
SGNDArray< T > & operator-=(SGNDArray &ndarray)
Definition: SGNDArray.cpp:204
T * get_matrix(index_t matIdx) const
Definition: SGNDArray.h:72
SGVector< index_t > get_dimensions() const
Definition: SGNDArray.cpp:112
#define ASSERT(x)
Definition: SGIO.h:201
virtual void free_data()
Definition: SGNDArray.cpp:94
shogun reference count managed data
T get_value(SGVector< index_t > index) const
Definition: SGNDArray.cpp:266
index_t num_dims
Definition: SGNDArray.h:180
virtual void copy_data(const SGReferencedData &orig)
Definition: SGNDArray.cpp:78
void set_const(T const_elem)
Definition: SGNDArray.cpp:146
index_t len_array
Definition: SGNDArray.h:183
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
index_t * dims
Definition: SGNDArray.h:177
T max_element(index_t &max_at)
Definition: SGNDArray.cpp:232
const T & operator[](index_t index) const
Definition: SGNDArray.h:88
void next_index(SGVector< index_t > &curr_index) const
Definition: SGNDArray.cpp:286
shogun n-dimensional array
Definition: SGNDArray.h:25
void expand(SGNDArray &big_array, SGVector< index_t > &axes)
Definition: SGNDArray.cpp:303

SHOGUN Machine Learning Toolbox - Documentation