bool for_each_element(behavior_flag<index_ascending>, FunT fun, tensor_continuous_data_base<ET, ShapeT, T> &t, Ts &... ts) { assert(all_same(t.shape(), ts.shape()...)); for (size_t i = 0; i < t.numel(); i++) { fun(element_at_index(t.derived(), i), element_at_index(ts.derived(), i)...); } return true; }
bool for_each_element(behavior_flag<break_on_false>, FunT fun, tensor_continuous_data_base<ET, ShapeT, T> &t, Ts &... ts) { assert(all_same(t.shape(), ts.shape()...)); for (size_t i = 0; i < t.numel(); i++) { bool r = fun(element_at_index(t.derived(), i), element_at_index(ts.derived(), i)...); if (!r) { return false; } } return true; }
bool for_each_element(behavior_flag<nonzero_only>, FunT fun, tensor_continuous_data_base<ET, ShapeT, T> &t, Ts &... ts) { assert(all_same(t.shape(), ts.shape()...)); bool visited_all = true; for (size_t i = 0; i < t.numel(); i++) { decltype(auto) e = element_at_index(t.derived(), i); if (e) { fun(e, element_at_index(ts.derived(), i)...); } else { visited_all = false; } } return visited_all; }
point *remove_point(point *start) { point *rem, *previous; int index,count; if (start == NULL) { printf("No elements to remove\n"); return start; } printf("Which element index do you want to remove? (starting from 0)\n"); scanf("%9d", &index); //The first element is a special case as the 2nd element will become the start if (index == 0) { point *next = start->next; free(start); return next; } //find the element to remove and the previous element rem = element_at_index(start, index); previous = element_at_index(start, index-1); if (rem == NULL) { printf("Invalid index: %d\n", index); return start; } //set the previous element to point to the one after the //one being removed previous->next = rem->next; free(rem); return start; }
//REMOVE POINT: This Funtion allows the user to remove an element from a linked list and returns a pointer point *remove_point(point *start) { point *rem, *previous; int index,count; if (start == NULL) // error checking { printf("No elements to remove\n"); return start; } printf("Which element index do you want to remove? (starting from 0)\n"); scanf("%9d", &index); //The first element is a special case as the 2nd element will become the start if (index == 0) { point *next = start->next; // set pointer free(start); // free memory return next; // return from function } //find the element to remove and the previous element rem = element_at_index(start, index); // find node to remove previous = element_at_index(start, index-1); // set previous node (node before node you want to remove) if (rem == NULL) // if node not found { printf("Invalid index: %d\n", index); return start; } previous->next = rem->next; // set the previous element to point to the one after the one being removed free(rem); // free memory return start; // return from function }
constexpr auto _element_at_cart_prod_result_seq(CartProdT &&t, SubsTupleT &&subs, const const_ints<size_t, Is...> &) { return as_tuple( element_at_index(std::get<Is>(t.inputs), std::get<Is>(subs))...); }