Peano
Loading...
Searching...
No Matches
Peano4DoubleArray.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
4from dastgen2.Utils import LLVMSymbol
5
6
8 """
9
10 Specialisation of dastgen2.attributes.DoubleArray which relies on
11 Peano's tarch. Therefore, things alike the vector initialisation
12 in the constructor do work.
13
14 """
15
16 def __init__(self, name, cardinality, valid_mantissa_bits=None, ifdefs=[]):
17 """
18 See superclass' constructor.
19
20 cardinality: String
21 This is important: It is not (necessarily) an integer, but can be
22 a string which is defined via a pragma or constexpr later.
23
24 """
25 super(Peano4DoubleArray, self).__init__(
26 name, cardinality, valid_mantissa_bits=valid_mantissa_bits, ifdefs=ifdefs
27 )
28 self._cardinality_cardinality = str(cardinality)
29
30 def get_methods(self, _full_qualified_class_name, for_declaration=True):
31 accessor_name = self._name_name[:1].title() + self._name_name[1:]
32 return [
33 (
34 "get" + accessor_name + "() const",
35 "tarch::la::Vector<" + self._cardinality_cardinality + ",double>",
36 ),
37 (
38 "set"
39 + accessor_name
40 + "(const tarch::la::Vector<"
42 + ",double>& value)",
43 "void",
44 ),
45 ("get" + accessor_name + "(int index) const", "double"),
46 ("set" + accessor_name + "(int index, double value)", "void"),
47 ]
48
52 def get_plain_C_attributes(self, for_constructor=False):
54 return [
55 (
56 "_" + self._name_name + "[" + self._cardinality_cardinality + "]",
57 "double",
58 "[[clang::truncate_mantissa("
60 + ")]]",
61 ["defined(" + LLVMSymbol + ")"],
62 ),
63 (
64 "_" + self._name_name,
65 "tarch::la::Vector<" + self._cardinality_cardinality + ",double>",
66 "",
67 ["!defined(" + LLVMSymbol + ")"],
68 ),
69 ]
70 else:
71 return [
72 (
73 "_" + self._name_name,
74 "tarch::la::Vector<" + self._cardinality_cardinality + ",double>",
75 )
76 ]
77
79 return [("_" + self._name_name + ".data()[0]", "double")]
80
82 return [
83 ("_" + self._name_name, "tarch::la::Vector<" + self._cardinality_cardinality + ",double>")
84 ]
85
86 def get_method_body(self, signature):
87 if self.use_data_store:
88 name = " _dataStore._" + self._name_name
89 else:
90 name = " _" + self._name_name
91 if (
92 signature.startswith("get")
93 and "index" in signature
95 ):
96 return " return " + name + "(index);\n"
97 elif (
98 signature.startswith("set")
99 and "index" in signature
101 ):
102 return name + "(index) = value;\n"
103 elif signature.startswith("get") and self._valid_mantissa_bits_valid_mantissa_bits_valid_mantissa_bits == None:
104 return " return " + name + ";\n"
105 elif signature.startswith("set") and self._valid_mantissa_bits_valid_mantissa_bits_valid_mantissa_bits == None:
106 return name + " = value;\n"
107 elif (
108 signature.startswith("get")
109 and "index" in signature
111 ):
112 return " return " + name + "[index];\n"
113 elif (
114 signature.startswith("set")
115 and "index" in signature
117 ):
118 return name + "[index] = value;\n"
119 elif signature.startswith("get") and self._valid_mantissa_bits_valid_mantissa_bits_valid_mantissa_bits != None:
120 return (
121 """
122 tarch::la::Vector<"""
124 + """,double> result;
125 for( int i=0; i<"""
127 + """; i++) {
128 result(i) = """
129 + name
130 + """[i];
131 }
132 return result;
133 """
134 )
135 elif signature.startswith("set") and self._valid_mantissa_bits_valid_mantissa_bits_valid_mantissa_bits != None:
136 return (
137 """
138 for( int i=0; i<"""
140 + """; i++) {
141 """
142 + name
143 + """[i] = value(i);
144 }
145 """
146 )
147 else:
148 assert False
149 return ""
150
152 return [("MPI_DOUBLE", self._cardinality_cardinality)]
153
154 def get_to_string(self):
155 """
156
157 Return string representation of attribute.
158
159 """
161 return "get" + self._name_name[0].upper() + self._name_name[1:] + "()"
162 elif self.use_data_store:
163 return "_dataStore._" + self._name_name
164 else:
165 return "_" + self._name_name
Specialisation of dastgen2.attributes.DoubleArray which relies on Peano's tarch.
get_constructor_arguments(self)
Return list of tuple of arguments for the constructor.
get_method_body(self, signature)
I hand in the method signature (see get_methods()) and wanna get the whole implementation.
get_to_string(self)
Return string representation of attribute.
get_methods(self, _full_qualified_class_name, for_declaration=True)
Return sequence of methods that are defined for this attribute.
get_first_plain_C_attribute(self)
For MPI for example, I need to know the first attribute.
get_native_MPI_type(self)
Return native (built-in) MPI datatype.
__init__(self, name, cardinality, valid_mantissa_bits=None, ifdefs=[])
See superclass' constructor.
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.