Skip to content

Commit aee0b2d

Browse files
update
1 parent c4fa639 commit aee0b2d

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

R/torch_dist.R

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,12 @@ torch_dist <- function(x, p = 1, device = NULL) {
6060
))
6161
}
6262

63-
# Initialize distance matrix
64-
mat <- matrix(0, nrow = N, ncol = N)
65-
66-
# Fill lower triangle
67-
mat[lower.tri(mat, diag = FALSE)] <- pd
68-
69-
# Mirror to upper triangle
70-
mat <- mat + t(mat)
71-
72-
# Return as dist object
73-
as.dist(mat)
63+
structure(
64+
pd,
65+
Size = N,
66+
Diag = FALSE,
67+
Upper = FALSE,
68+
method = if (p == 1) "manhattan" else if (p == 2) "euclidean" else paste0("minkowski_p_", p),
69+
class = "dist"
70+
)
7471
}

0 commit comments

Comments
 (0)