From 1af1c6a6dbcf1b68f3b4412ab2dce7fc92c749f2 Mon Sep 17 00:00:00 2001 From: Tristan Goodwill <48371600+tristangdwl@users.noreply.github.com> Date: Mon, 27 Oct 2025 16:24:03 -0400 Subject: [PATCH] get ids associated with an edge in a chunkgraph --- chunkie/@chunkgraph/edgeids.m | 11 +++++++++++ devtools/test/slicegraphTest.m | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 chunkie/@chunkgraph/edgeids.m diff --git a/chunkie/@chunkgraph/edgeids.m b/chunkie/@chunkgraph/edgeids.m new file mode 100644 index 0000000..548888a --- /dev/null +++ b/chunkie/@chunkgraph/edgeids.m @@ -0,0 +1,11 @@ +function ids = edgeids(cgrph, ichs) +%edgeids return the indices corresponding to points in cgrph.echnks(ichs) +npts = [cgrph.echnks.npt]; +% get starting index for each edge +idstart = [1,cumsum(npts)+1]; + +ids = []; +for i = 1:length(ichs) + ids = [ids, idstart(ichs(i)):(idstart(ichs(i)+1)-1)]; +end +end \ No newline at end of file diff --git a/devtools/test/slicegraphTest.m b/devtools/test/slicegraphTest.m index 3196d06..79671af 100644 --- a/devtools/test/slicegraphTest.m +++ b/devtools/test/slicegraphTest.m @@ -50,4 +50,18 @@ function slicegraphTest0() matdiff = norm(sysmat_slc - sysmat(idslce, idslce)); fprintf('error in sliced system matrix is %e\n',matdiff) assert(matdiff < 1e-10) -end \ No newline at end of file + + +% test getting ids of edges +ids = edgeids(cgrph,[3,4,2,1]); + +% test values are correct +assert(all(sort(ids) == (1:sum([cgrph.echnks(1:4).npt])))); +% test sorted by input list +assert(~all(sort(ids) == ids)); + +ids = edgeids(cgrph,ichs); +% compare edgeids to manual version +assert(all(ids == idslce)); + +end