Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
al-vector.H
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
31
43# ifndef AL_VECTOR
44# define AL_VECTOR
45
46# include <concepts>
47# include <memory>
48# include <sstream>
49# include <iostream>
50# include <string>
51# include <type_traits>
52# include <utility>
53# include <ah-errors.H>
54# include <ahFunctional.H>
55# include <ahDry.H>
56# include <ah-dry-mixin.H>
57# include <ahSort.H>
58# include <htlist.H>
59# include <ah-zip.H>
60# include <tpl_hash.H>
61# include <al-domain.H>
62
63namespace Aleph
64{
76 template <typename N>
77 concept AlNumber = std::copyable<N> and std::convertible_to<int, N>
78 and std::convertible_to<double, N>
79 and requires (const N & a, const N & b)
80 {
81 { -a } -> std::convertible_to<N>;
82 { a < 0 } -> std::convertible_to<bool>;
83 { a < b } -> std::convertible_to<bool>;
84 { a <= b } -> std::convertible_to<bool>;
85 { a >= b } -> std::convertible_to<bool>;
86 };
87
93 template <typename N>
94 concept AlAdditiveNumber = AlNumber<N> and requires (N & x, const N & a, const N & b)
95 {
96 { a + b } -> std::convertible_to<N>;
97 { a - b } -> std::convertible_to<N>;
98 x += b;
99 x -= b;
100 };
101
107 template <typename N>
108 concept AlMultiplicativeNumber = AlNumber<N> and requires (N & x, const N & a, const N & b)
109 {
110 { a * b } -> std::convertible_to<N>;
111 x *= b;
112 { a == 1 } -> std::convertible_to<bool>;
113 };
114
120 template <typename N>
121 concept AlDivisibleNumber = AlNumber<N> and requires (N & x, const N & a)
122 {
123 x /= a;
124 { a == 1 } -> std::convertible_to<bool>;
125 };
126
127 template <typename Trow, typename Tcol, typename NumType>
129 class Matrix;
130
146 template <typename T = int, typename NumType = double>
148 class Vector; // Forward declaration for CRTP
149
150 template <typename T, typename NumType>
152 class Vector : public TraverseMixin<Vector<T, NumType>, std::pair<T, NumType>>,
153 public LocateMixin<Vector<T, NumType>, std::pair<T, NumType>>,
154 public FunctionalMixin<Vector<T, NumType>, std::pair<T, NumType>>
155 {
156 public:
158 using DomainPtr = std::shared_ptr<Domain>;
160 using Item_Type = std::pair<T, NumType>; // Required by mixins
161
162 private:
163 static const NumType default_epsilon;
164
168
169 static NumType abs(const NumType & val) noexcept
170 {
171 return val < 0 ? -val : val;
172 }
173
174 bool is_zero(const NumType & val) const noexcept
175 {
176 assert(epsilon >= 0);
177 return abs(val) <= epsilon;
178 }
179
180 static bool test_epsilon(const NumType & e) noexcept { return e >= 0; }
181
182 public:
187 const NumType &get_epsilon() const noexcept { return epsilon; }
188
194 void set_epsilon(const NumType & e) noexcept
195 {
196 epsilon = e;
197 }
198
199 using Pair = std::pair<T, NumType>;
200
205 const Domain &get_domain() const noexcept { return *domain_ptr; }
206
208 const DomainPtr &get_domain_ptr() const noexcept { return domain_ptr; }
209
215 Vector(DomainPtr d, const NumType & zero = default_epsilon)
216 : domain_ptr(std::move(d)), epsilon(zero)
217 {
218 //Empty
219 }
220
227 Vector(const Domain & d, const NumType & zero = default_epsilon)
228 : domain_ptr(DomainPtr(&const_cast<Domain &>(d), [](Domain *) {})), epsilon(zero)
229 {
230 //Empty
231 }
232
244 Vector(Domain && d, const NumType & zero = default_epsilon)
245 : domain_ptr(std::make_shared<Domain>(std::move(d))), epsilon(zero)
246 {
247 //Empty
248 }
249
253 template <typename I> requires std::is_integral_v<I>
254 Vector(I, const NumType & = default_epsilon) = delete;
255
260 Vector(const Vector & v)
262 {
263 // empty
264 }
265
270 Vector(Vector && v) noexcept
271 : domain_ptr(v.domain_ptr), epsilon(v.epsilon),
272 entries(std::forward<Map>(v.entries))
273 {
274 // empty
275 }
276
285 const NumType & zero = default_epsilon)
286 requires AlOrderedDomainKey<T>
287 : domain_ptr(std::move(d)), epsilon(zero)
288 {
289 ah_length_error_if(l.size() != domain_ptr->size())
290 << "Vector(DynList): list sizes does not match";
291
292 for (auto it = zip_it(domain_ptr->keys(), l); it.has_curr(); it.next_ne())
293 {
294 auto t = it.get_curr();
295 set_entry(get<0>(t), get<1>(t));
296 }
297 }
298
307 Vector(const Domain & d, const DynList<NumType> & l,
308 const NumType & zero = default_epsilon)
309 requires AlOrderedDomainKey<T>
310 : Vector(DomainPtr(&const_cast<Domain &>(d), [](Domain *) {}), l, zero)
311 {}
312
322 const NumType & zero = default_epsilon)
323 requires AlOrderedDomainKey<T>
324 : Vector(std::make_shared<Domain>(std::move(d)), l, zero)
325 {}
326
330 template <typename I> requires std::is_integral_v<I>
331 Vector(I, const DynList<NumType> &, const NumType & = default_epsilon) = delete;
332
341 {
342 if (this == &v)
343 return *this;
344
346 << "Vector assignment: domains must be the same";
347
348 epsilon = v.epsilon;
349 entries = v.entries;
350
351 return *this;
352 }
353
362 {
363 if (this == &v)
364 return *this;
365
366 ah_domain_error_if(domain_ptr.get() != v.domain_ptr.get())
367 << "Vector assignment: domains must be the same";
368
369 epsilon = v.epsilon;
370 entries.swap(v.entries);
371
372 return *this;
373 }
374
381 void set_entry(const T & i, const NumType & value)
382 {
383 assert(domain_ptr->has(i));
384
385 auto *ptr = const_cast<Pair *>(entries.search(i));
386 if (is_zero(value))
387 {
388 if (ptr != nullptr)
389 entries.remove_ptr(ptr);
390 return;
391 }
392
393 if (ptr == nullptr)
394 entries.insert(i, value);
395 else
396 ptr->second = value;
397 }
398
399 private:
400 // For Proxy, which assigns an entry that is there itself, so that the
401 // assignment through v[i], the frequent case, stays small enough to be
402 // inlined: insert the entry of i, which is not there, or remove the one
403 // that ptr points to, as set_entry() does
404 [[gnu::noinline]] void insert_or_remove_entry(const T & i, const NumType & value,
405 Pair * ptr)
406 {
407 if (not is_zero(value))
408 {
409 if (ptr == nullptr)
410 entries.insert(i, value);
411 else
412 ptr->second = value;
413 }
414 else if (ptr != nullptr)
415 entries.remove_ptr(ptr);
416 }
417
418 public:
419
427 void set_entries(std::initializer_list<T> ld,
428 std::initializer_list<NumType> lr)
429 {
430 ah_range_error_if(ld.size() != lr.size())
431 << "size mismatch between domain and range";
432
433 auto itd = ld.begin();
434 auto itr = lr.begin();
435 for (; itd != ld.end(); ++itd, ++itr)
436 {
437 ah_domain_error_if(not domain_ptr->has(*itd))
438 << "An item of first list doesn't belong to domain";
439 set_entry(*itd, *itr);
440 }
441 }
442
451 template <template <typename> class Container = DynList>
452 void set_entries(const Container<T> & c, std::initializer_list<NumType> lr)
453 {
454 ah_range_error_if(c.size() != lr.size())
455 << "size mismatch between domain and range";
456
457 auto itr = lr.begin();
458 c.for_each([this, &itr](const T & key)
459 {
460 ah_domain_error_if(not domain_ptr->has(key))
461 << "Key does not belong to domain";
462
463 set_entry(key, *itr++);
464 });
465 }
466
474 NumType get_entry(const T & i)
475 {
476 assert(domain_ptr->has(i));
477
478 auto *ptr = entries.search(i);
479 if (ptr == nullptr)
480 return 0;
481
482 if (is_zero(ptr->second))
483 {
484 entries.remove_ptr(ptr);
485 return 0;
486 }
487
488 return ptr->second;
489 }
490
496 NumType get_entry(const T & i) const noexcept
497 {
498 assert(domain_ptr->has(i));
499
500 auto *ptr = entries.search(i);
501 if (ptr == nullptr)
502 return 0;
503
504 return ptr->second;
505 }
506
512 NumType * search_entry(const T & i) noexcept
513 {
514 assert(domain_ptr->has(i));
515
516 auto *ptr = entries.search(i);
517 if (ptr == nullptr)
518 return nullptr;
519
520 return &ptr->second;
521 }
522
525 const NumType * search_entry(const T & i) const noexcept
526 {
527 assert(domain_ptr->has(i));
528
529 auto *ptr = entries.search(i);
530 if (ptr == nullptr)
531 return nullptr;
532
533 return &ptr->second;
534 }
535
542 bool are_equal(const NumType & n1, const NumType & n2) const noexcept
544 {
545 return is_zero(n1 - n2);
546 }
547
553 bool equal_to(const Vector & other) const noexcept
555 {
556 assert(domain_ptr == other.domain_ptr);
557
558 return entries.all([&other, this](const Pair & p)
559 {
560 return are_equal(other.get_entry(p.first), p.second);
561 }) and
562 other.entries.all([this](const Pair & p)
563 {
564 return are_equal(get_entry(p.first), p.second);
565 });
566 }
567
569 bool operator ==(const Vector & v) const noexcept
571 {
572 return equal_to(v);
573 }
574
576 bool operator !=(const Vector & v) const noexcept
578 {
579 return not equal_to(v);
580 }
581
584 {
585 assert(domain_ptr == v.domain_ptr);
586
587 v.entries.for_each([this](const Pair & p)
588 {
589 set_entry(p.first, get_entry(p.first) + p.second);
590 });
591 return *this;
592 }
593
596 {
597 assert(domain_ptr == v.domain_ptr);
598
599 v.entries.for_each([this](const Pair & p)
600 {
601 set_entry(p.first, get_entry(p.first) - p.second);
602 });
603 return *this;
604 }
605
608 {
609 Vector ret_val = *this;
610 ret_val += r;
611 return ret_val;
612 }
613
616 {
617 Vector ret_val = *this;
618 ret_val -= r;
619 return ret_val;
620 }
621
623 Vector &product_by_scalar(const NumType & scalar) noexcept
625 {
626 if (is_zero(scalar))
627 {
628 entries = Map(); // Clear by assigning empty map
629 return *this;
630 }
631
632 if (scalar == 1)
633 return *this;
634
635 entries.for_each([&scalar](const Pair & p)
636 {
637 const_cast<Pair &>(p).second *= scalar;
638 });
639 return *this;
640 }
641
643 Vector operator *(const NumType & scalar) const
645 {
646 Vector ret_val = *this;
647 return ret_val.product_by_scalar(scalar);
648 }
649
651 Vector &divide_by_scalar(const NumType & scalar)
653 {
655 << "Zero division";
656
657 if (scalar == 1)
658 return *this;
659
660 entries.for_each([&scalar](const Pair & p)
661 {
662 const_cast<Pair &>(p).second /= scalar;
663 });
664 return *this;
665 }
666
668 Vector operator /(const NumType & scalar) const
670 {
671 Vector ret_val = *this;
672 return ret_val.divide_by_scalar(scalar);
673 }
674
676 Vector operator -() const requires AlMultiplicativeNumber<NumType>
677 {
678 Vector ret_val = *this;
679 return ret_val.product_by_scalar(-1.0);
680 }
681
683 NumType scalar_product(const Vector & v) const
685 {
686 ah_domain_error_if(domain_ptr != v.domain_ptr)
687 << "scalar_product: different domains";
688
689 // The lambdas return NumType: with numbers of expression templates,
690 // as mpq_class, a deduced type would keep a reference to the
691 // temporary that get_entry() returns, gone at the end of the lambda
692 if (entries.size() < v.entries.size())
693 return entries.
694 template foldl<NumType>(0, [&v](const NumType & acc, const Pair & p) -> NumType
695 {
696 return acc + p.second * v.get_entry(p.first);
697 });
698
699 return v.entries.
700 template foldl<NumType>(0, [this](const NumType & acc, const Pair & p) -> NumType
701 {
702 return acc + get_entry(p.first) * p.second;
703 });
704 }
705
707 NumType operator *(const Vector & v) const
709 {
710 return scalar_product(v);
711 }
712
720 {
721 return domain_ptr->keys().template maps<NumType>([this](const T & i)
722 {
723 return get_entry(i);
724 });
725 }
726
728 void print() const
730 {
731 domain_ptr->keys().for_each([&](const T & k)
732 {
733 if (entries.has(k) != 0)
734 std::cout << "(" << k << "," << entries(k) << ") ";
735 });
736 std::cout << '\n';
737 }
738
740 [[nodiscard]] std::string to_str() const
742 requires (const NumType & n) { { std::to_string(n) } -> std::convertible_to<std::string>; }
743 {
744 // Convert domain elements to strings
745 const DynList<std::string> keys_str =
746 domain_ptr->keys().template maps<std::string>([](const T & k)
747 {
748 std::ostringstream s;
749 s << k;
750 return s.str();
751 });
752
753 // Convert range elements to strings
755 domain_ptr->keys().template maps<std::string>([this](const T & d)
756 {
757 return std::to_string(get_entry(d));
758 });
759
760 typedef std::pair<std::string, std::string> Pair;
762
764 template maps<Pair>([](const Pair & p)
765 {
766 const size_t fsz = p.first.size();
767 const size_t ssz = p.second.size();
768 if (fsz > ssz)
769 return Pair(" " + p.first, std::string(fsz - ssz + 1, ' ') + p.second);
770 return Pair(std::string(ssz - fsz + 1, ' ') + p.first, " " + p.second);
771 });
772
773 std::pair<DynList<std::string>, DynList<std::string>> ret = unzip(format);
774
775 auto concatenate = [](const std::string & s1, const std::string & s2)
776 {
777 return s1 + s2;
778 };
779
780 const std::string dstr = ret.first.template foldl<std::string>("", concatenate);
781
782 const std::string estr = ret.second.template foldl<std::string>("", concatenate);
783
784 return dstr + "\n" + std::string(dstr.size(), '-') + "\n" + estr;
785 }
786
794 class Proxy
795 {
796 Vector *v_ptr = nullptr;
798
799 public:
801 Proxy(Vector & v, const T & k)
802 : v_ptr(&v), key(k)
803 {
804 // empty
805 }
806
808 Proxy(const Proxy &) = default;
809
811 Proxy &operator =(const Proxy & proxy)
812 {
813 // Read first: the assignment may move the entries
814 const NumType value = proxy;
816 return *this;
817 }
818
820 Proxy &operator =(const NumType & item)
821 {
822 // As set_entry(), with the assignment of an entry that is there
823 // here, small enough to be inlined, and the rest apart
824 assert(v_ptr->domain_ptr->has(key));
825 auto *ptr = const_cast<Pair *>(v_ptr->entries.search(key));
826 if (ptr != nullptr and not v_ptr->is_zero(item))
827 ptr->second = item;
828 else
829 v_ptr->insert_or_remove_entry(key, item, ptr);
830 return *this;
831 }
832
834 operator NumType() const noexcept
835 {
836 const NumType *ptr = std::as_const(*v_ptr).search_entry(key);
837 return ptr == nullptr ? NumType(0) : *ptr;
838 }
839 };
840
842 NumType operator [](const T & k) const noexcept
843 {
844 return get_entry(k);
845 }
846
849 {
850 return Proxy(*this, k);
851 }
852
854 NumType operator ()(const T & k) const noexcept
855 {
856 return get_entry(k);
857 }
858
861 {
862 return Proxy(*this, k);
863 }
864
865 struct Iterator : public Map::Iterator
866 {
869
871 Iterator(const Vector &) = delete;
872 };
873
876
877 Iterator get_itor() noexcept { return Iterator(*this); }
878 Iterator get_it() noexcept { return Iterator(*this); }
879
882 Const_Iterator get_itor() const noexcept { return Const_Iterator(*this); }
883
886 Const_Iterator get_it() const noexcept { return Const_Iterator(*this); }
887
888 // Note: traverse(), for_each(), all(), exists(), maps(), filter(),
889 // foldl(), fold(), partition(), take(), drop(), rev(), length(),
890 // nth(), nth_ne(), find_ptr(), find_item() are now provided
891 // by the CRTP mixins: TraverseMixin, FunctionalMixin, LocateMixin
892 };
893
894 template <typename T, typename NumType>
895 requires AlDomainKey<T> and AlNumber<NumType>
896 const NumType Vector<T, NumType>::default_epsilon = 1e-7;
897
898
900 template <typename T, typename NumType>
901 requires AlMultiplicativeNumber<NumType>
902 inline
903 Vector<T, NumType> operator *(const NumType & scalar,
904 const Vector<T, NumType> & v)
905 {
906 Vector<T, NumType> ret_val = v;
907 return ret_val.product_by_scalar(scalar);
908 }
909
911 template <typename T, typename NumType>
912 requires AlOrderedDomainKey<T> and AlStreamable<T> and
913 requires (const NumType & n) { { std::to_string(n) } -> std::convertible_to<std::string>; }
914 inline
915 std::ostream &operator <<(std::ostream & s, const Vector<T, NumType> & vec)
916 {
917 return s << vec.to_str();
918 }
919} // end namespace Aleph
920
921# endif // AL_VECTOR
CRTP Mixins for container functionality (DRY principle).
Exception handling system with formatted messages for Aleph-w.
#define ah_length_error_if(C)
Throws std::length_error if condition holds.
Definition ah-errors.H:846
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
Definition ah-errors.H:670
#define ah_range_error_if(C)
Throws std::range_error if condition holds.
Definition ah-errors.H:356
Zip iterators and functional operations for multiple containers.
DRY (Don't Repeat Yourself) utilities and macros.
Functional programming utilities for Aleph-w containers.
High-level sorting functions for Aleph containers.
Integer domain classes for sparse data structures.
size_t size_t int32_t value
Definition ca-c-api.h:116
Generic domain class based on hash set.
Definition al-domain.H:132
Read-only view of an Aleph iterator: the iterator of a constant container.
Doubly-linked list (defined in tpl_dynList.H).
Definition htlist.H:1231
size_t size() const noexcept
Return the number of items of the list, in constant time.
Definition htlist.H:1264
CRTP Mixin providing functional programming operations.
CRTP Mixin providing element location operations.
Sparse matrix with generic row and column domains.
Definition al-matrix.H:70
Number Theoretic Transform over Z / MOD Z.
Definition ntt.H:115
CRTP Mixin providing traversal operations.
The entry of a key, as v[k] gives it: reads and assigns it.
Definition al-vector.H:795
Proxy & operator=(const Proxy &proxy)
Assign the value of the entry of proxy, zero included.
Definition al-vector.H:811
Proxy(Vector &v, const T &k)
The entry of k in v.
Definition al-vector.H:801
Proxy(const Proxy &)=default
Another proxy of the same entry.
Sparse vector implementation with domain-based indexing.
Definition al-vector.H:155
Vector(DomainPtr d, const NumType &zero=default_epsilon)
Construct a vector over a given domain (shared_ptr version)
Definition al-vector.H:215
bool operator==(const Vector &v) const noexcept
Whether the entries of v are equal to these, within epsilon.
Definition al-vector.H:569
Iterator get_itor() noexcept
Definition al-vector.H:877
NumType scalar_product(const Vector &v) const and AlMultiplicativeNumber< NumType >
The scalar product of this vector and v, over the same domain.
Definition al-vector.H:683
std::pair< T, NumType > Item_Type
Definition al-vector.H:160
Vector operator-() const
The negation of this vector.
Definition al-vector.H:676
void insert_or_remove_entry(const T &i, const NumType &value, Pair *ptr)
Definition al-vector.H:404
const DynList< Pair > format
Definition al-vector.H:763
const Domain & get_domain() const noexcept
Get the domain over which this vector is defined.
Definition al-vector.H:205
std::pair< T, NumType > Pair
Definition al-vector.H:199
const DynList< std::string > entries_str
Definition al-vector.H:754
Vector(Domain &&d, const DynList< NumType > &l, const NumType &zero=default_epsilon)
Construct vector from a temporary domain, which it keeps, and a list of values.
Definition al-vector.H:321
Const_Iterator get_itor() const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition al-vector.H:882
Vector operator*(const NumType &scalar) const
This vector multiplied by scalar.
Definition al-vector.H:643
return dstr n std::string(dstr.size(), '-')+"\n"+estr
std::pair< DynList< std::string >, DynList< std::string > > ret
Definition al-vector.H:773
bool are_equal(const NumType &n1, const NumType &n2) const noexcept
Check if two numeric values are equal within epsilon.
Definition al-vector.H:542
void set_entry(const T &i, const NumType &value)
Set a vector entry at given index.
Definition al-vector.H:381
const NumType & get_epsilon() const noexcept
Get the epsilon value used for zero comparisons.
Definition al-vector.H:187
Vector(const Domain &d, const NumType &zero=default_epsilon)
Construct a vector over a given domain (reference version)
Definition al-vector.H:227
Vector & divide_by_scalar(const NumType &scalar)
Divide every entry by scalar, which must not be zero.
Definition al-vector.H:651
NumType * search_entry(const T &i) noexcept
Search for an entry and return pointer to its value.
Definition al-vector.H:512
Vector & operator=(const Vector &v)
Copy assignment operator.
Definition al-vector.H:340
Aleph::Const_Iterator< Iterator > Const_Iterator
Read-only iterator: the iterator of a constant vector.
Definition al-vector.H:875
DynList< NumType > to_list() const
The values of the vector, in the order of the sorted keys of its domain.
Definition al-vector.H:719
Vector(const Vector &v)
Copy constructor.
Definition al-vector.H:260
static NumType abs(const NumType &val) noexcept
Definition al-vector.H:169
std::pair< std::string, std::string > Pair
Definition al-vector.H:760
bool operator!=(const Vector &v) const noexcept
Whether some entry of v differs from this one, beyond epsilon.
Definition al-vector.H:576
Vector & product_by_scalar(const NumType &scalar) noexcept
Multiply every entry by scalar.
Definition al-vector.H:623
Vector operator+(const Vector &r) const
The sum of this vector and r, over the same domain.
Definition al-vector.H:607
bool is_zero(const NumType &val) const noexcept
Definition al-vector.H:174
DynList< Pair > pairs
Definition al-vector.H:761
static bool test_epsilon(const NumType &e) noexcept
Definition al-vector.H:180
Vector(I, const NumType &=default_epsilon)=delete
A vector needs a domain: Vector(IntRange(n)), not Vector(n), which would turn n into an empty domain.
Vector(I, const DynList< NumType > &, const NumType &=default_epsilon)=delete
A vector needs a domain: Vector(IntRange(n), l), not Vector(n, l), which would turn n into an empty d...
Iterator get_it() noexcept
Definition al-vector.H:878
void set_entries(const Container< T > &c, std::initializer_list< NumType > lr)
Set multiple entries using container and initializer list.
Definition al-vector.H:452
NumType get_entry(const T &i) const noexcept
Get vector entry at given index (const version)
Definition al-vector.H:496
NumType operator()(const T &k) const noexcept
The value of the entry of k, read-only: 0 if it has none.
Definition al-vector.H:854
NumType operator[](const T &k) const noexcept
The value of the entry of k, read-only: 0 if it has none.
Definition al-vector.H:842
bool equal_to(const Vector &other) const noexcept
Check if this vector equals another within epsilon tolerance.
Definition al-vector.H:553
void set_epsilon(const NumType &e) noexcept
Set the epsilon value for zero comparisons.
Definition al-vector.H:194
Vector(Domain &&d, const NumType &zero=default_epsilon)
Construct a vector over a temporary domain, which it keeps.
Definition al-vector.H:244
Vector & operator+=(const Vector &v)
Add v, over the same domain, to this vector.
Definition al-vector.H:583
Vector(Vector &&v) noexcept
Move constructor.
Definition al-vector.H:270
std::shared_ptr< Domain > DomainPtr
Definition al-vector.H:158
static const NumType default_epsilon
Definition al-vector.H:163
Vector & operator-=(const Vector &v)
Subtract v, over the same domain, from this vector.
Definition al-vector.H:595
NumType get_entry(const T &i)
Get vector entry at given index (non-const version)
Definition al-vector.H:474
void set_entries(std::initializer_list< T > ld, std::initializer_list< NumType > lr)
Set multiple entries using initializer lists.
Definition al-vector.H:427
Const_Iterator get_it() const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition al-vector.H:886
const DomainPtr & get_domain_ptr() const noexcept
Return the shared pointer to the domain.
Definition al-vector.H:208
NumType epsilon
Definition al-vector.H:166
void print() const and AlStreamable< T > and AlStreamable< NumType >
Print the nonzero entries, in the order of the sorted keys.
Definition al-vector.H:728
const std::string estr
Definition al-vector.H:782
const NumType * search_entry(const T &i) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition al-vector.H:525
const std::string dstr
Definition al-vector.H:780
Vector(const Domain &d, const DynList< NumType > &l, const NumType &zero=default_epsilon)
Construct vector from domain and list of values (reference version)
Definition al-vector.H:307
DomainPtr domain_ptr
Definition al-vector.H:165
Aleph::HashMap< T, NumType, MapODhash > Map
Definition al-vector.H:159
std::string to_str() const and AlStreamable< T > and
The keys over their values, in the order of the keys.
Definition al-vector.H:740
Vector operator/(const NumType &scalar) const
This vector divided by scalar, which must not be zero.
Definition al-vector.H:668
Vector(DomainPtr d, const DynList< NumType > &l, const NumType &zero=default_epsilon)
Construct vector from domain and list of values (shared_ptr version)
Definition al-vector.H:284
A number that adds and subtracts: what the sums, the differences and the comparisons of vectors and m...
Definition al-vector.H:94
A number that divides: what the division of a vector by a scalar needs.
Definition al-vector.H:121
A key of a domain: of an AlDomain, and so an index of a Vector or of a Matrix.
Definition al-domain.H:89
A number that multiplies: what the products by a scalar, and the products of vectors and matrices,...
Definition al-vector.H:108
A number of the entries of a Vector or of a Matrix.
Definition al-vector.H:77
A key of a domain that < orders: what AlDomain::keys(), and the members that take the keys in their o...
Definition al-domain.H:98
A value that << writes to a stream: what the members that print keys or numbers need.
Definition al-domain.H:109
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
ZipIterator< Cs... > zip_it(const Cs &...cs)
Alias for get_zip_it.
Definition ah-zip.H:359
auto unzip(const Container &l)
Separate a list of pairs into two lists.
DynList< std::pair< typename Container1::Item_Type, typename Container2::Item_Type > > zip(const Container1 &a, const Container2 &b)
Zip two containers into a list of pairs.
std::decay_t< typename HeadC::Item_Type > T
Definition ah-zip.H:152
and
Check uniqueness with explicit hash + equality functors.
Matrix< Trow, Tcol, NumType > operator*(const NumType &scalar, const Matrix< Trow, Tcol, NumType > &m)
Scalar-matrix multiplication (scalar * matrix).
Definition al-matrix.H:1228
std::ostream & operator<<(std::ostream &osObject, const Field< T > &rightOp)
Definition ahField.H:121
STL namespace.
Iterator(const Vector &)=delete
A constant vector is iterated through Const_Iterator.
Iterator(Vector &vec)
Iterator on the entries of the modifiable vector vec.
Definition al-vector.H:868
Aleph::DynList< T > keys() const
See items().
Definition ah-dry.H:2916
static int * k
Gsl_Compatible_Rng r
Unified hash table interface.
DynList< int > l