Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
al-matrix.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
37# include <gtest/gtest.h>
38
39# include <ahSort.H>
40# include <ah-string-utils.H>
41# include <al-matrix.H>
42
43using namespace std;
44using namespace testing;
45using namespace Aleph;
46
47struct SmallDomains : testing::Test
48{
49 AlDomain<char> rd = { 'a', 'b', 'c', 'd', 'e' };
50 AlDomain<string> cd = { "A", "B", "C", "D" };
55
56 V1 v1_zero = { rd };
57 V1 v1 = { rd, range<int>(rd.size()) };
58 V1 v1_odd = { rd, range<int>(rd.size()).
59 maps([] (auto i) { return (i % 2) == 0 ? 1 : 0; }) };
60 V1 v1_even = { rd, range<int>(rd.size()).
61 maps([] (auto i) { return (i % 2) == 0 ? 0 : 1; }) };
62
63 V2 v2_zero = { cd };
64 V2 v2 = { cd, range<int>(cd.size()) };
65 V2 v2_odd = { cd, range<int>(cd.size()).
66 maps([] (auto i) { return (i % 2) == 0 ? 1 : 0; }) };
67 V2 v2_even = { cd, range<int>(cd.size()).
68 maps([] (auto i) { return (i % 2) == 0 ? 0 : 1; }) };
69
70 Mat1 m1_zero = { rd, cd };
71 Mat1 m1_one = { rd, cd, rd.maps<DynList<int>>([&] (auto)
72 { return range<int>(cd.size()); }) };
75
76 Mat2 m2_zero = { cd, rd };
77 Mat2 m2_one = { cd, rd, cd.maps<DynList<int>>([&] (auto)
78 { return range<int>(cd.size()); }) };
81};
82
84{
85 EXPECT_EQ(m1_one.get_row_vector('a'), v2);
86 EXPECT_EQ(m1_one.get_row_vector('b'), v2);
87 EXPECT_EQ(m1_one.get_row_vector('c'), v2);
88 EXPECT_EQ(m1_one.get_row_vector('d'), v2);
89 EXPECT_EQ(m1_one.get_row_vector('e'), v2);
90
91 EXPECT_EQ(m1_one.get_col_vector("A"), V1(rd));
92 EXPECT_EQ(m1_one.get_col_vector("B"), V1(rd, rep(rd.size(), 1)));
93 EXPECT_EQ(m1_one.get_col_vector("C"), V1(rd, rep(rd.size(), 2)));
94 EXPECT_EQ(m1_one.get_col_vector("D"), V1(rd, rep(rd.size(), 3)));
95
96 EXPECT_EQ(v1*m1_zero, V2(cd, { 0, 0, 0, 0}));
97 EXPECT_EQ(m1_zero*v2, V1(rd, { 0, 0, 0, 0, 0}));
98
99 //cout << m1_even.matrix_vector_mult(m2_even) << endl << endl;
100
101 return;
102 cout << v1_zero << endl << endl
103 << v1 << endl << endl
104 << v1_odd << endl << endl
105 << v1_even << endl << endl
106 << endl
107 << v2_zero << endl << endl
108 << v2 << endl << endl
109 << v2_odd << endl << endl
110 << v2_even << endl << endl
111 << m1_even<< endl << endl
112 << m1_odd << endl << endl
113 << m2_even<< endl << endl
114 << m1_odd << endl << endl
115 << endl;
116}
117
119{
120 // using M1 = Matrix<char, char, int>;
121 // using M2 = Matrix<string, string, int>;
122 // cout << M1(rd, rd).identity() << endl
123 // << M2(cd, cd).identity() << endl;
124}
String manipulation utilities.
High-level sorting functions for Aleph containers.
Sparse matrix with generic domains.
TEST_F(SmallDomains, basic)
Definition al-matrix.cc:83
Generic domain class based on hash set.
Definition al-domain.H:85
Dynamic singly linked list with functional programming support.
Definition htlist.H:1423
Vector< Tcol, NumType > get_row_vector(const Trow &row) const
Given a row, build a vector corresponding to the row.
Definition al-matrix.H:515
Vector< Trow, NumType > get_col_vector(const Tcol &col) const
Given a column, build a vector corresponding to the column.
Definition al-matrix.H:530
static Matrix create_by_columns(const CDomain &cdomain, const DynList< Vector< string, int > > &cols, const int &e=default_epsilon)
Create a matrix from a list of column vectors.
Definition al-matrix.H:332
static Matrix create_by_rows(const RDomain &rdomain, const DynList< Vector< string, int > > &rows, const int &e=default_epsilon)
Create a matrix from a list of row vectors.
Definition al-matrix.H:301
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
DynList< T > maps(const C &c, Op op)
Classic map operation.
DynList< T > rep(size_t n, const T &item)
Create a sequence of repeated items.
STL namespace.
AlDomain< char > rd
Definition al-matrix.cc:49
AlDomain< string > cd
Definition al-matrix.cc:50