PLearn 0.1
|
00001 00002 #include "TransposeVariable.h" 00003 #include <plearn/var/Var_utils.h> 00004 00005 namespace PLearn { 00006 using namespace std; 00007 00008 00011 TransposeVariable::TransposeVariable(Variable* v) 00012 :UnaryVariable(v, v->width(), v->length()), startk(0) 00013 {} 00014 00015 00016 PLEARN_IMPLEMENT_OBJECT(TransposeVariable, "ONE LINE DESCR", "NO HELP"); 00017 00018 00019 void TransposeVariable::recomputeSize(int& l, int& w) const 00020 { l=input->width(); w=input->length(); } 00021 00022 00023 00024 00025 00026 00027 00028 00029 void TransposeVariable::fprop() 00030 { 00031 if(input->length()==1 || input->width()==1) 00032 { 00033 real* inputdata = input->valuedata; 00034 for(int k=0; k<nelems(); k++) 00035 valuedata[k] = inputdata[k]; 00036 } 00037 else // general case 00038 { 00039 real* inputrowdata = input->valuedata; 00040 int thiskcolstart = 0; // element index of start of column in this var 00041 for(int i=0; i<width(); i++) // the width() of this var is the length() of the submat 00042 { 00043 int thisk = thiskcolstart++; 00044 for(int j=0; j<length(); j++, thisk+=width()) // the length() of this var is the width() of the submat 00045 valuedata[thisk] = *inputrowdata++; 00046 } 00047 } 00048 } 00049 00050 00051 void TransposeVariable::bprop() 00052 { 00053 if(input->length()==1 || input->width()==1) 00054 { 00055 real* inputdata = input->gradientdata; 00056 for(int k=0; k<nelems(); k++) 00057 inputdata[k] += gradientdata[k]; 00058 } 00059 else // general case 00060 { 00061 real* inputrowdata = input->gradientdata; 00062 int thiskcolstart = 0; // element index of start of column in this var 00063 for(int i=0; i<width(); i++) // the width() of this var is the length() of the submat 00064 { 00065 int thisk = thiskcolstart++; 00066 for(int j=0; j<length(); j++, thisk+=width()) // the length() of this var is the width() of the submat 00067 *inputrowdata++ += gradientdata[thisk]; 00068 } 00069 } 00070 } 00071 00072 00073 void TransposeVariable::symbolicBprop() 00074 { 00075 PLERROR("Not implemented yet!"); 00076 /* 00077 int i = startk/input->width(); 00078 int j = startk%input->width(); 00079 int topextent = i; 00080 int bottomextent = input->length()-(i+width()); // the width() of this var is the length() of the submat 00081 int leftextent = j; 00082 int rightextent = input->width()-(j+length()); // the length() of this var is the width() of the submat 00083 input->accg(extend(transpose(g),topextent,bottomextent,leftextent,rightextent)); 00084 */ 00085 } 00086 00087 00088 void TransposeVariable::rfprop() 00089 { 00090 PLERROR("Not implemented yet!"); 00091 /* 00092 if (rValue.length()==0) resizeRValue(); 00093 if(input->length()==1 || input->width()==1) // optimized version for this special case... 00094 { 00095 real* inputdata = input->rvaluedata+startk; 00096 for(int k=0; k<nelems(); k++) 00097 rvaluedata[k] = inputdata[k]; 00098 } 00099 else // general case 00100 { 00101 real* inputrowdata = input->rvaluedata+startk; 00102 int thiskcolstart = 0; // element index of start of column in this var 00103 for(int i=0; i<width(); i++) // the width() of this var is the length() of the submat 00104 { 00105 int thisk = thiskcolstart++; 00106 for(int j=0; j<length(); j++, thisk+=width()) // the length() of this var is the width() of the submat 00107 rvaluedata[thisk] = inputrowdata[j]; 00108 inputrowdata += input->width(); 00109 } 00110 } 00111 */ 00112 } 00113 00114 00115 00116 } // end of namespace PLearn 00117 00118 00119 /* 00120 Local Variables: 00121 mode:c++ 00122 c-basic-offset:4 00123 c-file-style:"stroustrup" 00124 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00125 indent-tabs-mode:nil 00126 fill-column:79 00127 End: 00128 */ 00129 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :