Skip to content

Commit 5c5deb6

Browse files
Merge pull request #142 from alliander-opensource/feature/use-int64-for-internal-index
use int64_t as internal indexing
2 parents 0240bd9 + 2858903 commit 5c5deb6

File tree

7 files changed

+19
-19
lines changed

7 files changed

+19
-19
lines changed

include/power_grid_model/math_solver/sparse_lu_solver.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct sparse_lu_entry_trait<Tensor, RHSVector, XVector, enable_scalar_lu_t<Tens
5151
using Matrix = Tensor;
5252
using LUFactor = void;
5353
struct BlockPerm {};
54-
using BlockPermArray = int;
54+
using BlockPermArray = Idx;
5555
};
5656

5757
template <class Tensor, class RHSVector, class XVector>

include/power_grid_model/power_grid_model.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace power_grid_model {
3333
// id type
3434
using ID = int32_t;
3535
// idx type
36-
using Idx = int32_t;
36+
using Idx = int64_t;
3737
using IdxVector = std::vector<Idx>;
3838

3939
using IntS = int8_t;

src/power_grid_model/_power_grid_core.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ from libcpp.string cimport string
2222
from libcpp.vector cimport vector
2323

2424
# idx and id types
25-
from libc.stdint cimport int32_t as idx_t # isort: skip
26-
cdef np_idx_t = np.int32
25+
from libc.stdint cimport int64_t as idx_t # isort: skip
26+
cdef np_idx_t = np.int64
2727
from libc.stdint cimport int32_t as id_t # isort: skip
2828
cdef np_id_t = np.int32
2929

src/power_grid_model/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def convert_list_to_batch_data(list_data: BatchList) -> BatchDataset:
9393
# Convert the index pointers to a numpy array and combine the list of object numpy arrays into a singe
9494
# numpy array. All objects of all batches are now stores in one large array, the index pointers define
9595
# which elemets of the array (rows) belong to which batch.
96-
batch_data[component] = {"indptr": np.array(indptr, dtype=np.int32), "data": np.concatenate(data, axis=0)}
96+
batch_data[component] = {"indptr": np.array(indptr, dtype=np.int64), "data": np.concatenate(data, axis=0)}
9797

9898
return batch_data
9999

tests/benchmark_cpp/benchmark.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct PowerGridBenchmark {
3333
Idx const n_feeders = n_nodes / nodes_per_feeder;
3434

3535
// source node
36-
Idx const id_source_node = 0;
36+
ID const id_source_node = 0;
3737
NodeInput const source_node{{id_source_node}, 150.0e3};
3838
NodeInput const cycle_node_1{{id_source_node + 1}, 150.0e3}, cycle_node_2{{id_source_node + 2}, 150.0e3};
3939
LinkInput const link_1{{{3}, 0, 1, true, true}};
@@ -88,10 +88,10 @@ struct PowerGridBenchmark {
8888
link_input = {link_1, link_2, link_3};
8989

9090
// vector of node ids at far end
91-
IdxVector rind_nodes;
91+
std::vector<ID> ring_nodes;
9292

9393
// current id
94-
Idx id_gen = 10;
94+
ID id_gen = 10;
9595
for (Idx i = 0; i < n_feeders; i++) {
9696
NodeInput feeder_node = node;
9797
feeder_node.id = id_gen++;
@@ -101,10 +101,10 @@ struct PowerGridBenchmark {
101101
transformer_s.to_node = feeder_node.id;
102102
node_input.push_back(feeder_node);
103103
transformer_input.push_back(transformer_s);
104-
Idx prev_node_id = feeder_node.id;
104+
ID prev_node_id = feeder_node.id;
105105
for (Idx j = 0; j < nodes_per_feeder; j++) {
106106
// node
107-
Idx const current_node_id = id_gen++;
107+
ID const current_node_id = id_gen++;
108108
NodeInput node_s = node;
109109
node_s.id = current_node_id;
110110
// line
@@ -151,15 +151,15 @@ struct PowerGridBenchmark {
151151
prev_node_id = current_node_id;
152152
// push to rind node
153153
if (j == ring_node_pos) {
154-
rind_nodes.push_back(node_input.back().id);
154+
ring_nodes.push_back(node_input.back().id);
155155
}
156156
}
157157
}
158158
// add loop if needed, and there are more than one feeder, and there are ring nodes
159-
if (n_feeders > 1 && meshed && !rind_nodes.empty()) {
160-
rind_nodes.push_back(rind_nodes.front());
159+
if (n_feeders > 1 && meshed && !ring_nodes.empty()) {
160+
ring_nodes.push_back(ring_nodes.front());
161161
// loop all far end nodes
162-
for (auto it = rind_nodes.cbegin(); it != rind_nodes.cend() - 1; ++it) {
162+
for (auto it = ring_nodes.cbegin(); it != ring_nodes.cend() - 1; ++it) {
163163
// line
164164
LineInput line_s = line;
165165
line_s.id = id_gen++;

tests/cpp_unit_tests/test_container.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88
namespace power_grid_model {
99

1010
struct C {
11-
C(int a1) : a{a1} {
11+
C(Idx a1) : a{a1} {
1212
}
1313

14-
int a;
14+
Idx a;
1515
};
1616

1717
struct C1 : C {
18-
C1(int a1, double b1) : C{a1}, b{b1} {
18+
C1(Idx a1, double b1) : C{a1}, b{b1} {
1919
}
2020
double b;
2121
};
2222

2323
struct C2 : C {
24-
C2(int a1, uint16_t b1) : C{a1}, b{b1} {
24+
C2(Idx a1, uint16_t b1) : C{a1}, b{b1} {
2525
}
2626
uint16_t b;
2727
};

tests/cpp_unit_tests/test_main_model.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ TEST_CASE("Test main model") {
105105
main_model.set_construction_complete();
106106

107107
SUBCASE("Test get indexer") {
108-
IdxVector const node_id{2, 1, 3, 2};
108+
std::vector<ID> const node_id{2, 1, 3, 2};
109109
IdxVector const expected_indexer{1, 0, 2, 1};
110110
IdxVector indexer(4);
111111
main_model.get_indexer("node", node_id.data(), 4, indexer.data());

0 commit comments

Comments
 (0)