Skip to content

Commit

Permalink
[CORE] Fixed base class parameter property access
Browse files Browse the repository at this point in the history
On Windows with MSVC compiler the following error was raised error C2036: 'void *':
unknown size. The issue stems from how void* is being handled in your Cython code,
particularly the way parameters is accessed. On Windows, the MSVC compiler enforces
stricter type-checking and does not allow dereferencing a void* directly, which
causes errors like unknown size or invalid access.
  • Loading branch information
ShravanTata committed Dec 19, 2024
1 parent 93b2425 commit 922548b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
11 changes: 9 additions & 2 deletions farms_network/core/edge.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ cdef class PyEdge:
self.edge = <Edge*>malloc(sizeof(Edge))
if self.edge is NULL:
raise MemoryError("Failed to allocate memory for Edge")
self.edge.nparameters = 0

def __dealloc__(self):
if self.edge.source is not NULL:
Expand Down Expand Up @@ -84,5 +85,11 @@ cdef class PyEdge:

@property
def parameters(self):
""" Number of states in the network """
return self.edge.parameters[0]
"""Generic accessor for parameters."""
if not self.edge.parameters:
raise ValueError("Edge parameters are NULL")
if self.edge.nparameters == 0:
raise ValueError("No parameters available")

# The derived class should override this method to provide specific behavior
raise NotImplementedError("Base class does not define parameter handling")
12 changes: 10 additions & 2 deletions farms_network/core/node.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ cdef class PyNode:
self.node.model_type = strdup("base".encode('UTF-8'))
self.node.ode = ode
self.node.output = output
self.edge.nparameters = 0
self.edge.ninputs = 0

def __dealloc__(self):
if self.node.name is not NULL:
Expand Down Expand Up @@ -123,8 +125,14 @@ cdef class PyNode:

@property
def parameters(self):
""" Return a view of parameters in the network """
return self.node.parameters[0]
"""Generic accessor for parameters."""
if not self.node.parameters:
raise ValueError("Node parameters are NULL")
if self.node.nparameters == 0:
raise ValueError("No parameters available")

# The derived class should override this method to provide specific behavior
raise NotImplementedError("Base class does not define parameter handling")

# Methods to wrap the ODE and output functions
def ode(
Expand Down

0 comments on commit 922548b

Please sign in to comment.