From 334540f660e3b50ce29e4834aa9f951bb6805308 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 18 Jun 2022 13:48:04 +0200 Subject: [PATCH] Normalization of CellInstArray upon creation (GSI) --- src/db/db/gsiDeclDbCell.cc | 95 ++++++++++++++++------------ testdata/ruby/dbCellInstArrayTest.rb | 42 ++++++++++++ 2 files changed, 95 insertions(+), 42 deletions(-) diff --git a/src/db/db/gsiDeclDbCell.cc b/src/db/db/gsiDeclDbCell.cc index b0eaf1704..634716370 100644 --- a/src/db/db/gsiDeclDbCell.cc +++ b/src/db/db/gsiDeclDbCell.cc @@ -90,25 +90,51 @@ struct cell_inst_array_defs } } + static void normalize_array_arguments (const vector_type &a, const vector_type &b, unsigned long &na, unsigned long &nb) + { + if (na < 1 || a == vector_type ()) { + na = 1; + } + if (nb < 1 || b == vector_type ()) { + nb = 1; + } + } + static C * new_cell_inst_array_vector (db::cell_index_type ci, const vector_type &v, - const vector_type &a, const vector_type &b, unsigned int na, unsigned int nb) + const vector_type &a, const vector_type &b, unsigned long na, unsigned long nb) { - return new C (db::CellInst (ci), trans_type (v), a, b, na, nb); + normalize_array_arguments (a, b, na, nb); + if (na == 1 && nb == 1) { + // single instance + return new_cell_inst_vector (ci, v); + } else { + return new C (db::CellInst (ci), trans_type (v), a, b, na, nb); + } } static C * new_cell_inst_array (db::cell_index_type ci, const trans_type &t, - const vector_type &a, const vector_type &b, unsigned int na, unsigned int nb) + const vector_type &a, const vector_type &b, unsigned long na, unsigned long nb) { - return new C (db::CellInst (ci), t, a, b, na, nb); + normalize_array_arguments (a, b, na, nb); + if (na == 1 && nb == 1) { + // single instance + return new_cell_inst (ci, t); + } else { + return new C (db::CellInst (ci), t, a, b, na, nb); + } } static C * new_cell_inst_array_cplx (db::cell_index_type ci, const complex_trans_type &t, - const vector_type &a, const vector_type &b, unsigned int na, unsigned int nb) + const vector_type &a, const vector_type &b, unsigned long na, unsigned long nb) { - if (t.is_mag () || ! t.is_ortho ()) { + normalize_array_arguments (a, b, na, nb); + if (na == 1 && nb == 1) { + // single instance + return new_cell_inst_cplx (ci, t); + } else if (t.is_mag () || ! t.is_ortho ()) { return new C (db::CellInst (ci), t, a, b, na, nb); } else { return new C (db::CellInst (ci), trans_type (t), a, b, na, nb); @@ -160,6 +186,23 @@ struct cell_inst_array_defs return a; } + static void reset_array_reg (C *arr, const vector_type &a, const vector_type &b, unsigned long na, unsigned long nb) + { + if (na > 0 && nb > 0) { + if (arr->is_complex ()) { + *arr = C (arr->object (), arr->complex_trans (), a, b, na, nb); + } else { + *arr = C (arr->object (), arr->front (), a, b, na, nb); + } + } else { + if (arr->is_complex ()) { + *arr = C (arr->object (), arr->complex_trans ()); + } else { + *arr = C (arr->object (), arr->front ()); + } + } + } + static void set_array_a (C *arr, const vector_type &a_in) { vector_type a, b; @@ -168,11 +211,7 @@ struct cell_inst_array_defs a = a_in; - if (arr->is_complex ()) { - *arr = C (arr->object (), arr->complex_trans (), a, b, na, nb); - } else { - *arr = C (arr->object (), arr->front (), a, b, na, nb); - } + reset_array_reg (arr, a, b, na, nb); } static vector_type array_b (const C *arr) @@ -191,11 +230,7 @@ struct cell_inst_array_defs b = b_in; - if (arr->is_complex ()) { - *arr = C (arr->object (), arr->complex_trans (), a, b, na, nb); - } else { - *arr = C (arr->object (), arr->front (), a, b, na, nb); - } + reset_array_reg (arr, a, b, na, nb); } static unsigned long array_na (const C *arr) @@ -214,19 +249,7 @@ struct cell_inst_array_defs na = na_in; - if (na > 0 && nb > 0) { - if (arr->is_complex ()) { - *arr = C (arr->object (), arr->complex_trans (), a, b, na, nb); - } else { - *arr = C (arr->object (), arr->front (), a, b, na, nb); - } - } else { - if (arr->is_complex ()) { - *arr = C (arr->object (), arr->complex_trans ()); - } else { - *arr = C (arr->object (), arr->front ()); - } - } + reset_array_reg (arr, a, b, na, nb); } static unsigned long array_nb (const C *arr) @@ -245,19 +268,7 @@ struct cell_inst_array_defs nb = nb_in; - if (na > 0 && nb > 0) { - if (arr->is_complex ()) { - *arr = C (arr->object (), arr->complex_trans (), a, b, na, nb); - } else { - *arr = C (arr->object (), arr->front (), a, b, na, nb); - } - } else { - if (arr->is_complex ()) { - *arr = C (arr->object (), arr->complex_trans ()); - } else { - *arr = C (arr->object (), arr->front ()); - } - } + reset_array_reg (arr, a, b, na, nb); } static void set_trans (C *arr, const trans_type &t) diff --git a/testdata/ruby/dbCellInstArrayTest.rb b/testdata/ruby/dbCellInstArrayTest.rb index c8beacd24..b61aece95 100644 --- a/testdata/ruby/dbCellInstArrayTest.rb +++ b/testdata/ruby/dbCellInstArrayTest.rb @@ -387,6 +387,27 @@ class DBCellInst_TestClass < TestBase ii.na = 0 assert_equal(ii.to_s, "#8 r270 0,0") + i = RBA::CellInstArray.new(0, RBA::Vector::new(1, 2), RBA::Vector::new(10, 20), RBA::Vector::new, 2, 2) + assert_equal(i.to_s, "#0 r0 1,2 [10,20*2;0,0*1]") + + i = RBA::CellInstArray.new(0, RBA::Vector::new(1, 2), RBA::Vector::new(10, 20), RBA::Vector::new(11, 21), 2, 2) + assert_equal(i.to_s, "#0 r0 1,2 [10,20*2;11,21*2]") + + i = RBA::CellInstArray.new(0, RBA::Vector::new(1, 2), RBA::Vector::new, RBA::Vector::new(11, 21), 2, 2) + assert_equal(i.to_s, "#0 r0 1,2 [0,0*1;11,21*2]") + + i = RBA::CellInstArray.new(0, RBA::Vector::new(1, 2), RBA::Vector::new, RBA::Vector::new, 2, 2) + assert_equal(i.to_s, "#0 r0 1,2") + + i = RBA::CellInstArray.new(0, RBA::Vector::new(1, 2), RBA::Vector::new(10, 20), RBA::Vector::new(11, 21), 0, 2) + assert_equal(i.to_s, "#0 r0 1,2 [10,20*1;11,21*2]") + + i = RBA::CellInstArray.new(0, RBA::Vector::new(1, 2), RBA::Vector::new(10, 20), RBA::Vector::new(11, 21), 2, 0) + assert_equal(i.to_s, "#0 r0 1,2 [10,20*2;11,21*1]") + + i = RBA::CellInstArray.new(0, RBA::Vector::new(1, 2), RBA::Vector::new(10, 20), RBA::Vector::new(11, 21), 0, 0) + assert_equal(i.to_s, "#0 r0 1,2") + end # DCellInstArray functions @@ -459,6 +480,27 @@ class DBCellInst_TestClass < TestBase ii.na = 0 assert_equal(ii.to_s, "#8 r270 0,0") + i = RBA::DCellInstArray.new(0, RBA::DVector::new(1, 2), RBA::DVector::new(10, 20), RBA::DVector::new, 2, 2) + assert_equal(i.to_s, "#0 r0 1,2 [10,20*2;0,0*1]") + + i = RBA::DCellInstArray.new(0, RBA::DVector::new(1, 2), RBA::DVector::new(10, 20), RBA::DVector::new(11, 21), 2, 2) + assert_equal(i.to_s, "#0 r0 1,2 [10,20*2;11,21*2]") + + i = RBA::DCellInstArray.new(0, RBA::DVector::new(1, 2), RBA::DVector::new, RBA::DVector::new(11, 21), 2, 2) + assert_equal(i.to_s, "#0 r0 1,2 [0,0*1;11,21*2]") + + i = RBA::DCellInstArray.new(0, RBA::DVector::new(1, 2), RBA::DVector::new, RBA::DVector::new, 2, 2) + assert_equal(i.to_s, "#0 r0 1,2") + + i = RBA::DCellInstArray.new(0, RBA::DVector::new(1, 2), RBA::DVector::new(10, 20), RBA::DVector::new(11, 21), 0, 2) + assert_equal(i.to_s, "#0 r0 1,2 [10,20*1;11,21*2]") + + i = RBA::DCellInstArray.new(0, RBA::DVector::new(1, 2), RBA::DVector::new(10, 20), RBA::DVector::new(11, 21), 2, 0) + assert_equal(i.to_s, "#0 r0 1,2 [10,20*2;11,21*1]") + + i = RBA::DCellInstArray.new(0, RBA::DVector::new(1, 2), RBA::DVector::new(10, 20), RBA::DVector::new(11, 21), 0, 0) + assert_equal(i.to_s, "#0 r0 1,2") + end # DCellInstArray fuzzy compare