MCPcopy Create free account
hub / github.com/NGSolve/ngsolve / SetTupleScal

Method SetTupleScal

basiclinalg/python_bla.cpp:184–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

182 }
183
184 static void SetTupleScal( TMAT & self, py::tuple t, TSCAL val) {
185 py::object rows = t[0];
186 py::object cols = t[1];
187
188 // First element of tuple is of type int
189 if(py::isinstance<py::int_>(rows)) {
190 py::object row = py::cast( self.Row(rows.cast<int>()) );
191 row.attr("__setitem__")(cols,val);
192 return;
193 }
194
195 // Second element of tuple is of type int
196 if(py::isinstance<py::int_>(cols)) {
197 auto row_slice = rows.cast<py::slice>();
198 auto col = self.Col(cols.cast<int>());
199 size_t start, step, n;
200 InitSlice( row_slice, self.Height(), start, step, n );
201 for (int i=0; i<n; i++, start+=step)
202 col[start] = val;
203 return;
204 }
205
206 // Both elements are slices
207 try {
208 py::slice row_slice = rows.cast<py::slice> ();
209 size_t start, step, n;
210 InitSlice( row_slice, self.Height(), start, step, n );
211 for (int i=0; i<n; i++, start+=step) {
212 py::object row = py::cast(self.Row(start));
213 row.attr("__setitem__")(cols,val);
214 }
215 return;
216 } catch (py::error_already_set const &) {
217 cerr << "Invalid Matrix access!" << endl;
218 PyErr_Print();
219 }
220 }
221
222 static void SetTuple( TMAT & self, py::tuple t, const TMAT & rmat) {
223 py::object rows = t[0];

Callers

nothing calls this directly

Calls 4

InitSliceFunction · 0.85
RowMethod · 0.45
ColMethod · 0.45
HeightMethod · 0.45

Tested by

no test coverage detected