From e314d178d1e44f05bcc4f1843128cb7ec74a907e Mon Sep 17 00:00:00 2001 From: Robert Chisholm Date: Thu, 12 Oct 2023 12:47:04 +0100 Subject: [PATCH] 7/10 Python tests now pass. Failing tests all fail to compile agent fn. --- swig/python/flamegpu.i | 61 ++- .../test_environment_directed_graph.py | 447 +++++++++--------- .../test_environment_directed_graph.cu | 8 +- 3 files changed, 282 insertions(+), 234 deletions(-) diff --git a/swig/python/flamegpu.i b/swig/python/flamegpu.i index 491573dd5..b5b5e58b4 100644 --- a/swig/python/flamegpu.i +++ b/swig/python/flamegpu.i @@ -822,6 +822,43 @@ namespace std { } } +// Typemap to convert srcdest tuple to an array +%typemap(in) unsigned int[2](unsigned int temp[2]) { // temp[2] becomes a local variable + int i; + if (PyTuple_Check($input)) { + if (!PyArg_ParseTuple($input, "uu", temp, temp+1)) { + PyErr_SetString(PyExc_TypeError, "tuple must have 2 elements"); + SWIG_fail; + } + $1 = &temp[0]; + } else { + PyErr_SetString(PyExc_TypeError, "expected a tuple."); + SWIG_fail; + } +} +// Extend VertexMap/EdgeMap so they can be accessed like a dictionary +%extend flamegpu::HostEnvironmentDirectedGraph::VertexMap { + %pythoncode { + def __len__(self): + return self.size() + } + flamegpu::HostEnvironmentDirectedGraph::VertexMap::Vertex flamegpu::HostEnvironmentDirectedGraph::VertexMap::__getitem__(const unsigned int vertex_id) { + return $self->operator[](vertex_id); + } +} +%extend flamegpu::HostEnvironmentDirectedGraph::EdgeMap { + %pythoncode { + def __getitem__(self, srcdest): + src, dest = srcdest + return self.get_item(int(src), int(dest)) + def __len__(self): + return self.size() + } + flamegpu::HostEnvironmentDirectedGraph::EdgeMap::Edge flamegpu::HostEnvironmentDirectedGraph::EdgeMap::get_item(const unsigned int src, const unsigned int dest) { + return $self->operator[]({src, dest}); + } +} + // Template expansions. Go after the %include and %extension // ----------------- @@ -964,18 +1001,18 @@ TEMPLATE_VARIABLE_INSTANTIATE_ID(newEdgeProperty, flamegpu::EnvironmentDirectedG TEMPLATE_VARIABLE_INSTANTIATE_ID(newVertexPropertyArray, flamegpu::EnvironmentDirectedGraphDescription::newVertexPropertyArray) TEMPLATE_VARIABLE_INSTANTIATE_ID(newEdgePropertyArray, flamegpu::EnvironmentDirectedGraphDescription::newEdgePropertyArray) -TEMPLATE_VARIABLE_INSTANTIATE_ID(setVertexProperty, flamegpu::HostEnvironmentDirectedGraph::VertexMap::Vertex::setProperty) -TEMPLATE_VARIABLE_INSTANTIATE_ID(setEdgeProperty, flamegpu::HostEnvironmentDirectedGraph::EdgeMap::Edge::setProperty) -TEMPLATE_VARIABLE_INSTANTIATE_ID(getVertexProperty, flamegpu::HostEnvironmentDirectedGraph::VertexMap::Vertex::getProperty) -TEMPLATE_VARIABLE_INSTANTIATE_ID(getEdgeProperty, flamegpu::HostEnvironmentDirectedGraph::EdgeMap::Edge::getProperty) -TEMPLATE_VARIABLE_ARRAY_INSTANTIATE_ID(setVertexProperty, flamegpu::HostEnvironmentDirectedGraph::VertexMap::Vertex::setProperty) -TEMPLATE_VARIABLE_ARRAY_INSTANTIATE_ID(setEdgeProperty, flamegpu::HostEnvironmentDirectedGraph::EdgeMap::Edge::setProperty) -TEMPLATE_VARIABLE_ARRAY_INSTANTIATE_ID(getVertexProperty, flamegpu::HostEnvironmentDirectedGraph::VertexMap::Vertex::getProperty) -TEMPLATE_VARIABLE_ARRAY_INSTANTIATE_ID(getEdgeProperty, flamegpu::HostEnvironmentDirectedGraph::EdgeMap::Edge::getProperty) -TEMPLATE_VARIABLE_INSTANTIATE_ID(setVertexPropertyArray, flamegpu::HostEnvironmentDirectedGraph::VertexMap::Vertex::setPropertyArray) -TEMPLATE_VARIABLE_INSTANTIATE_ID(setEdgePropertyArray, flamegpu::HostEnvironmentDirectedGraph::EdgeMap::Edge::setPropertyArray) -TEMPLATE_VARIABLE_INSTANTIATE_ID(getVertexPropertyArray, flamegpu::HostEnvironmentDirectedGraph::VertexMap::Vertex::getPropertyArray) -TEMPLATE_VARIABLE_INSTANTIATE_ID(getEdgePropertyArray, flamegpu::HostEnvironmentDirectedGraph::EdgeMap::Edge::getPropertyArray) +TEMPLATE_VARIABLE_INSTANTIATE_ID(setProperty, flamegpu::HostEnvironmentDirectedGraph::VertexMap::Vertex::setProperty) +TEMPLATE_VARIABLE_INSTANTIATE_ID(setProperty, flamegpu::HostEnvironmentDirectedGraph::EdgeMap::Edge::setProperty) +TEMPLATE_VARIABLE_INSTANTIATE_ID(getProperty, flamegpu::HostEnvironmentDirectedGraph::VertexMap::Vertex::getProperty) +TEMPLATE_VARIABLE_INSTANTIATE_ID(getProperty, flamegpu::HostEnvironmentDirectedGraph::EdgeMap::Edge::getProperty) +TEMPLATE_VARIABLE_ARRAY_INSTANTIATE_ID(setProperty, flamegpu::HostEnvironmentDirectedGraph::VertexMap::Vertex::setProperty) +TEMPLATE_VARIABLE_ARRAY_INSTANTIATE_ID(setProperty, flamegpu::HostEnvironmentDirectedGraph::EdgeMap::Edge::setProperty) +TEMPLATE_VARIABLE_ARRAY_INSTANTIATE_ID(getProperty, flamegpu::HostEnvironmentDirectedGraph::VertexMap::Vertex::getProperty) +TEMPLATE_VARIABLE_ARRAY_INSTANTIATE_ID(getProperty, flamegpu::HostEnvironmentDirectedGraph::EdgeMap::Edge::getProperty) +TEMPLATE_VARIABLE_INSTANTIATE_ID(setPropertyArray, flamegpu::HostEnvironmentDirectedGraph::VertexMap::Vertex::setPropertyArray) +TEMPLATE_VARIABLE_INSTANTIATE_ID(setPropertyArray, flamegpu::HostEnvironmentDirectedGraph::EdgeMap::Edge::setPropertyArray) +TEMPLATE_VARIABLE_INSTANTIATE_ID(getPropertyArray, flamegpu::HostEnvironmentDirectedGraph::VertexMap::Vertex::getPropertyArray) +TEMPLATE_VARIABLE_INSTANTIATE_ID(getPropertyArray, flamegpu::HostEnvironmentDirectedGraph::EdgeMap::Edge::getPropertyArray) // Instantiate template versions of RunPlan functions from the API TEMPLATE_VARIABLE_INSTANTIATE_ID(setProperty, flamegpu::RunPlan::setProperty) diff --git a/tests/python/runtime/environment/test_environment_directed_graph.py b/tests/python/runtime/environment/test_environment_directed_graph.py index 9b2c88ca3..c7e20deeb 100644 --- a/tests/python/runtime/environment/test_environment_directed_graph.py +++ b/tests/python/runtime/environment/test_environment_directed_graph.py @@ -6,28 +6,29 @@ class InitGraph(pyflamegpu.HostFunction): def run(self, FLAMEGPU): graph = FLAMEGPU.environment.getDirectedGraph("graph"); graph.setVertexCount(10); - for i in range(10): - graph.setVertexID(i, i); - graph.setVertexPropertyFloat("vertex_float", i, i); - graph.setVertexPropertyDouble("vertex_double2", i, 0, i + 11); - graph.setVertexPropertyDouble("vertex_double2", i, 1, i + 21); # Redundant for Py - graph.setVertexPropertyArrayInt("vertex_int3", i, [i + 1, i + 2, i + 3]); + vertices = graph.vertices(); + for i in range(1, 11): + vertex = vertices[i]; + vertex.setPropertyFloat("vertex_float", i); + vertex.setPropertyDouble("vertex_double2", 0, i + 11); + vertex.setPropertyDouble("vertex_double2", 1, i + 21); # Redundant for Py + vertex.setPropertyArrayInt("vertex_int3", [i + 1, i + 2, i + 3]); graph.setEdgeCount(20); + edges = graph.edges(); for i in range(10): - graph.setEdgeSource(i, int(i / 2)); - graph.setEdgeDestination(i, (i + 2) % 10); - graph.setEdgePropertyInt("edge_int", i, i + 70); - graph.setEdgePropertyDouble("edge_double2", i, 0, i + 61); - graph.setEdgePropertyDouble("edge_double2", i, 1, i + 51); # Redundant for Py - graph.setEdgePropertyArrayFloat("edge_float3", i, [ i + 41, i + 42, i + 43]); + edge = edges[(i / 2) + 1,((i + 2) % 10) + 1]; + edge.setPropertyInt("edge_int", i + 70); + edge.setPropertyDouble("edge_double2", 0, i + 61); + edge.setPropertyDouble("edge_double2", 1, i + 51); # Redundant for Py + edge.setPropertyArrayFloat("edge_float3", [ i + 41, i + 42, i + 43]); for i in range(10, 20): - graph.setEdgeSourceDestination(i, int(i / 2), (i + 6) % 10); - graph.setEdgePropertyInt("edge_int", i, i + 70); - graph.setEdgePropertyDouble("edge_double2", i, 0, i + 61); - graph.setEdgePropertyDouble("edge_double2", i, 1, i + 51); # Redundant for Py - graph.setEdgePropertyArrayFloat("edge_float3", i, [ i + 41, i + 42, i + 43]); + edge = edges[(i / 2) + 1,((i + 6) % 10) + 1]; + edge.setPropertyInt("edge_int", i + 70); + edge.setPropertyDouble("edge_double2", 0, i + 61); + edge.setPropertyDouble("edge_double2", 1, i + 51); # Redundant for Py + edge.setPropertyArrayFloat("edge_float3", [ i + 41, i + 42, i + 43]); # Init's same as InitGraph, however fills the vertices/edges with zero @@ -35,141 +36,180 @@ class InitGraph2(pyflamegpu.HostFunction): def run(self, FLAMEGPU): graph = FLAMEGPU.environment.getDirectedGraph("graph"); graph.setVertexCount(10); - for i in range(10): - graph.setVertexID(i, i); - graph.setVertexPropertyFloat("vertex_float", i, 0); - graph.setVertexPropertyDouble("vertex_double2", i, 0, 0); - graph.setVertexPropertyDouble("vertex_double2", i, 1, 0); # Redundant for Py - graph.setVertexPropertyArrayInt("vertex_int3", i, [0, 0, 0]); + vertices = graph.vertices(); + for i in range(1, 11): + vertex = vertices[i]; + vertex.setPropertyFloat("vertex_float", 0); + vertex.setPropertyDouble("vertex_double2", 0, 0); + vertex.setPropertyDouble("vertex_double2", 1, 0); # Redundant for Py + vertex.setPropertyArrayInt("vertex_int3", [0, 0, 0]); graph.setEdgeCount(20); + edges = graph.edges(); for i in range(10): - graph.setEdgeSource(i, i % 10); - graph.setEdgeDestination(i, 0); - graph.setEdgePropertyInt("edge_int", i, 0); - graph.setEdgePropertyDouble("edge_double2", i, 0, 0); - graph.setEdgePropertyDouble("edge_double2", i, 1, 0); # Redundant for Py - graph.setEdgePropertyArrayFloat("edge_float3", i, [0, 0, 0]); + edge = edges[(i % 10) + 1, 1]; + edge.setPropertyInt("edge_int", 0); + edge.setPropertyDouble("edge_double2", 0, 0); + edge.setPropertyDouble("edge_double2", 1, 0); # Redundant for Py + edge.setPropertyArrayFloat("edge_float3", [0, 0, 0]); for i in range(10, 20): - graph.setEdgeSourceDestination(i, i % 10, (2 * i + 4) % 10); - graph.setEdgePropertyInt("edge_int", i, 0); - graph.setEdgePropertyDouble("edge_double2", i, 0, 0); - graph.setEdgePropertyDouble("edge_double2", i, 1, 0); # Redundant for Py - graph.setEdgePropertyArrayFloat("edge_float3", i, [0, 0, 0]); + edge = edges[(i % 10) + 1, 3]; + edge.setPropertyInt("edge_int", 0); + edge.setPropertyDouble("edge_double2", 0, 0); + edge.setPropertyDouble("edge_double2", 1, 0); # Redundant for Py + edge.setPropertyArrayFloat("edge_float3", [0, 0, 0]); # Alternate version to InitGraph class InitGraph3(pyflamegpu.HostFunction): def run(self, FLAMEGPU): graph = FLAMEGPU.environment.getDirectedGraph("graph"); graph.setVertexCount(30); - for i in range(30): - graph.setVertexID(i, i); - graph.setVertexPropertyFloat("vertex_float", i, i); - graph.setVertexPropertyDouble("vertex_double2", i, 0, i + 11); - graph.setVertexPropertyDouble("vertex_double2", i, 1, i + 21); # Redundant for Py - graph.setVertexPropertyArrayInt("vertex_int3", i, [i + 1, i + 2, i + 3]); + vertices = graph.vertices(); + for i in range(1, 31): + vertex = vertices[i]; + vertex.setPropertyFloat("vertex_float", i); + vertex.setPropertyDouble("vertex_double2", 0, i + 11); + vertex.setPropertyDouble("vertex_double2", 1, i + 21); # Redundant for Py + vertex.setPropertyArrayInt("vertex_int3", [i + 1, i + 2, i + 3]); graph.setEdgeCount(60); + edges = graph.edges(); for i in range(30): - graph.setEdgeSource(i, int(i / 2)); - graph.setEdgeDestination(i, (i + 2) % 30); - graph.setEdgePropertyInt("edge_int", i, i + 70); - graph.setEdgePropertyDouble("edge_double2", i, 0, i + 61); - graph.setEdgePropertyDouble("edge_double2", i, 1, i + 51); # Redundant for Py - graph.setEdgePropertyArrayFloat("edge_float3", i, [i + 41, i + 52, i + 43]); + edge = edges[(i / 2) + 1, ((i + 2) % 30) + 1]; + edge.setPropertyInt("edge_int", i + 70); + edge.setPropertyDouble("edge_double2", 0, i + 61); + edge.setPropertyDouble("edge_double2", 1, i + 51); # Redundant for Py + edge.setPropertyArrayFloat("edge_float3", [i + 41, i + 52, i + 43]); for i in range(30, 60): - graph.setEdgeSourceDestination(i, int(i / 2), (i + 18) % 30); - graph.setEdgePropertyInt("edge_int", i, i + 70); - graph.setEdgePropertyDouble("edge_double2", i, 0, i + 61); - graph.setEdgePropertyDouble("edge_double2", i, 1, i + 51); # Redundant for Py - graph.setEdgePropertyArrayFloat("edge_float3", i, [i + 41, i + 52, i + 43]); + edge = edges[(i / 2) + 1, ((i + 18) % 30) + 1]; + edge.setPropertyInt("edge_int", i + 70); + edge.setPropertyDouble("edge_double2", 0, i + 61); + edge.setPropertyDouble("edge_double2", 1, i + 51); # Redundant for Py + edge.setPropertyArrayFloat("edge_float3", [i + 41, i + 52, i + 43]); # Set graph to same data as InitGraph, it assumes vertice/edge counts are correct class SetGraph(pyflamegpu.HostFunction): def run(self, FLAMEGPU): graph = FLAMEGPU.environment.getDirectedGraph("graph"); + vertices = graph.vertices(); + for i in range(1, 11): + vertex = vertices[i]; + vertex.setPropertyFloat("vertex_float", i); + vertex.setPropertyDouble("vertex_double2", 0, i + 11); + vertex.setPropertyDouble("vertex_double2", 1, i + 21); # Redundant for Py + vertex.setPropertyArrayInt("vertex_int3", [i + 1, i + 2, i + 3]); + + edges = graph.edges(); for i in range(10): - graph.setVertexID(i, i); - graph.setVertexPropertyFloat("vertex_float", i, i); - graph.setVertexPropertyDouble("vertex_double2", i, 0, i + 11); - graph.setVertexPropertyDouble("vertex_double2", i, 1, i + 21); # Redundant for Py - graph.setVertexPropertyArrayInt("vertex_int3", i, [i + 1, i + 2, i + 3]); + edge = edges[(i % 10) + 1, 1]; + edge.setDestinationVertexID(2); + edge.setSourceVertexID(i + 1); + edge.setPropertyInt("edge_int", i + 70); + edge.setPropertyDouble("edge_double2", 0, i + 61); + edge.setPropertyDouble("edge_double2", 1, i + 51); # Redundant for Py + edge.setPropertyArrayFloat("edge_float3", [i + 41, i + 42, i + 43]); + + for i in range(10, 20): + edge = edges[(i % 10) + 1, 3]; + edge.setSourceDestinationVertexID(i - 9, 4); + edge.setPropertyInt("edge_int", i + 70); + edge.setPropertyDouble("edge_double2", 0, i + 61); + edge.setPropertyDouble("edge_double2", 1, i + 51); # Redundant for Py + edge.setPropertyArrayFloat("edge_float3", [i + 41, i + 42, i + 43]); + +class HostCheckSetGraph(pyflamegpu.HostFunction): + def run(self, FLAMEGPU): + graph = FLAMEGPU.environment.getDirectedGraph("graph"); + vertices = graph.vertices(); + # Vertices + assert graph.getVertexCount() == 10; + for i in range(1, 11): + vertex = vertices[i]; + assert vertex.getPropertyFloat("vertex_float") == i; + assert vertex.getPropertyDouble("vertex_double2", 0) == i + 11; + # assert vertex.getPropertyDouble("vertex_double2", 1) == i + 21; # Redundant for Py + assert vertex.getPropertyArrayInt("vertex_int3") == (i + 1, i + 2, i + 3); + # Edges + edges = graph.edges(); + assert graph.getEdgeCount() == 20; for i in range(10): - graph.setEdgeSource(i, int(i / 2)); - graph.setEdgeDestination(i, (i + 2) % 10); - graph.setEdgePropertyInt("edge_int", i, i + 70); - graph.setEdgePropertyDouble("edge_double2", i, 0, i + 61); - graph.setEdgePropertyDouble("edge_double2", i, 1, i + 51); # Redundant for Py - graph.setEdgePropertyArrayFloat("edge_float3", i, [i + 41, i + 42, i + 43]); + edge = edges[i + 1, 2]; + assert edge.getPropertyInt("edge_int") == i + 70; + assert edge.getPropertyDouble("edge_double2", 0) == i + 61; + # assert edge.getPropertyDouble("edge_double2", 1) == i + 51; # Redundant for Py + assert edge.getPropertyArrayFloat("edge_float3") == (i + 41, i + 42, i + 43); for i in range(10, 20): - graph.setEdgeSourceDestination(i, int(i / 2), (i + 6) % 10); - graph.setEdgePropertyInt("edge_int", i, i + 70); - graph.setEdgePropertyDouble("edge_double2", i, 0, i + 61); - graph.setEdgePropertyDouble("edge_double2", i, 1, i + 51); # Redundant for Py - graph.setEdgePropertyArrayFloat("edge_float3", i, [i + 41, i + 42, i + 43]); - + edge = edges[i - 9, 4]; + assert edge.getPropertyInt("edge_int") == i + 70; + assert edge.getPropertyDouble("edge_double2", 0) == i + 61; + # assert edge.getPropertyDouble("edge_double2", 1) == si + 51; # Redundant for Py + assert edge.getPropertyArrayFloat("edge_float3") == (i + 41, i + 42, i + 43); class HostCheckGraph(pyflamegpu.HostFunction): def run(self, FLAMEGPU): graph = FLAMEGPU.environment.getDirectedGraph("graph"); + vertices = graph.vertices(); # Vertices assert graph.getVertexCount() == 10; - for i in range(10): - assert graph.getVertexID(i) == i; - assert graph.getVertexPropertyFloat("vertex_float", i) == i; - assert graph.getVertexPropertyDouble("vertex_double2", i, 0) == i + 11; - # assert graph.getVertexPropertyDouble("vertex_double2", i, 1) == i + 21; # Redundant for Py - assert graph.getVertexPropertyArrayInt("vertex_int3", i) == (i + 1, i + 2, i + 3); + for i in range(1, 11): + vertex = vertices[i]; + assert vertex.getPropertyFloat("vertex_float") == i; + assert vertex.getPropertyDouble("vertex_double2", 0) == i + 11; + # assert vertex.getPropertyDouble("vertex_double2", 1) == i + 21; # Redundant for Py + assert vertex.getPropertyArrayInt("vertex_int3") == (i + 1, i + 2, i + 3); # Edges + edges = graph.edges(); assert graph.getEdgeCount() == 20; for i in range(10): - assert graph.getEdgeSource(i) == int(i / 2); - assert graph.getEdgeDestination(i) == (i + 2) % 10; - assert graph.getEdgePropertyInt("edge_int", i) == i + 70; - assert graph.getEdgePropertyDouble("edge_double2", i, 0) == i + 61; - # assert graph.getEdgePropertyDouble("edge_double2", i, 1) == i + 51; # Redundant for Py - assert graph.getEdgePropertyArrayFloat("edge_float3", i) == (i + 41, i + 42, i + 43); + edge = edges[(i / 2) + 1, ((i + 2) % 10) + 1]; + assert edge.getPropertyInt("edge_int") == i + 70; + assert edge.getPropertyDouble("edge_double2", 0) == i + 61; + # assert edge.getPropertyDouble("edge_double2", 1) == i + 51; # Redundant for Py + assert edge.getPropertyArrayFloat("edge_float3") == (i + 41, i + 42, i + 43); for i in range(10, 20): - assert graph.getEdgeSourceDestination(i) == (int(i / 2), (i + 6) % 10 ) - assert graph.getEdgePropertyInt("edge_int", i) == i + 70; - assert graph.getEdgePropertyDouble("edge_double2", i, 0) == i + 61; - # assert graph.getEdgePropertyDouble("edge_double2", i, 1) == si + 51; # Redundant for Py - assert graph.getEdgePropertyArrayFloat("edge_float3", i) == (i + 41, i + 42, i + 43); + edge = edges[(i / 2) + 1, ((i + 6) % 10) + 1]; + assert edge.getPropertyInt("edge_int") == i + 70; + assert edge.getPropertyDouble("edge_double2", 0) == i + 61; + # assert edge.getPropertyDouble("edge_double2", 1) == si + 51; # Redundant for Py + assert edge.getPropertyArrayFloat("edge_float3") == (i + 41, i + 42, i + 43); # Equivalent version to HostCheckGraph but for InitGraph3 class HostCheckGraph3(pyflamegpu.HostFunction): def run(self, FLAMEGPU): graph = FLAMEGPU.environment.getDirectedGraph("graph"); + vertices = graph.vertices(); # Vertices assert graph.getVertexCount() == 30; - for i in range(30): - assert graph.getVertexID(i) == i; - assert graph.getVertexPropertyFloat("vertex_float", i) == i; - assert graph.getVertexPropertyDouble("vertex_double2", i, 0) == i + 11; - # assert graph.getVertexPropertyDouble("vertex_double2", i, 1) == i + 21; # Redundant for Py - assert graph.getVertexPropertyArrayInt("vertex_int3", i) == (i + 1, i + 2, i + 3); + for i in range(1, 31): + vertex = vertices[i]; + assert vertex.getPropertyFloat("vertex_float") == i; + assert vertex.getPropertyDouble("vertex_double2", 0) == i + 11; + # assert vertex.getPropertyDouble("vertex_double2", 1) == i + 21; # Redundant for Py + assert vertex.getPropertyArrayInt("vertex_int3") == (i + 1, i + 2, i + 3); # Edges + edges = graph.edges(); assert graph.getEdgeCount() == 60; for i in range(30): - assert graph.getEdgeSource(i) == int(i / 2); - assert graph.getEdgeDestination(i) == (i + 2) % 30; - assert graph.getEdgePropertyInt("edge_int", i) == i + 70; - assert graph.getEdgePropertyDouble("edge_double2", i, 0) == i + 61; - # assert graph.getEdgePropertyDouble("edge_double2", i, 1) == i + 51; # Redundant for Py - assert graph.getEdgePropertyArrayFloat("edge_float3", i) == (i + 41, i + 52, i + 43); + edge = edges[(i / 2) + 1, ((i + 2) % 30) + 1]; + assert edge.getSourceVertexID() == int(i / 2) + 1; + assert edge.getDestinationVertexID() == ((i + 2) % 30)+1; + assert edge.getPropertyInt("edge_int") == i + 70; + assert edge.getPropertyDouble("edge_double2", 0) == i + 61; + # assert edge.getPropertyDouble("edge_double2", 1) == i + 51; # Redundant for Py + assert edge.getPropertyArrayFloat("edge_float3") == (i + 41, i + 52, i + 43); for i in range(30, 60): - assert graph.getEdgeSourceDestination(i) == (int(i / 2), (i + 18) % 30); - assert graph.getEdgePropertyInt("edge_int", i) == i + 70; - assert graph.getEdgePropertyDouble("edge_double2", i, 0) == i + 61; - # assert graph.getEdgePropertyDouble("edge_double2", i, 1) == i + 51; # Redundant for Py - assert graph.getEdgePropertyArrayFloat("edge_float3", i) == (i + 41, i + 52, i + 43); + edge = edges[(i / 2) + 1, ((i + 18) % 30) + 1]; + assert edge.getPropertyInt("edge_int") == i + 70; + assert edge.getPropertyDouble("edge_double2", 0) == i + 61; + # assert edge.getPropertyDouble("edge_double2", 1) == i + 51; # Redundant for Py + assert edge.getPropertyArrayFloat("edge_float3") == (i + 41, i + 52, i + 43); class HostException(pyflamegpu.HostFunction): def run(self, FLAMEGPU): @@ -179,201 +219,170 @@ def run(self, FLAMEGPU): assert e.value.type() == "InvalidGraphName" graph = FLAMEGPU.environment.getDirectedGraph("graph"); + vertices = graph.vertices(); + edges = graph.edges(); + with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException exception - graph.getVertexID(0) + vertices[1] assert e.value.type() == "OutOfBoundsException" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException exception - graph.getEdgeSource(0) + edges[1,2] assert e.value.type() == "OutOfBoundsException" - graph.setVertexCount(10); - graph.setEdgeCount(10); - + graph.setVertexCount(1); + graph.setEdgeCount(1); + + vertex = vertices[1]; + edge = edges[1, 1]; # Name with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.setVertexPropertyFloat("does not exist", 0, 0); + vertex.setPropertyFloat("does not exist", 0); assert e.value.type() == "InvalidGraphProperty" # with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - # graph.setVertexPropertyArrayDouble("does not exist", 0, 0, 0); + # vertex.setPropertyArrayDouble("does not exist", 0, 0); # assert e.value.type() == "InvalidGraphProperty" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.setVertexPropertyArrayInt("does not exist", 0, []); + vertex.setPropertyArrayInt("does not exist", []); assert e.value.type() == "InvalidGraphProperty" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.setEdgePropertyInt("does not exist", 0, 0); + edge.setPropertyInt("does not exist", 0); assert e.value.type() == "InvalidGraphProperty" # with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - # graph.setEdgePropertyArrayDouble("does not exist", 0, 0, 0); + # edge.setPropertyArrayDouble("does not exist", 0, 0); # assert e.value.type() == "InvalidGraphProperty" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.setEdgePropertyArrayFloat("does not exist", 0, []); + edge.setPropertyArrayFloat("does not exist", []); assert e.value.type() == "InvalidGraphProperty" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.getVertexPropertyFloat("does not exist", 0); + vertex.getPropertyFloat("does not exist"); assert e.value.type() == "InvalidGraphProperty" # with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - # graph.getVertexPropertyArrayDouble("does not exist", 0, 0); + # vertex.getPropertyArrayDouble("does not exist", 0); # assert e.value.type() == "InvalidGraphProperty" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.getVertexPropertyArrayInt("does not exist", 0); + vertex.getPropertyArrayInt("does not exist"); assert e.value.type() == "InvalidGraphProperty" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.getEdgePropertyInt("does not exist", 0); + edge.getPropertyInt("does not exist"); assert e.value.type() == "InvalidGraphProperty" # with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - # graph.getEdgePropertyArrayDouble("does not exist", 0, 0); + # edge.getPropertyArrayDouble("does not exist", 0); # assert e.value.type() == "InvalidGraphProperty" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.getEdgePropertyArrayFloat("does not exist", 0); + edge.getPropertyArrayFloat("does not exist"); assert e.value.type() == "InvalidGraphProperty" # Type with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.setVertexPropertyUInt("vertex_float", 0, 0); + vertex.setPropertyUInt("vertex_float", 0); assert e.value.type() == "InvalidGraphProperty" # with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - # graph.setVertexPropertyArrayUInt("vertex_double2", 0, 0, 0); + # vertex.setPropertyArrayUInt("vertex_double2", 0, 0); # assert e.value.type() == "InvalidGraphProperty" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.setVertexPropertyArrayUInt("vertex_int3", 0, []); + vertex.setPropertyArrayUInt("vertex_int3", []); assert e.value.type() == "InvalidGraphProperty" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.setEdgePropertyUInt("edge_int", 0, 0); + edge.setPropertyUInt("edge_int", 0); assert e.value.type() == "InvalidGraphProperty" # with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - # graph.setEdgePropertyArrayUInt("edge_double2", 0, 0, 0); + # edge.setPropertyArrayUInt("edge_double2", 0, 0); # assert e.value.type() == "InvalidGraphProperty" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.setEdgePropertyArrayUInt("edge_float3", 0, []); + edge.setPropertyArrayUInt("edge_float3", []); assert e.value.type() == "InvalidGraphProperty" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.getVertexPropertyUInt("vertex_float", 0); + vertex.getPropertyUInt("vertex_float"); assert e.value.type() == "InvalidGraphProperty" # with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - # graph.getVertexPropertyArrayUInt("vertex_double2", 0, 0); + # vertex.getPropertyArrayUInt("vertex_double2", 0); # assert e.value.type() == "InvalidGraphProperty" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.getVertexPropertyArrayUInt("vertex_int3", 0); + vertex.getPropertyArrayUInt("vertex_int3"); assert e.value.type() == "InvalidGraphProperty" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.getEdgePropertyUInt("edge_int", 0); + edge.getPropertyUInt("edge_int"); assert e.value.type() == "InvalidGraphProperty" # with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - # graph.getEdgePropertyArrayUInt("edge_double2", 0, 0); + # edge.getPropertyArrayUInt("edge_double2", 0); # assert e.value.type() == "InvalidGraphProperty" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.getEdgePropertyArrayUInt("edge_float3", 0); + edge.getPropertyArrayUInt("edge_float3"); assert e.value.type() == "InvalidGraphProperty" # Length with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.setVertexPropertyInt("vertex_int3", 0, 0); + vertex.setPropertyInt("vertex_int3", 0); assert e.value.type() == "InvalidGraphProperty" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.setVertexPropertyArrayInt("vertex_int3", 0, []); + vertex.setPropertyArrayInt("vertex_int3", []); assert e.value.type() == "InvalidGraphProperty" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.setVertexPropertyArrayInt("vertex_int3", 0, [1, 2]); + vertex.setPropertyArrayInt("vertex_int3", [1, 2]); assert e.value.type() == "InvalidGraphProperty" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.setEdgePropertyFloat("edge_float3", 0, 0); + edge.setPropertyFloat("edge_float3", 0); assert e.value.type() == "InvalidGraphProperty" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.setEdgePropertyArrayFloat("edge_float3", 0, []); + edge.setPropertyArrayFloat("edge_float3", []); assert e.value.type() == "InvalidGraphProperty" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.setEdgePropertyArrayFloat("edge_float3", 0, [1, 2]); + edge.setPropertyArrayFloat("edge_float3", [1, 2]); assert e.value.type() == "InvalidGraphProperty" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.getVertexPropertyInt("vertex_int3", 0); + vertex.getPropertyInt("vertex_int3"); assert e.value.type() == "InvalidGraphProperty" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidGraphProperty exception - graph.getEdgePropertyFloat("edge_float3", 0); + edge.getPropertyFloat("edge_float3"); assert e.value.type() == "InvalidGraphProperty" # Array Index # with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - # graph.setVertexPropertyArrayDouble("vertex_double2", 0, 3, 0); + # vertex.setPropertyArrayDouble("vertex_double2", 3, 0); # assert e.value.type() == "OutOfBoundsException" # with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - # graph.setEdgePropertyArrayDouble("edge_double2", 0, 3, 0); + # edge.setPropertyArrayDouble("edge_double2", 3, 0); # assert e.value.type() == "OutOfBoundsException" # with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - # graph.getVertexPropertyArrayDouble("vertex_double2", 0, 3); + # vertex.getPropertyArrayDouble("vertex_double2", 3); # assert e.value.type() == "OutOfBoundsException" # with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - # graph.getEdgePropertyArrayDouble("edge_double2", 0, 3); + # edge.getPropertyArrayDouble("edge_double2", 3); # assert e.value.type() == "OutOfBoundsException" # with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - # graph.setVertexPropertyArrayDouble("vertex_double2", 0, 3, 0); + # vertex.setPropertyArrayDouble("vertex_double2", 3, 0); # assert e.value.type() == "OutOfBoundsException" # with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - # graph.setEdgePropertyArrayDouble("edge_double2", 0, 3, 0); + # edge.setPropertyArrayDouble("edge_double2", 3, 0); # assert e.value.type() == "OutOfBoundsException" # Vertex/Edge Index with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - graph.setVertexID(11, 0); - assert e.value.type() == "OutOfBoundsException" + vertices[0]; + assert e.value.type() == "IDOutOfBounds" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - graph.setVertexPropertyFloat("vertex_float", 11, 0); - assert e.value.type() == "OutOfBoundsException" - # with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - # graph.setVertexPropertyArrayDouble("vertex_double2", 11, 0, 0); - # assert e.value.type() == "OutOfBoundsException" + vertex.setID(0) + assert e.value.type() == "IDOutOfBounds" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - graph.setVertexPropertyArrayInt("vertex_int3", 11, [1, 2, 3]); - assert e.value.type() == "OutOfBoundsException" + edges[0, 1]; + assert e.value.type() == "IDOutOfBounds" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - graph.setEdgeSource(11, 0); - assert e.value.type() == "OutOfBoundsException" + edges[1, 0]; + assert e.value.type() == "IDOutOfBounds" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - graph.setEdgeDestination(11, 0); - assert e.value.type() == "OutOfBoundsException" + edge.setSourceVertexID(0) + assert e.value.type() == "IDOutOfBounds" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - graph.setEdgeSourceDestination(11, 0, 0); - assert e.value.type() == "OutOfBoundsException" + edge.setDestinationVertexID(0) + assert e.value.type() == "IDOutOfBounds" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - graph.setEdgePropertyInt("edge_int", 11, 0); - assert e.value.type() == "OutOfBoundsException" - # with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - # graph.setEdgePropertyArrayDouble("edge_double2", 11, 0, 0); - # assert e.value.type() == "OutOfBoundsException" - with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - graph.setEdgePropertyArrayFloat("edge_float3", 11, [1, 2, 3]); - assert e.value.type() == "OutOfBoundsException" - with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - graph.getVertexID(11); - assert e.value.type() == "OutOfBoundsException" - with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - graph.getVertexPropertyFloat("vertex_float", 11); - assert e.value.type() == "OutOfBoundsException" - # with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - # graph.getVertexPropertyArrayDouble("vertex_double2", 11, 0); - # assert e.value.type() == "OutOfBoundsException" - with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - graph.getVertexPropertyArrayInt("vertex_int3", 11); - assert e.value.type() == "OutOfBoundsException" - with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - graph.getEdgeSource(11); - assert e.value.type() == "OutOfBoundsException" - with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - graph.getEdgeDestination(11); - assert e.value.type() == "OutOfBoundsException" + edge.setSourceDestinationVertexID(0, 1) + assert e.value.type() == "IDOutOfBounds" with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - graph.getEdgeSourceDestination(11); - assert e.value.type() == "OutOfBoundsException" - with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - graph.getEdgePropertyInt("edge_int", 11); - assert e.value.type() == "OutOfBoundsException" - # with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - # graph.getEdgePropertyArrayDouble("edge_double2", 11, 0); - # assert e.value.type() == "OutOfBoundsException" - with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::OutOfBoundsException - graph.getEdgePropertyArrayFloat("edge_float3", 11); - assert e.value.type() == "OutOfBoundsException" + edge.setSourceDestinationVertexID(1, 0) + assert e.value.type() == "IDOutOfBounds" class HostDeviceCheckGraph(pyflamegpu.HostFunction): def run(self, FLAMEGPU): @@ -416,24 +425,26 @@ def run(self, FLAMEGPU): graph = FLAMEGPU.environment.getDirectedGraph("graph"); graph.setVertexCount(5); graph.setEdgeCount(15); - k = int(0); + vertices = graph.vertices(); + edges = graph.edges(); for i in range(5): + vertices[i + 1]; for j in range(i + 1): - graph.setEdgePropertyID("src_copy", k, j); - graph.setEdgeSourceDestination(k, j, i); - k += 1; + edge = edges[j + 1, i + 1]; + edge.setPropertyID("src_copy", j); class HostTestEdgesIn(pyflamegpu.HostFunction): def run(self, FLAMEGPU): graph = FLAMEGPU.environment.getDirectedGraph("graph"); graph.setVertexCount(5); graph.setEdgeCount(15); - k = int(0); + vertices = graph.vertices(); + edges = graph.edges(); for i in range(5): + vertices[i + 1]; for j in range(i + 1): - graph.setEdgePropertyID("dest_copy", k, j); - graph.setEdgeSourceDestination(k, i, j); - k += 1; + edge = edges[i + 1, j + 1]; + edge.setPropertyID("dest_copy", j); class EnvironmentDirectedGraphTest(TestCase): def test_HostGetResetGet(self): @@ -482,7 +493,7 @@ def test_HostSetGet(self): # Set the graphs data to known data model.newLayer().addHostFunction(SetGraph().__disown__()); # Check the data persists - model.newLayer().addHostFunction(HostCheckGraph().__disown__()); + model.newLayer().addHostFunction(HostCheckSetGraph().__disown__()); sim = pyflamegpu.CUDASimulation(model); @@ -512,17 +523,17 @@ def test_HostException(self): CopyGraphToAgent1_func = """ FLAMEGPU_AGENT_FUNCTION(CopyGraphToAgent1, flamegpu::MessageNone, flamegpu::MessageNone) { - if (FLAMEGPU->getID() <= 20u) { - flamegpu::DeviceEnvironmentDirectedGraph graph = FLAMEGPU->environment.getDirectedGraph("graph"); - if (FLAMEGPU->getID() <= 10u) { - FLAMEGPU->setVariable("vertex_id", graph.getVertexID(FLAMEGPU->getID() - 1)); + if (FLAMEGPU->getID() <= 20) { + DeviceEnvironmentDirectedGraph graph = FLAMEGPU->environment.getDirectedGraph("graph"); + if (FLAMEGPU->getID() <= 10) { + FLAMEGPU->setVariable("vertex_id", graph.getVertexID(FLAMEGPU->getID() - 1)); FLAMEGPU->setVariable("vertex_float", graph.getVertexProperty("vertex_float", FLAMEGPU->getID() - 1)); FLAMEGPU->setVariable("vertex_double2", 0, graph.getVertexProperty("vertex_double2", FLAMEGPU->getID() - 1, 0)); FLAMEGPU->setVariable("vertex_double2", 1, graph.getVertexProperty("vertex_double2", FLAMEGPU->getID() - 1, 1)); // vertex_int3, device full array access not available, so skipped } - FLAMEGPU->setVariable("edge_source", graph.getEdgeSource(FLAMEGPU->getID() - 1)); - FLAMEGPU->setVariable("edge_dest", graph.getEdgeDestination(FLAMEGPU->getID() - 1)); + FLAMEGPU->setVariable("edge_source", graph.getVertexID(graph.getEdgeSource(FLAMEGPU->getID() - 1))); // Method returns index, convert back to ID + FLAMEGPU->setVariable("edge_dest", graph.getVertexID(graph.getEdgeDestination(FLAMEGPU->getID() - 1))); // Method returns index, convert back to ID FLAMEGPU->setVariable("edge_int", graph.getEdgeProperty("edge_int", FLAMEGPU->getID() - 1)); FLAMEGPU->setVariable("edge_double2", 0, graph.getEdgeProperty("edge_double2", FLAMEGPU->getID() - 1, 0)); FLAMEGPU->setVariable("edge_double2", 1, graph.getEdgeProperty("edge_double2", FLAMEGPU->getID() - 1, 1)); @@ -534,17 +545,17 @@ def test_HostException(self): CopyGraphToAgent3_func = """ FLAMEGPU_AGENT_FUNCTION(CopyGraphToAgent3, flamegpu::MessageNone, flamegpu::MessageNone) { - if (FLAMEGPU->getID() <= 60u) { - flamegpu::DeviceEnvironmentDirectedGraph graph = FLAMEGPU->environment.getDirectedGraph("graph"); - if (FLAMEGPU->getID() <= 30u) { - FLAMEGPU->setVariable("vertex_id", graph.getVertexID(FLAMEGPU->getID() - 1)); + if (FLAMEGPU->getID() <= 60) { + DeviceEnvironmentDirectedGraph graph = FLAMEGPU->environment.getDirectedGraph("graph"); + if (FLAMEGPU->getID() <= 30) { + FLAMEGPU->setVariable("vertex_id", graph.getVertexID(FLAMEGPU->getID() - 1)); FLAMEGPU->setVariable("vertex_float", graph.getVertexProperty("vertex_float", FLAMEGPU->getID() - 1)); FLAMEGPU->setVariable("vertex_double2", 0, graph.getVertexProperty("vertex_double2", FLAMEGPU->getID() - 1, 0)); FLAMEGPU->setVariable("vertex_double2", 1, graph.getVertexProperty("vertex_double2", FLAMEGPU->getID() - 1, 1)); // vertex_int3, device full array access not available, so skipped } - FLAMEGPU->setVariable("edge_source", graph.getEdgeSource(FLAMEGPU->getID() - 1)); - FLAMEGPU->setVariable("edge_dest", graph.getEdgeDestination(FLAMEGPU->getID() - 1)); + FLAMEGPU->setVariable("edge_source", graph.getVertexID(graph.getEdgeSource(FLAMEGPU->getID() - 1))); // Method returns index, convert back to ID + FLAMEGPU->setVariable("edge_dest", graph.getVertexID(graph.getEdgeDestination(FLAMEGPU->getID() - 1))); // Method returns index, convert back to ID FLAMEGPU->setVariable("edge_int", graph.getEdgeProperty("edge_int", FLAMEGPU->getID() - 1)); FLAMEGPU->setVariable("edge_double2", 0, graph.getEdgeProperty("edge_double2", FLAMEGPU->getID() - 1, 0)); FLAMEGPU->setVariable("edge_double2", 1, graph.getEdgeProperty("edge_double2", FLAMEGPU->getID() - 1, 1)); diff --git a/tests/test_cases/runtime/environment/test_environment_directed_graph.cu b/tests/test_cases/runtime/environment/test_environment_directed_graph.cu index 0b10c3b32..fa1a06751 100644 --- a/tests/test_cases/runtime/environment/test_environment_directed_graph.cu +++ b/tests/test_cases/runtime/environment/test_environment_directed_graph.cu @@ -372,10 +372,12 @@ FLAMEGPU_HOST_FUNCTION(HostException) { // Vertex/Edge Index EXPECT_THROW(vertices[ID_NOT_SET], exception::IDOutOfBounds); EXPECT_THROW(vertex.setID(ID_NOT_SET), exception::IDOutOfBounds); - EXPECT_THROW((edges[{ID_NOT_SET, 0}]), exception::IDOutOfBounds); - EXPECT_THROW((edges[{0, ID_NOT_SET}]), exception::IDOutOfBounds); + EXPECT_THROW((edges[{ID_NOT_SET, 1}]), exception::IDOutOfBounds); + EXPECT_THROW((edges[{1, ID_NOT_SET}]), exception::IDOutOfBounds); EXPECT_THROW(edge.setSourceVertexID(ID_NOT_SET), exception::IDOutOfBounds); EXPECT_THROW(edge.setDestinationVertexID(ID_NOT_SET), exception::IDOutOfBounds); + EXPECT_THROW(edge.setSourceDestinationVertexID(ID_NOT_SET, 1), exception::IDOutOfBounds); + EXPECT_THROW(edge.setSourceDestinationVertexID(1, ID_NOT_SET), exception::IDOutOfBounds); // Out of bounds EXPECT_THROW(vertices[2], exception::OutOfBoundsException); @@ -748,7 +750,6 @@ FLAMEGPU_HOST_FUNCTION(HostTestEdgesOut) { HostEnvironmentDirectedGraph graph = FLAMEGPU->environment.getDirectedGraph("graph"); graph.setVertexCount(5); graph.setEdgeCount(15); - int k = 0; auto vertices = graph.vertices(); auto edges = graph.edges(); for (int i = 0; i < 5; ++i) { @@ -779,7 +780,6 @@ FLAMEGPU_HOST_FUNCTION(HostTestEdgesIn) { HostEnvironmentDirectedGraph graph = FLAMEGPU->environment.getDirectedGraph("graph"); graph.setVertexCount(5); graph.setEdgeCount(15); - int k = 0; auto vertices = graph.vertices(); auto edges = graph.edges(); for (int i = 0; i < 5; ++i) {