Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tnl-dev
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
TNL
tnl-dev
Commits
c6d1173d
There was an error fetching the commit references. Please try again later.
Commit
c6d1173d
authored
4 years ago
by
Jakub Klinkovský
Committed by
Tomáš Oberhuber
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Ported SparseOperations to segments
parent
0d3b8798
No related branches found
No related tags found
1 merge request
!58
To/matrices
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Python/pytnl/tnl/SparseMatrix.cpp
+3
-2
3 additions, 2 deletions
src/Python/pytnl/tnl/SparseMatrix.cpp
src/TNL/Matrices/SparseOperations_impl.h
+18
-27
18 additions, 27 deletions
src/TNL/Matrices/SparseOperations_impl.h
with
21 additions
and
29 deletions
src/Python/pytnl/tnl/SparseMatrix.cpp
+
3
−
2
View file @
c6d1173d
...
...
@@ -21,10 +21,11 @@ void export_SparseMatrices( py::module & m )
export_Matrix
<
E_host
>
(
m
,
"Ellpack"
);
export_Matrix
<
SE_host
>
(
m
,
"SlicedEllpack"
);
// TODO: copySparseMatrix does not work with Legacy matrices anymore
//m.def("copySparseMatrix", &TNL::Matrices::copySparseMatrix< CSR_host, E_host >);
//m.def("copySparseMatrix", &TNL::Matrices::copySparseMatrix< E_host, CSR_host >);
//m.def("copySparseMatrix", &TNL::Matrices::copySparseMatrix< CSR_host, SE_host >);
//m.def("copySparseMatrix", &TNL::Matrices::copySparseMatrix< SE_host, CSR_host >);
m
.
def
(
"copySparseMatrix"
,
&
TNL
::
Matrices
::
copySparseMatrix
<
E_host
,
SE_host
>
);
m
.
def
(
"copySparseMatrix"
,
&
TNL
::
Matrices
::
copySparseMatrix
<
SE_host
,
E_host
>
);
//
m.def("copySparseMatrix", &TNL::Matrices::copySparseMatrix< E_host, SE_host >);
//
m.def("copySparseMatrix", &TNL::Matrices::copySparseMatrix< SE_host, E_host >);
}
This diff is collapsed.
Click to expand it.
src/TNL/Matrices/SparseOperations_impl.h
+
18
−
27
View file @
c6d1173d
...
...
@@ -36,11 +36,10 @@ SparseMatrixSetRowLengthsVectorKernel( Vector* rowLengths,
const
IndexType
gridSize
=
blockDim
.
x
*
gridDim
.
x
;
while
(
rowIdx
<
rows
)
{
const
auto
max_length
=
matrix
->
getRowLengthFast
(
rowIdx
);
const
auto
row
=
matrix
->
getRow
(
rowIdx
);
IndexType
length
=
0
;
for
(
IndexType
c_j
=
0
;
c_j
<
max_length
;
c_j
++
)
if
(
row
.
get
Element
Column
(
c_j
)
<
cols
)
for
(
IndexType
c_j
=
0
;
c_j
<
row
.
getSize
()
;
c_j
++
)
if
(
row
.
getColumn
Index
(
c_j
)
<
cols
)
length
++
;
else
break
;
...
...
@@ -66,7 +65,7 @@ SparseMatrixCopyKernel( Matrix1* A,
const
auto
rowB
=
B
->
getRow
(
rowIdx
);
auto
rowA
=
A
->
getRow
(
rowIdx
);
for
(
IndexType
c
=
0
;
c
<
length
;
c
++
)
rowA
.
setElement
(
c
,
rowB
.
get
Element
Column
(
c
),
rowB
.
get
Element
Value
(
c
)
);
rowA
.
setElement
(
c
,
rowB
.
getColumn
Index
(
c
),
rowB
.
getValue
(
c
)
);
rowIdx
+=
gridSize
;
}
}
...
...
@@ -102,11 +101,10 @@ copySparseMatrix_impl( Matrix1& A, const Matrix2& B )
#pragma omp parallel for if( Devices::Host::isOMPEnabled() )
#endif
for
(
IndexType
i
=
0
;
i
<
rows
;
i
++
)
{
const
auto
max_length
=
B
.
getRowLength
(
i
);
const
auto
row
=
B
.
getRow
(
i
);
IndexType
length
=
0
;
for
(
IndexType
c_j
=
0
;
c_j
<
max_length
;
c_j
++
)
if
(
row
.
get
Element
Column
(
c_j
)
<
cols
)
for
(
IndexType
c_j
=
0
;
c_j
<
row
.
getSize
()
;
c_j
++
)
if
(
row
.
getColumn
Index
(
c_j
)
<
cols
)
length
++
;
else
break
;
...
...
@@ -122,7 +120,7 @@ copySparseMatrix_impl( Matrix1& A, const Matrix2& B )
const
auto
rowB
=
B
.
getRow
(
i
);
auto
rowA
=
A
.
getRow
(
i
);
for
(
IndexType
c
=
0
;
c
<
length
;
c
++
)
rowA
.
setElement
(
c
,
rowB
.
get
Element
Column
(
c
),
rowB
.
get
Element
Value
(
c
)
);
rowA
.
setElement
(
c
,
rowB
.
getColumn
Index
(
c
),
rowB
.
getValue
(
c
)
);
}
}
...
...
@@ -228,11 +226,10 @@ copyAdjacencyStructure( const Matrix& A, AdjacencyMatrix& B,
rowLengths
.
setSize
(
N
);
rowLengths
.
setValue
(
0
);
for
(
IndexType
i
=
0
;
i
<
A
.
getRows
();
i
++
)
{
const
int
maxLength
=
A
.
getRowLength
(
i
);
const
auto
row
=
A
.
getRow
(
i
);
IndexType
length
=
0
;
for
(
int
c_j
=
0
;
c_j
<
maxLength
;
c_j
++
)
{
const
IndexType
j
=
row
.
get
Element
Column
(
c_j
);
for
(
int
c_j
=
0
;
c_j
<
row
.
getSize
()
;
c_j
++
)
{
const
IndexType
j
=
row
.
getColumn
Index
(
c_j
);
if
(
j
>=
A
.
getColumns
()
)
break
;
length
++
;
...
...
@@ -248,10 +245,9 @@ copyAdjacencyStructure( const Matrix& A, AdjacencyMatrix& B,
// set non-zeros
for
(
IndexType
i
=
0
;
i
<
A
.
getRows
();
i
++
)
{
const
int
maxLength
=
A
.
getRowLength
(
i
);
const
auto
row
=
A
.
getRow
(
i
);
for
(
int
c_j
=
0
;
c_j
<
maxLength
;
c_j
++
)
{
const
IndexType
j
=
row
.
get
Element
Column
(
c_j
);
for
(
int
c_j
=
0
;
c_j
<
row
.
getSize
()
;
c_j
++
)
{
const
IndexType
j
=
row
.
getColumn
Index
(
c_j
);
if
(
j
>=
A
.
getColumns
()
)
break
;
if
(
!
ignore_diagonal
||
i
!=
j
)
...
...
@@ -282,11 +278,10 @@ reorderSparseMatrix( const Matrix1& matrix1, Matrix2& matrix2, const Permutation
typename
Matrix2
::
CompressedRowLengthsVector
rowLengths
;
rowLengths
.
setSize
(
matrix1
.
getRows
()
);
for
(
IndexType
i
=
0
;
i
<
matrix1
.
getRows
();
i
++
)
{
const
IndexType
maxLength
=
matrix1
.
getRowLength
(
perm
[
i
]
);
const
auto
row
=
matrix1
.
getRow
(
perm
[
i
]
);
IndexType
length
=
0
;
for
(
IndexType
j
=
0
;
j
<
maxLength
;
j
++
)
if
(
row
.
get
Element
Column
(
j
)
<
matrix1
.
getColumns
()
)
for
(
IndexType
j
=
0
;
j
<
row
.
getSize
()
;
j
++
)
if
(
row
.
getColumn
Index
(
j
)
<
matrix1
.
getColumns
()
)
length
++
;
rowLengths
[
i
]
=
length
;
}
...
...
@@ -303,8 +298,8 @@ reorderSparseMatrix( const Matrix1& matrix1, Matrix2& matrix2, const Permutation
typename
Matrix2
::
IndexType
columns
[
rowLength
];
typename
Matrix2
::
RealType
values
[
rowLength
];
for
(
IndexType
j
=
0
;
j
<
rowLength
;
j
++
)
{
columns
[
j
]
=
iperm
[
row1
.
get
Element
Column
(
j
)
];
values
[
j
]
=
row1
.
get
Element
Value
(
j
);
columns
[
j
]
=
iperm
[
row1
.
getColumn
Index
(
j
)
];
values
[
j
]
=
row1
.
getValue
(
j
);
}
// sort
...
...
@@ -319,14 +314,10 @@ reorderSparseMatrix( const Matrix1& matrix1, Matrix2& matrix2, const Permutation
};
std
::
sort
(
indices
,
indices
+
rowLength
,
comparator
);
typename
Matrix2
::
IndexType
sortedColumns
[
rowLength
];
typename
Matrix2
::
RealType
sortedValues
[
rowLength
];
for
(
IndexType
j
=
0
;
j
<
rowLength
;
j
++
)
{
sortedColumns
[
j
]
=
columns
[
indices
[
j
]
];
sortedValues
[
j
]
=
values
[
indices
[
j
]
];
}
matrix2
.
setRow
(
i
,
sortedColumns
,
sortedValues
,
rowLength
);
// set the row
auto
row2
=
matrix2
.
getRow
(
i
);
for
(
IndexType
j
=
0
;
j
<
rowLength
;
j
++
)
row2
.
setElement
(
j
,
columns
[
indices
[
j
]
],
values
[
indices
[
j
]
]
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment