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 array using Peano's tarch
11
12 Specialisation of dastgen2.attributes.DoubleArray which relies on
13 Peano's tarch. Therefore, things alike the vector initialisation
14 in the constructor do work. We can also directly use Peano's linear
15 algebra operators.
16
17 This routine should include Vector and SmartPointerVector. I'm however
18 lazy here and assume that someone else will inject these includes, and
19 indeed Peano uses this class always in combination with MPIAndStorageAspect
20 which in turn includes the right headers.
21
22 """
23
24 def __init__(self,
25 name,
26 cardinality,
27 valid_mantissa_bits=None,
28 ifdefs=[],
29 ):
30 """
31 See superclass' constructor.
32
33 @param cardinality: String
34 This is important: It is not (necessarily) an integer, but can be
35 a string which is defined via a pragma or constexpr later.
36
37 """
38 super(Peano4DoubleArray, self).__init__(
39 name, cardinality, valid_mantissa_bits=valid_mantissa_bits, ifdefs=ifdefs
40 )
41 self._cardinality_cardinality = str(cardinality)
42
43 def get_methods(self, _full_qualified_class_name, for_declaration=True):
44 accessor_name = self._name_name[:1].title() + self._name_name[1:]
45 return [
46 (
47 "get" + accessor_name + "() const",
48 "tarch::la::Vector<" + self._cardinality_cardinality + ",double>",
49 ),
50 (
51 "set"
52 + accessor_name
53 + "(const tarch::la::Vector<"
55 + ",double>& value)",
56 "void",
57 ),
58 ("get" + accessor_name + "(int index) const", "double"),
59 ("set" + accessor_name + "(int index, double value)", "void"),
60 ]
61
65 def get_plain_C_attributes(self, for_constructor=False):
67 return [
68 (
69 "_" + self._name_name + "[" + self._cardinality_cardinality + "]",
70 "double",
71 "[[clang::truncate_mantissa("
73 + ")]]",
74 ["defined(" + LLVMSymbol + ")"],
75 ),
76 (
77 "_" + self._name_name,
78 "tarch::la::Vector<" + self._cardinality_cardinality + ",double>",
79 "",
80 ["!defined(" + LLVMSymbol + ")"],
81 ),
82 ]
83 else:
84 return [
85 (
86 "_" + self._name_name,
87 "tarch::la::Vector<" + self._cardinality_cardinality + ",double>",
88 )
89 ]
90
92 return [("_" + self._name_name + ".data()[0]", "double")]
93
95 return [
96 ("_" + self._name_name, "tarch::la::Vector<" + self._cardinality_cardinality + ",double>")
97 ]
98
99 def get_method_body(self, signature):
100 if self.use_data_store:
101 name = " _dataStore._" + self._name_name
102 else:
103 name = " _" + self._name_name
104 if (
105 signature.startswith("get")
106 and "index" in signature
108 ):
109 return " return " + name + "(index);\n"
110 elif (
111 signature.startswith("set")
112 and "index" in signature
114 ):
115 return name + "(index) = value;\n"
116 elif signature.startswith("get") and self._valid_mantissa_bits_valid_mantissa_bits_valid_mantissa_bits == None:
117 return " return " + name + ";\n"
118 elif signature.startswith("set") and self._valid_mantissa_bits_valid_mantissa_bits_valid_mantissa_bits == None:
119 return name + " = value;\n"
120 elif (
121 signature.startswith("get")
122 and "index" in signature
124 ):
125 return " return " + name + "[index];\n"
126 elif (
127 signature.startswith("set")
128 and "index" in signature
130 ):
131 return name + "[index] = value;\n"
132 elif signature.startswith("get") and self._valid_mantissa_bits_valid_mantissa_bits_valid_mantissa_bits != None:
133 return (
134 """
135 tarch::la::Vector<"""
137 + """,double> result;
138 for( int i=0; i<"""
140 + """; i++) {
141 result(i) = """
142 + name
143 + """[i];
144 }
145 return result;
146 """
147 )
148 elif signature.startswith("set") and self._valid_mantissa_bits_valid_mantissa_bits_valid_mantissa_bits != None:
149 return (
150 """
151 for( int i=0; i<"""
153 + """; i++) {
154 """
155 + name
156 + """[i] = value(i);
157 }
158 """
159 )
160 else:
161 assert False
162 return ""
163
165 return [("MPI_DOUBLE", self._cardinality_cardinality)]
166
167 def get_to_string(self):
168 """
169
170 Return string representation of attribute.
171
172 """
174 return "get" + self._name_name[0].upper() + self._name_name[1:] + "()"
175 elif self.use_data_store:
176 return "_dataStore._" + self._name_name
177 else:
178 return "_" + self._name_name
Specialisation of array using 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.