Device class¶
(Shortest import: from brian2.devices import Device)
-
class
brian2.devices.device.
Device
[source]¶ Bases:
object
Base Device object.
Attributes
network_schedule
The network schedule that this device supports. Methods
activate
([build_on_run])Called when this device is set as the current device. add_array
(var)Add an array to this device. build
(**kwds)For standalone projects, called when the project is ready to be built. code_object
(owner, name, abstract_code, …)code_object_class
([codeobj_class, fallback_pref])Return CodeObject
class according to input/default settingsfill_with_array
(var, arr)Fill an array with the values given in another array. get_array_name
(var[, access_data])Return a globally unique name for var()
.get_len
(array)Return the length of the array. init_with_arange
(var, start, dtype)Initialize an array with an integer range. init_with_zeros
(var, dtype)Initialize an array with zeros. insert_code
(slot, code)Insert code directly into a given slot in the device. insert_device_code
(slot, code)reinit
()Reinitialize the device. resize
(var, new_size)Resize a DynamicArrayVariable
.resize_along_first
(var, new_size)seed
([seed])Set the seed for the random number generator. spike_queue
(source_start, source_end)Create and return a new SpikeQueue
for thisDevice
.Details
-
network_schedule
¶ The network schedule that this device supports. If the device only supports a specific, fixed schedule, it has to set this attribute to the respective schedule (see
Network.schedule
for details). If it supports arbitrary schedules, it should be set toNone
(the default).
-
activate
(build_on_run=True, **kwargs)[source]¶ Called when this device is set as the current device.
-
add_array
(var)[source]¶ Add an array to this device.
Parameters: var :
ArrayVariable
The array to add.
-
build
(**kwds)[source]¶ For standalone projects, called when the project is ready to be built. Does nothing for runtime mode.
-
code_object
(owner, name, abstract_code, variables, template_name, variable_indices, codeobj_class=None, template_kwds=None, override_conditional_write=None)[source]¶
-
code_object_class
(codeobj_class=None, fallback_pref='codegen.target')[source]¶ Return
CodeObject
class according to input/default settingsParameters: codeobj_class : a
CodeObject
class, optionalIf this is keyword is set to None or no arguments are given, this method will return the default.
fallback_pref : str, optional
String describing which attribute of prefs to access to retrieve the ‘default’ target. Usually this is codegen.target, but in some cases we want to use object-specific targets such as codegen.string_expression_target.
Returns: codeobj_class : class
The
CodeObject
class that should be used
-
fill_with_array
(var, arr)[source]¶ Fill an array with the values given in another array.
Parameters: var :
ArrayVariable
The array to fill.
arr :
ndarray
The array values that should be copied to
var()
.
-
get_array_name
(var, access_data=True)[source]¶ Return a globally unique name for
var()
.Parameters: access_data : bool, optional
Returns: name : str
The name for
var()
.
-
get_len
(array)[source]¶ Return the length of the array.
Parameters: array :
ArrayVariable
The array for which the length is requested.
Returns: l : int
The length of the array.
-
init_with_arange
(var, start, dtype)[source]¶ Initialize an array with an integer range.
Parameters: var :
ArrayVariable
The array to fill with the integer range.
start : int
The start value for the integer range
dtype :
dtype
The data type to use for the array.
-
init_with_zeros
(var, dtype)[source]¶ Initialize an array with zeros.
Parameters: var :
ArrayVariable
The array to initialize with zeros.
dtype :
dtype
The data type to use for the array.
-
insert_code
(slot, code)[source]¶ Insert code directly into a given slot in the device. By default does nothing.
-
reinit
()[source]¶ Reinitialize the device. For standalone devices, clears all the internal state of the device.
-
resize
(var, new_size)[source]¶ Resize a
DynamicArrayVariable
.Parameters: var :
DynamicArrayVariable
The variable that should be resized.
new_size : int
The new size of the variable
-