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 "InterleaveVMatrix.h"
00042
00043
namespace PLearn {
00044
using namespace std;
00045
00046
00049
PLEARN_IMPLEMENT_OBJECT(InterleaveVMatrix,
"ONE LINE DESC",
"ONE LINE HELP");
00050
00051 InterleaveVMatrix::InterleaveVMatrix()
00052 {
00053 }
00054
00055 InterleaveVMatrix::InterleaveVMatrix(
Array<VMat> the_vm)
00056 : vm(the_vm)
00057 {
00058
build();
00059 }
00060
00061 InterleaveVMatrix::InterleaveVMatrix(
VMat d1,
VMat d2)
00062 : vm(d1,d2)
00063 {
00064
build();
00065 }
00066
00067
void
00068 InterleaveVMatrix::build()
00069 {
00070 inherited::build();
00071
build_();
00072 }
00073
00074
void
00075 InterleaveVMatrix::build_()
00076 {
00077
if (
vm) {
00078
int n =
vm.
size();
00079
if (n<1)
00080
PLERROR(
"InterleaveVMatrix expects >= 1 underlying-distribution, got %d",n);
00081
00082
00083 fieldinfos =
vm[0]->getFieldInfos();
00084
00085 width_ = vm[0]->width();
00086
int maxl = 0;
00087
for (
int i = 0; i < n; i++) {
00088
if (vm[i]->width() != width_)
00089
PLERROR(
"InterleaveVMatrix: underlying-distr %d has %d width, while 0-th has %d",i,vm[i]->
width(),width_);
00090
int l = vm[i]->length();
00091
if (l > maxl)
00092 maxl=l;
00093 }
00094 length_ = n * maxl;
00095 }
00096 }
00097
00098
void
00099 InterleaveVMatrix::declareOptions(
OptionList &ol)
00100 {
00101
declareOption(ol,
"vm", &InterleaveVMatrix::vm, OptionBase::buildoption,
"");
00102 inherited::declareOptions(ol);
00103 }
00104
00105 real InterleaveVMatrix::get(
int i,
int j)
const
00106
{
00107
#ifdef BOUNDCHECK
00108
if(i<0 || i>=
length() || j<0 || j>=
width())
00109
PLERROR(
"In InterleaveVMatrix::get OUT OF BOUNDS");
00110
#endif
00111
int n=
vm.
size();
00112
int m = i%n;
00113
int pos =
int(i/n) %
vm[m].
length();
00114
return vm[m]->get(pos,j);
00115 }
00116
00117 void InterleaveVMatrix::getSubRow(
int i,
int j,
Vec v)
const
00118
{
00119
#ifdef BOUNDCHECK
00120
if(i<0 || i>=
length() || j<0 || j+v.
length()>
width())
00121
PLERROR(
"In InterleaveVMatrix::getRow OUT OF BOUNDS");
00122
#endif
00123
int n=
vm.
size();
00124
int m = i%n;
00125
int pos =
int(i/n) %
vm[m].
length();
00126
vm[m]->getSubRow(pos, j, v);
00127 }
00128
00129 }