-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathflamegpu.i
More file actions
703 lines (630 loc) · 28.7 KB
/
Copy pathflamegpu.i
File metadata and controls
703 lines (630 loc) · 28.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
%begin %{
// define SWIG_PYTHON_INTERPRETER_NO_DEBUG on windows debug builds as pythonXX_d is not packaged unless built from source
#ifdef _MSC_VER
#define SWIG_PYTHON_INTERPRETER_NO_DEBUG
#endif
%}
// Don't translate doxygen from doxygen format to pydoc format
%feature("doxygen:notranslate")
/* Compilation header includes */
%{
/* Includes the header in the wrapper code */
#include "flamegpu/flame_api.h"
#include "flamegpu/runtime/HostFunctionCallback.h"
%}
// supress known warnings
//#pragma SWIG nowarn=325,302,401
//#pragma SWIG nowarn=302
// string support
%include <stl.i>
%include <std_string.i>
%include <std_vector.i>
%include <std_unordered_map.i>
%include <std_array.i>
%include <std_list.i>
// typemaps for integer types (allows mapping of python types to stdint types)
%include <stdint.i>
%include "flamegpu/defines.h"
// Directors required for callback functions
%module(directors="1") pyflamegpu
/* Instantiate the vector types used in the templated variable functions. Types must match those in TEMPLATE_VARIABLE_INSTANTIATE and TEMPLATE_VARIABLE_INSTANTIATE_N macros*/
%template(Int8Vector) std::vector<int8_t>;
%template(Int16Vector) std::vector<int16_t>;
%template(Int32Vector) std::vector<int32_t>;
%template(Int64Vector) std::vector<int64_t>;
%template(UInt8Vector) std::vector<uint8_t>;
%template(UInt16Vector) std::vector<uint16_t>;
%template(UInt32Vector) std::vector<uint32_t>;
%template(UInt64Vector) std::vector<uint64_t>;
%template(FloatVector) std::vector<float>;
%template(DoubleVector) std::vector<double>;
//%template(BoolVector) std::vector<bool>;
//%template(DoubleVector) std::vector<double>;
/**
* TEMPLATE_VARIABLE_INSTANTIATE_FLOATS macro
* Expands for floating point types
*/
%define TEMPLATE_VARIABLE_INSTANTIATE_FLOATS(function, classfunction)
// float and double
%template(function ## Float) classfunction<float>;
%template(function ## Double) classfunction<double>;
%enddef
/**
* TEMPLATE_VARIABLE_INSTANTIATE macro
* Expands for int types
*/
%define TEMPLATE_VARIABLE_INSTANTIATE_INTS(function, classfunction)
// signed ints
%template(function ## Int16) classfunction<int16_t>;
%template(function ## Int32) classfunction<int32_t>;
%template(function ## Int64) classfunction<int64_t>;
// unsigned ints
%template(function ## UInt16) classfunction<uint16_t>;
%template(function ## UInt32) classfunction<uint32_t>;
%template(function ## UInt64) classfunction<uint64_t>;
// default int types
%template(function ## Int) classfunction<int>;
%template(function ## UInt) classfunction<unsigned int>;
%enddef
/**
* TEMPLATE_VARIABLE_INSTANTIATE macro
* Given a function name and a class::function specifier, this macro instaciates a typed version of the function for a set of basic types.
* E.g. TEMPLATE_VARIABLE_INSTANTIATE(function, SomeClass:function) will generate swig typed versions of the function like the following
* typedef SomeClass:function<int> functionInt;
* typedef SomeClass:function<float> functionFloat;
* ...
*/
%define TEMPLATE_VARIABLE_INSTANTIATE(function, classfunction)
TEMPLATE_VARIABLE_INSTANTIATE_FLOATS(function, classfunction)
TEMPLATE_VARIABLE_INSTANTIATE_INTS(function, classfunction)
// char types
%template(function ## Int8) classfunction<int8_t>;
%template(function ## UInt8) classfunction<uint8_t>;
%template(function ## Char) classfunction<char>;
%template(function ## UChar) classfunction<unsigned char>;
// bool type (not supported causes error)
//%template(function ## Bool) classfunction<bool>;
%enddef
/**
* Special case of the macro for message types
* This also maps ID to id_t, this should be synonymous with UInt/unsigned int
*/
%define TEMPLATE_VARIABLE_INSTANTIATE_ID(function, classfunction)
TEMPLATE_VARIABLE_INSTANTIATE(function, classfunction)
%template(function ## ID) classfunction<id_t>;
%enddef
/**
* TEMPLATE_SUM_INSTANTIATE macro
* Specific template expansion for sum which allows different return types to avoid range issues
* Return with same type is not Instantiated. I.e. All int type use 64 bit signed returned types
*/
%define TEMPLATE_SUM_INSTANTIATE(sum_class)
// float and double
%template(sumFloat) sum_class ## ::sum<float>;
%template(sumDouble) sum_class ## ::sum<double>;
// int types
%template(sumInt8) sum_class ## ::sumOutT<int8_t, int64_t>;
%template(sumUInt8) sum_class ## ::sumOutT<uint8_t, uint64_t>;
%template(sumInt16) sum_class ## ::sumOutT<int16_t, int64_t>;
%template(sumUInt16) sum_class ## ::sumOutT<uint16_t, uint64_t>;
%template(sumInt32) sum_class ## ::sumOutT<int32_t, int32_t>;
%template(sumUInt32) sum_class ## ::sumOutT<uint32_t, uint32_t>;
%template(sumInt64) sum_class ## ::sumOutT<int64_t, int64_t>;
%template(sumUInt64) sum_class ## ::sumOutT<uint64_t, uint64_t>;
// generic int types
%template(sumInt) sum_class ## ::sumOutT<int, int64_t>;
%template(sumUInt) sum_class ## ::sumOutT<unsigned int, uint64_t>;
// no chars or bool
%enddef
/* Custom Iterator to Swigify iterable types (RunPlanVec, AgentVector) */
%pythoncode %{
class FLAMEGPUIterator(object):
def __init__(self, pointerToVector):
self.pointerToVector = pointerToVector
self.index = -1
def __next__(self):
self.index += 1
if self.index < len(self.pointerToVector):
return self.pointerToVector[self.index]
else:
raise StopIteration
%}
/* Instantiate array types, these are required by message types when setting dimensions. */
%template(UIntArray2) std::array<unsigned int, 2>;
%template(UIntArray3) std::array<unsigned int, 3>;
/** Exception handling
* FGPURuntimeException class is a wrapper class to replace specific instances of FGPUException. It is constructed with a error mesage and type which can be queried to give the original error and the original exception class.
* The FGPURuntimeException is constructed form the original FGPUException in the handler and then translated into the python version.
* The approach avoids having to wrap every exception class which extends FGPUException
*/
%exceptionclass FGPURuntimeException;
// It was hoped that the following would provide a nice repr implementation of the Python FGPURuntimeException objects. It does not.
//%feature("python:slot", "tp_str", functype="reprfunc") FGPURuntimeException::what
%inline %{
class FGPURuntimeException : public std::exception {
public:
FGPURuntimeException(std::string msg, std::string type) {
err_message = msg;
type_str = type;
str_str = std::string("(") + type + ") " + msg;
}
const char* what() const noexcept {
return err_message.c_str();
}
const char* type() const {
return type_str.c_str();
}
const char* __str__() const {
return str_str.c_str();
}
protected:
std::string err_message;
std::string type_str;
std::string str_str;
};
%}
// Exception handling
%include "exception.i"
// swig director exceptions (handle python callback exceptions as C++ exceptions not Runtime errors)
%feature("director:except") {
if ($error != NULL) {
throw Swig::DirectorMethodException();
}
}
%exception {
try {
$action
}
catch (FGPUException& e) {
FGPURuntimeException *except = new FGPURuntimeException(std::string(e.what()), std::string(e.exception_type()));
PyObject *err = SWIG_NewPointerObj(except, SWIGTYPE_p_FGPURuntimeException, 1);
SWIG_Python_Raise(err, except.type(), SWIGTYPE_p_FGPURuntimeException);
SWIG_fail;
}
catch (Swig::DirectorException&) {
SWIG_fail;
}
catch(const std::exception& e) {
SWIG_exception(SWIG_RuntimeError, const_cast<char*>(e.what()) );
}
catch (...) {
SWIG_exception(SWIG_RuntimeError, "Unknown Exception");
}
}
/* Create some type objects to obtain sizes and type info of flamegpu2 basic types.
* It is not required to demangle type names. These can be used to compare directly with the type_index
* returned by the flamegpu2 library
*/
%nodefaultctor std::type_index;
%inline %{
namespace Types{
template <typename T>
struct type_info{
static unsigned int size(){
return sizeof(T);
}
static const char* typeName() {
return std::type_index(typeid(T)).name();
}
static T empty() {
return T();
}
static T fromValue(T value) {
return value;
}
};
const char* typeName(const std::type_index& type) {
return type.name();
}
}
%}
%template(IntType) Types::type_info<int>;
%template(Int8Type) Types::type_info<int8_t>;
%template(Int16Type) Types::type_info<int16_t>;
%template(Int32Type) Types::type_info<int32_t>;
%template(Int64Type) Types::type_info<int64_t>;
%template(UIntType) Types::type_info<unsigned int>;
%template(UInt8Type) Types::type_info<uint8_t>;
%template(UInt16Type) Types::type_info<uint16_t>;
%template(UInt32Type) Types::type_info<uint32_t>;
%template(UInt64Type) Types::type_info<uint64_t>;
%template(FloatType) Types::type_info<float>;
%template(DoubleType) Types::type_info<double>;
//%template(BoolType) Types::type_info<bool>;
/* Enable callback functions for step, exit and init through the use of "director" which allows Python -> C and C-> Python in callback.
* FGPU2 supports callback or function pointers so no special tricks are needed.
* To prevent raw pointer functions being exposed in Python these are ignored so only the callback versions are accessible.
*/
%feature("director") HostFunctionCallback;
%feature("director") HostFunctionConditionCallback;
%include "flamegpu/runtime/HostFunctionCallback.h"
/* Rather than input a header with lots of other function pointer stuff just inline declare the required enum */
enum FLAME_GPU_CONDITION_RESULT { CONTINUE, EXIT };
// Disable non RTC function and function condition set methods
%ignore AgentDescription::newFunction;
%ignore AgentFunctionDescription::getFunctionPtr;
%ignore AgentFunctionDescription::setFunctionCondition;
%ignore AgentFunctionDescription::getConditionPtr;
// Disable functions which allow raw C pointers in favour of callback objects
%ignore ModelDescription::addInitFunction;
%ignore ModelDescription::addStepFunction;
%ignore ModelDescription::addExitFunction;
%ignore ModelDescription::addExitCondition;
%ignore LayerDescription::addHostFunction;
/* Define ModelData and EnvironmentManager size type (as both are internal to the classes which are not a generated swig object) */
namespace ModelData{
typedef unsigned int size_type;
}
namespace EnvironmentManager{
typedef unsigned int size_type;
}
/* SWIG header includes used to generate wrappers */
%include "flamegpu/model/DependencyNode.h"
%include "flamegpu/model/DependencyGraph.h"
%include "flamegpu/model/HostFunctionDescription.h"
%include "flamegpu/model/ModelDescription.h"
%include "flamegpu/model/AgentDescription.h"
%include "flamegpu/model/AgentFunctionDescription.h"
%include "flamegpu/model/EnvironmentDescription.h"
%include "flamegpu/model/LayerDescription.h"
%include "flamegpu/model/SubModelDescription.h"
%include "flamegpu/model/SubAgentDescription.h"
%include "flamegpu/model/SubEnvironmentDescription.h"
/* DependencyNode template instantiations */
%template(dependsOn) DependencyNode::dependsOn<DependencyNode>;
/* Include AgentVector/AgentView/AgentInstance */
// Disable functions which use C++ iterators/type_index
%ignore AgentVector::const_iterator;
%ignore AgentVector::const_reverse_iterator;
%ignore AgentVector::iterator;
%ignore AgentVector::const_iterator;
%ignore AgentVector::reverse_iterator;
%ignore AgentVector::const_reverse_iterator;
%ignore AgentVector::begin;
%ignore AgentVector::cbegin;
%ignore AgentVector::end;
%ignore AgentVector::cend;
%ignore AgentVector::rbegin;
%ignore AgentVector::crbegin;
%ignore AgentVector::rend;
%ignore AgentVector::crend;
%ignore AgentVector::insert;
%ignore AgentVector::erase;
%ignore AgentVector::getVariableType;
%ignore AgentVector::getVariableMetaData;
%ignore AgentVector::data;
%rename(insert) AgentVector::py_insert;
%rename(erase) AgentVector::py_erase;
// Extend AgentVector so that it is python iterable
%extend AgentVector {
%pythoncode {
def __iter__(self):
return FLAMEGPUIterator(self)
def __len__(self):
return self.size()
}
AgentVector::Agent AgentVector::__getitem__(const int &index) {
if (index >= 0)
return $self->operator[](index);
return $self->operator[]($self->size() + index);
}
void AgentVector::__setitem__(const AgentVector::size_type &index, const AgentVector::Agent &value) {
$self->operator[](index).setData(value);
}
}
%include "flamegpu/pop/AgentVector.h"
%include "flamegpu/pop/AgentVector_Agent.h"
%include "flamegpu/pop/AgentInstance.h"
/* Include Simulation and CUDASimulation */
%feature("flatnested"); // flat nested on to ensure Config is included
%rename (CUDASimulation_Config) CUDASimulation::Config;
%rename (Simulation_Config) Simulation::Config;
%include <argcargv.i> // Include and apply to swig library healer for processing argc and argv values
%apply (int ARGC, char **ARGV) { (int argc, const char **) } // This is required for CUDASimulation.initialise()
%include "flamegpu/sim/Simulation.h"
%include "flamegpu/gpu/CUDASimulation.h"
%feature("flatnested", ""); // flat nested off
//%include "flamegpu/runtime/DeviceAPI.h"
%ignore VarOffsetStruct; // not required but defined in HostNewAgentAPI
%feature("valuewrapper") DeviceAgentVector;
%include "flamegpu/runtime/HostAPI.h"
%include "flamegpu/runtime/HostNewAgentAPI.h"
%ignore DeviceAgentVector_t; // Not required, internal
%ignore DeviceAgentVector_t::VariableBufferPair; // Not required, internal
// Disable functions which use C++ iterators/type_index
%ignore DeviceAgentVector::const_iterator;
%ignore DeviceAgentVector::const_reverse_iterator;
%ignore DeviceAgentVector::iterator;
%ignore DeviceAgentVector::const_iterator;
%ignore DeviceAgentVector::reverse_iterator;
%ignore DeviceAgentVector::const_reverse_iterator;
%ignore DeviceAgentVector::begin;
%ignore DeviceAgentVector::cbegin;
%ignore DeviceAgentVector::end;
%ignore DeviceAgentVector::cend;
%ignore DeviceAgentVector::rbegin;
%ignore DeviceAgentVector::crbegin;
%ignore DeviceAgentVector::rend;
%ignore DeviceAgentVector::crend;
%ignore DeviceAgentVector::insert;
%ignore DeviceAgentVector::erase;
%ignore DeviceAgentVector::getVariableType;
%ignore DeviceAgentVector::getVariableMetaData;
%ignore DeviceAgentVector::data;
%rename(insert) DeviceAgentVector::py_insert;
%rename(erase) DeviceAgentVector::py_erase;
// Extend DeviceAgentVector so that it is python iterable
%extend DeviceAgentVector {
%pythoncode {
def __iter__(self):
return FLAMEGPUIterator(self)
def __len__(self):
return self.size()
}
DeviceAgentVector::Agent DeviceAgentVector::__getitem__(const int &index) {
if (index >= 0)
return $self->operator[](index);
return $self->operator[]($self->size() + index);
}
void DeviceAgentVector::__setitem__(const size_type &index, const Agent &value) {
$self->operator[](index).setData(value);
}
}
%include "flamegpu/pop/DeviceAgentVector.h"
%include "flamegpu/runtime/HostAgentAPI.h"
/* Extend HostAgentAPI to add a templated version of the sum function (with differing return type) with a different name so this can be instantiated */
%extend HostAgentAPI{
template<typename InT, typename OutT> OutT HostAgentAPI::sumOutT(const std::string& variable) const {
return $self->sum<InT,OutT>(variable);
}
}
/* Extend HostRandom to add a templated version of the uniform function with a different name so this can be instantiated
* It is required to ingore the orginal defintion of uniform and seperate the two functions to have a distinct name
*/
%include "flamegpu/runtime/utility/HostRandom.cuh"
%ignore HostRandom::uniform;
%extend HostRandom{
template<typename T> inline T uniformRange(const T& min, const T& max) const {
return $self->uniform<T>(min, max);
}
template<typename T> inline T uniformNoRange() const {
return $self->uniform<T>();
}
}
%include "flamegpu/runtime/utility/HostEnvironment.cuh"
%include "flamegpu/runtime/AgentFunction_shim.h"
%include "flamegpu/runtime/AgentFunctionCondition_shim.h"
%feature("flatnested"); // flat nested on
// Ignore some of the internal host classes defined for messaging
%ignore *::Data;
%ignore *::CUDAModelHandler;
%ignore *::MetaData;
%rename (MsgBruteForce_Description) MsgBruteForce::Description;
%rename (MsgSpatial2D_Description) MsgSpatial2D::Description;
%rename (MsgSpatial3D_Description) MsgSpatial3D::Description;
%rename (MsgSpatial3D_MetaData) MsgSpatial3D::MetaData;
%rename (MsgArray_Description) MsgArray::Description;
%rename (MsgArray2D_Description) MsgArray2D::Description;
%rename (MsgArray3D_Description) MsgArray3D::Description;
%rename (MsgBucket_Description) MsgBucket::Description;
%include "flamegpu/runtime/messaging/None.h"
%include "flamegpu/runtime/messaging/None/NoneHost.h"
%include "flamegpu/runtime/messaging/BruteForce.h"
%include "flamegpu/runtime/messaging/BruteForce/BruteForceHost.h"
%include "flamegpu/runtime/messaging/Spatial2D.h"
%include "flamegpu/runtime/messaging/Spatial2D/Spatial2DHost.h"
%include "flamegpu/runtime/messaging/Spatial3D.h"
%include "flamegpu/runtime/messaging/Spatial3D/Spatial3DHost.h"
%include "flamegpu/runtime/messaging/Array.h"
%include "flamegpu/runtime/messaging/Array/ArrayHost.h"
%include "flamegpu/runtime/messaging/Array2D.h"
%include "flamegpu/runtime/messaging/Array2D/Array2DHost.h"
%include "flamegpu/runtime/messaging/Array3D.h"
%include "flamegpu/runtime/messaging/Array3D/Array3DHost.h"
%include "flamegpu/runtime/messaging/Bucket.h"
%include "flamegpu/runtime/messaging/Bucket/BucketHost.h"
%feature("flatnested", ""); // flat nested off
// Manually map all template type redirections defined by AgentLoggingConfig
%apply double { sum_input_t<float>::result_t, sum_input_t<double>::result_t }
%apply uint64_t { sum_input_t<char>::result_t, sum_input_t<uint8_t>::result_t, sum_input_t<uint16_t>::result_t, sum_input_t<uint32_t>::result_t, sum_input_t<uint64_t>::result_t }
%apply int64_t { sum_input_t<int8_t>::result_t, sum_input_t<int16_t>::result_t, sum_input_t<int32_t>::result_t, sum_input_t<int64_t>::result_t }
// Include logging implementations
%ignore flamegpu_internal;
%include "flamegpu/sim/LoggingConfig.h"
%include "flamegpu/sim/AgentLoggingConfig.h"
%include "flamegpu/sim/LogFrame.h"
%template(LogFrameList) std::list<LogFrame>;
// Extend RunPlanVec so that it is python iterable
%extend RunPlanVec {
%pythoncode {
def __iter__(self):
return FLAMEGPUIterator(self)
def __len__(self):
return self.size()
def insert(self, i, x):
if isinstance(i, int): # "insert" is used as if the vector is a Python list
self.insert(self, self.begin() + i, x)
else: # "insert" is used as if the vector is a native C++ container
return self.insert(self, i, x)
}
RunPlan &RunPlanVec::__getitem__(const int &index) {
if (index >= 0)
return $self->operator[](index);
return $self->operator[]($self->size() + index);
}
void RunPlanVec::__setitem__(const size_t &index, RunPlan &value) {
$self->operator[](index) = value;
}
}
// Include ensemble implementations
%include "flamegpu/sim/RunPlan.h"
%include "flamegpu/sim/RunPlanVec.h"
%feature("flatnested"); // flat nested on to ensure Config is included
%rename (CUDAEnsembleConfig) CUDAEnsemble::EnsembleConfig;
%include "flamegpu/gpu/CUDAEnsemble.h"
%feature("flatnested", ""); // flat nested off
%template(RunLogVec) std::vector<RunLog>;
// Instantiate template versions of agent functions from the API
TEMPLATE_VARIABLE_INSTANTIATE_ID(newVariable, AgentDescription::newVariable)
TEMPLATE_VARIABLE_INSTANTIATE_ID(newVariableArray, AgentDescription::newVariableArray)
// Instantiate template versions of AgentVector_Agent/AgentInstance from the API
TEMPLATE_VARIABLE_INSTANTIATE_ID(setVariable, AgentVector_Agent::setVariable)
TEMPLATE_VARIABLE_INSTANTIATE_ID(setVariableArray, AgentVector_Agent::setVariableArray)
TEMPLATE_VARIABLE_INSTANTIATE_ID(getVariable, AgentVector_Agent::getVariable)
TEMPLATE_VARIABLE_INSTANTIATE_ID(getVariableArray, AgentVector_Agent::getVariableArray)
TEMPLATE_VARIABLE_INSTANTIATE_ID(setVariable, AgentInstance::setVariable)
TEMPLATE_VARIABLE_INSTANTIATE_ID(setVariableArray, AgentInstance::setVariableArray)
TEMPLATE_VARIABLE_INSTANTIATE_ID(getVariable, AgentInstance::getVariable)
TEMPLATE_VARIABLE_INSTANTIATE_ID(getVariableArray, AgentInstance::getVariableArray)
// Instantiate template versions of host agent instance functions from the API
// Not currently supported: custom reductions, transformations or histograms
TEMPLATE_VARIABLE_INSTANTIATE(sort, HostAgentAPI::sort)
TEMPLATE_VARIABLE_INSTANTIATE(count, HostAgentAPI::count)
TEMPLATE_VARIABLE_INSTANTIATE(min, HostAgentAPI::min)
TEMPLATE_VARIABLE_INSTANTIATE(max, HostAgentAPI::max)
TEMPLATE_SUM_INSTANTIATE(HostAgentAPI)
// Instantiate template versions of host environment functions from the API
TEMPLATE_VARIABLE_INSTANTIATE_ID(getProperty, HostEnvironment::getProperty)
TEMPLATE_VARIABLE_INSTANTIATE_ID(getPropertyArray, HostEnvironment::getPropertyArray)
TEMPLATE_VARIABLE_INSTANTIATE_ID(setProperty, HostEnvironment::setProperty)
TEMPLATE_VARIABLE_INSTANTIATE_ID(setPropertyArray, HostEnvironment::setPropertyArray)
// Instantiate template versions of host agent functions from the API
TEMPLATE_VARIABLE_INSTANTIATE_ID(getVariable, HostNewAgentAPI::getVariable)
TEMPLATE_VARIABLE_INSTANTIATE_ID(getVariableArray, HostNewAgentAPI::getVariableArray)
TEMPLATE_VARIABLE_INSTANTIATE_ID(setVariable, HostNewAgentAPI::setVariable)
TEMPLATE_VARIABLE_INSTANTIATE_ID(setVariableArray, HostNewAgentAPI::setVariableArray)
// Instantiate template versions of environment description functions from the API
TEMPLATE_VARIABLE_INSTANTIATE_ID(newProperty, EnvironmentDescription::newProperty)
TEMPLATE_VARIABLE_INSTANTIATE_ID(newPropertyArray, EnvironmentDescription::newPropertyArray)
TEMPLATE_VARIABLE_INSTANTIATE_ID(getProperty, EnvironmentDescription::getProperty)
TEMPLATE_VARIABLE_INSTANTIATE_ID(getPropertyArray, EnvironmentDescription::getPropertyArray)
//TEMPLATE_VARIABLE_INSTANTIATE_ID(getPropertyAt, EnvironmentDescription::getPropertyArrayAtIndex)
TEMPLATE_VARIABLE_INSTANTIATE_ID(setProperty, EnvironmentDescription::setProperty)
TEMPLATE_VARIABLE_INSTANTIATE_ID(setPropertyArray, EnvironmentDescription::setPropertyArray)
// Instantiate template versions of RunPlan functions from the API
TEMPLATE_VARIABLE_INSTANTIATE_ID(setProperty, RunPlan::setProperty)
TEMPLATE_VARIABLE_INSTANTIATE_ID(setPropertyArray, RunPlan::setPropertyArray)
TEMPLATE_VARIABLE_INSTANTIATE_ID(getProperty, RunPlan::getProperty)
TEMPLATE_VARIABLE_INSTANTIATE_ID(getPropertyArray, RunPlan::getPropertyArray)
// Instantiate template versions of RunPlanVec functions from the API
TEMPLATE_VARIABLE_INSTANTIATE_ID(setProperty, RunPlanVec::setProperty)
TEMPLATE_VARIABLE_INSTANTIATE_ID(setPropertyArray, RunPlanVec::setPropertyArray)
TEMPLATE_VARIABLE_INSTANTIATE(setPropertyUniformDistribution, RunPlanVec::setPropertyUniformDistribution)
TEMPLATE_VARIABLE_INSTANTIATE(setPropertyUniformRandomDistribution, RunPlanVec::setPropertyUniformRandom)
TEMPLATE_VARIABLE_INSTANTIATE_FLOATS(setPropertyNormalRandomDistribution, RunPlanVec::setPropertyNormalRandom)
TEMPLATE_VARIABLE_INSTANTIATE_FLOATS(setPropertyLogNormalRandomDistribution, RunPlanVec::setPropertyLogNormalRandom)
// Instantiate template versions of AgentLoggingConfig functions from the API
TEMPLATE_VARIABLE_INSTANTIATE(logMean, AgentLoggingConfig::logMean)
TEMPLATE_VARIABLE_INSTANTIATE(logMin, AgentLoggingConfig::logMin)
TEMPLATE_VARIABLE_INSTANTIATE(logMax, AgentLoggingConfig::logMax)
TEMPLATE_VARIABLE_INSTANTIATE(logStandardDev, AgentLoggingConfig::logStandardDev)
TEMPLATE_VARIABLE_INSTANTIATE(logSum, AgentLoggingConfig::logSum)
// Instantiate template versions of LogFrame functions from the API
TEMPLATE_VARIABLE_INSTANTIATE_ID(getEnvironmentProperty, LogFrame::getEnvironmentProperty)
TEMPLATE_VARIABLE_INSTANTIATE_ID(getEnvironmentPropertyArray, LogFrame::getEnvironmentPropertyArray)
// Instantiate template versions of AgentLogFrame functions from the API
TEMPLATE_VARIABLE_INSTANTIATE(getMin, AgentLogFrame::getMin)
TEMPLATE_VARIABLE_INSTANTIATE(getMax, AgentLogFrame::getMax)
TEMPLATE_VARIABLE_INSTANTIATE(getSum, AgentLogFrame::getSum)
// Instantiate template versions of new and get message types from the API
%template(newMessageBruteForce) ModelDescription::newMessage<MsgBruteForce>;
%template(newMessageSpatial2D) ModelDescription::newMessage<MsgSpatial2D>;
%template(newMessageSpatial3D) ModelDescription::newMessage<MsgSpatial3D>;
%template(newMessageArray) ModelDescription::newMessage<MsgArray>;
%template(newMessageArray2D) ModelDescription::newMessage<MsgArray2D>;
%template(newMessageArray3D) ModelDescription::newMessage<MsgArray3D>;
%template(newMessageBucket) ModelDescription::newMessage<MsgBucket>;
%template(getMessageBruteForce) ModelDescription::getMessage<MsgBruteForce>;
%template(getMessageSpatial2D) ModelDescription::getMessage<MsgSpatial2D>;
%template(getMessageSpatial3D) ModelDescription::getMessage<MsgSpatial3D>;
%template(getMessageArray) ModelDescription::getMessage<MsgArray>;
%template(getMessageArray2D) ModelDescription::getMessage<MsgArray2D>;
%template(getMessageArray3D) ModelDescription::getMessage<MsgArray3D>;
%template(getMessageBucket) ModelDescription::getMessage<MsgBucket>;
// Instantiate template versions of message functions from the API
TEMPLATE_VARIABLE_INSTANTIATE_ID(newVariable, MsgBruteForce::Description::newVariable)
TEMPLATE_VARIABLE_INSTANTIATE_ID(newVariable, MsgSpatial2D::Description::newVariable)
TEMPLATE_VARIABLE_INSTANTIATE_ID(newVariable, MsgSpatial3D::Description::newVariable)
TEMPLATE_VARIABLE_INSTANTIATE_ID(newVariable, MsgArray::Description::newVariable)
TEMPLATE_VARIABLE_INSTANTIATE_ID(newVariable, MsgArray2D::Description::newVariable)
TEMPLATE_VARIABLE_INSTANTIATE_ID(newVariable, MsgArray3D::Description::newVariable)
TEMPLATE_VARIABLE_INSTANTIATE_ID(newVariable, MsgBucket::Description::newVariable)
// Instantiate template versions of host random functions from the API
TEMPLATE_VARIABLE_INSTANTIATE_FLOATS(uniform, HostRandom::uniformNoRange)
TEMPLATE_VARIABLE_INSTANTIATE_INTS(uniform, HostRandom::uniformRange)
TEMPLATE_VARIABLE_INSTANTIATE_FLOATS(normal, HostRandom::normal)
TEMPLATE_VARIABLE_INSTANTIATE_FLOATS(logNormal, HostRandom::logNormal)
// Optionally instantiate visualisation classes
#ifdef VISUALISATION
%{
#include "flamegpu/visualiser/visualiser_api.h"
#include "config/Stock.h"
%}
// SWIG is unable to wrap `Color::operator StaticColor()`
// Therefore we manually add two functions to handle the implict conversion
%extend AgentStateVis {
void AgentStateVis::setColor(const Color &cf) {
$self->setColor(cf);
}
}
%extend AgentVis {
void AgentVis::setColor(const Color &cf) {
$self->setColor(cf);
}
}
// Disable functions which return std::type_index
%ignore getAgentVariableRequiredType;
// Disable functions which use C++
%ignore Palette::const_iterator;
%ignore Palette::begin;
%ignore Palette::end;
%ignore Palette::colors; // This is protected, i've no idea why SWIG is trying to wrap it
// Extend Palette
%extend Palette {
%pythoncode {
def __iter__(self):
return FLAMEGPUIterator(self)
def __len__(self):
return self.size()
}
Color Palette::__getitem__(const int &index) {
if (index >= 0)
return $self->operator[](index);
return $self->operator[]($self->size() + index);
}
// Palettes are currently immutable
//void Palette::__setitem__(const AgentVector::size_type &index, const Color &value) {
// $self->operator[](index) = value;
//}
}
%include "flamegpu/visualiser/AgentStateVis.h"
%include "flamegpu/visualiser/AgentVis.h"
%include "flamegpu/visualiser/LineVis.h"
%include "flamegpu/visualiser/ModelVis.h"
%include "flamegpu/visualiser/StaticModelVis.h"
%include "flamegpu/visualiser/color/Color.h"
%include "flamegpu/visualiser/color/Palette.h"
%include "flamegpu/visualiser/color/DiscreteColor.h"
%include "flamegpu/visualiser/color/StaticColor.h"
%include "flamegpu/visualiser/color/HSVInterpolation.h"
%include "config/Stock.h"
// Manually create the two DiscretColor templates
%template(iDiscreteColor) DiscreteColor<int32_t>;
%template(uDiscreteColor) DiscreteColor<uint32_t>;
// This messes with a define, so must occur after all other files which might check VISUALISATION
// #define VISUALISATION false, still causes #ifdef VISUALISATION as true
// I tried `%inline %{const boolean VISUALISATION = false;%}` but swig didnt like it
#undef VISUALISATION
#define VISUALISATION true
#else
#define VISUALISATION false
#endif
#if defined(SEATBELTS) && SEATBELTS
#undef SEATBELTS
#define SEATBELTS true
#elif defined(SEATBELTS)
#undef SEATBELTS
#define SEATBELTS false
#else
#define SEATBELTS false
#endif