VMat.h
Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037  
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00047 
#ifndef VMat_INC
00048 
#define VMat_INC
00049 
00050 
#include <cstdlib>
00051 
#include <plearn/base/PP.h>
00052 
#include <plearn/math/TMat.h>
00053 
#include "VMField.h"
00054 
#include "VMatrix.h"
00055 
#include "VVec.h"
00056 
00057 
namespace PLearn {
00058 
using namespace std;
00059 
00060 
class Ker;
00061 
00062 class VMat: 
public PP<VMatrix>
00063 {
00064 
public:
00065   
VMat();
00066   
VMat(
VMatrix* d);
00067   
VMat(
const VMat& d);
00068   
VMat(
const Mat& datamat); 
00069 
00070   int length()
 const { 
return ptr->
length(); }
00071   int width()
 const { 
return ptr->
width(); }
00072 
00073   string fieldName(
int fieldindex)
 const 
00074 
  { 
return ptr->
fieldName(fieldindex); } 
00075 
00076   int getFieldIndex(
const string& fieldname_or_num)
 const
00077 
  { 
return ptr->
getFieldIndex(fieldname_or_num); }
00078 
00079 
00080   real operator()(
int i, 
int j)
 const { 
return ptr->
get(i,j); }
00081   VVec operator()(
int i)
 const { 
return VVec(*
this, i); }
00082   Vec getColumn(
int i)
 const { 
Vec v(ptr->
length()); ptr->
getColumn(i,v); 
return v; }
00083   Vec getSubRow(
int i, 
int s)
 const { 
Vec v(s); ptr->
getSubRow(i, 0, v); 
return v; }
00084 
00085   VMat subMat(
int i, 
int j, 
int l, 
int w)
 const { 
return ptr->
subMat(i,j,l,w); }
00086   
VMat subMatRows(
int i, 
int l) 
const;
00087   
00088   VMat subMatColumns(
int j, 
int w)
 const { 
return ptr->
subMat(0,j,
length(),w); }
00089 
00090   inline void getExample(
int i, 
Vec& input, 
Vec& target, 
real& weight)
00091     { ptr->
getExample(i, input, target, weight); }
00092 
00093   VMat row(
int i)
 const { 
return subMatRows(i,1); }
00094   VMat firstRow()
 const { 
return row(0); }
00095   VMat lastRow()
 const { 
return row(
length()-1); }
00096   VMat column(
int j)
 const { 
return subMatColumns(j,1); }
00097   VMat firstColumn()
 const { 
return column(0); }
00098   VMat lastColumn()
 const { 
return column(
width()-1); }
00099   Mat toMat()
 const { 
return ptr->
toMat();}  
00100 
00102   
VMat rows(
TVec<int> rows_indices) 
const;
00104   
VMat rows(
Vec rows_indices) 
const;
00106   
VMat rows(
const string& indexfile) 
const;
00107 
00109   
VMat columns(
TVec<int> columns_indices) 
const;
00111   
VMat columns(
Vec columns_indices) 
const;
00112 
00113 
00114   operator Mat()
 const { 
return ptr->
toMat(); }
00115   inline void save(
const string& filename)
 const { ptr->
save(filename); }
00116 
00121   
void precompute();
00122   
00131   
void precompute(
const string& pmatfile, 
bool use_existing_file=
false);
00132 
00133   inline void print(ostream& out)
 const { ptr->
print(out); }
00134 
00135   
~VMat();
00136 };
00137 
00138 
DECLARE_OBJECT_PP(VMat, VMatrix);
00139 
00140 inline void operator<<(
const Mat& dest, 
const VMatrix& src)
00141 {
00142   
if(dest.
length()!=src.
length() || dest.
width()!=src.
width())
00143     
PLERROR(
"In operator<<(const Mat& dest, const VMatrix& src), incompatible dimensions");
00144   src.
getMat(0,0,dest);
00145 }
00146 
00147 inline void operator>>(
const VMatrix& src, 
const Mat& dest)
00148 { dest << src; }
00149 
00150 inline void operator<<(
const Mat& dest, 
const VMat& src)
00151 { dest << *(
VMatrix*)src; }
00152 
00153 inline void operator>>(
const VMat& src, 
const Mat& dest)
00154 { dest << src; }
00155 
00156 
00157 
00163 inline Array<VMat> operator&(
const VMat& d1, 
const VMat& d2)
00164 { 
return Array<VMat>(d1,d2); }
00165 
00166 inline ostream& 
operator<<(ostream& out, 
const VMat& m)
00167 { m.
print(out); 
return out; }
00168 
00169 
template <> 
void deepCopyField(VMat& field, CopiesMap& copies);
00170 
00173 VMat 
loadAsciiAsVMat(
const string& filename);
00174 
00175 } 
00176 
00177 
#endif
00178 
Generated on Tue Aug 17 16:10:27 2004 for PLearn by
 1.3.7