Peano
Loading...
Searching...
No Matches
Double.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
4
5
7 """!
8
9 cardinality is a string (you can thus use symbols as well as long as
10 they will be defined at compile time). Pass None if you are working
11 with a scalar.
12
13 """
14
16 self,
17 name,
18 valid_mantissa_bits=None,
19 ifdefs=[],
20 qualifier=Attribute.Qualifier.NONE,
21 initval=None,
22 ):
23 """
24
25 @Pawel Can you add some docu?
26
27 """
28
29 # Do we need to expose this attribute in the header file?
30 # Only necessary for functions that will be inlined, i.e. constexpr
31 expose = qualifier == Attribute.Qualifier.CONSTEXPR
32
33 Attribute.__init__(
34 self,
35 name,
36 ifdefs,
37 qualifier=qualifier,
38 initval=initval,
39 expose_in_header_file=expose,
40 )
41 self._valid_mantissa_bits = valid_mantissa_bits
42
43 return
44
45 def get_methods(self, _full_qualified_class_name, for_declaration=True):
46 accessor_name = self.get_accessor_name()
47 methods = []
48
49 if self._is_static:
50 if for_declaration:
51 # No 'const' here: static member function cannot have 'const' qualifier
52 getter = ("get" + accessor_name + "()", "static double")
53 else:
54 # No 'static' here: 'static' can only be specified inside the class definition
55 getter = ("get" + accessor_name + "()", "double")
56
57 elif self._is_const_static:
58 if for_declaration:
59 # No 'const' here: static member function cannot have 'const' qualifier
60 getter = ("get" + accessor_name + "()", "static double")
61 else:
62 # No 'static' here: 'static' can only be specified inside the class definition
63 # No 'const' here either: function definition will then differ from that in declaration
64 getter = ("get" + accessor_name + "()", "double")
65
66 elif self._is_const:
67 getter = ("get" + accessor_name + "() const", "const double")
68
70 getter = ("get" + accessor_name + "() const", "constexpr double")
71
72 else:
73 # default case.
74 getter = ("get" + accessor_name + "() const", "double")
75
76 methods.append(getter)
77
78 # Add a setter method, if it makes sense.
80 methods.append(("set" + accessor_name + "(double value)", "void"))
81
82 return methods
83
84 def get_plain_C_attributes(self, for_constructor=False):
85 typestring = "double"
86 namestring = "_" + self._name
87
88 # add const/static qualifiers and initialization values, if needed
89 if self._is_static:
90 typestring = "inline static double"
91 if self._initval is not None:
92 namestring += " = " + str(self._initval)
93
94 elif self._is_const_static:
95 typestring = "inline const static double"
96 namestring += " = " + str(self._initval)
97
98 elif self._is_const:
99 typestring = "const double"
100 namestring += " = " + str(self._initval)
101
103 typestring = "constexpr static double"
104 namestring += " = " + str(self._initval)
105
106 else:
107 # default case
108 # If an initial value is provided, add it
109 # However, only add it if we need it for a definition,
110 # not as optional argument for constructor method
111 if self._initval is not None and not for_constructor:
112 namestring += " = " + str(self._initval)
113
114 # Set up compression/packaging
115 if self._valid_mantissa_bits is None:
116 return [(namestring, typestring, "")]
117 else:
118 mantissastring = (
119 "[[clang::truncate_mantissa(" + str(self._valid_mantissa_bits) + ")]]"
120 )
121 return [(namestring, typestring, mantissastring)]
122
123 def get_method_body(self, signature):
124 if signature.startswith("get") and self.use_data_store:
125 return " return _dataStore._" + self._name + ";\n"
126 elif signature.startswith("get") and not self.use_data_store:
127 return " return _" + self._name + ";\n"
128 elif signature.startswith("set") and self.use_data_store:
129 return " _dataStore._" + self._name + " = value;\n"
130 elif signature.startswith("set") and not self.use_data_store:
131 return " _" + self._name + " = value;\n"
132 else:
133 assert False
134 return ""
135
137 return [("MPI_DOUBLE", 1)]
138
139 def get_to_string(self):
140 """
141
142 Return string representation of attribute.
143
144 """
145 if self.use_data_store:
146 return "_dataStore._" + self._name
147 else:
148 return "_" + self._name
149
150 @property
152 return self._valid_mantissa_bits
153
154 @valid_mantissa_bits.setter
155 def valid_mantissa_bits(self, value):
156 """!
157
158 Set mantissa used
159
160 Pass in None, if you want to use the default accuracy.
161
162 """
163 assert value == None or value > 0
164 self._valid_mantissa_bits = value
Represents one attribute.
Definition Attribute.py:8
get_accessor_name(self)
Generate the accessor name used throughout dastgen2 to create variables, function names,...
Definition Attribute.py:259
cardinality is a string (you can thus use symbols as well as long as they will be defined at compile ...
Definition Double.py:6
get_to_string(self)
Return string representation of attribute.
Definition Double.py:139
get_method_body(self, signature)
I hand in the method signature (see get_methods()) and wanna get the whole implementation.
Definition Double.py:123
get_plain_C_attributes(self, for_constructor=False)
Return list of n-tuples.
Definition Double.py:84
get_native_MPI_type(self)
Return native (built-in) MPI datatype.
Definition Double.py:136
__init__(self, name, valid_mantissa_bits=None, ifdefs=[], qualifier=Attribute.Qualifier.NONE, initval=None)
@Pawel Can you add some docu?
Definition Double.py:22
get_methods(self, _full_qualified_class_name, for_declaration=True)
Return sequence of methods that are defined for this attribute.
Definition Double.py:45