1
// SUMMARY : matrix manipulation
3
// ORG : LJLL Universite Pierre et Marie Curie, Paris, FRANCE
5
// E-MAIL : Pierre Jolivet <pierre.jolivet@ljll.math.upmc.fr>
9
This file is part of Freefem++
11
Freefem++ is free software; you can redistribute it and/or modify
12
it under the terms of the GNU Lesser General Public License as published by
13
the Free Software Foundation; either version 2.1 of the License, or
14
(at your option) any later version.
16
Freefem++ is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
GNU Lesser General Public License for more details.
21
You should have received a copy of the GNU Lesser General Public License
22
along with Freefem++; if not, write to the Free Software
23
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34
step(int x, int y) : x(x), y(y) { }
35
int operator()() { return x += y; }
41
template<unsigned char M, unsigned char S>
42
static void CSR2COO(unsigned int n, int* compressedI, int* uncompressedI) {
44
for(int i = n - 1; i > -1; --i) {
46
std::fill(uncompressedI + compressedI[i] - 1, uncompressedI + compressedI[i + 1] - 1, i + 1);
48
std::fill(uncompressedI + compressedI[i], uncompressedI + compressedI[i + 1], i + 1);
52
for(int i = 1; i < n; ++i) {
54
std::fill(uncompressedI + compressedI[i] - i - 1, uncompressedI + compressedI[i + 1] - i - 1, i + 1);
56
std::fill(uncompressedI + compressedI[i] - i, uncompressedI + compressedI[i + 1] - i - 1, i + 1);
61
template<bool WithDiagonal, unsigned char N,typename Scalar>
62
static unsigned int trimCSR(unsigned int n, int* trimmedI, int* untrimmedI, int* trimmedJ, int* untrimmedJ, Scalar* trimmedC, Scalar* untrimmedC) {
63
unsigned int upper = 0;
64
for(unsigned int i = 0; i < n - WithDiagonal; ++i) {
65
trimmedI[i] = upper + (N == 'F');
66
int* jIndex = lower_bound(untrimmedJ + untrimmedI[i], untrimmedJ + untrimmedI[i + 1], i + !WithDiagonal);
67
unsigned int j = untrimmedI[i] + jIndex - (untrimmedJ + untrimmedI[i]);
69
for(unsigned int k = j; k < untrimmedI[i + 1]; ++k)
70
trimmedJ[upper + k - j] = untrimmedJ[k] + 1;
73
std::copy(untrimmedJ + j, untrimmedJ + untrimmedI[i + 1], trimmedJ + upper);
74
std::copy(untrimmedC + j, untrimmedC + untrimmedI[i + 1], trimmedC + upper);
75
upper += untrimmedI[i + 1] - j;
78
trimmedI[n - 1] = upper + (N == 'F');
79
trimmedI[n] = trimmedI[n - 1] + 1;
80
trimmedJ[upper] = n - (N == 'C');
81
trimmedC[upper] = untrimmedC[untrimmedI[n] - 1];
85
trimmedI[n] = trimmedI[n - 1];
86
return trimmedI[n + 1];