Skip to content

Commit c3d1dac

Browse files
committed
revision class IncidenceMatrix
1 parent 0174643 commit c3d1dac

File tree

2 files changed

+18
-67
lines changed

2 files changed

+18
-67
lines changed

src/matrix.cpp

Lines changed: 12 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad).
3-
* Copyright (c) 2022-2023 Jochen Meidow, Fraunhofer IOSB
3+
* Copyright (c) 2022-2025 Jochen Meidow, Fraunhofer IOSB
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -18,68 +18,20 @@
1818

1919
#include "matrix.h"
2020

21-
#include<QDataStream>
21+
#include <QDataStream>
22+
#include <QtCompilerDetection>
23+
#include <qassert.h>
24+
25+
#include <Eigen/Core>
26+
#include <Eigen/SparseCore>
27+
2228
#include <vector>
2329

2430
namespace Graph {
2531

26-
// using Eigen::IOFormat;
27-
// using Eigen::DontAlignCols;
2832
using Eigen::Triplet;
2933
using Eigen::Index;
3034

31-
// const IOFormat IncidenceMatrix::fmt = IOFormat( 4, DontAlignCols, ", ", "\n", "| ", "|", "", ".\n");
32-
33-
34-
35-
/* void IncidenceMatrix::serialize( QDataStream &out ) const
36-
{
37-
// qDebug() << Q_FUNC_INFO
38-
39-
out << uint( rows() );
40-
out << uint( cols() );
41-
out << uint( nonZeros() );
42-
43-
for( Index c=0; c<outerSize(); ++c) {
44-
SparseMatrix<int,ColMajor>::InnerIterator it( *this, c);
45-
for( ; it; ++it) {
46-
out << int(it.row()) << int(it.col());
47-
}
48-
}
49-
}
50-
51-
52-
bool IncidenceMatrix::deserialize( QDataStream &in )
53-
{
54-
// qDebug() << Q_FUNC_INFO;
55-
56-
uint nrows;
57-
uint ncols;
58-
uint nnz;
59-
int r;
60-
int c;
61-
in >> nrows >> ncols >> nnz;
62-
63-
if ( nnz> UINT_MAX ) {
64-
return false;
65-
}
66-
67-
std::vector< Triplet<int> > tripletList;
68-
tripletList.reserve( nnz );
69-
for ( uint i=0; i<nnz; i++ ) {
70-
in >> r >> c;
71-
tripletList.emplace_back( Triplet<int>(r, c, 1) );
72-
}
73-
if ( in.status() != 0 ) {
74-
return false;
75-
}
76-
77-
resize( int(nrows), int(ncols) );
78-
setFromTriplets( tripletList.begin(),
79-
tripletList.end() );
80-
81-
return true;
82-
}*/
8335

8436

8537
bool IncidenceMatrix::isSet( const Index r, const Index c) const
@@ -102,8 +54,10 @@ SparseMatrix<int> IncidenceMatrix::biadjacency() const {
10254
for ( Index k = 0; k < outerSize(); ++k) {
10355
for (SparseMatrix<int>::InnerIterator it(*this,k); it; ++it)
10456
{
105-
tripletList.emplace_back( Triplet<int, Index>( it.row(), it.col() +R_, it.value() ));
106-
tripletList.emplace_back( Triplet<int, Index>( it.col() +R_, it.row(), it.value() ));
57+
// tripletList.emplace_back( Triplet<int, Index>( it.row(), it.col() +R_, it.value() ));
58+
// tripletList.emplace_back( Triplet<int, Index>( it.col() +R_, it.row(), it.value() ));
59+
tripletList.emplace_back( it.row(), it.col() +R_, it.value() );
60+
tripletList.emplace_back( it.col() +R_, it.row(), it.value() );
10761
}
10862
}
10963
AA.setFromTriplets( tripletList.begin(), tripletList.end() );

src/matrix.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad).
3-
* Copyright (c) 2022-2023 Jochen Meidow, Fraunhofer IOSB
3+
* Copyright (c) 2022-2025 Jochen Meidow, Fraunhofer IOSB
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -19,15 +19,15 @@
1919
#ifndef MATRIX_H
2020
#define MATRIX_H
2121

22+
#include <Eigen/Core>
2223
#include <Eigen/Dense>
23-
#include <Eigen/Sparse>
24+
#include <Eigen/SparseCore>
2425

2526
namespace Graph {
2627

2728
using Eigen::ColMajor;
2829
using Eigen::SparseMatrix;
2930
using Eigen::VectorXi;
30-
// using Eigen::IOFormat;
3131

3232
//! Sparse incidence matrix to encode relationships
3333
class IncidenceMatrix : public SparseMatrix<int, ColMajor, int>
@@ -41,9 +41,9 @@ class IncidenceMatrix : public SparseMatrix<int, ColMajor, int>
4141
return *this;
4242
}
4343

44-
VectorXi findInColumn( int c ) const; //!< Matlab: find(A(:,c))
45-
bool isSet( Index r, Index c) const; //!< Check if r and c are related
46-
SparseMatrix<int> biadjacency() const; //!< Create biadjacency matrix [O, A; A', O]
44+
[[nodiscard]] VectorXi findInColumn( int c ) const; //!< Matlab: find(A(:,c))
45+
[[nodiscard]] bool isSet( Index r, Index c) const; //!< Check if r and c are related
46+
[[nodiscard]] SparseMatrix<int> biadjacency() const; //!< Create biadjacency matrix [O, A; A', O]
4747

4848
void set( Index r, Index c) { coeffRef(r,c) = 1; } //!< Set relation (row r, column c)
4949
void unset( Index r, Index c) { coeffRef(r,c) = 0; } //!< Delete relation (row r, column c)
@@ -54,9 +54,6 @@ class IncidenceMatrix : public SparseMatrix<int, ColMajor, int>
5454

5555
//! Augment matrix by one row and one column
5656
void augment() { conservativeResize( rows()+1, cols()+1); }
57-
58-
private:
59-
// static const IOFormat fmt;
6057
};
6158

6259
} // namespace Graph

0 commit comments

Comments
 (0)