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

Method GenerateCode

fem/tensorcoefficient.cpp:1232–1315  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1230 }
1231
1232 void EinsumCoefficientFunction::GenerateCode(
1233 Code &code, FlatArray<int> inputs, int index,
1234 bool skip_zeroes) const
1235 {
1236 if (node)
1237 {
1238 node->GenerateCode(code, inputs, index);
1239 return;
1240 }
1241
1242 LocalHeap lh(100000, "TP code gen");
1243
1244 Array<FlatArray<int>> input_dims(cfs.Size());
1245 Array<Vector<bool>> nz_vecs_mem;
1246 FlatArray<Vector<bool>> nz_vecs;
1247 if (nz_inputs.Size())
1248 nz_vecs.Assign(nz_inputs);
1249 else
1250 nz_vecs_mem.SetSize(cfs.Size());
1251
1252 for (size_t i: Range(cfs)) {
1253 if (nz_vecs_mem.Size())
1254 nz_vecs[i] = nonzero_pattern(cfs[i]);
1255 const auto dims_i = cfs[i]->Dimensions();
1256 input_dims[i].Assign(dims_i.Size(), lh);
1257 input_dims[i] = dims_i;
1258 }
1259 if (nz_vecs_mem.Size())
1260 nz_vecs.Assign(nz_vecs);
1261
1262 Vector<bool> result_nz_mem{};
1263 FlatVector<bool> result_nz_vec;
1264
1265 if (nz_result.Size())
1266 result_nz_vec.AssignMemory(nz_result.Size(), nz_result.Data());
1267 else {
1268 auto this_cv = const_cast<EinsumCoefficientFunction *>(this);
1269 result_nz_mem = nonzero_pattern(this_cv->shared_from_this());
1270 result_nz_vec.AssignMemory(result_nz_mem.Size(), result_nz_mem.Data());
1271 }
1272
1273 const FlatArray<int> result_dims = Dimensions();
1274
1275 FlatArray<bool> declared(index_maps.Height(), lh);
1276 declared = false;
1277
1278 const bool sparse_eval = get_option(options, "sparse_evaluation", sparse_evaluation_default);
1279 const auto cres = cfs.Size();
1280 for (size_t I: Range(declared)) {
1281 const auto I_map = index_maps.Row(I);
1282 const auto res_idx = I_map(cres);
1283
1284 if (skip_zeroes && !result_nz_vec[res_idx])
1285 continue;
1286
1287 CodeExpr s;
1288
1289 if (!sparse_eval || result_nz_vec[res_idx]) {

Callers

nothing calls this directly

Calls 15

nonzero_patternFunction · 0.85
DimensionsFunction · 0.85
get_optionFunction · 0.85
VarFunction · 0.85
DimensionsMethod · 0.80
SMethod · 0.80
DeclareMethod · 0.80
RangeFunction · 0.50
SizeMethod · 0.45
AssignMethod · 0.45
SetSizeMethod · 0.45
AssignMemoryMethod · 0.45

Tested by

no test coverage detected