| 1 |
/* WorkvectorPool_def.h |
| 2 |
* |
| 3 |
* Copyright (C) 2024 David Weenink |
| 4 |
* |
| 5 |
* This code is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 2 of the License, or (at |
| 8 |
* your option) any later version. |
| 9 |
* |
| 10 |
* This code is distributed in the hope that it will be useful, but |
| 11 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
#define ooSTRUCT WorkvectorPool |
| 20 |
oo_DEFINE_CLASS (WorkvectorPool, Daata) |
| 21 |
|
| 22 |
oo_INTEGER (poolMemorySize) |
| 23 |
oo_VEC (memoryPool, poolMemorySize) |
| 24 |
oo_INTEGER (numberOfVectors) |
| 25 |
oo_INTVEC (vectorSizes, numberOfVectors) |
| 26 |
oo_INTVEC (vectorStart, numberOfVectors) |
| 27 |
oo_BOOLVEC (inuse, numberOfVectors) |
| 28 |
oo_BOOLEAN (reusable) |
| 29 |
|
| 30 |
#if oo_DECLARING |
| 31 |
|
| 32 |
VEC getRawVEC (integer vectorIndex, integer size) { |
| 33 |
Melder_assert (vectorIndex > 0 && vectorIndex <= numberOfVectors); |
| 34 |
Melder_assert (size <= vectorSizes [vectorIndex]); |
| 35 |
Melder_assert (reusable || (! reusable && ! inuse [vectorIndex])); |
| 36 |
inuse [vectorIndex] = true; |
| 37 |
const integer end = vectorStart [vectorIndex] + size - 1; |
| 38 |
return memoryPool.part (vectorStart [vectorIndex], end); |
| 39 |
} |
| 40 |
|
| 41 |
VEC getZeroVEC (integer vectorIndex, integer size) { |
| 42 |
VEC result = getRawVEC (vectorIndex, size); |
| 43 |
result <<= 0.0; |
| 44 |
return result; |
| 45 |
} |
| 46 |
|
| 47 |
MAT getRawMAT (integer vectorIndex, integer nrow, integer ncol) { |
| 48 |
Melder_assert (vectorIndex > 0 && vectorIndex <= numberOfVectors); |
| 49 |
const integer wantedSize = nrow * ncol; |
| 50 |
Melder_assert (wantedSize <= vectorSizes [vectorIndex]); |
| 51 |
inuse [vectorIndex] = true; |
| 52 |
const integer end = vectorStart [vectorIndex] + wantedSize - 1; |
| 53 |
VEC pool = memoryPool.part (vectorStart [vectorIndex], end); |
| 54 |
return pool.asmatrix (nrow, ncol); |
| 55 |
} |
| 56 |
|
| 57 |
MAT getZeroMAT (integer vectorIndex, integer nrow, integer ncol) { |
| 58 |
MAT result = getRawMAT (vectorIndex, nrow, ncol); |
| 59 |
result <<= 0.0; |
| 60 |
return result; |
| 61 |
} |
| 62 |
|
| 63 |
void freeVEC (integer vectorIndex) { |
| 64 |
Melder_assert (vectorIndex > 0 && vectorIndex <= numberOfVectors); |
| 65 |
Melder_assert (inuse [vectorIndex]); |
| 66 |
inuse [vectorIndex] = false; |
| 67 |
} |
| 68 |
|
| 69 |
#endif |
| 70 |
|
| 71 |
oo_END_CLASS (WorkvectorPool) |
| 72 |
#undef ooSTRUCT |
| 73 |
|
| 74 |
/* End of file WorkvectorPool_def.h */ |