Specify igraph_vs_t from an array of integers?

I am attempting to induce a subgraph based on a specific set of vertices. I have their vertex IDs as a 1-dimensional array of integers (for exampls int x[2] = {1, 4};), but igraph_induce_subgraph requires igraph_vs_t.

What is the simplest way to obtain the subgraph based on my array of integers ?

Copy your array into an igraph_vector_t then use igraph_vs_vector()

https://igraph.org/c/html/latest/igraph-Iterators.html#igraph_vs_vector

Thank you. Is there a way to tell igraph_vector_t that it will be holding integers and not floats? I was getting warnings while trying to create the vector from integers.

You can ignore these warnings safely.

igraph_vector_t holds values of type igraph_real_t, which is currently double. In igraph 0.9 and earlier, most values used for indexing, such as vertex IDs, are stored as igraph_real_t. This is because igraph was originally written to be an R package, and R uses doubles for everything, including integer values.

There is also igraph_vector_int_t, which holds igraph_integer_t. Currently, igraph_integer_t is int.

Starting with igraph 0.10, all values used for indexing, such as edge and vertex IDs, will be consistently igraph_integer_t. This means that igraph_vs_vector() will also take an igraph_vector_int_t argument, not an igraph_vector_t one. Additionally, igraph_integer_t will be a 64-bit type on 64-bit systems by default. You can find these changes on the develop branch of the igraph repository. If you decide to use this development version, keep in mind that a large number of breaking changes have been made compared to 0.9, and you will need to adapt your existing code. These are mostly updating the types of IDs to be integers, but there are also some renamings and other interface changes. See the changelog. You are very welcome to use the development version and give feedback, but be prepared for the rug to be pulled from under you from time to time: breaking changes are made regularly. That said, the development version should be more stable and less buggy than 0.9.

Why are we making so many breaking changes? From 1.0 onwards, the igraph API should be stable. We are cleaning up the API and making it more consistent for that release. Most, but not all breaking changes will be made in 0.10, with a 0.11 almost certain to follow before 1.0.

Thank you so much for the answer and broader context! Your work on igraph is greatly appreciated.