Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
dynmat_test.cc
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
48#include <gtest/gtest.h>
49
50#include <string>
51#include <memory>
52#include <vector>
53#include <stdexcept>
54#include <cmath>
55
56#include <tpl_dynMat.H>
57#include <ahFunctional.H>
58
59using namespace std;
60using namespace testing;
61using namespace Aleph;
62
63// =============================================================================
64// Test Fixtures
65// =============================================================================
66
67constexpr size_t SMALL_N = 3;
68constexpr size_t SMALL_M = 4;
69constexpr size_t MEDIUM_N = 10;
70constexpr size_t MEDIUM_M = 15;
71constexpr size_t LARGE_N = 100;
72
74struct SmallIntMatrix : public Test
75{
77
79};
80
82struct FilledMatrix : public Test
83{
85
87 {
88 for (size_t i = 0; i < SMALL_N; ++i)
89 for (size_t j = 0; j < SMALL_M; ++j)
90 mat.write(i, j, static_cast<int>(i * SMALL_M + j));
91 }
92};
93
95struct SquareMatrix : public Test
96{
98
99 SquareMatrix() : mat(4, 4, 0.0)
100 {
101 // Identity-like diagonal
102 for (size_t i = 0; i < 4; ++i)
103 mat.write(i, i, 1.0);
104 }
105};
106
108struct Counted
109{
110 static int constructions;
111 static int destructions;
112 static int copies;
113 static int moves;
114
115 int value;
116
117 static void reset()
118 {
120 }
121
122 explicit Counted(int v = 0) : value(v) { ++constructions; }
124 {
126 ++copies;
127 }
129 {
131 ++moves;
132 }
134
136 {
137 value = other.value;
138 ++copies;
139 return *this;
140 }
142 {
143 value = other.value;
144 ++moves;
145 return *this;
146 }
147
148 bool operator==(const Counted& other) const { return value == other.value; }
149 bool operator!=(const Counted& other) const { return value != other.value; }
150};
151
154int Counted::copies = 0;
155int Counted::moves = 0;
156
157// =============================================================================
158// Constructor Tests
159// =============================================================================
160
162{
163 DynMatrix<int> mat;
164 EXPECT_TRUE(mat.is_empty());
165 EXPECT_EQ(mat.rows(), 0);
166 EXPECT_EQ(mat.cols(), 0);
167 EXPECT_EQ(mat.size(), 0);
168}
169
171{
172 DynMatrix<int> mat(5, 7);
173
174 EXPECT_EQ(mat.rows(), 5);
175 EXPECT_EQ(mat.cols(), 7);
176 EXPECT_EQ(mat.size(), 35);
177 EXPECT_FALSE(mat.is_empty());
178 EXPECT_FALSE(mat.is_square());
179}
180
182{
183 DynMatrix<int> mat(3, 3, 42);
184
185 EXPECT_EQ(mat.get_default_value(), 42);
186 EXPECT_EQ(mat.read(0, 0), 42);
187 EXPECT_EQ(mat.read(1, 2), 42);
188}
189
191{
192 EXPECT_THROW(DynMatrix<int>(0, 5), std::invalid_argument);
193 EXPECT_THROW(DynMatrix<int>(5, 0), std::invalid_argument);
194 EXPECT_THROW(DynMatrix<int>(0, 0), std::invalid_argument);
195}
196
198{
199 DynMatrix<int> mi(2, 3);
200 DynMatrix<double> md(3, 4);
201 DynMatrix<string> ms(2, 2, "default");
203
204 EXPECT_EQ(mi.rows(), 2);
205 EXPECT_EQ(md.cols(), 4);
206 EXPECT_EQ(ms.read(0, 0), "default");
207 EXPECT_TRUE(mv.read(0, 0).empty());
208}
209
210// =============================================================================
211// Copy Constructor Tests
212// =============================================================================
213
215{
216 DynMatrix<int> copy(mat);
217
218 EXPECT_EQ(copy.rows(), mat.rows());
219 EXPECT_EQ(copy.cols(), mat.cols());
220
221 for (size_t i = 0; i < SMALL_N; ++i)
222 for (size_t j = 0; j < SMALL_M; ++j)
223 EXPECT_EQ(copy.read(i, j), mat.read(i, j));
224
225 // Modify original, copy should be unchanged
226 mat.write(0, 0, 999);
227 EXPECT_NE(copy.read(0, 0), mat.read(0, 0));
228}
229
231{
232 DynMatrix<int> empty;
233 DynMatrix<int> copy(empty);
234
235 EXPECT_TRUE(copy.is_empty());
236}
237
239{
240 // Write only a few entries
241 mat.write(0, 0, 1);
242 mat.write(2, 3, 2);
243
244 DynMatrix<int> copy(mat);
245
246 EXPECT_EQ(copy.read(0, 0), 1);
247 EXPECT_EQ(copy.read(2, 3), 2);
248 EXPECT_EQ(copy.read(1, 1), 0); // Default value
249}
250
251// =============================================================================
252// Move Constructor Tests
253// =============================================================================
254
256{
257 size_t original_rows = mat.rows();
258 size_t original_cols = mat.cols();
259 int original_value = mat.read(1, 2);
260
261 DynMatrix<int> moved(std::move(mat));
262
265 EXPECT_EQ(moved.read(1, 2), original_value);
266 EXPECT_TRUE(mat.is_empty());
267}
268
276
278{
279 EXPECT_TRUE(std::is_nothrow_move_constructible_v<DynMatrix<int>>);
280}
281
282// =============================================================================
283// Copy Assignment Tests
284// =============================================================================
285
287{
288 DynMatrix<int> other(2, 2);
289 other.write(0, 0, 100);
290
291 other = mat;
292
293 EXPECT_EQ(other.rows(), SMALL_N);
294 EXPECT_EQ(other.cols(), SMALL_M);
295 EXPECT_EQ(other.read(1, 2), mat.read(1, 2));
296}
297
299{
300 mat = mat;
301
302 EXPECT_EQ(mat.rows(), SMALL_N);
303 EXPECT_EQ(mat.read(0, 0), 0);
304}
305
307{
308 DynMatrix<int> source(5, 5, 7);
309 DynMatrix<int> dest(2, 3, 0);
310
311 dest = source;
312
313 EXPECT_EQ(dest.rows(), 5);
314 EXPECT_EQ(dest.cols(), 5);
315 EXPECT_EQ(dest.read(2, 2), 7);
316}
317
318// =============================================================================
319// Move Assignment Tests
320// =============================================================================
321
323{
324 DynMatrix<int> dest(2, 2);
325 size_t original_rows = mat.rows();
326
327 dest = std::move(mat);
328
330 EXPECT_TRUE(mat.is_empty());
331}
332
334{
335 EXPECT_TRUE(std::is_nothrow_move_assignable_v<DynMatrix<int>>);
336}
337
338// =============================================================================
339// Swap Tests
340// =============================================================================
341
343{
344 DynMatrix<int> mat1(3, 4, 1);
345 DynMatrix<int> mat2(5, 6, 2);
346
347 mat1.write(0, 0, 10);
348 mat2.write(0, 0, 20);
349
350 mat1.swap(mat2);
351
352 EXPECT_EQ(mat1.rows(), 5);
353 EXPECT_EQ(mat1.cols(), 6);
354 EXPECT_EQ(mat1.read(0, 0), 20);
355
356 EXPECT_EQ(mat2.rows(), 3);
357 EXPECT_EQ(mat2.cols(), 4);
358 EXPECT_EQ(mat2.read(0, 0), 10);
359}
360
362{
363 DynMatrix<int> mat1(3, 3, 5);
365
366 mat1.swap(mat2);
367
369 EXPECT_EQ(mat2.rows(), 3);
370}
371
377
378// =============================================================================
379// Dimension and Query Tests
380// =============================================================================
381
386
391
396
402
408
414
419
420// =============================================================================
421// Read/Write Tests
422// =============================================================================
423
425{
426 mat.write(1, 2, 42);
427
428 EXPECT_EQ(mat.read(1, 2), 42);
429}
430
432{
433 EXPECT_EQ(mat.read(0, 0), 0);
434 EXPECT_EQ(mat.read(2, 3), 0);
435}
436
438{
439 int& ref = mat.write(1, 1, 10);
440
441 EXPECT_EQ(ref, 10);
442 ref = 20;
443 EXPECT_EQ(mat.read(1, 1), 20);
444}
445
447{
448 EXPECT_THROW(mat.read(SMALL_N, 0), std::out_of_range);
449 EXPECT_THROW(mat.read(0, SMALL_M), std::out_of_range);
450 EXPECT_THROW(mat.read(100, 100), std::out_of_range);
451}
452
454{
455 EXPECT_THROW(mat.write(SMALL_N, 0, 1), std::out_of_range);
456 EXPECT_THROW(mat.write(0, SMALL_M, 1), std::out_of_range);
457}
458
460{
461 mat.write(1, 2, 42);
462 EXPECT_EQ(mat.read_ne(1, 2), 42);
463 EXPECT_EQ(mat.read_ne(0, 0), 0);
464}
465
467{
468 DynMatrix<string> mat(2, 2);
469 string value = "hello";
470
471 mat.write(0, 0, std::move(value));
472
473 EXPECT_EQ(mat.read(0, 0), "hello");
474 EXPECT_TRUE(value.empty()); // moved-from
475}
476
477// =============================================================================
478// Access and operator() Tests
479// =============================================================================
480
482{
483 mat.allocate();
484 mat(1, 2) = 99;
485
486 EXPECT_EQ(mat.access(1, 2), 99);
487 EXPECT_EQ(mat(1, 2), 99);
488}
489
491{
492 mat.allocate();
493 mat(0, 0) = 42;
494
495 const DynMatrix<int>& const_mat = mat;
496 EXPECT_EQ(const_mat(0, 0), 42);
497}
498
500{
501 mat.allocate();
502
503 mat(0, 0) = 100;
504 EXPECT_EQ(mat(0, 0), 100);
505
506 const DynMatrix<int>& cmat = mat;
507 EXPECT_EQ(cmat(0, 0), 100);
508}
509
510// =============================================================================
511// Fill Tests
512// =============================================================================
513
515{
516 mat.fill(42);
517
518 for (size_t i = 0; i < SMALL_N; ++i)
519 for (size_t j = 0; j < SMALL_M; ++j)
520 EXPECT_EQ(mat.read(i, j), 42);
521}
522
524{
525 DynMatrix<int> mat(3, 3, 0);
526 mat.write(1, 1, 100);
527
528 mat.fill(5);
529
530 EXPECT_EQ(mat.read(1, 1), 5);
531 EXPECT_EQ(mat.read(0, 0), 5);
532}
533
534// =============================================================================
535// Transpose Tests
536// =============================================================================
537
539{
540 auto transposed = mat.transpose();
541
544}
545
547{
548 auto transposed = mat.transpose();
549
550 for (size_t i = 0; i < SMALL_N; ++i)
551 for (size_t j = 0; j < SMALL_M; ++j)
552 EXPECT_EQ(transposed.read(j, i), mat.read(i, j));
553}
554
556{
557 auto transposed = mat.transpose();
558
559 for (size_t i = 0; i < 4; ++i)
560 EXPECT_EQ(transposed.read(i, i), mat.read(i, i));
561}
562
564{
565 DynMatrix<int> mat(3, 5, 0);
566 mat.write(0, 4, 1);
567 mat.write(2, 1, 2);
568
569 auto transposed = mat.transpose();
570
571 EXPECT_EQ(transposed.read(4, 0), 1);
572 EXPECT_EQ(transposed.read(1, 2), 2);
573 EXPECT_EQ(transposed.read(0, 0), 0);
574}
575
576// =============================================================================
577// set_dimension Tests
578// =============================================================================
579
581{
582 mat.set_dimension(5, 5);
583
584 EXPECT_EQ(mat.rows(), 5);
585 EXPECT_EQ(mat.cols(), 5);
586 // Data should be cleared
587 EXPECT_EQ(mat.read(0, 0), 0);
588}
589
591{
592 mat.set_default_initial_value(99);
593 mat.set_dimension(2, 2);
594
595 EXPECT_EQ(mat.read(0, 0), 99);
596}
597
598// =============================================================================
599// Default Value Tests
600// =============================================================================
601
602TEST_F(SmallIntMatrix, set_default_initial_value)
603{
604 mat.set_default_initial_value(42);
605
606 EXPECT_EQ(mat.get_default_value(), 42);
607}
608
610{
611 DynMatrix<int> mat(3, 3, 100);
612
613 EXPECT_EQ(mat.read(0, 0), 100);
614 EXPECT_EQ(mat.read(2, 2), 100);
615}
616
618{
619 DynMatrix<int> mat(3, 3, 0);
620
621 EXPECT_EQ(mat.read(1, 1), 0);
622
624
625 // Unwritten entries should now return new default
626 EXPECT_EQ(mat.read(2, 2), 99);
627}
628
629// =============================================================================
630// Equality Tests
631// =============================================================================
632
641
650
652{
653 DynMatrix<int> mat1(3, 3, 0);
654 DynMatrix<int> mat2(3, 3, 0);
655
656 mat1.write(1, 1, 5);
657
660}
661
668
669// =============================================================================
670// Iterator Tests
671// =============================================================================
672
674{
675 mat.fill(1);
676
677 auto it = mat.get_it();
678 size_t count = 0;
679
680 while (it.has_curr())
681 {
682 EXPECT_EQ(it.get_curr(), 1);
683 it.next();
684 ++count;
685 }
686
687 EXPECT_EQ(count, mat.size());
688}
689
691{
692 auto it = mat.get_it();
693
694 for (size_t i = 0; i < SMALL_N; ++i)
695 for (size_t j = 0; j < SMALL_M; ++j)
696 {
697 ASSERT_TRUE(it.has_curr());
698 EXPECT_EQ(it.get_row(), i);
699 EXPECT_EQ(it.get_col(), j);
700 EXPECT_EQ(it.get_curr(), mat.read(i, j));
701 it.next();
702 }
703
704 EXPECT_FALSE(it.has_curr());
705}
706
708{
709 auto it = mat.get_it();
710
711 // Exhaust the iterator
712 while (it.has_curr())
713 it.next();
714
715 EXPECT_THROW(it.get_curr(), std::overflow_error);
716}
717
719{
720 auto it = mat.get_it();
721
722 while (it.has_curr())
723 it.next();
724
725 EXPECT_THROW(it.next(), std::overflow_error);
726}
727
729{
730 auto it = mat.get_it();
731
732 it.next();
733 it.next();
734 it.reset();
735
736 EXPECT_EQ(it.get_row(), 0);
737 EXPECT_EQ(it.get_col(), 0);
738}
739
740// =============================================================================
741// Traverse Tests
742// =============================================================================
743
745{
746 size_t count = 0;
747 int sum = 0;
748
749 mat.traverse([&](int val)
750 {
751 ++count;
752 sum += val;
753 return true;
754 });
755
756 EXPECT_EQ(count, mat.size());
757
758 // Sum of 0 to N*M-1
759 int expected = (SMALL_N * SMALL_M - 1) * SMALL_N * SMALL_M / 2;
761}
762
764{
765 size_t count = 0;
766
767 bool result = mat.traverse([&](int)
768 {
769 ++count;
770 return count < 5;
771 });
772
773 EXPECT_FALSE(result);
774 EXPECT_EQ(count, 5);
775}
776
778{
779 mat.write(0, 0, 10);
780 mat.write(2, 3, 20);
781
782 int sum = 0;
783 mat.traverse([&](int val)
784 {
785 sum += val;
786 return true;
787 });
788
789 EXPECT_EQ(sum, 30); // 10 + 20, rest are 0
790}
791
793{
794 // Write two entries - this allocates the blocks containing them
795 mat.write(0, 0, 10);
796 mat.write(1, 1, 20);
797
798 size_t count = 0;
799 int sum = 0;
800
801 mat.traverse_allocated([&](int val)
802 {
803 ++count;
804 sum += val;
805 return true;
806 });
807
808 // Note: traverse_allocated visits all entries in allocated blocks,
809 // not just explicitly written entries. The exact count depends on
810 // the DynArray block size configuration.
811 EXPECT_GE(count, 2u); // At least the 2 written entries
812 EXPECT_GE(sum, 30); // At least 10 + 20 from written entries
813}
814
815// =============================================================================
816// Functional Methods Tests (inherited from mixins)
817// =============================================================================
818
820{
821 int sum = 0;
822 mat.for_each([&sum](int val) { sum += val; });
823
824 int expected = (SMALL_N * SMALL_M - 1) * SMALL_N * SMALL_M / 2;
826}
827
829{
830 // All values are >= 0
831 bool result = mat.all([](int val) { return val >= 0; });
832 EXPECT_TRUE(result);
833}
834
836{
837 // Not all values are < 5
838 bool result = mat.all([](int val) { return val < 5; });
839 EXPECT_FALSE(result);
840}
841
843{
844 bool result = mat.exists([](int val) { return val == 5; });
845 EXPECT_TRUE(result);
846}
847
849{
850 bool result = mat.exists([](int val) { return val == 999; });
851 EXPECT_FALSE(result);
852}
853
855{
856 int sum = mat.foldl(0, [](int acc, int val) { return acc + val; });
857
858 int expected = (SMALL_N * SMALL_M - 1) * SMALL_N * SMALL_M / 2;
860}
861
862// =============================================================================
863// Type Aliases Tests
864// =============================================================================
865
867{
868 using Matrix = DynMatrix<int>;
869
870 static_assert(std::is_same_v<Matrix::Item_Type, int>);
871 static_assert(std::is_same_v<Matrix::Key_Type, int>);
872 static_assert(std::is_same_v<Matrix::Set_Type, Matrix>);
873}
874
875// =============================================================================
876// Memory Management Tests
877// =============================================================================
878
880{
882
883 {
884 DynMatrix<Counted> mat(5, 5, Counted(0));
885 mat.allocate();
886 for (size_t i = 0; i < 5; ++i)
887 for (size_t j = 0; j < 5; ++j)
888 mat.write(i, j, Counted(static_cast<int>(i * 5 + j)));
889 }
890
891 // All elements should be destroyed
893}
894
896{
897 DynMatrix<int> mat(10, 10);
898 mat.allocate();
899
900 // Should be able to access any entry without write
901 for (size_t i = 0; i < 10; ++i)
902 for (size_t j = 0; j < 10; ++j)
903 mat(i, j) = static_cast<int>(i * 10 + j);
904
905 EXPECT_EQ(mat(5, 5), 55);
906}
907
908// =============================================================================
909// Edge Cases
910// =============================================================================
911
913{
914 DynMatrix<int> mat(1, 1, 42);
915
916 EXPECT_EQ(mat.rows(), 1);
917 EXPECT_EQ(mat.cols(), 1);
918 EXPECT_EQ(mat.size(), 1);
919 EXPECT_TRUE(mat.is_square());
920 EXPECT_EQ(mat.read(0, 0), 42);
921}
922
924{
925 DynMatrix<int> mat(1, 10, 0);
926
927 EXPECT_EQ(mat.rows(), 1);
928 EXPECT_EQ(mat.cols(), 10);
929 EXPECT_FALSE(mat.is_square());
930
931 for (size_t j = 0; j < 10; ++j)
932 mat.write(0, j, static_cast<int>(j));
933
934 EXPECT_EQ(mat.read(0, 5), 5);
935}
936
938{
939 DynMatrix<int> mat(10, 1, 0);
940
941 EXPECT_EQ(mat.rows(), 10);
942 EXPECT_EQ(mat.cols(), 1);
943
944 for (size_t i = 0; i < 10; ++i)
945 mat.write(i, 0, static_cast<int>(i));
946
947 EXPECT_EQ(mat.read(5, 0), 5);
948}
949
951{
952 DynMatrix<int> mat(1000, 1000, 0);
953
954 // Write only a few entries
955 mat.write(0, 0, 1);
956 mat.write(999, 999, 2);
957 mat.write(500, 500, 3);
958
959 EXPECT_EQ(mat.read(0, 0), 1);
960 EXPECT_EQ(mat.read(999, 999), 2);
961 EXPECT_EQ(mat.read(500, 500), 3);
962 EXPECT_EQ(mat.read(100, 100), 0); // Default
963}
964
965// =============================================================================
966// Stress Tests
967// =============================================================================
968
970{
972
973 // Write diagonal
974 for (size_t i = 0; i < LARGE_N; ++i)
975 mat.write(i, i, static_cast<int>(i));
976
977 // Verify
978 for (size_t i = 0; i < LARGE_N; ++i)
979 {
980 ASSERT_EQ(mat.read(i, i), static_cast<int>(i));
981 if (i + 1 < LARGE_N)
982 ASSERT_EQ(mat.read(i, i + 1), 0);
983 }
984}
985
987{
989
990 for (size_t i = 0; i < LARGE_N; ++i)
991 original.write(i, i, static_cast<int>(i));
992
994
995 EXPECT_EQ(copy.rows(), LARGE_N);
996
997 for (size_t i = 0; i < LARGE_N; ++i)
998 ASSERT_EQ(copy.read(i, i), static_cast<int>(i));
999}
1000
1001// =============================================================================
1002// Special Value Tests
1003// =============================================================================
1004
1006{
1007 DynMatrix<double> mat(3, 3, 0.0);
1008
1009 mat.write(0, 0, 1.5);
1010 mat.write(1, 1, 2.7);
1011 mat.write(2, 2, 3.9);
1012
1013 EXPECT_DOUBLE_EQ(mat.read(0, 0), 1.5);
1014 EXPECT_DOUBLE_EQ(mat.read(1, 1), 2.7);
1015 EXPECT_DOUBLE_EQ(mat.read(2, 2), 3.9);
1016}
1017
1019{
1020 DynMatrix<string> mat(2, 2, "empty");
1021
1022 mat.write(0, 0, "hello");
1023 mat.write(1, 1, "world");
1024
1025 EXPECT_EQ(mat.read(0, 0), "hello");
1026 EXPECT_EQ(mat.read(0, 1), "empty");
1027 EXPECT_EQ(mat.read(1, 0), "empty");
1028 EXPECT_EQ(mat.read(1, 1), "world");
1029}
1030
1031// =============================================================================
1032// Regression Tests
1033// =============================================================================
1034
1036{
1037 // 2x6 vs 3x4 - same total size, different shape
1038 DynMatrix<int> mat1(2, 6, 0);
1039 DynMatrix<int> mat2(3, 4, 0);
1040
1041 EXPECT_FALSE(mat1 == mat2); // Should not be equal
1042}
1043
1045{
1046 DynMatrix<int> mat1(2, 2);
1047 DynMatrix<int> mat2(3, 3);
1048
1049 DynMatrix<int>& ref = (mat1 = std::move(mat2));
1050
1051 EXPECT_EQ(&ref, &mat1);
1052}
1053
1054// =============================================================================
1055// Main
1056// =============================================================================
1057
1058int main(int argc, char **argv)
1059{
1060 ::testing::InitGoogleTest(&argc, argv);
1061 return RUN_ALL_TESTS();
1062}
Functional programming utilities for Aleph-w containers.
int main()
void empty() noexcept
empty the list
Definition htlist.H:1689
DynList & swap(DynList &l) noexcept
Swap this with l.
Definition htlist.H:1448
Dynamic matrix with sparse storage.
Definition tpl_dynMat.H:120
const T & read(const size_t i, const size_t j) const
Read the entry at position (i, j).
Definition tpl_dynMat.H:452
constexpr bool is_empty() const noexcept
Check if the matrix is empty (uninitialized).
Definition tpl_dynMat.H:437
constexpr size_t cols() const noexcept
Get the number of columns.
Definition tpl_dynMat.H:419
T & write(const size_t i, const size_t j, const T &data)
Write a value to position (i, j).
Definition tpl_dynMat.H:486
void allocate()
Pre-allocate memory for the entire matrix.
Definition tpl_dynMat.H:249
const T & get_default_value() const noexcept
Get the default value for unwritten entries.
Definition tpl_dynMat.H:192
constexpr size_t rows() const noexcept
Get the number of rows.
Definition tpl_dynMat.H:413
void set_default_initial_value(const T &value)
Set the default value for unwritten entries.
Definition tpl_dynMat.H:181
constexpr size_t size() const noexcept
Get the total number of entries.
Definition tpl_dynMat.H:425
constexpr bool is_square() const noexcept
Check if the matrix is square.
Definition tpl_dynMat.H:431
DynMatrix< T > transpose() const
Create a transposed copy of the matrix.
Definition tpl_dynMat.H:577
void fill(const T &value)
Fill all entries with a value.
Definition tpl_dynMat.H:562
constexpr bool is_empty() const noexcept
Return true if list is empty.
Definition htlist.H:523
Sparse matrix with generic row and column domains.
Definition al-matrix.H:66
#define TEST(name)
constexpr size_t LARGE_N
constexpr size_t SMALL_M
TEST_F(FilledMatrix, copy_constructor_creates_independent_copy)
constexpr size_t SMALL_N
constexpr size_t MEDIUM_N
constexpr size_t MEDIUM_M
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
Definition ahAlgo.H:584
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Definition ahAlgo.H:127
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
STL namespace.
Type that counts constructions/destructions.
Counted & operator=(Counted &&other) noexcept
Counted & operator=(const Counted &other)
Counted(Counted &&other) noexcept
static int moves
static int constructions
bool operator==(const Counted &other) const
static int destructions
static int copies
static void reset()
Counted(int v=0)
bool operator!=(const Counted &other) const
Counted(const Counted &other)
Fixture with a pre-filled matrix.
DynMatrix< int > mat
Fixture with a small integer matrix.
DynMatrix< int > mat
Fixture with a square matrix.
DynMatrix< double > mat
Dynamic matrix with lazy allocation.