Skip to content

Commit

Permalink
removed for loops from get.incidence.dense
Browse files Browse the repository at this point in the history
  • Loading branch information
schochastics authored and krlmlr committed Oct 3, 2024
1 parent df6796f commit 934c5ec
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions R/conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -845,15 +845,14 @@ get.incidence.dense <- function(graph, types, names, attr) {
recode[!types] <- seq_len(n1)
recode[types] <- seq_len(n2)

for (i in seq(length.out = ecount(graph))) {
eo <- ends(graph, i, names = FALSE)
e <- recode[eo]
if (!types[eo[1]]) {
res[e[1], e[2]] <- edge_attr(graph, attr, i)
} else {
res[e[2], e[1]] <- edge_attr(graph, attr, i)
}
}
el <- as_edgelist(graph, names = FALSE)
idx <- types[el[, 1]]
el[, 1] <- recode[el[, 1]]
el[, 2] <- recode[el[, 2]]

tmp <- el[idx, 2:1]
el[idx, ] <- tmp
res[el] <- edge_attr(graph, attr)

if (names && "name" %in% vertex_attr_names(graph)) {
rownames(res) <- V(graph)$name[which(!types)]
Expand Down

0 comments on commit 934c5ec

Please sign in to comment.