MCPcopy Create free account
hub / github.com/ERGO-Code/HiGHS / assessMatrixDimensions

Function assessMatrixDimensions

highs/util/HighsMatrixUtils.cpp:313–380  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

311}
312
313HighsStatus assessMatrixDimensions(const HighsLogOptions& log_options,
314 const HighsInt num_vec,
315 const bool partitioned,
316 const vector<HighsInt>& matrix_start,
317 const vector<HighsInt>& matrix_p_end,
318 const vector<HighsInt>& matrix_index,
319 const vector<double>& matrix_value) {
320 bool ok = true;
321 // Assess main dimensions
322 const bool legal_num_vec = num_vec >= 0;
323 if (!legal_num_vec)
324 highsLogUser(
325 log_options, HighsLogType::kError,
326 "Matrix dimension validation fails on number of vectors = %d < 0\n",
327 (int)num_vec);
328 ok = legal_num_vec && ok;
329 const bool legal_matrix_start_size =
330 (HighsInt)matrix_start.size() >= num_vec + 1;
331 if (!legal_matrix_start_size) {
332 highsLogUser(log_options, HighsLogType::kError,
333 "Matrix dimension validation fails on start size = %d < %d = "
334 "num vectors + 1\n",
335 (int)matrix_start.size(), (int)(num_vec + 1));
336 }
337 ok = legal_matrix_start_size && ok;
338 if (partitioned) {
339 const bool legal_matrix_p_end_size =
340 (HighsInt)matrix_p_end.size() >= num_vec + 1;
341 if (!legal_matrix_p_end_size)
342 highsLogUser(log_options, HighsLogType::kError,
343 "Matrix dimension validation fails on p_end size = %d < %d "
344 "= num vectors + 1\n",
345 (int)matrix_p_end.size(), (int)(num_vec + 1));
346 ok = (HighsInt)matrix_p_end.size() >= num_vec + 1 && ok;
347 }
348 // Possibly check the sizes of the index and value vectors. Can only
349 // do this with the number of nonzeros, and this is only known if
350 // the start vector has a legal size. Setting num_nz = 0 otherwise
351 // means that all tests pass, as they just check that the sizes of
352 // the index and value vectors are non-negative.
353 const HighsInt num_nz = legal_matrix_start_size ? matrix_start[num_vec] : 0;
354 if (num_nz >= 0) {
355 const bool legal_matrix_index_size =
356 (HighsInt)matrix_index.size() >= num_nz;
357 if (!legal_matrix_index_size)
358 highsLogUser(log_options, HighsLogType::kError,
359 "Matrix dimension validation fails on index size = %d < %d "
360 "= number of nonzeros\n",
361 (int)matrix_index.size(), (int)num_nz);
362 ok = legal_matrix_index_size && ok;
363 const bool legal_matrix_value_size =
364 (HighsInt)matrix_value.size() >= num_nz;
365 if (!legal_matrix_value_size)
366 highsLogUser(log_options, HighsLogType::kError,
367 "Matrix dimension validation fails on value size = %d < %d "
368 "= number of nonzeros\n",
369 (int)matrix_value.size(), (int)num_nz);
370 ok = legal_matrix_value_size && ok;

Callers 3

assessHessianDimensionsFunction · 0.85
lpDimensionsOkFunction · 0.85
assessMatrixFunction · 0.85

Calls 2

highsLogUserFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected