Peano
Loading...
Searching...
No Matches
DoubleArray.py
Go to the documentation of this file.
1# This file is part of the DaStGen2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3from .Attribute import Attribute
4from .Double import Double
5
6
8 """
9 An array of doubles, i.e. a vector in the mathematical sense
10
11
12 :Arguments:
13
14 name: String
15 Name of this vector
16
17 cardinality: String
18 Cardinality of data. This has to be a string. Therefore it can be a
19 symbol, i.e. a name defined via ifdef somewhere in your code.
20
21 """
22
24 self,
25 name,
26 cardinality,
27 valid_mantissa_bits=None,
28 ifdefs=[],
29 qualifier=Attribute.Qualifier.NONE,
30 initval=None,
31 ):
32 if qualifier != Attribute.Qualifier.NONE:
33 raise NotImplementedError(
34 f"Attribute {name}: This data type can't work with qualifiers (yet)"
35 )
36 if initval is not None:
37 raise NotImplementedError(
38 f"Attribute {name}: Can't generate arrays with initial values (yet)."
39 )
40 Double.__init__(self, name, ifdefs=ifdefs, qualifier=qualifier, initval=initval)
41
42 self._cardinality = str(cardinality)
44
46 """
47
48 Cannot use the default copy constructor, as it is an array,
49 i.e. we need some manual deep copying.
50
51 """
52 return False
53
54 def get_methods(self, _full_qualified_class_name, for_declaration=True):
55 accessor_name = self._name[:1].title() + self._name[1:]
56 return [
57 ("get" + accessor_name + "() const", "const double*"),
58 (
59 "set"
60 + accessor_name
61 + "(const double value["
62 + self._cardinality
63 + "])",
64 "void",
65 ),
66 ("get" + accessor_name + "(int index) const", "double"),
67 ("set" + accessor_name + "(int index, double value)", "void"),
68 ]
69
70 def get_plain_C_attributes(self, for_constructor=False):
72 return [
73 (
74 "_" + self._name + "[" + self._cardinality + "]",
75 "double",
76 "[[clang::truncate_mantissa("
78 + ")]]",
79 )
80 ]
81 else:
82 return [("_" + self._name + "[" + self._cardinality + "]", "double", "")]
83
85 return [("_" + self._name + "[0]", "double")]
86
87 def get_method_body(self, signature):
88 if self.use_data_store:
89 name = " _dataStore._" + self._name
90 else:
91 name = " _" + self._name
92 if signature.startswith("get") and "index" in signature:
93 return " return " + name + "[index];\n"
94 elif signature.startswith("set") and "index" in signature:
95 return name + "[index] = value;\n"
96 elif signature.startswith("get"):
97 return " return " + name + ";\n"
98 elif signature.startswith("set"):
99 return " std::copy_n(value, " + self._cardinality + ", " + name + " );\n"
100 else:
101 assert False
102 return ""
103
105 return [("MPI_DOUBLE", self._cardinality)]
106
107 def get_to_string(self):
108 """
109
110 Return string representation of attribute.
111
112 """
113 if self.use_data_store:
114 return "_dataStore._" + self._name + '[0] << ",..."'
115 else:
116 return "_" + self._name + '[0] << ",..."'
117
118 @property
122 @valid_mantissa_bits.setter
123 def valid_mantissa_bits(self, value):
124 """!
125
126 Set mantissa used
127
128 Pass in None, if you want to use the default accuracy.
129
130 """
131 assert value == None or value > 0
get_first_plain_C_attribute(self)
For MPI for example, I need to know the first attribute.
get_methods(self, _full_qualified_class_name, for_declaration=True)
Return sequence of methods that are defined for this attribute.
get_to_string(self)
Return string representation of attribute.
get_native_MPI_type(self)
Return native (built-in) MPI datatype.
get_method_body(self, signature)
I hand in the method signature (see get_methods()) and wanna get the whole implementation.
use_default_copy_constructor(self)
Cannot use the default copy constructor, as it is an array, i.e.
get_plain_C_attributes(self, for_constructor=False)
Return list of n-tuples.
__init__(self, name, cardinality, valid_mantissa_bits=None, ifdefs=[], qualifier=Attribute.Qualifier.NONE, initval=None)
@Pawel Can you add some docu?
cardinality is a string (you can thus use symbols as well as long as they will be defined at compile ...
Definition Double.py:6