📄 arith.ops.template.cpp
字号:
friend tseries operator_OP_(const tseries<DateT>& left, const tseries<DateT>& right) { // only support equal cols fo now if(left.cols!=right.cols) { return tseries(); } // find intersection of dates RangeSpecifier<DateT> range(left.dates,right.dates,left.rows,right.rows); // if empty intersection, return null tseries if(!range.size) { return tseries(); } // else do the stuff... // new data range double *ans_data = new double[range.size*left.cols]; // new date range DateT *ans_dates = new DateT[range.size]; if(ans_data==NULL || ans_dates==NULL) { cerr << "tseries::_OP_operator: out of memory." << endl; } // for looping double *ans_col, *left_col, *right_col; for(unsigned int c = 0; c < left.cols; c++) { ans_col = &ans_data[c*range.size]; left_col = &left.data[c*left.rows]; right_col = &right.data[c*right.rows]; for(unsigned int r = 0; r < range.size; r++) { ans_col[r] = left_col[ range.arg1[r] ] _OP_ right_col[ range.arg2[r] ]; } } // make new dates memcpy(ans_dates,range.dates,sizeof(DateT)*range.size); return tseries(ans_data,ans_dates,range.size,left.cols,true);}friend tseries operator_OP_(const tseries& left, const double& right) { double *ans_data = new double[left.rows*left.cols]; DateT *ans_dates = new DateT[left.rows]; if(ans_data==NULL || ans_dates==NULL) { cerr << "operator_OP_(const tseries& left, const double right)" << endl; cerr << " out of memory." << endl; return tseries(); } // preserve dates memcpy(ans_dates,left.dates,sizeof(DateT)*left.rows); for(unsigned int i=0; i < left.rows*left.cols; i++) { ans_data[i] = left.data[i] _OP_ right; } return tseries(ans_data,ans_dates,left.rows,left.cols,left.colnames,true); } friend tseries operator_OP_(const double& left, const tseries& right) { double *ans_data = new double[right.rows*right.cols]; DateT *ans_dates = new DateT[right.rows]; if(ans_data==NULL || ans_dates==NULL) { cerr << "operator_OP_(const tseries& right, const double right)" << endl; cerr << " out of memory." << endl; return tseries(); } // preserve dates memcpy(ans_dates,right.dates,sizeof(DateT)*right.rows); for(unsigned int i=0; i < right.rows*right.cols; i++) { ans_data[i] = left _OP_ right.data[i]; } return tseries(ans_data,ans_dates,right.rows,right.cols,right.colnames,true); } tseries& operator_OP_=(const double& right) { for(unsigned int i=0; i < rows*cols; i++) { data[i] _OP_= right; } return *this; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -