/// APLSubscriptFunction void SubscriptFunction::applyOp ( Expr& target, APLValue* left, APLValue* right ) { if (right->shape()->length() >= 2) { target = error("subscript requires vector second arg"); return; } int rsize = right->size(); int lsize = lastSize(left->shape()); int extent = (left->size() / lsize)* rsize; APLValue* newval = new APLValue(replaceLast(left->shape(), rsize), extent); for (int i = 0; i < extent; i++) { newval->atPut ( i, left->at((i / rsize)* lsize + (right->at(i % rsize) - 1)) ); } target = newval; }
void CompressionFunction::applyOp(Expr& target, APLValue* left, APLValue* right) { if (left->shape()->length() >= 2) { target = error("compression requires vector left arg"); return; } int lsize = left->size(); // works for both scalar and vec int rsize = lastSize(right->shape()); if (lsize != rsize) { target = error("compression conformability error"); return; } // compute the number of non-zero values int i, nsize; nsize = 0; for (i = 0; i < lsize; i++) { if (left->at(i)) { nsize++; } } // now compute the new size int rextent = right->size(); int extent = (rextent / lsize)* nsize; APLValue* newval = new APLValue(replaceLast(right->shape(), nsize), extent); // now fill in the values int index = 0; for (i = 0; i <= rextent; i++) { if (left->at(i % lsize)) { newval->atPut(index++, right->at(i)); } } target = newval; }
string StringUtil::replaceLastCopy(const string& str, const string& ths, const string& with) { string strn = str; replaceLast(strn, ths, with); return strn; }