Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions src/vendor/cigraph/src/layout/mds.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "igraph_layout.h"

#include "igraph_bitset.h"
#include "igraph_blas.h"
#include "igraph_components.h"
#include "igraph_eigen.h"
Expand Down Expand Up @@ -91,8 +92,8 @@ igraph_error_t igraph_i_layout_mds_single(const igraph_t* graph, igraph_matrix_t
IGRAPH_FINALLY(igraph_matrix_destroy, &vectors);

/* Take the square of the distance matrix */
for (i = 0; i < no_of_nodes; i++) {
for (j = 0; j < no_of_nodes; j++) {
for (j = 0; j < no_of_nodes; j++) {
for (i = 0; i < no_of_nodes; i++) {
MATRIX(*dist, i, j) *= MATRIX(*dist, i, j);
}
}
Expand All @@ -103,8 +104,8 @@ igraph_error_t igraph_i_layout_mds_single(const igraph_t* graph, igraph_matrix_t
IGRAPH_CHECK(igraph_blas_dgemv(0, 1, dist, &values, 0, &row_means));
grand_mean = igraph_vector_sum(&row_means) / no_of_nodes;
igraph_matrix_add_constant(dist, grand_mean);
for (i = 0; i < no_of_nodes; i++) {
for (j = 0; j < no_of_nodes; j++) {
for (j = 0; j < no_of_nodes; j++) {
for (i = 0; i < no_of_nodes; i++) {
MATRIX(*dist, i, j) -= VECTOR(row_means)[i] + VECTOR(row_means)[j];
MATRIX(*dist, i, j) *= -0.5;
}
Expand Down Expand Up @@ -188,9 +189,9 @@ igraph_error_t igraph_i_layout_mds_single(const igraph_t* graph, igraph_matrix_t
* Time complexity: usually around O(|V|^2 dim).
*/

igraph_error_t igraph_layout_mds(const igraph_t* graph, igraph_matrix_t *res,
igraph_error_t igraph_layout_mds(const igraph_t *graph, igraph_matrix_t *res,
const igraph_matrix_t *dist, igraph_integer_t dim) {
igraph_integer_t i, no_of_nodes = igraph_vcount(graph);
const igraph_integer_t no_of_nodes = igraph_vcount(graph);
igraph_matrix_t m;
igraph_bool_t conn;

Expand Down Expand Up @@ -218,7 +219,7 @@ igraph_error_t igraph_layout_mds(const igraph_t* graph, igraph_matrix_t *res,
IGRAPH_CHECK(igraph_matrix_init_copy(&m, dist));
IGRAPH_FINALLY(igraph_matrix_destroy, &m);
/* Make sure that the diagonal contains zeroes only */
for (i = 0; i < no_of_nodes; i++) {
for (igraph_integer_t i = 0; i < no_of_nodes; i++) {
MATRIX(m, i, i) = 0.0;
}
}
Expand All @@ -236,8 +237,8 @@ igraph_error_t igraph_layout_mds(const igraph_t* graph, igraph_matrix_t *res,
igraph_t subgraph;
igraph_matrix_t layout;
igraph_matrix_t dist_submatrix;
igraph_bool_t *seen_vertices;
igraph_integer_t j, n, processed_vertex_count = 0;
igraph_bitset_t seen_vertices;
igraph_integer_t n, processed_vertex_count = 0;

IGRAPH_VECTOR_INT_INIT_FINALLY(&comp, 0);
IGRAPH_VECTOR_INT_INIT_FINALLY(&vertex_order, no_of_nodes);
Expand All @@ -248,14 +249,10 @@ igraph_error_t igraph_layout_mds(const igraph_t* graph, igraph_matrix_t *res,
IGRAPH_CHECK(igraph_matrix_init(&dist_submatrix, 0, 0));
IGRAPH_FINALLY(igraph_matrix_destroy, &dist_submatrix);

seen_vertices = IGRAPH_CALLOC(no_of_nodes, igraph_bool_t);
if (seen_vertices == 0) {
IGRAPH_ERROR("cannot calculate MDS layout", IGRAPH_ENOMEM); /* LCOV_EXCL_LINE */
}
IGRAPH_FINALLY(igraph_free, seen_vertices);
IGRAPH_BITSET_INIT_FINALLY(&seen_vertices, no_of_nodes);

for (i = 0; i < no_of_nodes; i++) {
if (seen_vertices[i]) {
for (igraph_integer_t i = 0; i < no_of_nodes; i++) {
if (IGRAPH_BIT_TEST(seen_vertices, i)) {
continue;
}

Expand All @@ -276,8 +273,8 @@ igraph_error_t igraph_layout_mds(const igraph_t* graph, igraph_matrix_t *res,
IGRAPH_FINALLY_CLEAN(1);
/* Mark all the vertices in the component as visited */
n = igraph_vector_int_size(&comp);
for (j = 0; j < n; j++) {
seen_vertices[VECTOR(comp)[j]] = 1;
for (igraph_integer_t j = 0; j < n; j++) {
IGRAPH_BIT_SET(seen_vertices, VECTOR(comp)[j]);
VECTOR(vertex_order)[VECTOR(comp)[j]] = processed_vertex_count++;
}
}
Expand All @@ -286,7 +283,7 @@ igraph_error_t igraph_layout_mds(const igraph_t* graph, igraph_matrix_t *res,
/* Reordering the rows of res to match the original graph */
IGRAPH_CHECK(igraph_matrix_select_rows(&dist_submatrix, res, &vertex_order));

igraph_free(seen_vertices);
igraph_bitset_destroy(&seen_vertices);
igraph_matrix_destroy(&dist_submatrix);
igraph_matrix_destroy(&layout);
igraph_matrix_list_destroy(&layouts);
Expand Down
4 changes: 2 additions & 2 deletions src/vendor/igraph_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@

__BEGIN_DECLS

#define IGRAPH_VERSION "0.10.15-90-gdcdad62cb"
#define IGRAPH_VERSION "0.10.15-91-gfc6860b31"
#define IGRAPH_VERSION_MAJOR 0
#define IGRAPH_VERSION_MINOR 10
#define IGRAPH_VERSION_PATCH 15
#define IGRAPH_VERSION_PRERELEASE "90-gdcdad62cb"
#define IGRAPH_VERSION_PRERELEASE "91-gfc6860b31"

IGRAPH_EXPORT void igraph_version(const char **version_string,
int *major,
Expand Down