std::vector<std::shared_ptr<sarray<flexible_type>>> vertex_apply(sgraph& g, flex_type_enum result_type, Fn fn) { std::vector<std::shared_ptr<sarray<flexible_type>>> ret(g.get_num_partitions()); // get all the vertex partitions. const std::vector<sframe>& vdata = g.vertex_group(); parallel_for((size_t)(0), (size_t)g.get_num_partitions(), [&](size_t i) { std::shared_ptr<sarray<flexible_type>> ret_partition = std::make_shared<sarray<flexible_type>>(); ret_partition->open_for_write(1); ret_partition->set_type(result_type); transform(vdata[i], *ret_partition, fn); ret_partition->close(); ret[i] = ret_partition; }); return ret; }
std::vector<std::shared_ptr<sarray<flexible_type>>> vertex_apply(sgraph& g, std::string column_name, std::vector<std::shared_ptr<sarray<T>>> & other, flex_type_enum result_type, Fn fn) { ASSERT_EQ(g.get_num_partitions(), other.size()); std::vector<std::shared_ptr<sarray<flexible_type>>> ret(g.get_num_partitions()); // get all the vertex partitions. const std::vector<sframe>& vdata = g.vertex_group(); parallel_for((size_t)(0), (size_t)g.get_num_partitions(), [&](size_t i) { std::shared_ptr<sarray<flexible_type>> graph_field = vdata[i].select_column(column_name); std::shared_ptr<sarray<flexible_type>> ret_partition = std::make_shared<sarray<flexible_type>>(); ret_partition->open_for_write(1); ret_partition->set_type(result_type); binary_transform(*graph_field, *other[i], *ret_partition, fn); ret_partition->close(); ret[i] = ret_partition; }); return ret; }
ResultType vertex_reduce(sgraph& g, std::string column_name, Reducer fn, Combiner combine, ResultType init = ResultType()) { const std::vector<sframe>& vdata = g.vertex_group(); mutex lock; ResultType ret = init; parallel_for((size_t)(0), (size_t)g.get_num_partitions(), [&](size_t i) { std::shared_ptr<sarray<flexible_type>> graph_field = vdata[i].select_column(column_name); std::vector<ResultType> result = graphlab::reduce(*graph_field, [&](const flexible_type& left, ResultType& right) { fn(left, right); return true; }, init); std::unique_lock<mutex> result_lock(lock); for (ResultType& res: result) { combine(res, ret); } }); return ret; }
typename std::enable_if<!std::is_convertible<Reducer, std::string>::value, ResultType>::type /*ResultType*/ vertex_reduce(sgraph& g, Reducer fn, Combiner combine, ResultType init = ResultType()) { const std::vector<sframe>& vdata = g.vertex_group(); mutex lock; ResultType ret = init; parallel_for((size_t)(0), (size_t)g.get_num_partitions(), [&](size_t i) { std::vector<ResultType> result = graphlab::reduce(vdata[i], [&](const std::vector<flexible_type>& left, ResultType& right) { fn(left, right); return true; }, init); std::unique_lock<mutex> result_lock(lock); for (ResultType& res: result) { combine(res, ret); } }); return ret; }