|
PLearn 0.1
|
A VMatrix that exists in a .pmat file (native PLearn matrix format, same as for Mat). More...
#include <FileVMatrix.h>


Public Member Functions | |
| FileVMatrix () | |
| FileVMatrix (const PPath &filename, bool writable_=false) | |
| opens an existing file | |
| FileVMatrix (const PPath &filename, int the_length, int the_width, bool force_float=false, bool call_build_=true) | |
| create a new matrix file | |
| FileVMatrix (const PPath &filename, int the_length, const TVec< string > &fieldnames) | |
| create a new matrix file | |
| virtual void | updateHeader () |
| Re-write the header with all current field values. | |
| virtual void | put (int i, int j, real value) |
| This method must be implemented in all subclasses of writable matrices. | |
| virtual void | putSubRow (int i, int j, Vec v) |
| It is suggested that this method be implemented in subclasses of writable matrices to speed up accesses (default version repeatedly calls put(i,j,value) which may have a significant overhead) | |
| virtual void | appendRow (Vec v) |
| This method must be implemented for matrices that are allowed to grow. | |
| virtual void | flush () |
| For matrices stored on disk, this should flush all pending buffered write operations. | |
| virtual void | build () |
| Simply calls inherited::build() then build_(). | |
| virtual string | classname () const |
| virtual OptionList & | getOptionList () const |
| virtual OptionMap & | getOptionMap () const |
| virtual RemoteMethodMap & | getRemoteMethodMap () const |
| virtual FileVMatrix * | deepCopy (CopiesMap &copies) const |
| virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
| Transform a shallow copy into a deep copy. | |
| virtual | ~FileVMatrix () |
| Destructor. | |
| virtual int64_t | getSizeOnDisk () |
Static Public Member Functions | |
| static string | _classname_ () |
| FileVMatrix. | |
| static OptionList & | _getOptionList_ () |
| static RemoteMethodMap & | _getRemoteMethodMap_ () |
| static Object * | _new_instance_for_typemap_ () |
| static bool | _isa_ (const Object *o) |
| static void | _static_initialize_ () |
| static const PPath & | declaringFile () |
Public Attributes | |
| int | remove_when_done |
| Deprecated! | |
| int | track_ref |
| Deprecated! | |
Static Public Attributes | |
| static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
| virtual void | getNewRow (int i, const Vec &v) const |
| This is the only method requiring implementation in subclasses. | |
| virtual void | closeCurrentFile () |
| Close the current '.pmat' file. | |
Static Protected Member Functions | |
| static void | declareOptions (OptionList &ol) |
| Declare this class' options. | |
Protected Attributes | |
| PPath | filename_ |
| FILE * | f |
| bool | file_is_bigendian |
| bool | file_is_float |
| bool | force_float |
Private Types | |
| typedef RowBufferedVMatrix | inherited |
Private Member Functions | |
| void | openfile (const PPath &path, const char *mode, PRIntn flags, PRIntn mode2) |
| void | build_ () |
| This does the actual building. | |
| void | moveto (int i, int j=0) const |
Private Attributes | |
| bool | build_new_file |
A VMatrix that exists in a .pmat file (native PLearn matrix format, same as for Mat).
Definition at line 59 of file FileVMatrix.h.
typedef RowBufferedVMatrix PLearn::FileVMatrix::inherited [private] |
Reimplemented from PLearn::RowBufferedVMatrix.
Reimplemented in PLearn::TemporaryFileVMatrix.
Definition at line 64 of file FileVMatrix.h.
| PLearn::FileVMatrix::FileVMatrix | ( | ) |
Definition at line 60 of file FileVMatrix.cc.
References remove_when_done, track_ref, and PLearn::VMatrix::writable.
:
filename_ (""),
f (0),
build_new_file (false)
{
writable=true;
remove_when_done = track_ref = -1;
}
opens an existing file
Definition at line 69 of file FileVMatrix.cc.
References build_(), remove_when_done, track_ref, and PLearn::VMatrix::writable.
:
inherited (true),
filename_ (filename.absolute()),
f (0),
build_new_file (!isfile(filename))
{
remove_when_done = track_ref = -1;
writable = writable_;
build_();
}

| PLearn::FileVMatrix::FileVMatrix | ( | const PPath & | filename, |
| int | the_length, | ||
| int | the_width, | ||
| bool | force_float = false, |
||
| bool | call_build_ = true |
||
| ) |
create a new matrix file
Definition at line 80 of file FileVMatrix.cc.
References build_(), remove_when_done, track_ref, and PLearn::VMatrix::writable.
:
inherited (the_length, the_width, true),
filename_ (filename.absolute()),
f (0),
file_is_float (force_float),
force_float (force_float),
build_new_file (true)
{
remove_when_done = track_ref = -1;
writable = true;
if(call_build_)
build_();
}

| PLearn::FileVMatrix::FileVMatrix | ( | const PPath & | filename, |
| int | the_length, | ||
| const TVec< string > & | fieldnames | ||
| ) |
create a new matrix file
Definition at line 95 of file FileVMatrix.cc.
References build_(), PLearn::VMatrix::declareFieldNames(), remove_when_done, PLearn::VMatrix::saveFieldInfos(), track_ref, and PLearn::VMatrix::writable.
:
inherited (the_length, fieldnames.length(), true),
filename_ (filename.absolute()),
f (0),
build_new_file (true)
{
remove_when_done = track_ref = -1;
writable = true;
build_();
declareFieldNames(fieldnames);
saveFieldInfos();
}

| PLearn::FileVMatrix::~FileVMatrix | ( | ) | [virtual] |
Destructor.
Definition at line 366 of file FileVMatrix.cc.
References closeCurrentFile(), PLearn::VMatrix::hasMetaDataDir(), PLearn::VMatrix::isWritable(), and PLearn::VMatrix::saveFieldInfos().
{
if (hasMetaDataDir() && isWritable())
saveFieldInfos();
FileVMatrix::closeCurrentFile();
}

| string PLearn::FileVMatrix::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::RowBufferedVMatrix.
Reimplemented in PLearn::TemporaryFileVMatrix.
Definition at line 55 of file FileVMatrix.cc.
| OptionList & PLearn::FileVMatrix::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::RowBufferedVMatrix.
Reimplemented in PLearn::TemporaryFileVMatrix.
Definition at line 55 of file FileVMatrix.cc.
| RemoteMethodMap & PLearn::FileVMatrix::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::RowBufferedVMatrix.
Reimplemented in PLearn::TemporaryFileVMatrix.
Definition at line 55 of file FileVMatrix.cc.
Reimplemented from PLearn::RowBufferedVMatrix.
Reimplemented in PLearn::TemporaryFileVMatrix.
Definition at line 55 of file FileVMatrix.cc.
| Object * PLearn::FileVMatrix::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Reimplemented in PLearn::TemporaryFileVMatrix.
Definition at line 55 of file FileVMatrix.cc.
| StaticInitializer FileVMatrix::_static_initializer_ & PLearn::FileVMatrix::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::RowBufferedVMatrix.
Reimplemented in PLearn::TemporaryFileVMatrix.
Definition at line 55 of file FileVMatrix.cc.
| void PLearn::FileVMatrix::appendRow | ( | Vec | v | ) | [virtual] |
This method must be implemented for matrices that are allowed to grow.
Reimplemented from PLearn::VMatrix.
Definition at line 460 of file FileVMatrix.cc.
References PLearn::TVec< T >::data(), f, file_is_bigendian, file_is_float, PLearn::fwrite_double(), PLearn::fwrite_float(), PLearn::TVec< T >::length(), PLearn::VMatrix::length_, moveto(), PLearn::PR_Write_double(), PLearn::PR_Write_float(), and updateHeader().
Referenced by PLearn::FileVMatrixTest::perform().
{
moveto(length_,0);
#ifdef USE_NSPR_FILE
if(file_is_float)
PR_Write_float(f, v.data(), v.length(), file_is_bigendian);
else
PR_Write_double(f, v.data(), v.length(), file_is_bigendian);
#else
if(file_is_float)
fwrite_float(f, v.data(), v.length(), file_is_bigendian);
else
fwrite_double(f, v.data(), v.length(), file_is_bigendian);
#endif
length_++;
updateHeader();
}


| void PLearn::FileVMatrix::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::VMatrix.
Reimplemented in PLearn::TemporaryFileVMatrix.
Definition at line 119 of file FileVMatrix.cc.
References PLearn::VMatrix::build(), and build_().
Referenced by PLearn::TemporaryFileVMatrix::build(), and makeDeepCopyFromShallowCopy().
{
inherited::build();
build_();
}


| void PLearn::FileVMatrix::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::VMatrix.
Reimplemented in PLearn::TemporaryFileVMatrix.
Definition at line 128 of file FileVMatrix.cc.
References PLearn::PPath::absolute(), build_new_file, c, closeCurrentFile(), DATAFILE_HEADERLENGTH, f, file_is_bigendian, file_is_float, filename_, force_float, PLearn::force_mkdir_for_file(), PLearn::force_rmdir(), PLearn::VMatrix::getFieldInfos(), PLearn::Object::info(), PLearn::PPath::isEmpty(), PLearn::isfile(), PLearn::VMatrix::length_, PLearn::VMatrix::loadFieldInfos(), PLearn::VMatrix::map_rs, PLearn::VMatrix::map_sr, moveto(), PLearn::mtime(), openfile(), PLASSERT, PLDEPRECATED, PLERROR, PLWARNING, remove_when_done, PLearn::VMatrix::setMetaDataDir(), PLearn::VMatrix::setMtime(), track_ref, updateHeader(), PLearn::VMatrix::width_, and PLearn::VMatrix::writable.
Referenced by build(), and FileVMatrix().
{
// Check for deprecated options.
if (remove_when_done != -1) {
PLDEPRECATED("In FileVMatrix::build_ - The option 'remove_when_done' "
"is now deprecated, please use the "
"TemporaryFileVMatrix class instead: this data file "
"may thus not be properly deleted");
PLASSERT( remove_when_done == 0 || remove_when_done == 1 );
}
if (track_ref != -1) {
PLDEPRECATED("In FileVMatrix::build_ - The option 'track_ref' "
"is now deprecated, please use the "
"TemporaryFileVMatrix class instead: this data file "
"may thus not be properly deleted");
PLASSERT( track_ref == 0 || track_ref == 1 );
}
// Since we are going to re-create it, we can close the current f.
closeCurrentFile();
// If no file is given, we can stop here.
if (filename_.isEmpty())
return;
char header[DATAFILE_HEADERLENGTH];
char matorvec[20];
char datatype[20];
char endiantype[20];
if (build_new_file || !isfile(filename_))
force_mkdir_for_file(filename_);
if (build_new_file || !isfile(filename_))
{
if (!writable)
PLERROR("In FileVMatrix::build_ - You asked to create a new file (%s), but 'writable' is set to 0 !", filename_.c_str());
openfile(filename_,"w+b",
PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE, 0666);
if (!f)
PLERROR("In FileVMatrix constructor, could not open file %s",filename_.c_str());
#ifdef USEFLOAT
file_is_float = true;
#endif
#ifdef USEDOUBLE
file_is_float = false;
#endif
#ifdef LITTLEENDIAN
file_is_bigendian = false;
#endif
#ifdef BIGENDIAN
file_is_bigendian = true;
#endif
if(force_float)
file_is_float = true;
updateHeader();
if(length_ > 0 && width_ > 0)
{
// Ensure we can allocate enough space... if len>0
#ifdef USE_NSPR_FILE
moveto(length_-1,width_-1);
char c = '\0';
PR_Write(f, &c, 1);
PR_Sync(f);
#else
if( fseek(f, DATAFILE_HEADERLENGTH+length_*width_*sizeof(real)-1, SEEK_SET) <0 )
{
perror("");
PLERROR("In FileVMatrix::build_ - Could not fseek to last byte");
}
fputc('\0',f);
#endif
}
// Get rid of any pre-existing .metadata :: this ensures that old
// fieldsizes do not pollute a newly-created FileVMatrix
force_rmdir(filename_ + ".metadata");
}
else
{
if (writable)
openfile(filename_, "r+b", PR_RDWR | PR_CREATE_FILE, 0666);
else
openfile(filename_, "rb", PR_RDONLY, 0666);
if (! f)
PLERROR("FileVMatrix::build: could not open file %s", filename_.c_str());
#ifdef USE_NSPR_FILE
PR_Read(f,header,DATAFILE_HEADERLENGTH);
#else
fread(header,DATAFILE_HEADERLENGTH,1,f);
#endif
if(header[DATAFILE_HEADERLENGTH-1]!='\n')
PLERROR("In FileVMatrix constructor, wrong header for PLearn binary matrix format. Please use checkheader (in PLearn/Scripts) to check the file.(0)");
int file_length, file_width;
bool need_update_header = false;
sscanf(header, "%s%d%d%s%s", matorvec, &file_length, &file_width, datatype, endiantype);
if (file_length == -1 && this->length_ >= 0 && writable) {
// The length set in the file is not valid, but we have specified a length.
// This can happen if build() has been called once before the sizes have
// been specified. In this case we must modify the file's length.
need_update_header = true;
} else if (file_length >= 0 && this->length_ >= 0 && file_length != this->length_) {
PLWARNING("In FileVMatrix::build_ - The length option of the VMatrix and the "
"loaded file differ; using the loaded file length (%d instead of %d)",
file_length, this->length_);
this->length_ = file_length;
} else {
this->length_ = file_length;
}
if (file_width == -1 && this->width_ >= 0 && writable) {
// Same as above, but for the width.
need_update_header = true;
} else if (file_width >= 0 && this->width_ >= 0 && file_width != this->width_) {
PLWARNING("In FileVMatrix::build_ - The width option of the VMatrix and the "
"loaded file differ; using the loaded file width (%d instead of %d)",
file_width, this->width_);
this->width_ = file_width;
} else {
this->width_ = file_width;
}
if (need_update_header) {
updateHeader();
}
if (strcmp(matorvec,"MATRIX")!=0)
PLERROR("In FileVMatrix constructor, wrong header for PLearn binary matrix format. Please use checkheader (in PLearn/Scripts) to check the file.(1)");
if (strcmp(endiantype,"LITTLE_ENDIAN")==0)
file_is_bigendian = false;
else if (strcmp(endiantype,"BIG_ENDIAN")==0)
file_is_bigendian = true;
else
PLERROR("In FileVMatrix constructor, wrong header for PLearn binary matrix format. Please use checkheader (in PLearn/Scripts) to check the file.(2)");
if (strcmp(datatype,"FLOAT")==0)
file_is_float = true;
else if (strcmp(datatype,"DOUBLE")==0)
file_is_float = false;
else
PLERROR("In FileVMatrix constructor, wrong header for PLearn binary matrix format. Please use checkheader (in PLearn/Scripts) to check the file.(3)");
//resize the string mappings
if (width_ >= 0) {
map_sr = TVec<map<string,real> >(width_);
map_rs = TVec<map<real,string> >(width_);
}
#ifdef USE_NSPR_FILE
//check if the file have all data
PRFileInfo64 info;
if(PR_FAILURE==PR_GetFileInfo64(filename_.absolute().c_str(), &info))
PLERROR("In FileVMatrix::build_() - can't get file info for file '%s'",
filename_.c_str());
PRInt64 elemsize = file_is_float ? sizeof(float) : sizeof(double);
PRInt64 expectedsize=DATAFILE_HEADERLENGTH+length_*width_*elemsize;
if(info.size!=expectedsize)
PLWARNING("In FileVMatrix::build_() - The file '%s' have a size"
" of %ld, expected %ld",
filename_.c_str(), (long int)info.size, (long int)expectedsize);
#endif
}
setMetaDataDir(filename_ + ".metadata");
setMtime(mtime(filename_));
if (width_ >= 0)
getFieldInfos();
loadFieldInfos();
}


| string PLearn::FileVMatrix::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Reimplemented in PLearn::TemporaryFileVMatrix.
Definition at line 55 of file FileVMatrix.cc.
| void PLearn::FileVMatrix::closeCurrentFile | ( | ) | [protected, virtual] |
Close the current '.pmat' file.
Reimplemented in PLearn::TemporaryFileVMatrix.
Definition at line 310 of file FileVMatrix.cc.
References f.
Referenced by build_(), PLearn::TemporaryFileVMatrix::closeCurrentFile(), and ~FileVMatrix().

| void PLearn::FileVMatrix::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declare this class' options.
Reimplemented from PLearn::VMatrix.
Reimplemented in PLearn::TemporaryFileVMatrix.
Definition at line 326 of file FileVMatrix.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::VMatrix::declareOptions(), filename_, PLearn::OptionBase::learntoption, remove_when_done, and track_ref.
Referenced by PLearn::TemporaryFileVMatrix::declareOptions().
{
declareOption(ol, "filename", &FileVMatrix::filename_, OptionBase::buildoption, "Filename of the matrix");
declareOption(ol, "remove_when_done", &FileVMatrix::remove_when_done,
OptionBase::learntoption,
"Deprecated option! (use TemporaryFileVMatrix instead).");
declareOption(ol, "track_ref", &FileVMatrix::track_ref,
OptionBase::learntoption,
"Deprecated option! (use TemporaryFileVMatrix instead).");
inherited::declareOptions(ol);
}


| static const PPath& PLearn::FileVMatrix::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::RowBufferedVMatrix.
Reimplemented in PLearn::TemporaryFileVMatrix.
Definition at line 116 of file FileVMatrix.h.
:
| FileVMatrix * PLearn::FileVMatrix::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::RowBufferedVMatrix.
Reimplemented in PLearn::TemporaryFileVMatrix.
Definition at line 55 of file FileVMatrix.cc.
| void PLearn::FileVMatrix::flush | ( | ) | [virtual] |
For matrices stored on disk, this should flush all pending buffered write operations.
Reimplemented from PLearn::VMatrix.
Definition at line 482 of file FileVMatrix.cc.
References f.
Referenced by PLearn::FileVMatrixTest::perform().

This is the only method requiring implementation in subclasses.
Implements PLearn::RowBufferedVMatrix.
Definition at line 377 of file FileVMatrix.cc.
References PLearn::TVec< T >::data(), f, file_is_bigendian, file_is_float, PLearn::fread_double(), PLearn::fread_float(), PLearn::TVec< T >::length(), moveto(), PLERROR, PLearn::PR_Read_double(), PLearn::PR_Read_float(), and PLearn::VMatrix::width_.
{
#ifdef BOUNDCHECK
if(v.length()!=width_)
PLERROR("In FileVMatrix::getNewRow length of v (%d) differs from matrix width (%d)",v.length(),width_);
#endif
moveto(i);
#ifdef USE_NSPR_FILE
if(file_is_float)
PR_Read_float(f, v.data(), v.length(), file_is_bigendian);
else
PR_Read_double(f, v.data(), v.length(), file_is_bigendian);
#else
if(file_is_float)
fread_float(f, v.data(), v.length(), file_is_bigendian);
else
fread_double(f, v.data(), v.length(), file_is_bigendian);
#endif
}

| OptionList & PLearn::FileVMatrix::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Reimplemented in PLearn::TemporaryFileVMatrix.
Definition at line 55 of file FileVMatrix.cc.
| OptionMap & PLearn::FileVMatrix::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Reimplemented in PLearn::TemporaryFileVMatrix.
Definition at line 55 of file FileVMatrix.cc.
| RemoteMethodMap & PLearn::FileVMatrix::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Reimplemented in PLearn::TemporaryFileVMatrix.
Definition at line 55 of file FileVMatrix.cc.
| int64_t PLearn::FileVMatrix::getSizeOnDisk | ( | ) | [virtual] |
Reimplemented from PLearn::VMatrix.
Definition at line 541 of file FileVMatrix.cc.
References DATAFILE_HEADERLENGTH, file_is_float, PLearn::VMatrix::length_, and PLearn::VMatrix::width_.
Referenced by PLearn::VMatCommand::run().
{
return DATAFILE_HEADERLENGTH + width_*length_*(file_is_float ? 4 : 8);
}

| void PLearn::FileVMatrix::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transform a shallow copy into a deep copy.
Reimplemented from PLearn::RowBufferedVMatrix.
Reimplemented in PLearn::TemporaryFileVMatrix.
Definition at line 344 of file FileVMatrix.cc.
References build(), build_new_file, f, PLearn::RowBufferedVMatrix::makeDeepCopyFromShallowCopy(), and PLearn::VMatrix::writable.
Referenced by PLearn::TemporaryFileVMatrix::makeDeepCopyFromShallowCopy().
{
inherited::makeDeepCopyFromShallowCopy(copies);
// it is unclear whether f should be shared or not...
// if we allow multi-threading, we should probably not share it
// so for now we will not share it. But a cleaner behavoiur would probably be
// to share it in multiple threads but make sure that getRow, putRow, etc... operations
// are atomic (no context switch to another thread).
f = 0; // Because we will open again the file (f should not be shared).
// however reopening the file twice in write mode is certainly a VERY bad idea.
// thus we switch to read-mode
build_new_file = false;
writable = false;
build(); // To open the file.
}


Definition at line 419 of file FileVMatrix.cc.
References DATAFILE_HEADERLENGTH, f, file_is_float, i, j, and PLearn::VMatrix::width_.
Referenced by appendRow(), build_(), getNewRow(), put(), and putSubRow().
{
#ifdef USE_NSPR_FILE
PRInt64 offset = i;
int elemsize = file_is_float ? sizeof(float) : sizeof(double);
offset *= width_;
offset += j;
offset *= elemsize;
offset += DATAFILE_HEADERLENGTH;
PR_Seek64(f, offset, PR_SEEK_SET);
#else
if(file_is_float)
fseek(f, DATAFILE_HEADERLENGTH+(i*width_+j)*sizeof(float), SEEK_SET);
else
fseek(f, DATAFILE_HEADERLENGTH+(i*width_+j)*sizeof(double), SEEK_SET);
#endif
}

| void PLearn::FileVMatrix::openfile | ( | const PPath & | path, |
| const char * | mode, | ||
| PRIntn | flags, | ||
| PRIntn | mode2 | ||
| ) | [private] |
Definition at line 530 of file FileVMatrix.cc.
References PLearn::PPath::absolute(), and f.
Referenced by build_().
{
#ifdef USE_NSPR_FILE
f = PR_Open(path.absolute().c_str(), flags, mode2);
#else
f = fopen(path.absolute().c_str(), mode);
#endif
}


This method must be implemented in all subclasses of writable matrices.
Sets element (i,j) to value.
Reimplemented from PLearn::VMatrix.
Definition at line 440 of file FileVMatrix.cc.
References f, file_is_bigendian, file_is_float, PLearn::fwrite_double(), PLearn::fwrite_float(), PLearn::RowBufferedVMatrix::invalidateBuffer(), moveto(), PLearn::PR_Write_double(), and PLearn::PR_Write_float().
{
moveto(i,j);
#ifdef USE_NSPR_FILE
if(file_is_float)
PR_Write_float(f,float(value),file_is_bigendian);
else
PR_Write_double(f,double(value),file_is_bigendian);
#else
if(file_is_float)
fwrite_float(f,float(value),file_is_bigendian);
else
fwrite_double(f,double(value),file_is_bigendian);
#endif
invalidateBuffer();
}

It is suggested that this method be implemented in subclasses of writable matrices to speed up accesses (default version repeatedly calls put(i,j,value) which may have a significant overhead)
Reimplemented from PLearn::VMatrix.
Definition at line 401 of file FileVMatrix.cc.
References PLearn::TVec< T >::data(), f, file_is_bigendian, file_is_float, PLearn::fwrite_double(), PLearn::fwrite_float(), PLearn::RowBufferedVMatrix::invalidateBuffer(), PLearn::TVec< T >::length(), moveto(), PLearn::PR_Write_double(), and PLearn::PR_Write_float().
{
moveto(i,j);
#ifdef USE_NSPR_FILE
if(file_is_float)
PR_Write_float(f, v.data(), v.length(), file_is_bigendian);
else
PR_Write_double(f, v.data(), v.length(), file_is_bigendian);
#else
if(file_is_float)
fwrite_float(f, v.data(), v.length(), file_is_bigendian);
else
fwrite_double(f, v.data(), v.length(), file_is_bigendian);
#endif
invalidateBuffer();
}

| void PLearn::FileVMatrix::updateHeader | ( | ) | [virtual] |
Re-write the header with all current field values.
Definition at line 497 of file FileVMatrix.cc.
References DATAFILE_HEADERLENGTH, f, file_is_float, PLearn::VMatrix::length_, PLearn::strlen(), and PLearn::VMatrix::width_.
Referenced by appendRow(), and build_().
{
char header[DATAFILE_HEADERLENGTH];
string real = "DOUBLE";
if(file_is_float)
real = "FLOAT";
#ifdef LITTLEENDIAN
sprintf(header,"MATRIX %d %d %s LITTLE_ENDIAN", length_, width_, real.c_str());
#endif
#ifdef BIGENDIAN
sprintf(header,"MATRIX %d %d %s BIG_ENDIAN", length_, width_, real.c_str());
#endif
int pos = strlen(header);
for(; pos<DATAFILE_HEADERLENGTH; pos++)
{
header[pos] = ' ';
}
header[DATAFILE_HEADERLENGTH-1] = '\n';
#ifdef USE_NSPR_FILE
PR_Seek64(f, 0, PR_SEEK_SET);
PR_Write(f, header, DATAFILE_HEADERLENGTH);
#else
fseek(f,0,SEEK_SET);
fwrite(header,1,DATAFILE_HEADERLENGTH,f);
#endif
}


Reimplemented from PLearn::RowBufferedVMatrix.
Reimplemented in PLearn::TemporaryFileVMatrix.
Definition at line 116 of file FileVMatrix.h.
bool PLearn::FileVMatrix::build_new_file [private] |
Definition at line 81 of file FileVMatrix.h.
Referenced by build_(), and makeDeepCopyFromShallowCopy().
FILE* PLearn::FileVMatrix::f [protected] |
Definition at line 73 of file FileVMatrix.h.
Referenced by appendRow(), PLearn::TemporaryFileVMatrix::build_(), build_(), PLearn::TemporaryFileVMatrix::closeCurrentFile(), closeCurrentFile(), flush(), getNewRow(), makeDeepCopyFromShallowCopy(), moveto(), openfile(), put(), putSubRow(), and updateHeader().
bool PLearn::FileVMatrix::file_is_bigendian [protected] |
Definition at line 75 of file FileVMatrix.h.
Referenced by appendRow(), build_(), getNewRow(), put(), and putSubRow().
bool PLearn::FileVMatrix::file_is_float [protected] |
Definition at line 76 of file FileVMatrix.h.
Referenced by appendRow(), build_(), getNewRow(), getSizeOnDisk(), moveto(), put(), putSubRow(), and updateHeader().
PPath PLearn::FileVMatrix::filename_ [protected] |
Definition at line 68 of file FileVMatrix.h.
Referenced by PLearn::TemporaryFileVMatrix::build_(), build_(), declareOptions(), and PLearn::TemporaryFileVMatrix::~TemporaryFileVMatrix().
bool PLearn::FileVMatrix::force_float [protected] |
Definition at line 77 of file FileVMatrix.h.
Referenced by build_().
Deprecated!
Definition at line 103 of file FileVMatrix.h.
Referenced by build_(), declareOptions(), and FileVMatrix().
Deprecated!
Definition at line 104 of file FileVMatrix.h.
Referenced by build_(), declareOptions(), and FileVMatrix().
1.7.4