Skip to content

Commit

Permalink
7/10 Python tests now pass.
Browse files Browse the repository at this point in the history
Failing tests all fail to compile agent fn.
  • Loading branch information
Robadob committed Oct 12, 2023
1 parent 0795729 commit e314d17
Show file tree
Hide file tree
Showing 3 changed files with 282 additions and 234 deletions.
61 changes: 49 additions & 12 deletions swig/python/flamegpu.i
Original file line number Diff line number Diff line change
Expand Up @@ -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
// -----------------

Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit e314d17

Please sign in to comment.