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
#include "SubVMatrix.h"
00042
00043
namespace PLearn {
00044
using namespace std;
00045
00046
00049
PLEARN_IMPLEMENT_OBJECT(SubVMatrix,
"ONE LINE DESCR",
"NO HELP");
00050
00052
00054 SubVMatrix::SubVMatrix()
00055 :istart(0),
00056 jstart(0),
00057 fistart(-1),
00058 flength(-1)
00059 {}
00060
00061 SubVMatrix::SubVMatrix(
VMat the_parent,
int the_istart,
int the_jstart,
int the_length,
int the_width)
00062 :
VMatrix(the_length, the_width), parent(the_parent), istart(the_istart), jstart(the_jstart),
00063 fistart(-1), flength(-1)
00064 {
00065
build_();
00066 }
00067
00068 SubVMatrix::SubVMatrix(
VMat the_parent,
real the_fistart,
int the_jstart,
real the_flength,
int the_width)
00069 :
VMatrix(
int(the_flength * the_parent->length()), the_width),
00070 parent(the_parent), istart(-1), jstart(the_jstart), fistart(the_fistart), flength(the_flength)
00071
00072 {
00073
build_();
00074 }
00075
00077
00079 void SubVMatrix::declareOptions(
OptionList &ol)
00080 {
00081
declareOption(ol,
"parent", &SubVMatrix::parent, OptionBase::buildoption,
"Source VMatrix");
00082
declareOption(ol,
"istart", &SubVMatrix::istart, OptionBase::buildoption,
"Start i coordinate(row wise)");
00083
declareOption(ol,
"jstart", &SubVMatrix::jstart, OptionBase::buildoption,
"Start j coordinate(column wise)");
00084
declareOption(ol,
"fistart", &SubVMatrix::fistart, OptionBase::buildoption,
00085
"If provided, will override istart to fistart * parent.length()");
00086
declareOption(ol,
"flength", &SubVMatrix::flength, OptionBase::buildoption,
00087
"If provided, will override length to flength * parent.length()");
00088 inherited::declareOptions(ol);
00089 }
00090
00091 void SubVMatrix::build()
00092 {
00093 inherited::build();
00094
build_();
00095 }
00096
00097 void SubVMatrix::build_()
00098 {
00099
int pl =
parent.
length();
00100
if (
fistart >= 0) {
00101
istart =
int(
fistart * pl);
00102 }
00103
if (
flength >= 0) {
00104 length_ =
int(
flength * pl);
00105 }
00106
if(length_<0)
00107 length_ =
parent->
length() -
istart;
00108
00109
if(width_<0 &&
parent->
width()>=0)
00110 width_ =
parent->
width() -
jstart;
00111
00112
if(
istart+
length()>
parent->
length() ||
jstart+
width()>
parent->
width())
00113
PLERROR(
"In SubVMatrix constructor OUT OF BOUNDS of parent VMatrix");
00114
00115
00116 fieldinfos.
resize(width_);
00117
if (
parent->getFieldInfos().size() > 0)
00118
for(
int j=0; j<width_; j++)
00119 fieldinfos[j] =
parent->getFieldInfos()[
jstart+j];
00120
00121
00122 map_rs.
resize(width_);
00123 map_sr.
resize(width_);
00124
for (
int j =
jstart; j < width_ + jstart; j++) {
00125 map_rs[j - jstart] =
parent->getRealToStringMapping(j);
00126 map_sr[j - jstart] =
parent->getStringToRealMapping(j);
00127 }
00128
00129
if (width_ ==
parent->
width())
00130 {
00131
if(inputsize_<0) inputsize_ =
parent->inputsize();
00132
if(targetsize_<0) targetsize_ =
parent->targetsize();
00133
if(weightsize_<0) weightsize_ =
parent->weightsize();
00134 }
else {
00135
00136
00137
if(targetsize_<0) targetsize_ = 0;
00138
if(weightsize_<0) weightsize_ = 0;
00139
if(inputsize_<0) inputsize_ = width_ - targetsize_ - weightsize_;
00140 }
00141
00142
00143 }
00144
00145 void SubVMatrix::reset_dimensions()
00146 {
00147
int delta_length =
parent->
length()-length_;
00148
int delta_width = 0;
00149
parent->reset_dimensions();
00150 length_=
parent->
length()-delta_length;
00151 width_=
parent->
width()-delta_width;
00152 }
00153
00154 real SubVMatrix::get(
int i,
int j)
const
00155
{
00156
#ifdef BOUNDCHECK
00157
if(i<0 || i>=
length() || j<0 || j>=
width())
00158
PLERROR(
"In SubVMatrix::get(i,j) OUT OF BOUND access");
00159
#endif
00160
return parent->get(i+
istart,j+
jstart);
00161 }
00162 void SubVMatrix::getSubRow(
int i,
int j,
Vec v)
const
00163
{
00164
#ifdef BOUNDCHECK
00165
if(i<0 || i>=
length() || j<0 || j+v.
length()>
width())
00166
PLERROR(
"In SubVMatrix::getSubRow(i,j,v) OUT OF BOUND access");
00167
#endif
00168
parent->
getSubRow(i+
istart,j+
jstart,v);
00169 }
00170
00171 void SubVMatrix::getMat(
int i,
int j,
Mat m)
const
00172
{
00173
#ifdef BOUNDCHECK
00174
if(i<0 || i+m.
length()>
length() || j<0 || j+m.
width()>
width())
00175
PLERROR(
"In SubVMatrix::getMat OUT OF BOUND access");
00176
#endif
00177
parent->getMat(i+
istart, j+
jstart, m);
00178 }
00179
00180 void SubVMatrix::put(
int i,
int j,
real value)
00181 {
00182
#ifdef BOUNDCHECK
00183
if(i<0 || i>=
length() || j<0 || j>=
width())
00184
PLERROR(
"In SubVMatrix::put(i,j,value) OUT OF BOUND access");
00185
#endif
00186
return parent->put(i+
istart,j+
jstart,value);
00187 }
00188 void SubVMatrix::putSubRow(
int i,
int j,
Vec v)
00189 {
00190
#ifdef BOUNDCHECK
00191
if(i<0 || i>=
length() || j<0 || j>=
width())
00192
PLERROR(
"In SubVMatrix::putSubRow(i,j,v) OUT OF BOUND access");
00193
#endif
00194
parent->putSubRow(i+
istart,j+
jstart,v);
00195 }
00196
00197 void SubVMatrix::putMat(
int i,
int j,
Mat m)
00198 {
00199
#ifdef BOUNDCHECK
00200
if(i<0 || i+m.
length()>
length() || j<0 || j+m.
width()>
width())
00201
PLERROR(
"In SubVMatrix::putMat(i,j,m) OUT OF BOUND access");
00202
#endif
00203
parent->putMat(i+
istart, j+
jstart, m);
00204 }
00205
00206 VMat SubVMatrix::subMat(
int i,
int j,
int l,
int w)
00207 {
00208
return parent->
subMat(
istart+i,
jstart+j,l,w);
00209 }
00210
00212
00214 real SubVMatrix::dot(
int i1,
int i2,
int inputsize)
const
00215
{
00216
if(
jstart==0)
00217
return parent->dot(
istart+i1,
istart+i2, inputsize);
00218
else
00219
return VMatrix::dot(i1,i2,inputsize);
00220 }
00221
00222 real SubVMatrix::dot(
int i,
const Vec& v)
const
00223
{
00224
if(
jstart==0)
00225
return parent->dot(
istart+i,v);
00226
else
00227
return VMatrix::dot(i,v);
00228 }
00229
00231
00233 void SubVMatrix::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies) {
00234 inherited::makeDeepCopyFromShallowCopy(copies);
00235
deepCopyField(
parent, copies);
00236 }
00237
00238 }