Skip to content

Commit

Permalink
py wheel now builds, just need to test it
Browse files Browse the repository at this point in the history
Expect I will need to override the function for accessing the map as operator[] is unlikely to naturally overload.
  • Loading branch information
Robadob committed Oct 11, 2023
1 parent 9cf0262 commit 0795729
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,6 @@ class HostEnvironmentDirectedGraph {
* It is necessary to first call setEdgeCount() to initialise the storage for edges
*/
EdgeMap edges();
#ifdef SWIG
template<typename T>
void setVertexPropertyArray(const std::string& property_name, unsigned int vertex_index, const std::vector<T>& property_value) const;
template<typename T>
std::vector<T> getVertexPropertyArray(const std::string& property_name, unsigned int vertex_index) const;
template<typename T>
void setEdgePropertyArray(const std::string& property_name, unsigned int vertex_index, const std::vector<T>& property_value) const;
template<typename T>
std::vector<T> getEdgePropertyArray(const std::string& property_name, unsigned int edge_index) const;
#endif
#ifdef FLAMEGPU_ADVANCED_API
/**
* Returns a shared_ptr to the CUDAEnvironmentDirectedGraphBuffers object which allows direct access to the graph's buffers
Expand Down Expand Up @@ -184,6 +174,13 @@ class HostEnvironmentDirectedGraph {
T getProperty(const std::string& property_name, unsigned int element_index) const;
template<typename T, flamegpu::size_type N>
std::array<T, N> getProperty(const std::string& property_name) const;

#ifdef SWIG
template<typename T>
void setPropertyArray(const std::string& property_name, const std::vector<T>& property_value) const;
template<typename T>
std::vector<T> getPropertyArray(const std::string& property_name) const;
#endif
};
};
/**
Expand Down Expand Up @@ -267,66 +264,53 @@ class HostEnvironmentDirectedGraph {
T getProperty(const std::string& property_name, unsigned int element_index) const;
template<typename T, flamegpu::size_type N>
std::array<T, N> getProperty(const std::string& property_name) const;
#ifdef SWIG
template<typename T>
void setPropertyArray(const std::string& property_name, const std::vector<T>& property_value) const;
template<typename T>
std::vector<T> getPropertyArray(const std::string& property_name) const;
#endif
};
};
};

#ifdef SWIG
template<typename T>
void HostEnvironmentDirectedGraph::setVertexPropertyArray(const std::string& property_name, const unsigned int vertex_index, const std::vector<T>& property_value) const {
if (const auto dg = directed_graph.lock()) {
size_type n = property_value.size();
T* val = dg->getVertexPropertyBuffer<T>(property_name, n, stream);
if (!property_value.size()) {
THROW exception::InvalidGraphProperty("Vertex property with name '%s' length mismatch '%u' != '%u', in CUDAEnvironmentDirectedGraphBuffers::setVertexPropertyArray()",
property_name.c_str(), n, static_cast<unsigned int>(property_value.size()));
}
const size_type vertex_count = dg->getVertexCount();
if (vertex_index >= vertex_count) {
THROW exception::OutOfBoundsException("Vertex index %u is out of range %u, in HostEnvironmentDirectedGraph::setEdgePropertyArray()\n",
vertex_index, vertex_count);
} else {
memcpy(val + vertex_index * property_value.size(), property_value.data(), sizeof(T) * property_value.size());
}
} else {
THROW exception::ExpiredWeakPtr("Graph nolonger exists, weak pointer could not be locked, in HostEnvironmentDirectedGraph::setEdgePropertyArray()\n");
void HostEnvironmentDirectedGraph::VertexMap::Vertex::setPropertyArray(const std::string& property_name, const std::vector<T>& property_value) const {
// Get index
const unsigned int vertex_index = directed_graph->getVertexIndex(vertex_id);
size_type n = property_value.size();
T* val = directed_graph->getVertexPropertyBuffer<T>(property_name, n, stream);
if (!property_value.size()) {
THROW exception::InvalidGraphProperty("Vertex property with name '%s' length mismatch '%u' != '%u', in HostEnvironmentDirectedGraph::VertexMap::Vertex::setPropertyArray()",
property_name.c_str(), n, static_cast<unsigned int>(property_value.size()));
}
const size_type vertex_count = directed_graph->getVertexCount();
memcpy(val + vertex_index * property_value.size(), property_value.data(), sizeof(T) * property_value.size());
}
template<typename T>
std::vector<T> HostEnvironmentDirectedGraph::getVertexPropertyArray(const std::string& property_name, const unsigned int vertex_index) const {
if (const auto dg = directed_graph.lock()) {
return dg->getVertexPropertyArray<T>(property_name, vertex_index, stream);
} else {
THROW exception::ExpiredWeakPtr("Graph nolonger exists, weak pointer could not be locked, in HostEnvironmentDirectedGraph::getVertexPropertyArray()\n");
}
std::vector<T> HostEnvironmentDirectedGraph::VertexMap::Vertex::getPropertyArray(const std::string& property_name) const {
// Get index
const unsigned int vertex_index = directed_graph->getVertexIndex(vertex_id);
return directed_graph->getVertexPropertyArray<T>(property_name, vertex_index, stream);
}
template<typename T>
void HostEnvironmentDirectedGraph::setEdgePropertyArray(const std::string& property_name, const unsigned int edge_index, const std::vector<T>& property_value) const {
if (const auto dg = directed_graph.lock()) {
size_type n = property_value.size();
T* val = dg->getEdgePropertyBuffer<T>(property_name, n, stream);
if (!property_value.size()) {
THROW exception::InvalidGraphProperty("Edge property with name '%s' length mismatch '%u' != '%u', in CUDAEnvironmentDirectedGraphBuffers::setEdgePropertyArray()",
property_name.c_str(), n, static_cast<unsigned int>(property_value.size()));
}
const size_type edge_count = dg->getEdgeCount();
if (edge_index >= edge_count) {
THROW exception::OutOfBoundsException("Edge index %u is out of range %u, in HostEnvironmentDirectedGraph::getEdgePropertyArray()\n",
edge_index, edge_count);
} else {
memcpy(val + edge_index * property_value.size(), property_value.data(), sizeof(T) * property_value.size());
}
} else {
THROW exception::ExpiredWeakPtr("Graph nolonger exists, weak pointer could not be locked, in HostEnvironmentDirectedGraph::getEdgePropertyArray()\n");
void HostEnvironmentDirectedGraph::EdgeMap::Edge::setPropertyArray(const std::string& property_name, const std::vector<T>& property_value) const {
// Get index
const unsigned int edge_index = directed_graph->getEdgeIndex(source_vertex_id, destination_vertex_id);
size_type n = property_value.size();
T* val = directed_graph->getEdgePropertyBuffer<T>(property_name, n, stream);
if (!property_value.size()) {
THROW exception::InvalidGraphProperty("Edge property with name '%s' length mismatch '%u' != '%u', in HostEnvironmentDirectedGraph::EdgeMap::Edge::setPropertyArray()",
property_name.c_str(), n, static_cast<unsigned int>(property_value.size()));
}
memcpy(val + edge_index * property_value.size(), property_value.data(), sizeof(T) * property_value.size());
}
template<typename T>
std::vector<T> HostEnvironmentDirectedGraph::getEdgePropertyArray(const std::string& property_name, const unsigned int edge_index) const {
if (const auto dg = directed_graph.lock()) {
return dg->getEdgePropertyArray<T>(property_name, edge_index, stream);
} else {
THROW exception::ExpiredWeakPtr("Graph nolonger exists, weak pointer could not be locked, in HostEnvironmentDirectedGraph::getEdgePropertyArray()\n");
}
std::vector<T> HostEnvironmentDirectedGraph::EdgeMap::Edge::getPropertyArray(const std::string& property_name) const {
// Get index
const unsigned int edge_index = directed_graph->getEdgeIndex(source_vertex_id, destination_vertex_id);
return directed_graph->getEdgePropertyArray<T>(property_name, edge_index, stream);
}
#endif

Expand Down
33 changes: 21 additions & 12 deletions swig/python/flamegpu.i
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,12 @@ class FLAMEGPURuntimeException : public std::exception {

// Renames which require flatnested, as swig/python does not support nested classes.
%feature("flatnested"); // flat nested on to ensure Config is included
%rename (HostEnvironmentDirectedGraph_Vertex) flamegpu::HostEnvironmentDirectedGraph::VertexMap::Vertex;
%rename (HostEnvironmentDirectedGraph_Edge) flamegpu::HostEnvironmentDirectedGraph::EdgeMap::Edge;
%rename (HostEnvironmentDirectedGraph_VertexMap) flamegpu::HostEnvironmentDirectedGraph::VertexMap;
%rename (HostEnvironmentDirectedGraph_EdgeMap) flamegpu::HostEnvironmentDirectedGraph::EdgeMap;


%rename (CUDASimulation_Config) flamegpu::CUDASimulation::Config;
%rename (Simulation_Config) flamegpu::Simulation::Config;

Expand Down Expand Up @@ -651,7 +657,10 @@ class ModelVis;
%ignore flamegpu::EnvironmentDirectedGraphData;
%ignore flamegpu::CUDAEnvironmentDirectedGraphBuffers;
%include "flamegpu/model/EnvironmentDirectedGraphDescription.cuh"
%feature("flatnested"); // flat nested on to maps and children are included
%include "flamegpu/runtime/environment/HostEnvironmentDirectedGraph.cuh"
%feature("flatnested", ""); // flat nested off



%include "flamegpu/model/EnvironmentDescription.h"
Expand Down Expand Up @@ -955,18 +964,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::setVertexProperty)
TEMPLATE_VARIABLE_INSTANTIATE_ID(setEdgeProperty, flamegpu::HostEnvironmentDirectedGraph::setEdgeProperty)
TEMPLATE_VARIABLE_INSTANTIATE_ID(getVertexProperty, flamegpu::HostEnvironmentDirectedGraph::getVertexProperty)
TEMPLATE_VARIABLE_INSTANTIATE_ID(getEdgeProperty, flamegpu::HostEnvironmentDirectedGraph::getEdgeProperty)
TEMPLATE_VARIABLE_ARRAY_INSTANTIATE_ID(setVertexProperty, flamegpu::HostEnvironmentDirectedGraph::setVertexProperty)
TEMPLATE_VARIABLE_ARRAY_INSTANTIATE_ID(setEdgeProperty, flamegpu::HostEnvironmentDirectedGraph::setEdgeProperty)
TEMPLATE_VARIABLE_ARRAY_INSTANTIATE_ID(getVertexProperty, flamegpu::HostEnvironmentDirectedGraph::getVertexProperty)
TEMPLATE_VARIABLE_ARRAY_INSTANTIATE_ID(getEdgeProperty, flamegpu::HostEnvironmentDirectedGraph::getEdgeProperty)
TEMPLATE_VARIABLE_INSTANTIATE_ID(setVertexPropertyArray, flamegpu::HostEnvironmentDirectedGraph::setVertexPropertyArray)
TEMPLATE_VARIABLE_INSTANTIATE_ID(setEdgePropertyArray, flamegpu::HostEnvironmentDirectedGraph::setEdgePropertyArray)
TEMPLATE_VARIABLE_INSTANTIATE_ID(getVertexPropertyArray, flamegpu::HostEnvironmentDirectedGraph::getVertexPropertyArray)
TEMPLATE_VARIABLE_INSTANTIATE_ID(getEdgePropertyArray, flamegpu::HostEnvironmentDirectedGraph::getEdgePropertyArray)
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)

// Instantiate template versions of RunPlan functions from the API
TEMPLATE_VARIABLE_INSTANTIATE_ID(setProperty, flamegpu::RunPlan::setProperty)
Expand Down

0 comments on commit 0795729

Please sign in to comment.