PLearn 0.1
Public Member Functions | Protected Attributes | Private Types
PLearn::SDBVMatrix Class Reference

#include <SDBVMat.h>

Inheritance diagram for PLearn::SDBVMatrix:
Inheritance graph
[legend]
Collaboration diagram for PLearn::SDBVMatrix:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 SDBVMatrix (const string &dbname, bool detect_missing=false)
 Currently, the constructor assumes that the SDB exists on-disk.
void appendField (const string &name, SDBVMField *new_field)
 Use default dtor, copy ctor, op=.
const FieldsVectorgetFields () const
 Obtain a list of the added fields.
virtual void getRow (int i, Vec v) const
 Transform row i of the SimpldDB into a row of the VMatrix.
SDBWithStatssdb ()
 Access underlying sdb.
const SDBWithStatssdb () const

Protected Attributes

SDBWithStats sdb_
FieldsVector fields_
Row row_
bool detect_missing_

Private Types

typedef RowBufferedVMatrix inherited
typedef vector< PSDBVMFieldFieldsVector

Detailed Description

This is a VMatrix that acts as a front-end to a SimpleDB (actually, an SDBWithStats). You can add as many fields derived from SDBVMField as required with the appendField function.

Definition at line 251 of file SDBVMat.h.


Member Typedef Documentation

typedef vector<PSDBVMField> PLearn::SDBVMatrix::FieldsVector [private]

Definition at line 254 of file SDBVMat.h.

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 253 of file SDBVMat.h.


Constructor & Destructor Documentation

PLearn::SDBVMatrix::SDBVMatrix ( const string &  dbname,
bool  detect_missing = false 
)

Currently, the constructor assumes that the SDB exists on-disk.

Definition at line 216 of file SDBVMat.cc.

References PLearn::SDBWithStats::computeStats(), PLearn::SimpleDB< KeyType, QueryResult >::getSchema(), PLearn::SDBWithStats::hasStats(), PLearn::VMatrix::length_, PLearn::SDBWithStats::loadStats(), row_, PLearn::SDBWithStats::saveStats(), sdb_, PLearn::SimpleDB< KeyType, QueryResult >::size(), and PLearn::VMatrix::width_.

    : sdb_(dbname, "", SDB::readonly), detect_missing_(detect_missing)
{
    row_ = Row(&sdb_.getSchema());
    length_ = sdb_.size();
    width_  = 0;
    if (sdb_.hasStats())
        sdb_.loadStats();
    else {
        sdb_.computeStats();
        sdb_.saveStats();
    }
}

Here is the call graph for this function:


Member Function Documentation

void PLearn::SDBVMatrix::appendField ( const string &  name,
SDBVMField new_field 
)

Use default dtor, copy ctor, op=.

Add a new field to the VMatrix. The VMatrix assumes ownership of the field.

Definition at line 230 of file SDBVMat.cc.

References PLearn::RowBufferedVMatrix::current_row, PLearn::VMatrix::declareField(), fields_, PLearn::SDBVMField::fieldType(), PLearn::SDBVMField::fieldWidth(), i, PLearn::TVec< T >::resize(), PLearn::split(), and PLearn::VMatrix::width_.

{
    int fieldwidth = new_field->fieldWidth();
    vector<string> fieldnames = split(name);
    if(fieldwidth>1 && int(fieldnames.size())==fieldwidth)
    {
        for(unsigned int i=0; i<fieldnames.size(); i++)
        {
            width_++;
            declareField(width_-1,fieldnames[i],new_field->fieldType());
        }
    }
    else
    {
        for(int k=0; k<fieldwidth; k++)
        {
            width_++;
            declareField(width_-1,name,new_field->fieldType());
        }
    }

    fields_.push_back(PSDBVMField(new_field));
    current_row.resize(width_);
}

Here is the call graph for this function:

const FieldsVector& PLearn::SDBVMatrix::getFields ( ) const [inline]

Obtain a list of the added fields.

Definition at line 267 of file SDBVMat.h.

                                          {
        return fields_;
    }
void PLearn::SDBVMatrix::getRow ( int  i,
Vec  v 
) const [virtual]

Transform row i of the SimpldDB into a row of the VMatrix.

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 255 of file SDBVMat.cc.

References detect_missing_, fields_, PLearn::SimpleDB< KeyType, QueryResult >::getInRow(), PLearn::TVec< T >::hasMissing(), PLWARNING, row_, sdb_, and PLearn::TVec< T >::subVec().

{
    //prof.start("getrow");
    //prof.start("getrow1");
    sdb_.getInRow(i, row_);
    //prof.end("getrow1");
    FieldsVector::const_iterator it = fields_.begin(), end = fields_.end();
    int curpos=0, curwidth;
    for (int f=0; it != end; ++it, curpos+=curwidth, f++) {
        curwidth = (*it)->fieldWidth();
        Vec output = v.subVec(curpos,curwidth);
        //prof.start("getrow2");
        (*it)->convertField(sdb_, row_, output);
        //prof.end("getrow2");
        if (detect_missing_ && output.hasMissing())
            PLWARNING("SDBVMatrix::getRow(%d,v) has missing value for %d-th field (columns %d-%d)",
                      i,f,curpos,curpos+curwidth-1);
    }
    //prof.end("getrow");
}

Here is the call graph for this function:

SDBWithStats& PLearn::SDBVMatrix::sdb ( ) [inline]

Access underlying sdb.

Definition at line 275 of file SDBVMat.h.

                        {
        return sdb_;
    }
const SDBWithStats& PLearn::SDBVMatrix::sdb ( ) const [inline]

Definition at line 278 of file SDBVMat.h.

                                    {
        return sdb_;
    }

Member Data Documentation

Definition at line 286 of file SDBVMat.h.

Referenced by getRow().

Definition at line 284 of file SDBVMat.h.

Referenced by appendField(), and getRow().

Row PLearn::SDBVMatrix::row_ [mutable, protected]

Definition at line 285 of file SDBVMat.h.

Referenced by getRow(), and SDBVMatrix().

Definition at line 283 of file SDBVMat.h.

Referenced by getRow(), and SDBVMatrix().


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