/** * Checks the entailment sh_pos => sh_neg * using the sound procedure of shad. */ int sh_check (void) { #ifndef NDEBUG1 fprintf (stdout, "Sh_check: sh_pos = \n"); sh_fprint (stdout, sh_pos); fflush (stdout); fprintf (stdout, "Sh_check: sh_neg = \n"); sh_fprint (stdout, sh_neg); fflush (stdout); #endif // Step 1: deal with the trivial cases if (!sh_pos) { // consider sh_pos as true fprintf (stdout, "Sh_check: trivial entailment true => phi returns false.\n"); return 0; } if (!sh_neg) { // consider sh_neg as true fprintf (stdout, "Sh_check: trivial entailment phi => true returns true.\n"); return 1; } // Step 2: collect informations about the dataword domains // PENDING: generate files cinv.txt and, for guards, cinv-ucons.txt // Step 3: build the abstract values // create a manager for shape, parameters are read from cinv files above ap_manager_t* shm = shape_manager_alloc (); if (!shm) return 0; shape_t * top = shape_top (shm, 1, 1); for (int i = 0; i < AP_EXC_SIZE; i++) { shm->option.abort_if_exception[i] = true; } int max_anon = (sh_guards >= (4 << 8)) ? 1 : 0; int segm_anon = (sh_guards >= (2 << 8)) ? 2 : 1; shape_approximate (shm, top, max_anon | (segm_anon << 4) | sh_guards); shape_free (shm, top); // build abstract values from shad formula shape_t *shp = shape_of_formula (shm, sh_pos); // assigns shp_crt shape_t *shn = shape_of_formula (shm, sh_neg); // Step 4: do the inclusion test // The inclusion test call saturation if the test does not follow from // the shape form bool r = shape_is_leq (shm, shp, shn); return (r == true) ? 1 : -1; ; }
void FilterLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { // bottom[0...k-1] are the blobs to filter // bottom[last] is the "selector_blob" int_tp selector_index = bottom.size() - 1; for (int_tp i = 1; i < bottom[selector_index]->num_axes(); ++i) { CHECK_EQ(bottom[selector_index]->shape(i), 1) << "Selector blob dimensions must be singletons (1), except the first"; } for (int_tp i = 0; i < bottom.size() - 1; ++i) { CHECK_EQ(bottom[selector_index]->shape(0), bottom[i]->shape(0)) << "Each bottom should have the same 0th dimension as the selector blob"; } const Dtype* bottom_data_selector = bottom[selector_index]->cpu_data(); indices_to_forward_.clear(); // look for non-zero elements in bottom[0]. Items of each bottom that // have the same index as the items in bottom[0] with value == non-zero // will be forwarded for (int_tp item_id = 0; item_id < bottom[selector_index]->shape(0); ++item_id) { // we don't need an offset because item size == 1 const Dtype* tmp_data_selector = bottom_data_selector + item_id; if (*tmp_data_selector) { indices_to_forward_.push_back(item_id); } } // only filtered items will be forwarded int_tp new_tops_num = indices_to_forward_.size(); // init if (first_reshape_) { new_tops_num = bottom[0]->shape(0); first_reshape_ = false; } for (int_tp t = 0; t < top.size(); ++t) { int_tp num_axes = bottom[t]->num_axes(); vector<int_tp> shape_top(num_axes); shape_top[0] = new_tops_num; for (int_tp ts = 1; ts < num_axes; ++ts) shape_top[ts] = bottom[t]->shape(ts); top[t]->Reshape(shape_top); } }