g++ produces symbol including std::common_type<double, double, double>::type with as many entries as were contained in a variadic argument list - c++11

I wrote some
template<typename ...T>
inline ARRAY<typename std::common_type<T...>::type, sizeof...(T)> make_array_(const T&..._r)
{ return ARRAY<typename std::common_type<T...>::type, sizeof...(T)>(_r...);
}
which creates a symbol
0000000000000361 t namespace::ARRAY_IMPL<std::common_type<double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double>::type, sizeof (double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double), std::is_trivial<std::common_type<double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double>::type>::value> namespace::make_array_<double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double>(double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&, double const&)
Why is std::common_type<double, double, double>::type not collapsing?
g++ version is 5.3.0.
#include <type_traits>
template<typename T, std::size_t SIZE>
struct ARRAY
{ template<typename ...T1>
ARRAY(T1&&...)
{
}
};
template<typename ...T>
inline ARRAY<typename std::common_type<T...>::type, sizeof...(T)> make_array_(const T&..._r)
{ return ARRAY<typename std::common_type<T...>::type, sizeof...(T)>(_r...);
}
const auto sA = make_array_(1.0, 2.0, 3.0);
int main(int, char**)
{
}

Two declarations for function templates are only considered to refer to the same function template if their return types are also equivalent, in contrast to functions where the return type is not considered for matching of declarations.
So you can define a function template
template<typename ...T>
ARRAY<double, sizeof...(T)> make_array_(const T&..._r) {
//...
}
in addition to your template and this will not be considered the same template. Specialization of the two templates for the same template argument list are then also separate functions that could behave completely differently, even if the return type and parameter types of the specializations will be the same.
So in order for the linker to be able to tell the two templates apart, the compiler cannot collapse member typedefs in the symbol.
(Note that "equivalent" here is a technical term with a rather complex definition. It is not always immediately obvious whether two constructs are equivalent if they don't follow the same token sequence and other ODR rules, and there is also the concept of "functionally equivalent" under which there are cases that two declarations for which equivalency can't be determined the program is IFNDR (ill-formed, no diagnostic required).)

Related

How does the constant value auto type work in golang?

Here is the code snippet:
a := 40
f := float64(a/100.0)
fmt.Println("Hello, playground", f)
f=0, why?
Spec: Constants:
An untyped constant has a default type which is the type to which the constant is implicitly converted in contexts where a typed value is required, for instance, in a short variable declaration such as i := 0 where there is no explicit type. The default type of an untyped constant is bool, rune, int, float64, complex128 or string respectively, depending on whether it is a boolean, rune, integer, floating-point, complex, or string constant.
a := 40 is a short variable declaration, the untyped integer constant 40 has a default type int, so a will be of type int.
In a/100.0 since a is of type int and 100.0 is representable by an integer, it will take the type of int, and a/100.0 will be an integer division, resulting in 0.
This 0 int value will be then converted to float64.
Note that if you would change the first line to:
a := 40.0
Then the output would be 0.4 because the 40.0 is an untyped floating point literal and so it has a default type of float64. So a will be of type float64, and a/100.0 will be a floating-point division, resulting in 0.4. Try it on the Go Playground.
You would get the same result if you'd use a typed constant, because here no default type is used, float64(40) is a typed constant, obviously of type float64 (try it on the Go Playground):
a := float64(40)
See The Go Blog: Constants.
Here default type for a is int since you use a:=40 and but 100.0 is just a constant so no auto-detect of type for variable.
So a/100.0 consider as integer division and which result is 0 which means f := float64(0) executed
Case Analysis
If you set 100.0 in a variable.
a := 40
b := 100.0
f := float64(a/b)
Then b is a float64 type. So you get error like
invalid operation: a / b (mismatched types int and float64)
Because you are trying to do divide operation with two different type
And if type cast a into float64() then it works
a := 40
b := 100.0
f := float64(a)/b
So, here both variable is float64 type in divide operation.
Now, as we cast a into float64 then in divide operation we can directly use 100.0 without variable.
a := 40
f := float64(a)/100.0

Boost Delta stepping

I am trying to run the Delta Stepping Algorithm using Parallel Boost Graph Library but it does not compile. Could you please help.
#include <boost/graph/use_mpi.hpp>
#include <boost/graph/distributed/mpi_process_group.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/distributed/delta_stepping_shortest_paths.hpp>
#include <boost/graph/distributed/adjacency_list.hpp>
#include <boost/graph/metis.hpp>
#include <boost/graph/distributed/graphviz.hpp>
#include <boost/property_map/property_map.hpp>
#include <fstream>
#include <string>
#ifdef BOOST_NO_EXCEPTIONS
void
boost::throw_exception(std::exception const& ex)
{
std::cout << ex.what() << std::endl;
abort();
}
#endif
using namespace boost;
using boost::graph::distributed::mpi_process_group;
/* An undirected, weighted graph with distance values stored on the
vertices. */
typedef adjacency_list<vecS, distributedS<mpi_process_group, vecS>, undirectedS,
/*Vertex properties=*/property<vertex_distance_t, float>,
/*Edge properties=*/property<edge_weight_t, float> >
Graph;
int main(int argc, char *argv[]) {
boost::mpi::environment env(argc, argv);
// Parse command-line options
const char *filename = "weighted_graph.gr";
if (argc > 1) filename = argv[1];
// Open the METIS input file
std::ifstream in(filename);
graph::metis_reader reader(in);
// Load the graph using the default distribution
Graph g(reader.begin(), reader.end(), reader.weight_begin(),
reader.num_vertices());
// Get vertex 0 in the graph
graph_traits<Graph>::vertex_descriptor start = vertex(0, g);
// Compute shortest paths from vertex 0
// dijkstra_shortest_paths(g, start,
// distance_map(get(vertex_distance, g)));
typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
typedef typename std::map<vertex_t, vertex_t> vertex_map_t;
typedef associative_property_map<vertex_map_t> predecessor_map_t;
vertex_map_t default_vertex_map;
predecessor_map_t default_predecessor_map(default_vertex_map);
typedef typename std::map<vertex_t, double> vertex_double_map_t;
typedef associative_property_map<vertex_double_map_t> distance_map_t;
vertex_double_map_t default_vertex_double_map;
distance_map_t default_distance_map(default_vertex_double_map);
graph::distributed::delta_stepping_shortest_paths(g, start, dummy_property_map(),
distance_map(get(vertex_distance, g)),
weight_map(get(edge_weight, g)));
// Output a Graphviz DOT file
std::string outfile = filename;
if (argc > 2)
outfile = argv[2];
else {
int i = outfile.rfind('.');
if (i != std::string::npos)
outfile.erase(outfile.begin() + i, outfile.end());
outfile += "-dijkstra.dot";
}
if (process_id(process_group(g)) == 0) {
std::cout << "Writing GraphViz output to " << outfile << "... ";
std::cout.flush();
}
write_graphviz(outfile, g,
make_label_writer(get(vertex_distance, g)),
make_label_writer(get(edge_weight, g)));
if (process_id(process_group(g)) == 0)
std::cout << "Done." << std::endl;
return 0;
}
I ran the code as follows:
pratsriv#flowerpot:/home/pratsriv/Desktop/ReadGraph$ mpic++ parallelDeltastepping.cpp -I /home/pratsriv/boost_1_64_0/include/ -L/home/pratsriv/boost_1_64_0/lib/ -lboost_mpi -lboost_graph_parallel -lboost_system -lboost_serialization
It gives me the following error:
In file included from parallelDeltastepping.cpp:18:0:
/home/pratsriv/boost_1_64_0/include/boost/graph/distributed/delta_stepping_shortest_paths.hpp: In instantiation of ‘class boost::graph::distributed::delta_stepping_impl<boost::adjacency_list<boost::vecS, boost::distributedS<boost::graph::distributed::mpi_process_group, boost::vecS>, boost::undirectedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_weight_t, float> >, boost::dummy_property_map, boost::bgl_named_params<boost::parallel::distributed_property_map<boost::graph::distributed::mpi_process_group, boost::detail::parallel::global_descriptor_property_map<long unsigned int>, boost::vec_adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>, boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>*, float, float&, boost::vertex_distance_t> >, boost::vertex_distance_t, boost::no_property>, boost::bgl_named_params<boost::parallel::distributed_property_map<boost::graph::distributed::mpi_process_group, boost::detail::parallel::edge_global_property_map<boost::detail::edge_desc_impl<boost::directed_tag, long unsigned int> >, boost::adj_list_edge_property_map<boost::directed_tag, float, float&, long unsigned int, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::edge_weight_t> >, boost::edge_weight_t, boost::no_property> >’:
/home/pratsriv/boost_1_64_0/include/boost/graph/distributed/delta_stepping_shortest_paths.hpp:504:5: required from ‘void boost::graph::distributed::delta_stepping_shortest_paths(const Graph&, typename boost::graph_traits<Graph>::vertex_descriptor, PredecessorMap, DistanceMap, EdgeWeightMap) [with Graph = boost::adjacency_list<boost::vecS, boost::distributedS<boost::graph::distributed::mpi_process_group, boost::vecS>, boost::undirectedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_weight_t, float> >; PredecessorMap = boost::dummy_property_map; DistanceMap = boost::bgl_named_params<boost::parallel::distributed_property_map<boost::graph::distributed::mpi_process_group, boost::detail::parallel::global_descriptor_property_map<long unsigned int>, boost::vec_adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>, boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>*, float, float&, boost::vertex_distance_t> >, boost::vertex_distance_t, boost::no_property>; EdgeWeightMap = boost::bgl_named_params<boost::parallel::distributed_property_map<boost::graph::distributed::mpi_process_group, boost::detail::parallel::edge_global_property_map<boost::detail::edge_desc_impl<boost::directed_tag, long unsigned int> >, boost::adj_list_edge_property_map<boost::directed_tag, float, float&, long unsigned int, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::edge_weight_t> >, boost::edge_weight_t, boost::no_property>; typename boost::graph_traits<Graph>::vertex_descriptor = boost::detail::parallel::global_descriptor<long unsigned int>]’
parallelDeltastepping.cpp:80:37: required from here
/home/pratsriv/boost_1_64_0/include/boost/graph/distributed/delta_stepping_shortest_paths.hpp:74:63: error: no type named ‘value_type’ in ‘struct boost::property_traits<boost::bgl_named_params<boost::parallel::distributed_property_map<boost::graph::distributed::mpi_process_group, boost::detail::parallel::edge_global_property_map<boost::detail::edge_desc_impl<boost::directed_tag, long unsigned int> >, boost::adj_list_edge_property_map<boost::directed_tag, float, float&, long unsigned int, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::edge_weight_t> >, boost::edge_weight_t, boost::no_property> >’
ypedef typename property_traits<EdgeWeightMap>::value_type Dist;
^
/home/pratsriv/boost_1_64_0/include/boost/graph/distributed/delta_stepping_shortest_paths.hpp:123:8: error: no type named ‘value_type’ in ‘struct boost::property_traits<boost::bgl_named_params<boost::parallel::distributed_property_map<boost::graph::distributed::mpi_process_group, boost::detail::parallel::edge_global_property_map<boost::detail::edge_desc_impl<boost::directed_tag, long unsigned int> >, boost::adj_list_edge_property_map<boost::directed_tag, float, float&, long unsigned int, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::edge_weight_t> >, boost::edge_weight_t, boost::no_property> >’
void handle_relax_message(Vertex v, const std::pair<Dist, Vert
^
In file included from /home/pratsriv/boost_1_64_0/include/boost/graph/distributed/crauser_et_al_shortest_paths.hpp:34:0,
from /home/pratsriv/boost_1_64_0/include/boost/graph/distributed/dijkstra_shortest_paths.hpp:20,
from /home/pratsriv/boost_1_64_0/include/boost/graph/dijkstra_shortest_paths.hpp:620,
from parallelDeltastepping.cpp:17:
/home/pratsriv/boost_1_64_0/include/boost/graph/distributed/detail/dijkstra_shortest_paths.hpp: In instantiation of ‘class boost::graph::distributed::detail::dijkstra_msg_value<boost::bgl_named_params<boost::parallel::distributed_property_map<boost::graph::distributed::mpi_process_group, boost::detail::parallel::global_descriptor_property_map<long unsigned int>, boost::vec_adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>, boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>*, float, float&, boost::vertex_distance_t> >, boost::vertex_distance_t, boost::no_property>, boost::dummy_property_map>’:
/home/pratsriv/boost_1_64_0/include/boost/graph/distributed/delta_stepping_shortest_paths.hpp:129:8: required from ‘class boost::graph::distributed::delta_stepping_impl<boost::adjacency_list<boost::vecS, boost::distributedS<boost::graph::distributed::mpi_process_group, boost::vecS>, boost::undirectedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_weight_t, float> >, boost::dummy_property_map, boost::bgl_named_params<boost::parallel::distributed_property_map<boost::graph::distributed::mpi_process_group, boost::detail::parallel::global_descriptor_property_map<long unsigned int>, boost::vec_adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>, boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>*, float, float&, boost::vertex_distance_t> >, boost::vertex_distance_t, boost::no_property>, boost::bgl_named_params<boost::parallel::distributed_property_map<boost::graph::distributed::mpi_process_group, boost::detail::parallel::edge_global_property_map<boost::detail::edge_desc_impl<boost::directed_tag, long unsigned int> >, boost::adj_list_edge_property_map<boost::directed_tag, float, float&, long unsigned int, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::edge_weight_t> >, boost::edge_weight_t, boost::no_property> >’
/home/pratsriv/boost_1_64_0/include/boost/graph/distributed/delta_stepping_shortest_paths.hpp:504:5: required from ‘void boost::graph::distributed::delta_stepping_shortest_paths(const Graph&, typename boost::graph_traits<Graph>::vertex_descriptor, PredecessorMap, DistanceMap, EdgeWeightMap) [with Graph = boost::adjacency_list<boost::vecS, boost::distributedS<boost::graph::distributed::mpi_process_group, boost::vecS>, boost::undirectedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_weight_t, float> >; PredecessorMap = boost::dummy_property_map; DistanceMap = boost::bgl_named_params<boost::parallel::distributed_property_map<boost::graph::distributed::mpi_process_group, boost::detail::parallel::global_descriptor_property_map<long unsigned int>, boost::vec_adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>, boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>*, float, float&, boost::vertex_distance_t> >, boost::vertex_distance_t, boost::no_property>; EdgeWeightMap = boost::bgl_named_params<boost::parallel::distributed_property_map<boost::graph::distributed::mpi_process_group, boost::detail::parallel::edge_global_property_map<boost::detail::edge_desc_impl<boost::directed_tag, long unsigned int> >, boost::adj_list_edge_property_map<boost::directed_tag, float, float&, long unsigned int, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::edge_weight_t> >, boost::edge_weight_t, boost::no_property>; typename boost::graph_traits<Graph>::vertex_descriptor = boost::detail::parallel::global_descriptor<long unsigned int>]’
parallelDeltastepping.cpp:80:37: required from here
/home/pratsriv/boost_1_64_0/include/boost/graph/distributed/detail/dijkstra_shortest_paths.hpp:40:59: error: no type named ‘key_type’ in ‘struct boost::property_traits<boost::bgl_named_params<boost::parallel::distributed_property_map<boost::graph::distributed::mpi_process_group, boost::detail::parallel::global_descriptor_property_map<long unsigned int>, boost::vec_adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>, boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>*, float, float&, boost::vertex_distance_t> >, boost::vertex_distance_t, boost::no_property> >’
edef typename property_traits<DistanceMap>::key_type vertex_desc
^
/home/pratsriv/boost_1_64_0/include/boost/graph/distributed/detail/dijkstra_shortest_paths.hpp:42:61: error: no type named ‘value_type’ in ‘struct boost::property_traits<boost::bgl_named_params<boost::parallel::distributed_property_map<boost::graph::distributed::mpi_process_group, boost::detail::parallel::global_descriptor_property_map<long unsigned int>, boost::vec_adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>, boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>*, float, float&, boost::vertex_distance_t> >, boost::vertex_distance_t, boost::no_property> >’
typedef typename property_traits<DistanceMap>::value_type type;
^
In file included from /home/pratsriv/boost_1_64_0/include/boost/graph/distributed/breadth_first_search.hpp:23:0,
from /home/pratsriv/boost_1_64_0/include/boost/graph/breadth_first_search.hpp:409,
from /home/pratsriv/boost_1_64_0/include/boost/graph/dijkstra_shortest_paths.hpp:21,
from parallelDeltastepping.cpp:17:
/home/pratsriv/boost_1_64_0/include/boost/graph/parallel/properties.hpp: In instantiation of ‘void boost::set_property_map_role(Property, PropertyMap) [with Property = boost::vertex_distance_t; PropertyMap = boost::bgl_named_params<boost::parallel::distributed_property_map<boost::graph::distributed::mpi_process_group, boost::detail::parallel::global_descriptor_property_map<long unsigned int>, boost::vec_adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>, boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>*, float, float&, boost::vertex_distance_t> >, boost::vertex_distance_t, boost::no_property>]’:
/home/pratsriv/boost_1_64_0/include/boost/graph/distributed/delta_stepping_shortest_paths.hpp:499:24: required from ‘void boost::graph::distributed::delta_stepping_shortest_paths(const Graph&, typename boost::graph_traits<Graph>::vertex_descriptor, PredecessorMap, DistanceMap, EdgeWeightMap) [with Graph = boost::adjacency_list<boost::vecS, boost::distributedS<boost::graph::distributed::mpi_process_group, boost::vecS>, boost::undirectedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_weight_t, float> >; PredecessorMap = boost::dummy_property_map; DistanceMap = boost::bgl_named_params<boost::parallel::distributed_property_map<boost::graph::distributed::mpi_process_group, boost::detail::parallel::global_descriptor_property_map<long unsigned int>, boost::vec_adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>, boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>*, float, float&, boost::vertex_distance_t> >, boost::vertex_distance_t, boost::no_property>; EdgeWeightMap = boost::bgl_named_params<boost::parallel::distributed_property_map<boost::graph::distributed::mpi_process_group, boost::detail::parallel::edge_global_property_map<boost::detail::edge_desc_impl<boost::directed_tag, long unsigned int> >, boost::adj_list_edge_property_map<boost::directed_tag, float, float&, long unsigned int, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::edge_weight_t> >, boost::edge_weight_t, boost::no_property>; typename boost::graph_traits<Graph>::vertex_descriptor = boost::detail::parallel::global_descriptor<long unsigned int>]’
parallelDeltastepping.cpp:80:37: required from here
/home/pratsriv/boost_1_64_0/include/boost/graph/parallel/properties.hpp:105:63: error: no type named ‘value_type’ in ‘struct boost::property_traits<boost::bgl_named_params<boost::parallel::distributed_property_map<boost::graph::distributed::mpi_process_group, boost::detail::parallel::global_descriptor_property_map<long unsigned int>, boost::vec_adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>, boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>*, float, float&, boost::vertex_distance_t> >, boost::vertex_distance_t, boost::no_property> >’
ef typename property_traits<PropertyMap>::value_type value_type;
^
/home/pratsriv/boost_1_64_0/include/boost/graph/parallel/properties.hpp:109:5: error: ‘struct boost::bgl_named_params<boost::parallel::distributed_property_map<boost::graph::distributed::mpi_process_group, boost::detail::parallel::global_descriptor_property_map<long unsigned int>, boost::vec_adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>, boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_distance_t, float>, boost::property<boost::edge_locally_owned_t, bool, boost::property<boost::edge_target_processor_id_t, short int, boost::property<boost::edge_weight_t, float> > >, boost::no_property, boost::listS>*, float, float&, boost::vertex_distance_t> >, boost::vertex_distance_t, boost::no_property>’ has no member named ‘set_reduce’
pm.set_reduce(reduce());
You seem to be confusing named parameters with positional ones.
The distance and weight maps need to be passed, not wrapped as positional parameter objects for this overload:
template<typename Graph, typename PredecessorMap, typename DistanceMap,
typename EdgeWeightMap>
void
delta_stepping_shortest_paths
(const Graph& g,
typename graph_traits<Graph>::vertex_descriptor s,
PredecessorMap predecessor, DistanceMap distance, EdgeWeightMap weight)
{
So, remove the named-parameter constructor functions:
graph::distributed::delta_stepping_shortest_paths(g, start, dummy_property_map(),
distance_map(get(vertex_distance, g)),
weight_map(get(edge_weight, g)));
Should be
graph::distributed::delta_stepping_shortest_paths(g, start, dummy_property_map(),
get(vertex_distance, g),
get(edge_weight, g));

Cannot assign int to a variable in Go

Go version - 1.2.1
package main
import "fmt"
func main(){
type INTEGER int
var aa INTEGER
var bb INTEGER
aa, bb = F(100,50)
fmt.Println(aa,bb)
}
func F(a int, b int) (sum int, difference int){
return a+b, a-b
}
Output:
/g.go:9: cannot assign int to aa (type INTEGER) in multiple assignment
./g.go:9: cannot assign int to bb (type INTEGER) in multiple assignment
type creates a new type, so this will obviously fail. You have to explicitly convert the values from int to INTEGER:
aaInt, bbInt := F(100, 50)
aa, bb = INTEGER(aaInt), INTEGER(bbInt)

What is the reason for requiring &mut foo instead of &foo when foo has been declared mutable?

For a C routine like
MPI_Comm_rank(MPI_Comm comm, int *rank);
The Rust foreign function interface could be declared like this:
use libc::c_int; // 0.2.79
#[link(name = "mpi")]
extern "C" {
fn MPI_Comm_rank(mpi_comm: c_int, rank: *mut c_int);
}
I call the binding like this, which works, but left me puzzled about syntax:
pub static MPI_COMM_WORLD: libc::c_int = 0x44000000;
fn main() {
let mut rank: c_int = 999999;
/* but why '&mut rank' and not simply '&rank' ? */
unsafe { MPI_Comm_rank(MPI_COMM_WORLD, &mut rank) }
}
I originally tried
unsafe { MPI_Comm_rank(MPI_COMM_WORLD, &rank) }
but this gives a compiler error:
error[E0308]: mismatched types
--> src/main.rs:12:44
|
12 | unsafe { MPI_Comm_rank(MPI_COMM_WORLD, &rank) }
| ^^^^^ types differ in mutability
|
= note: expected raw pointer `*mut i32`
found reference `&i32`
I declared 'rank' as mut, so what gives?
You’re conflating two completely distinct features.
let mut x; makes a mutable binding x, allowing you to modify what x is bound to (x = 42) and for non-reference types to modify its contents (x.y = 42). It does not control the mutability of the target of references.
This is different from the type of references you’re dealing with.
&mut T is a mutable reference and can be coerced to *mut T.
&T is an immutable reference can be coerced to *const T.
As the function you are calling wants *mut T, you must pass it a *mut T or a &mut T; *const T or &T will not do.
To be sure, you can only take a mutable reference to mutable data, so let x = 42; &mut x doesn’t work as it needs let mut x instead of let x, but that’s still entirely distinct and is a part of Rust’s rules about mutability.
Your function expects *mut c_int pointer (a mutable raw pointer), and you need to use &mut operator to obtain it. However, you can only take &mut pointer to mut variables, hence you need to declare rank variable as mut rank.
If your function expected *const c_int pointer, you would be able to use &, but this is not the case.

Convert an integer to a float number

How do I convert an integer value to float64 type?
I tried
float(integer_value)
But this does not work. And can't find any package that does this on Golang.org
How do I get float64 values from integer values?
There is no float type. Looks like you want float64. You could also use float32 if you only need a single-precision floating point value.
package main
import "fmt"
func main() {
i := 5
f := float64(i)
fmt.Printf("f is %f\n", f)
}
Just for the sake of completeness, here is a link to the golang documentation which describes all types. In your case it is numeric types:
uint8 the set of all unsigned 8-bit integers (0 to 255)
uint16 the set of all unsigned 16-bit integers (0 to 65535)
uint32 the set of all unsigned 32-bit integers (0 to 4294967295)
uint64 the set of all unsigned 64-bit integers (0 to 18446744073709551615)
int8 the set of all signed 8-bit integers (-128 to 127)
int16 the set of all signed 16-bit integers (-32768 to 32767)
int32 the set of all signed 32-bit integers (-2147483648 to 2147483647)
int64 the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807)
float32 the set of all IEEE-754 32-bit floating-point numbers
float64 the set of all IEEE-754 64-bit floating-point numbers
complex64 the set of all complex numbers with float32 real and imaginary parts
complex128 the set of all complex numbers with float64 real and imaginary parts
byte alias for uint8
rune alias for int32
Which means that you need to use float64(integer_value).
just do these
package main
func main(){
a:= 70
afloat := float64(a)
fmt.Printf("type of a is %T\n", a) // will int
fmt.Printf("type of a is %T\n", afloat) //will float64
}
intutils.ToFloat32
// ToFloat32 converts a int num to a float32 num
func ToFloat32(in int) float32 {
return float32(in)
}
// ToFloat64 converts a int num to a float64 num
func ToFloat64(in int) float64 {
return float64(in)
}
Proper parentheses placement is key:
package main
import (
"fmt"
)
func main() {
var payload uint32
var fpayload float32
payload = 1320
// works
fpayload = float32(payload) / 100.0
fmt.Printf("%T = %d, %T = %f\n", payload, payload, fpayload, fpayload)
// doesn't work
fpayload = float32(payload / 100.0)
fmt.Printf("%T = %d, %T = %f\n", payload, payload, fpayload, fpayload)
}
results:
uint32 = 1320, float32 = 13.200000
uint32 = 1320, float32 = 13.000000
The Go Playground
Type Conversions T() where T is the desired datatype of the result are quite simple in GoLang.
In my program, I scan an integer i from the user input, perform a type conversion on it and store it in the variable f. The output prints the float64 equivalent of the int input. float32 datatype is also available in GoLang
Code:
package main
import "fmt"
func main() {
var i int
fmt.Println("Enter an Integer input: ")
fmt.Scanf("%d", &i)
f := float64(i)
fmt.Printf("The float64 representation of %d is %f\n", i, f)
}
Solution:
>>> Enter an Integer input:
>>> 232332
>>> The float64 representation of 232332 is 232332.000000

Resources