예제 #1
0
void ExprCopy::visit(const ExprVector& e) {
	for (int i=0; i<e.nb_args; i++)
		visit(e.arg(i));

	if (fold) {
		int i=0;
		for (; i<e.nb_args; i++) {
			if (!dynamic_cast<const ExprConstant*>(&ARG(i))) break;
		}
		if (i==e.nb_args) {
			if (e.dim.is_vector()) {
				IntervalVector v(e.dim.vec_size());
				for (i=0; i<e.nb_args; i++) {
					v[i]=((const ExprConstant&) ARG(i)).get_value();
				}
				clone.insert(e, &ExprConstant::new_vector(v,e.row_vector()));
			} else if (e.dim.type()==Dim::MATRIX) {
				IntervalMatrix m(e.dim.dim2,e.dim.dim3);
				for (i=0; i<e.nb_args; i++) {
					m.set_row(i,((const ExprConstant&) ARG(i)).get_vector_value());
				}
				clone.insert(e, &ExprConstant::new_matrix(m));
			} else {
				assert(e.dim.type()==Dim::MATRIX_ARRAY);
				IntervalMatrixArray ma(e.dim.dim1,e.dim.dim2,e.dim.dim3);
				for (i=0; i<e.nb_args; i++) {
					ma[i]=((const ExprConstant&) ARG(i)).get_matrix_value();
				}
				clone.insert(e, &ExprConstant::new_matrix_array(ma));
			}
			return;
		}
	}

	Array<const ExprNode> args2(e.nb_args);
	for (int i=0; i<e.nb_args; i++) {
		args2.set_ref(i,ARG(i));
		// don't remove this node even if it is a constant because
		// it is an element of this vector.
		mark(e.arg(i));
	}

	clone.insert(e, &ExprVector::new_(args2,e.row_vector()));
}
예제 #2
0
void ConstantGenerator::visit(const ExprVector& e) {
	// TODO: test
	Domain* d= new Domain(e.dim);
//	assert(d->dim.is_vector() || d->dim.type()==Dim::MATRIX);
	// we forbid a "vector operation" between constants
	// to yield an array of matrices

	for (int i=0; i<e.nb_args; i++) {
		visit(e.arg(i));
		NOT_INF;
		const Domain* di=map[e.arg(i)];
		if (d->dim.is_vector()) d->v()[i]=di->i();
		else if (d->dim.type()==Dim::MATRIX) d->m()[i]=di->v();
		else d->ma()[i]=di->m();
		delete di;
	}

	map.insert(e, d);
}