Peano
Loading...
Searching...
No Matches
Peano4IntegerArray.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 def __init__(self, name, cardinality, min_value=None, max_value=None, ifdefs=[]):
9 dastgen2.attributes.IntegerArray.__init__(
10 self, name, cardinality, min_value, max_value, ifdefs=ifdefs
11 )
12 self._cardinality_cardinality = str(cardinality)
13
14 def get_methods(self, _full_qualified_class_name, for_declaration=True):
15 accessor_name = self._name_name[:1].title() + self._name_name[1:]
16 return [
17 (
18 "get" + accessor_name + "() const",
19 "tarch::la::Vector<" + self._cardinality_cardinality + ",int>",
20 ),
21 (
22 "set"
23 + accessor_name
24 + "(const tarch::la::Vector<"
26 + ",int>& value)",
27 "void",
28 ),
29 ("get" + accessor_name + "(int index) const", "int"),
30 ("set" + accessor_name + "(int index, int value)", "void"),
31 ]
32
33 def get_plain_C_attributes(self, for_constructor=False):
34 if self.compress:
35 return [
36 (
37 "_" + self._name_name + "[" + self._cardinality_cardinality + "]",
38 "int",
39 "[[clang::pack_range("
41 + ","
43 + ")]]",
44 ["defined(" + LLVMSymbol + ")"],
45 ),
46 (
47 "_" + self._name_name,
48 "tarch::la::Vector<" + self._cardinality_cardinality + ",int>",
49 "",
50 ["!defined(" + LLVMSymbol + ")"],
51 ),
52 ]
53 else:
54 return [
55 ("_" + self._name_name, "tarch::la::Vector<" + self._cardinality_cardinality + ",int>")
56 ]
57
59 return [("_" + self._name_name + ".data()[0]", "int")]
60
62 return [("_" + self._name_name, "tarch::la::Vector<" + self._cardinality_cardinality + ",int>")]
63
65 return not self.compress
66
67 def get_method_body(self, signature):
68 if self.use_data_store:
69 name = " _dataStore._" + self._name_name
70 else:
71 name = " _" + self._name_name
72
73 if signature.startswith("get") and "index" in signature and not self.compress:
74 return " return " + name + "(index);\n"
75 elif signature.startswith("set") and "index" in signature and not self.compress:
76 return name + "(index) = value;\n"
77 elif signature.startswith("get") and "index" in signature and not self.compress:
78 return " return " + name + "(index);\n"
79 elif signature.startswith("set") and "index" in signature and not self.compress:
80 return name + "(index) = value;\n"
81 elif signature.startswith("get") and not self.compress:
82 return " return " + name + ";\n"
83 elif signature.startswith("set") and not self.compress:
84 return name + " = value;\n"
85
86 elif signature.startswith("get") and "index" in signature:
87 return " return " + name + "[index];\n"
88 elif signature.startswith("set") and "index" in signature:
89 return name + "[index] = value;\n"
90 elif signature.startswith("get"):
91 return (
92 """
93 tarch::la::Vector<"""
95 + """,int> result;
96 for( int i=0; i<"""
98 + """; i++) {
99 result(i) = """
100 + name
101 + """[i];
102 }
103 return result;
104 """
105 )
106 elif signature.startswith("set"):
107 return (
108 """
109 for( int i=0; i<"""
111 + """; i++) {
112 """
113 + name
114 + """[i] = value(i);
115 }
116 """
117 )
118 else:
119 assert False, "signature=" + signature
120
121 return ""
122
124 return [("MPI_INT", self._cardinality_cardinality)]
125
126 def get_to_string(self):
127 """
128
129 Return string representation of attribute.
130
131 """
132 if self.compress:
133 return "get" + self._name_name[0].upper() + self._name_name[1:] + "()"
134 elif self.use_data_store:
135 return "_dataStore._" + self._name_name
136 else:
137 return "_" + self._name_name
get_constructor_arguments(self)
Return list of tuple of arguments for the constructor.
get_to_string(self)
Return string representation of attribute.
get_native_MPI_type(self)
Return native (built-in) MPI datatype.
get_plain_C_attributes(self, for_constructor=False)
Return list of n-tuples.
get_methods(self, _full_qualified_class_name, for_declaration=True)
Return sequence of methods that are defined for this attribute.
use_default_copy_constructor(self)
Cannot use the default copy constructor, as it is an array, i.e.
get_method_body(self, signature)
I hand in the method signature (see get_methods()) and wanna get the whole implementation.
get_first_plain_C_attribute(self)
For MPI for example, I need to know the first attribute.
__init__(self, name, cardinality, min_value=None, max_value=None, ifdefs=[])
min_value: None or integer value Has to be smaller than max_value.