00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2012 Fernando José Iglesias García 00008 * Written (W) 2010,2012 Soeren Sonnenburg 00009 * Copyright (C) 2010 Berlin Institute of Technology 00010 * Copyright (C) 2012 Soeren Sonnenburg 00011 */ 00012 00013 #ifndef __SGNDARRAY_H__ 00014 #define __SGNDARRAY_H__ 00015 00016 #include <shogun/lib/config.h> 00017 #include <shogun/lib/DataType.h> 00018 #include <shogun/lib/SGReferencedData.h> 00019 00020 namespace shogun 00021 { 00023 template<class T> class SGNDArray : public SGReferencedData 00024 { 00025 public: 00027 SGNDArray(); 00028 00030 SGNDArray(T* a, index_t* d, index_t nd, bool ref_counting=true); 00031 00033 SGNDArray(index_t* d, index_t nd, bool ref_counting=true); 00034 00036 SGNDArray(const SGNDArray &orig); 00037 00039 virtual ~SGNDArray(); 00040 00046 T* get_matrix(index_t matIdx) const 00047 { 00048 ASSERT(array && dims && num_dims > 2 && dims[2] > matIdx); 00049 return &array[matIdx*dims[0]*dims[1]]; 00050 } 00051 00056 void transpose_matrix(index_t matIdx) const; 00057 00062 inline const T& operator[](index_t index) const 00063 { 00064 return array[index]; 00065 } 00066 00071 inline T& operator[](index_t index) 00072 { 00073 return array[index]; 00074 } 00075 00076 protected: 00077 00079 virtual void copy_data(const SGReferencedData &orig); 00080 00082 virtual void init_data(); 00083 00085 virtual void free_data(); 00086 00087 public: 00088 00090 T* array; 00091 00093 index_t* dims; 00094 00096 index_t num_dims; 00097 }; 00098 } 00099 #endif // __SGNDARRAY_H__