PLearn 0.1
Public Member Functions | Protected Attributes
PLearn::DoubleAccessSparseMatrix< T > Class Template Reference

#include <DoubleAccessSparseMatrix.h>

Inheritance diagram for PLearn::DoubleAccessSparseMatrix< T >:
Inheritance graph
[legend]
Collaboration diagram for PLearn::DoubleAccessSparseMatrix< T >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 DoubleAccessSparseMatrix (int n_rows=0, int n_cols=0, string _name="<no-name>", int _mode=ROW_WISE, bool _double_access=false, T _null_elem=0)
virtual ~DoubleAccessSparseMatrix ()
virtual void resize (int n_rows, int n_cols, bool clear_data=true)
virtual void clear ()
virtual void clearRow (int i, bool force_synchro_if_double_accessible)
virtual void clearCol (int j, bool force_synchro_if_double_accessible)
virtual void clearElem (int i, int j)
virtual T get (int i, int j) const
virtual T operator() (int i, int j) const
virtual bool exists (int i, int j) const
virtual void set (int i, int j, T value)
virtual void incr (int i, int j, T inc)
virtual map< int, T > & getRow (int i)
virtual const map< int, T > & getCol (int j) const
virtual void addRow (map< int, T > &row)
virtual void addCol (map< int, T > &col)
virtual int size ()
virtual T sumRow (int i)
virtual T sumCol (int j)
virtual T * getAsCompressedVec ()
virtual void getAsMaxSizedCompressedVecs (int max_size, vector< pair< T *, int > > &vectors)
virtual void addCompressedVec (T *compressed_vec, int n_elems)
virtual void setCompressedVec (T *compressed_vec, int n_elems)
virtual T sumOfElements ()
virtual int getHeight () const
virtual int getWidth () const
virtual void setDoubleAccessible (bool da)
virtual bool isDoubleAccessible ()
virtual void setMode (int new_mode)
virtual int getMode ()
virtual void setName (string n)
virtual string getName ()
virtual void write (PStream &out) const
virtual void read (PStream &in)
virtual T getNullElem ()
virtual string getClassName () const

Protected Attributes

vector< map< int, T > > rows
vector< map< int, T > > cols
string name
int mode
bool double_access
int height
int width
null_elem

Detailed Description

template<class T>
class PLearn::DoubleAccessSparseMatrix< T >

Definition at line 81 of file DoubleAccessSparseMatrix.h.


Constructor & Destructor Documentation

template<class T>
PLearn::DoubleAccessSparseMatrix< T >::DoubleAccessSparseMatrix ( int  n_rows = 0,
int  n_cols = 0,
string  _name = "<no-name>",
int  _mode = ROW_WISE,
bool  _double_access = false,
_null_elem = 0 
)
template<class T>
virtual PLearn::DoubleAccessSparseMatrix< T >::~DoubleAccessSparseMatrix ( ) [inline, virtual]

Definition at line 106 of file DoubleAccessSparseMatrix.h.

{}

Member Function Documentation

template<class T>
void PLearn::DoubleAccessSparseMatrix< T >::addCol ( map< int, T > &  col) [virtual]

Definition at line 327 of file DoubleAccessSparseMatrix_impl.h.

References PLERROR, and ROW_WISE.

{
    if (mode == ROW_WISE || double_access)
    {
        PLERROR("cannot add col in the row-wise matrix");
    } else
    {
        cols.push_back(col);
        width++;
    }
}
template<class T>
void PLearn::DoubleAccessSparseMatrix< T >::addCompressedVec ( T *  compressed_vec,
int  n_elems 
) [virtual]

Definition at line 502 of file DoubleAccessSparseMatrix_impl.h.

References i, and PLERROR.

{
    if ((n_elems % 3) != 0) PLERROR("n_elems mod 3 must = 0");
    for (int i = 0; i < n_elems; i += 3)
        incr((int)compressed_vec[i], (int)compressed_vec[i + 1], compressed_vec[i + 2]);
}
template<class T>
void PLearn::DoubleAccessSparseMatrix< T >::addRow ( map< int, T > &  row) [virtual]

Definition at line 314 of file DoubleAccessSparseMatrix_impl.h.

References COLUMN_WISE, and PLERROR.

{
    if (mode == COLUMN_WISE || double_access)
    {
        PLERROR("cannot add row in the column-wise matrix");
    } else
    {
        rows.push_back(row);
        height++;
    }
}
template<class T >
void PLearn::DoubleAccessSparseMatrix< T >::clear ( ) [virtual]

Definition at line 84 of file DoubleAccessSparseMatrix_impl.h.

References PLearn::clear(), COLUMN_WISE, i, and ROW_WISE.

Referenced by PLearn::ComplementedProbSparseMatrix::complement(), PLearn::GraphicalBiText::compute_likelihood(), PLearn::GraphicalBiText::init(), PLearn::ProbSparseMatrix::normalizeCond(), PLearn::SmoothedProbSparseMatrix::normalizeCondBackoff(), PLearn::SmoothedProbSparseMatrix::normalizeCondLaplace(), PLearn::ProbSparseMatrix::normalizeJoint(), and PLearn::GraphicalBiText::update_WSD_model().

{
    if (mode == ROW_WISE || double_access)
    {
        // norman: added explicit cast
        int rs = (int)rows.size();
        for (int i = 0; i < rs; i++)
            rows[i].clear();
    }
    if (mode == COLUMN_WISE || double_access)
    {
        // norman: added explicit cast
        int cs = (int)cols.size();
        for (int i = 0; i < cs; i++)
            cols[i].clear();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T >
void PLearn::DoubleAccessSparseMatrix< T >::clearCol ( int  j,
bool  force_synchro_if_double_accessible 
) [virtual]

Definition at line 130 of file DoubleAccessSparseMatrix_impl.h.

References COLUMN_WISE, i, j, PLERROR, PLWARNING, and ROW_WISE.

{
    if (!double_access)
    {
        if (mode == ROW_WISE)
            PLERROR("cannot access columns in the row-wise matrix");
        else if (mode == COLUMN_WISE)
            cols[j].clear();
    } else
    {
        if (force_synchro_if_double_accessible)
        {
            for (int i = 0; i < height; j++)
            {
                map<int, T>& row_i = rows[i];
                if (row_i.find(j) != row_i.end())
                    row_i.erase(j);
            }
        } else
        {
            PLWARNING("can only clear columns in the column-wise matrix (internal matrices are now out of sync)");
            cols[j].clear();
        }
    }
}
template<class T >
void PLearn::DoubleAccessSparseMatrix< T >::clearElem ( int  i,
int  j 
) [virtual]

Definition at line 157 of file DoubleAccessSparseMatrix_impl.h.

References COLUMN_WISE, i, j, and ROW_WISE.

{
    if (mode == ROW_WISE || double_access)
    {
        map<int, T>& row_i = rows[i];
        if (row_i.find(j) != row_i.end())
            row_i.erase(j);
    }
    if (mode == COLUMN_WISE || double_access)
    {
        map<int, T>& col_j = cols[j];
        if (col_j.find(i) != col_j.end())
            col_j.erase(i);
    }
}
template<class T >
void PLearn::DoubleAccessSparseMatrix< T >::clearRow ( int  i,
bool  force_synchro_if_double_accessible 
) [virtual]

Definition at line 103 of file DoubleAccessSparseMatrix_impl.h.

References COLUMN_WISE, i, j, PLERROR, and PLWARNING.

{
    if (!double_access)
    {
        if (mode == COLUMN_WISE)
            PLERROR("cannot access rows in the column-wise matrix");
        else
            rows[i].clear();
    } else
    {
        if (force_synchro_if_double_accessible)
        {
            for (int j = 0; j < width; j++)
            {
                map<int, T>& col_j = cols[j];
                if (col_j.find(i) != col_j.end())
                    col_j.erase(i);
            }
        } else
        {
            PLWARNING("can only clear rows in the row-wise matrix (internal matrices are now out of sync)");
            rows[i].clear();
        }
    }
}
template<class T >
bool PLearn::DoubleAccessSparseMatrix< T >::exists ( int  i,
int  j 
) const [virtual]

Definition at line 198 of file DoubleAccessSparseMatrix_impl.h.

References i, j, PLERROR, and ROW_WISE.

Referenced by PLearn::ProbSparseMatrix::add().

{
#ifdef BOUNDCHECK      
    if (i < 0 || i >= height || j < 0 || j >= width)
        PLERROR("out-of-bound access to (%d, %d), dims = (%d, %d)", i, j, height, width);
#endif
    if (mode == ROW_WISE)
    {
        const map<int, T>& row_i = rows[i];
        return (row_i.find(j) != row_i.end());
    } else
    {
        const map<int, T>& col_j = cols[j];
        return (col_j.find(i) != col_j.end());
    }    
}

Here is the caller graph for this function:

template<class T >
T PLearn::DoubleAccessSparseMatrix< T >::get ( int  i,
int  j 
) const [virtual]

Definition at line 174 of file DoubleAccessSparseMatrix_impl.h.

References i, j, PLERROR, and ROW_WISE.

Referenced by PLearn::ProbSparseMatrix::add(), PLearn::GraphicalBiText::compute_BN_likelihood(), PLearn::GraphicalBiText::compute_efs_likelihood(), PLearn::GraphicalBiText::compute_likelihood(), PLearn::GraphicalBiText::computeKL(), PLearn::ProbSparseMatrix::euclidianDistance(), PLearn::GraphicalBiText::init(), PLearn::GraphicalBiText::printNode(), and PLearn::GraphicalBiText::test_WSD().

{
#ifdef BOUNDCHECK      
    if (i < 0 || i >= height || j < 0 || j >= width)
        PLERROR("out-of-bound access to (%d, %d), dims = (%d, %d)", i, j, height, width);
#endif
    if (mode == ROW_WISE)
    {
        const map<int, T>& row_i = rows[i];
        typename map<int, T>::const_iterator it = row_i.find(j);
        if (it == row_i.end())
            return null_elem;
        return it->second;
    } else
    {
        const map<int, T>& col_j = cols[j];
        typename map<int, T>::const_iterator it = col_j.find(i);
        if (it == col_j.end())
            return null_elem;
        return it->second;
    }
}

Here is the caller graph for this function:

template<class T >
T * PLearn::DoubleAccessSparseMatrix< T >::getAsCompressedVec ( ) [virtual]

Definition at line 392 of file DoubleAccessSparseMatrix_impl.h.

References COLUMN_WISE, i, j, PLERROR, and ROW_WISE.

{
    int vector_size = size() * 3;
    T* compressed_vec = NULL;
    int pos = 0;
    if (mode == ROW_WISE || double_access)
    {
        compressed_vec = new T[vector_size];
        for (int i = 0; i < height; i++)
        {
            map<int, T>& row_i = rows[i];
            for (typename map<int, T>::iterator it = row_i.begin(); it != row_i.end(); ++it)
            {
                int j = it->first;
                T value = it->second;
                compressed_vec[pos++] = (T)i;
                compressed_vec[pos++] = (T)j;
                compressed_vec[pos++] = value;
            }
        }
        if (pos != vector_size)
            PLERROR("weird");
    } else if (mode == COLUMN_WISE)
    {
        compressed_vec = new T[vector_size];
        for (int j = 0; j < width; j++)
        {
            map<int, T>& col_j = cols[j];
            for (typename map<int, T>::iterator it = col_j.begin(); it != col_j.end(); ++it)
            {
                int i = it->first;
                T value = it->second;
                compressed_vec[pos++] = (T)i;
                compressed_vec[pos++] = (T)j;
                compressed_vec[pos++] = value;
            }
        }
        if (pos != vector_size)
            PLERROR("weird");
    }
    return compressed_vec;
}
template<class T>
void PLearn::DoubleAccessSparseMatrix< T >::getAsMaxSizedCompressedVecs ( int  max_size,
vector< pair< T *, int > > &  vectors 
) [virtual]

Definition at line 436 of file DoubleAccessSparseMatrix_impl.h.

References COLUMN_WISE, i, j, PLWARNING, and ROW_WISE.

{
    if ((max_size % 3) != 0) PLWARNING("dangerous vector size (max_size mod 3 must equal 0)");

    int n_elems = size() * 3;
    int n_vecs = n_elems / max_size;
    int remaining = n_elems % max_size;
    int pos = 0;
    if (remaining > 0) // padding to get sure that last block size (= remaining) is moddable by 3
    {
        n_vecs += 1;
        int mod3 = remaining % 3;
        if (mod3 != 0)
            remaining += (3 - mod3);
    }
    vectors.resize(n_vecs);
    for (int i = 0; i < n_vecs; i++)
    {
        if (i == (n_vecs - 1) && remaining > 0)
        {
            vectors[i].first = new T[remaining];
            vectors[i].second = remaining;
        } else
        {
            vectors[i].first = new T[max_size];
            vectors[i].second = max_size;
        }
    }
    if (mode == ROW_WISE)
    {
        for (int i = 0; i < height; i++)
        {
            map<int, T>& row_i = rows[i];
            for (typename map<int, T>::iterator it = row_i.begin(); it != row_i.end(); ++it)
            {
                int j = it->first;
                T value = it->second;
                vectors[pos / max_size].first[pos++ % max_size] = (T)i;
                vectors[pos / max_size].first[pos++ % max_size] = (T)j;
                vectors[pos / max_size].first[pos++ % max_size] = value;
            }
        }
    } else if (mode == COLUMN_WISE)
    {
        for (int j = 0; j < width; j++)
        {
            map<int, T>& col_j = cols[j];
            for (typename map<int, T>::iterator it = col_j.begin(); it != col_j.end(); ++it)
            {
                int i = it->first;
                T value = it->second;
                vectors[pos / max_size].first[pos++ % max_size] = (T)i;
                vectors[pos / max_size].first[pos++ % max_size] = (T)j;
                vectors[pos / max_size].first[pos++ % max_size] = value;
            }
        }
    }
    while (pos < n_elems) // pad with (null_elem, null_elem, null_elem)
    {
        vectors[pos / max_size].first[pos++ % max_size] = null_elem;
        vectors[pos / max_size].first[pos++ % max_size] = null_elem;
        vectors[pos / max_size].first[pos++ % max_size] = null_elem;
    }
}
template<class T>
virtual string PLearn::DoubleAccessSparseMatrix< T >::getClassName ( ) const [inline, virtual]

Reimplemented in PLearn::ProbSparseMatrix, and PLearn::SmoothedProbSparseMatrix.

Definition at line 176 of file DoubleAccessSparseMatrix.h.

{ return "DoubleAccesSparseMatrix"; }
template<class T >
const map< int, T > & PLearn::DoubleAccessSparseMatrix< T >::getCol ( int  j) const [virtual]
template<class T>
virtual int PLearn::DoubleAccessSparseMatrix< T >::getHeight ( ) const [inline, virtual]
template<class T>
virtual int PLearn::DoubleAccessSparseMatrix< T >::getMode ( ) [inline, virtual]
template<class T>
virtual string PLearn::DoubleAccessSparseMatrix< T >::getName ( ) [inline, virtual]

Definition at line 168 of file DoubleAccessSparseMatrix.h.

Referenced by PLearn::SmoothedProbSparseMatrix::normalizeCondBackoff().

{ return name; }

Here is the caller graph for this function:

template<class T>
virtual T PLearn::DoubleAccessSparseMatrix< T >::getNullElem ( ) [inline, virtual]

Definition at line 174 of file DoubleAccessSparseMatrix.h.

{ return null_elem; }
template<class T >
map< int, T > & PLearn::DoubleAccessSparseMatrix< T >::getRow ( int  i) [virtual]

Definition at line 280 of file DoubleAccessSparseMatrix_impl.h.

References i, PLERROR, and ROW_WISE.

Referenced by PLearn::ProbSparseMatrix::add(), PLearn::ComplementedProbSparseMatrix::complement(), PLearn::ProbSparseMatrix::euclidianDistance(), PLearn::ProbSparseMatrix::iterativeProportionalFittingStep(), PLearn::ProbSparseMatrix::normalizeCond(), PLearn::SmoothedProbSparseMatrix::normalizeCondBackoff(), PLearn::SmoothedProbSparseMatrix::normalizeCondLaplace(), and PLearn::ProbSparseMatrix::normalizeJoint().

{
    if (mode == ROW_WISE || double_access)
    {
#ifdef BOUNDCHECK
        if (i < 0 || i > height)
            PLERROR("out-of-bound access to row %d, dims = (%d, %d)", i, height, width);
#endif
        return rows[i];
    } else
    {
        PLERROR("cannot access rows in the column-wise matrix");
        return rows[0];
    }
}

Here is the caller graph for this function:

template<class T>
virtual int PLearn::DoubleAccessSparseMatrix< T >::getWidth ( ) const [inline, virtual]
template<class T>
void PLearn::DoubleAccessSparseMatrix< T >::incr ( int  i,
int  j,
inc 
) [virtual]

Definition at line 235 of file DoubleAccessSparseMatrix_impl.h.

References i, and j.

{
    if (inc != null_elem)
        set(i, j, get(i, j) + inc);
}
template<class T>
virtual bool PLearn::DoubleAccessSparseMatrix< T >::isDoubleAccessible ( ) [inline, virtual]
template<class T>
virtual T PLearn::DoubleAccessSparseMatrix< T >::operator() ( int  i,
int  j 
) const [inline, virtual]

Definition at line 120 of file DoubleAccessSparseMatrix.h.

{ return get(i, j); }
template<class T >
void PLearn::DoubleAccessSparseMatrix< T >::read ( PStream in) [virtual]

Reimplemented in PLearn::SmoothedProbSparseMatrix.

Definition at line 660 of file DoubleAccessSparseMatrix_impl.h.

References c, PLearn::PStream::get(), i, PLearn::PStream::inmode, PLearn::PStream::plearn_ascii, PLearn::PStream::plearn_binary, PLERROR, PLearn::PStream::raw_ascii, PLearn::PStream::raw_binary, and PLearn::PStream::skipBlanksAndCommentsAndSeparators().

Referenced by PLearn::operator>>().

{
    string class_name = getClassName();
    switch (in.inmode)
    {
    case PStream::raw_ascii :
        PLERROR("raw_ascii read not implemented in %s", class_name.c_str());
        break;
    case PStream::raw_binary :
        PLERROR("raw_binary read not implemented in %s", class_name.c_str());
        break;
    case PStream::plearn_ascii :
    case PStream::plearn_binary :
    {
        in.skipBlanksAndCommentsAndSeparators();
        string word(class_name.size() + 1, ' ');
        for (unsigned int i = 0; i < class_name.size() + 1; i++)
            in.get(word[i]);
        if (word != class_name + "(")
            PLERROR("in %s::(PStream& in), '%s' is not a proper header", class_name.c_str(), word.c_str());
        in.skipBlanksAndCommentsAndSeparators();
        in >> rows;
        in.skipBlanksAndCommentsAndSeparators();
        in >> cols;
        in.skipBlanksAndCommentsAndSeparators();
        in >> name;
        in.skipBlanksAndCommentsAndSeparators();
        in >> mode;
        in.skipBlanksAndCommentsAndSeparators();
        in >> double_access;
        in.skipBlanksAndCommentsAndSeparators();
        in >> height;
        in.skipBlanksAndCommentsAndSeparators();
        in >> width;
        in.skipBlanksAndCommentsAndSeparators();
        in >> null_elem;
        in.skipBlanksAndCommentsAndSeparators();
        int c = in.get();
        if(c != ')')
            PLERROR("in %s::(PStream& in), expected a closing parenthesis, found '%c'", class_name.c_str(), c);
    }
    break;
    default:
        PLERROR("unknown inmode in %s::write(PStream& out)", class_name.c_str());
        break;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T >
void PLearn::DoubleAccessSparseMatrix< T >::resize ( int  n_rows,
int  n_cols,
bool  clear_data = true 
) [virtual]

Definition at line 64 of file DoubleAccessSparseMatrix_impl.h.

References PLearn::clear(), and ROW_WISE.

Referenced by PLearn::GraphicalBiText::build_(), and PLearn::GraphicalBiText::compute_likelihood().

{
    height = n_rows;
    width = n_cols;
    if (double_access)
    {
        rows.resize(n_rows);
        cols.resize(n_cols);
    } else if (mode == ROW_WISE)
    {
        rows.resize(n_rows);
    } else
    {
        cols.resize(n_cols);
    }
    if (clear_data)
        clear();
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T>
void PLearn::DoubleAccessSparseMatrix< T >::set ( int  i,
int  j,
value 
) [virtual]

Definition at line 216 of file DoubleAccessSparseMatrix_impl.h.

References COLUMN_WISE, i, j, PLERROR, and ROW_WISE.

{
#ifdef BOUNDCHECK      
    if (i < 0 || i >= height || j < 0 || j >= width)
        PLERROR("out-of-bound access to (%d, %d), dims = (%d, %d)", i, j, height, width);
#endif
    if (value != null_elem)
    {
        if (mode == ROW_WISE || double_access)
            rows[i][j] = value;
        if (mode == COLUMN_WISE || double_access)
            cols[j][i] = value;
    } else
    {
        clearElem(i, j);
    }
}
template<class T>
void PLearn::DoubleAccessSparseMatrix< T >::setCompressedVec ( T *  compressed_vec,
int  n_elems 
) [virtual]

Definition at line 510 of file DoubleAccessSparseMatrix_impl.h.

References PLearn::clear(), i, and PLERROR.

{
    if ((n_elems % 3) != 0) PLERROR("n_elems mod 3 must = 0");
    clear();
    for (int i = 0; i < n_elems; i += 3)
        set((int)compressed_vec[i], (int)compressed_vec[i + 1], compressed_vec[i + 2]);
}

Here is the call graph for this function:

template<class T >
void PLearn::DoubleAccessSparseMatrix< T >::setDoubleAccessible ( bool  da) [virtual]

Definition at line 543 of file DoubleAccessSparseMatrix_impl.h.

References COLUMN_WISE, i, j, and ROW_WISE.

{
    if (double_access != da)
    {
        double_access = da;
        if (!double_access)
        {
            if (mode == ROW_WISE)
                cols.clear();
            else if (mode == COLUMN_WISE)
                rows.clear();
        } else
        {
            if (mode == ROW_WISE)
            {
                cols.resize(width);
                for (int i = 0; i < height; i++)
                {
                    map<int, T>& row_i = rows[i];
                    for (typename map<int, T>::iterator it = row_i.begin(); it != row_i.end(); ++it)
                    {
                        int j = it->first;
                        T value = it->second;
                        set(i, j, value);
                    }
                }
            } else if (mode == COLUMN_WISE)
            {
                rows.resize(height);
                for (int j = 0; j < width; j++)
                {
                    map<int, T>& col_j = cols[j];
                    for (typename map<int, T>::iterator it = col_j.begin(); it != col_j.end(); ++it)
                    {
                        int i = it->first;
                        T value = it->second;
                        set(i, j, value);
                    }
                }
            } 
        }
    }
}
template<class T >
void PLearn::DoubleAccessSparseMatrix< T >::setMode ( int  new_mode) [virtual]

Definition at line 588 of file DoubleAccessSparseMatrix_impl.h.

References COLUMN_WISE, i, j, PLERROR, and ROW_WISE.

Referenced by PLearn::GraphicalBiText::build_(), and PLearn::GraphicalBiText::compute_likelihood().

{
    if (mode != ROW_WISE && mode != COLUMN_WISE) PLERROR("mode must be either row-wise or column-wise");

    if (mode != new_mode)
    {
        mode = new_mode;
        if (mode == ROW_WISE && !double_access)
        {
            rows.resize(height);
            for (int j = 0; j < width; j++)
            {
                map<int, T>& col_j = cols[j];
                for (typename map<int, T>::iterator it = col_j.begin(); it != col_j.end(); ++it)
                {
                    int i = it->first;
                    T value = it->second;
                    set(i, j, value);
                }
            }
            cols.clear();
        } else if (mode == COLUMN_WISE && !double_access)
        {
            cols.resize(width);
            for (int i = 0; i < height; i++)
            {
                map<int, T>& row_i = rows[i];
                for (typename map<int, T>::iterator it = row_i.begin(); it != row_i.end(); ++it)
                {
                    int j = it->first;
                    T value = it->second;
                    set(i, j, value);
                }
            }
            rows.clear();
        }
    }
}

Here is the caller graph for this function:

template<class T>
virtual void PLearn::DoubleAccessSparseMatrix< T >::setName ( string  n) [inline, virtual]

Definition at line 166 of file DoubleAccessSparseMatrix.h.

Referenced by PLearn::GraphicalBiText::build_(), and PLearn::GraphicalBiText::compute_likelihood().

{ name = n; }

Here is the caller graph for this function:

template<class T >
int PLearn::DoubleAccessSparseMatrix< T >::size ( ) [virtual]

Definition at line 340 of file DoubleAccessSparseMatrix_impl.h.

References i, j, and ROW_WISE.

{
    int s = 0;
    if (mode == ROW_WISE)
    {
        for (unsigned int i = 0; i < rows.size(); i++)
            // norman: added explicit cast
            s += (int)rows[i].size();
    } else
    {
        for (unsigned int j = 0; j < cols.size(); j++)
            // norman: added explicit cast
            s += (int)cols[j].size();
    }
    return s;
}
template<class T >
T PLearn::DoubleAccessSparseMatrix< T >::sumCol ( int  j) [virtual]

Definition at line 375 of file DoubleAccessSparseMatrix_impl.h.

References COLUMN_WISE, j, PLERROR, and PLearn::sum().

Referenced by PLearn::GraphicalBiText::computeKL(), PLearn::GraphicalBiText::init(), PLearn::ProbSparseMatrix::iterativeProportionalFittingStep(), PLearn::ProbSparseMatrix::normalizeCond(), PLearn::SmoothedProbSparseMatrix::normalizeCondBackoff(), and PLearn::SmoothedProbSparseMatrix::normalizeCondLaplace().

{
    if (mode == COLUMN_WISE || double_access)
    {
        T sum = 0;
        map<int, T>& col_j = cols[j];
        for (typename map<int, T>::iterator it = col_j.begin(); it != col_j.end(); ++it)
            sum += it->second;
        return sum;
    } else
    {
        PLERROR("cannot access columns in the row-wise matrix");
        return 0;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T >
T PLearn::DoubleAccessSparseMatrix< T >::sumOfElements ( ) [virtual]

Definition at line 519 of file DoubleAccessSparseMatrix_impl.h.

References COLUMN_WISE, i, j, ROW_WISE, and PLearn::sum().

Referenced by PLearn::GraphicalBiText::check_consitency(), and PLearn::ProbSparseMatrix::normalizeJoint().

{
    T sum = 0;
    if (mode == ROW_WISE)
    {
        for (int i = 0; i < height; i++)
        {
            map<int, T>& row_i = rows[i];
            for (typename map<int, T>::iterator it = row_i.begin(); it != row_i.end(); ++it)
                sum += it->second;
        }
    } else if (mode == COLUMN_WISE)
    {
        for (int j = 0; j < width; j++)
        {
            map<int, T>& col_j = cols[j];
            for (typename map<int, T>::iterator it = col_j.begin(); it != col_j.end(); ++it)
                sum += it->second;
        }
    }
    return sum;
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T >
T PLearn::DoubleAccessSparseMatrix< T >::sumRow ( int  i) [virtual]

Definition at line 358 of file DoubleAccessSparseMatrix_impl.h.

References i, PLERROR, ROW_WISE, and PLearn::sum().

Referenced by PLearn::ProbSparseMatrix::iterativeProportionalFittingStep(), PLearn::ProbSparseMatrix::normalizeCond(), PLearn::SmoothedProbSparseMatrix::normalizeCondBackoff(), and PLearn::SmoothedProbSparseMatrix::normalizeCondLaplace().

{
    if (mode == ROW_WISE || double_access)
    {
        T sum = 0;
        map<int, T>& row_i = rows[i];
        for (typename map<int, T>::iterator it = row_i.begin(); it != row_i.end(); ++it)
            sum += it->second;
        return sum;
    } else
    {
        PLERROR("cannot access rows in the column-wise matrix");
        return 0;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T >
void PLearn::DoubleAccessSparseMatrix< T >::write ( PStream out) const [virtual]

Reimplemented in PLearn::SmoothedProbSparseMatrix.

Definition at line 628 of file DoubleAccessSparseMatrix_impl.h.

References PLearn::PStream::outmode, PLearn::PStream::plearn_ascii, PLearn::PStream::plearn_binary, PLERROR, PLearn::PStream::pretty_ascii, PLearn::PStream::raw_ascii, PLearn::PStream::raw_binary, and PLearn::PStream::write().

Referenced by PLearn::operator<<().

{
    string class_name = getClassName();
    switch(out.outmode)
    {
    case PStream::raw_ascii :
    case PStream::pretty_ascii :
        PLERROR("raw/pretty_ascii write not implemented in %s", class_name.c_str());
        break;        
    case PStream::raw_binary :
        PLERROR("raw_binary write not implemented in %s", class_name.c_str());
        break;        
    case PStream::plearn_binary :
    case PStream::plearn_ascii :
        out.write(class_name + "(");
        out << rows;
        out << cols;
        out << name;
        out << mode;
        out << double_access;
        out << height;
        out << width;
        out << null_elem;
        out.write(")\n");
        break;
    default:
        PLERROR("unknown outmode in %s::write(PStream& out)", class_name.c_str());
        break;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

template<class T>
vector<map<int, T> > PLearn::DoubleAccessSparseMatrix< T >::cols [protected]
template<class T>
bool PLearn::DoubleAccessSparseMatrix< T >::double_access [protected]
template<class T>
int PLearn::DoubleAccessSparseMatrix< T >::height [protected]
template<class T>
int PLearn::DoubleAccessSparseMatrix< T >::mode [protected]
template<class T>
string PLearn::DoubleAccessSparseMatrix< T >::name [protected]

Definition at line 90 of file DoubleAccessSparseMatrix.h.

template<class T>
T PLearn::DoubleAccessSparseMatrix< T >::null_elem [protected]

Definition at line 100 of file DoubleAccessSparseMatrix.h.

template<class T>
vector<map<int, T> > PLearn::DoubleAccessSparseMatrix< T >::rows [protected]
template<class T>
int PLearn::DoubleAccessSparseMatrix< T >::width [protected]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines