Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ci/scripts/requirements.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#!/bin/env python
import os


def deps():
import toml

c = toml.load("pyproject.toml")
requires = c["build-system"]["requires"]
develop = c["project"]["optional-dependencies"]["develop"]
return requires + develop


def main():
ret = os.system("python -m pip install --prefer-binary toml")
if ret != 0:
Expand Down
1 change: 1 addition & 0 deletions conda/dev-environment-unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies:
- cyrus-sasl
- deprecated
- docutils<0.22.1
- numba-cfunc-compiler>=1.0.0
- exprtk
- flex
- graphviz
Expand Down
1 change: 1 addition & 0 deletions conda/dev-environment-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies:
- cyrus-sasl
- deprecated
- docutils<0.22.1
- numba-cfunc-compiler>=1.0.0
- exprtk
# - flex # not available on windows
- graphviz
Expand Down
2 changes: 1 addition & 1 deletion cpp/csp/engine/CppNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class CppNode : public csp::Node
if( nodedef.outputs.size() > OutputId::maxOutputs() )
CSP_THROW( ValueError, "number of outputs exceeds limit of " << OutputId::maxOutputs() << " on node " << name() );

return csp::NodeDef{ INOUT_ID_TYPE( nodedef.inputs.size() ), INOUT_ID_TYPE( nodedef.outputs.size() ) };
return csp::NodeDef{ nodedef.inputs.size(), nodedef.outputs.size() };
}

void validateNodeDef() const
Expand Down
12 changes: 10 additions & 2 deletions cpp/csp/engine/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ class InputAdapter;

struct NodeDef
{
NodeDef( INOUT_ID_TYPE numIn, INOUT_ID_TYPE numOut ) : numInputs( numIn ), numOutputs( numOut )
{}
NodeDef( size_t numIn, size_t numOut )
{
if( numIn > InputId::maxId() )
CSP_THROW( ValueError, "number of inputs exceeds limit of " << InputId::maxId() );
if( numOut > OutputId::maxId() )
CSP_THROW( ValueError, "number of outputs exceeds limit of " << OutputId::maxId() );

numInputs = static_cast<INOUT_ID_TYPE>( numIn );
numOutputs = static_cast<INOUT_ID_TYPE>( numOut );
}

INOUT_ID_TYPE numInputs;
INOUT_ID_TYPE numOutputs;
Expand Down
1 change: 1 addition & 0 deletions cpp/csp/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ add_library(cspimpl SHARED
PyInputProxy.cpp
PyNode.cpp
PyNodeWrapper.cpp
NumbaStructFFI.cpp
PyNumbaNode.cpp
PyNumpyAdapter.cpp
PyOutputAdapter.cpp
Expand Down
45 changes: 45 additions & 0 deletions cpp/csp/python/NumbaStructFFI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <csp/core/Platform.h>
#include <csp/engine/CspEnum.h>
#include <csp/engine/Struct.h>
#include <csp/python/PyStruct.h>

#include <algorithm>
#include <cstdint>

namespace csp::python
{

extern "C" CSPIMPL_EXPORT int64_t csp_numba_struct_enum_field_value( const void * struct_ptr, int64_t field_offset ) noexcept
{
const char * bytes = static_cast<const char *>( struct_ptr );
return reinterpret_cast<const CspEnum *>( bytes + field_offset ) -> value();
}

extern "C" CSPIMPL_EXPORT int8_t csp_numba_struct_enum_field_set(
void * struct_ptr, int64_t field_offset, int64_t value, const void * struct_type ) noexcept
{
const auto * pyStructMeta = static_cast<const PyStructMeta *>( struct_type );
if( !struct_ptr || !pyStructMeta || !pyStructMeta -> structMeta || field_offset < 0 )
return 0;

const auto & fields = pyStructMeta -> structMeta -> fields();
auto fieldIt = std::find_if( fields.begin(), fields.end(), [field_offset]( const auto & field )
{
return field -> offset() == static_cast<size_t>( field_offset );
} );
if( fieldIt == fields.end() || ( *fieldIt ) -> type() -> type() != CspType::Type::ENUM )
return 0;

try
{
const auto * enumType = static_cast<const CspEnumType *>( ( *fieldIt ) -> type().get() );
( *fieldIt ) -> setValue<CspEnum>( static_cast<Struct *>( struct_ptr ), enumType -> meta() -> create( value ) );
return 1;
}
catch( ... )
{
return 0;
}
}

} // namespace csp::python
Loading
Loading