1#ifndef FSTINDEXEDVECTOR_H
2#define FSTINDEXEDVECTOR_H
87template<
typename DATATYPE,
typename DIMTYPE,
class SUBSET>
90template<
typename DATATYPE,
typename DIMTYPE,
class SUBSET>
93template<
typename DATATYPE,
typename DIMTYPE,
class SUBSET>
99template<
typename DATATYPE,
typename DIMTYPE,
class SUBSET>
100class Indexed_Vector {
103 Indexed_Vector() :
_n_max(0),
_n(0),
_d(0) {
notify(
"Indexed_Vector (empty) constructor");}
108 void reset(
const DIMTYPE n_max);
109 void redim(
const DIMTYPE n=0);
134 friend std::ostream& operator<< <>(std::ostream& os,
const Indexed_Vector& tdb);
150template<
typename DATATYPE,
typename DIMTYPE,
class SUBSET>
151Indexed_Vector<DATATYPE,DIMTYPE,SUBSET>::Indexed_Vector(
const Indexed_Vector& iv) :
156 notify(
"Indexed_Vector copy-constructor.");
164template<
typename DATATYPE,
typename DIMTYPE,
class SUBSET>
167 notify(
"Indexed_Vector operator=.");
188 memcpy((
void *)
_data.get(),(
void *)(iv.
_data).get(),
sizeof(DATATYPE)*
_n_max);
195template<
typename DATATYPE,
typename DIMTYPE,
class SUBSET>
198 notify(
"Indexed_Vector reset.");
203 _index.reset(
new DIMTYPE[n_max]);
212template<
typename DATATYPE,
typename DIMTYPE,
class SUBSET>
215 notify(
"Indexed_Vector redim.");
220 for(DIMTYPE i=0;i<
_n;i++)
_index[i]=i;
223template<
typename DATATYPE,
typename DIMTYPE,
class SUBSET>
226 assert(
_n>=sub->get_d_raw());
229 for(DIMTYPE f : sub->selected_features())
_index[
_d++]=f;
233template<
typename DATATYPE,
typename DIMTYPE,
class SUBSET>
237 for(DIMTYPE i=0;i<
_n;i++)
_index[i]=i;
241template<
typename DATATYPE,
typename DIMTYPE,
class SUBSET>
245 for(DIMTYPE i=0;i<
_n;i++)
_data[i]=val;
248template<
typename DATATYPE,
typename DIMTYPE,
class SUBSET>
257template<
typename DATATYPE,
typename DIMTYPE,
class SUBSET>
271template<
typename DATATYPE,
typename DIMTYPE,
class SUBSET>
272std::ostream&
operator<<(std::ostream& os,
const Indexed_Vector<DATATYPE,DIMTYPE,SUBSET>& tdb)
278 os <<
"----------------"<<std::endl;
279 os <<
"Indexed_Vector::" << std::endl;
280 os <<
"_index: ";
for(DIMTYPE j=0;j<tdb.
_d;j++) {os << tdb.
_index[j] <<
" ";} os<<std::endl;
281 os <<
"_data (indexed): ";
for(DIMTYPE j=0;j<tdb.
_d;j++) {os << tdb.
_data[tdb.
_index[j]] <<
" ";} os << std::endl;
282 os <<
"----------------"<<std::endl;
Matrix representation and operations, allows operation in selected subspace.
Definition indexed_matrix.hpp:102
Vector representation and operations, allows operation in selected subspace. Also serves as the helpe...
Definition indexed_vector.hpp:100
void copy_raw(const Indexed_Vector &vr)
this = vr, elementwise over the raw get_n() entries (requires vr.get_n()==get_n())
Definition indexed_vector.hpp:258
DIMTYPE _n
full ("raw") dimensionality currently in use, _n<=_n_max; see get_n()
Definition indexed_vector.hpp:143
const DATATYPE & at_raw(const DIMTYPE i) const
read-only raw (unindexed) element access – same as the const operator[]
Definition indexed_vector.hpp:116
DATATYPE & at(const DIMTYPE i)
indexed access through the narrow_to() subset map, i in [0,get_d())
Definition indexed_vector.hpp:113
void denarrow()
reset _index[] -> access is reset to the full vector (identity map, get_d()==get_n())
Definition indexed_vector.hpp:234
DATATYPE & at_raw(const DIMTYPE i)
raw (unindexed) element access, i in [0,get_n()) – same as operator[]
Definition indexed_vector.hpp:112
const DATATYPE * get_raw() const
read-only raw pointer to the underlying buffer (get_n() valid entries)
Definition indexed_vector.hpp:118
void subtract_raw(const Indexed_Vector &vr)
this -= vr, elementwise over the raw get_n() entries (requires vr.get_n()==get_n())
Definition indexed_vector.hpp:249
const DATATYPE & operator[](const DIMTYPE i) const
read-only raw (unindexed) element access, i in [0,get_n())
Definition indexed_vector.hpp:115
DATATYPE & operator[](const DIMTYPE i)
raw (unindexed) element access, i in [0,get_n())
Definition indexed_vector.hpp:111
DATATYPE * get_raw()
raw pointer to the underlying buffer (get_n() valid entries)
Definition indexed_vector.hpp:114
void redim(const DIMTYPE n=0)
keeps the existing allocation (reset() must have run already), resets to an unnarrowed identity index...
Definition indexed_vector.hpp:213
std::unique_ptr< DIMTYPE[]> _index
maps virtual sub-vector _d dimensions to original _n dimensions (identity after reset()/redim()/denar...
Definition indexed_vector.hpp:147
const DATATYPE & at(const DIMTYPE i) const
read-only indexed access through the narrow_to() subset map, i in [0,get_d())
Definition indexed_vector.hpp:117
DIMTYPE get_n() const
the full ("raw") dimensionality set by reset()/redim()
Definition indexed_vector.hpp:125
void reset(const DIMTYPE n_max)
(re)allocates for n_max features and resets to full, unnarrowed dimensionality (get_n()==get_d()==n_m...
Definition indexed_vector.hpp:196
DIMTYPE _d
current virtual (narrow_to()'d) sub-vector dimensionality, _d<=_n; see get_d()
Definition indexed_vector.hpp:146
std::shared_ptr< SUBSET > PSubset
shared pointer to a feature subset (the narrowing selector)
Definition indexed_vector.hpp:102
Indexed_Vector & operator=(Indexed_Vector const &iv)
deep-copy assignment (reallocates only if iv's capacity differs)
Definition indexed_vector.hpp:165
Indexed_Vector(const DIMTYPE n)
allocates for n features via reset(); starts unnarrowed (get_n()==get_d()==n)
Definition indexed_vector.hpp:104
DIMTYPE _n_max
allocated capacity: _data/_index can hold up to _n_max elements
Definition indexed_vector.hpp:142
std::unique_ptr< DATATYPE[]> _data
raw vector data buffer (_n_max entries allocated)
Definition indexed_vector.hpp:144
void set_all_raw_to(const DATATYPE val)
sets all get_n() raw entries to val (ignores the index map)
Definition indexed_vector.hpp:242
DIMTYPE get_d() const
the current virtual (narrow_to()'d) dimensionality, get_d()<=get_n()
Definition indexed_vector.hpp:126
void narrow_to(const PSubset sub)
fill _index[] -> access to data is then mapped to sub-vector; get_d() becomes the subset size.
Definition indexed_vector.hpp:224
FST4 specific error passing class.
Matrix representation and operations, allows operation in selected subspace.
The Feature Selection Toolbox 4 library: every library component – data access, criteria and classifi...
Definition data_accessor.hpp:80
void notify(const std::string msg)
Prints msg followed by a newline via syncout::print(); a no-op unless the preprocessor macro DEBUG is...
Definition global.hpp:112
std::ostream & operator<<(std::ostream &os, const Data_Intervaller< CONTAINER, IDXTYPE > &ia)
Streams every contained interval as "si:<startidx>, c:<count>" lines to os.
Definition data_intervaller.hpp:152