| Message ID | 20260928-awb-state-v1-2-9b1bb8b9e51b@ideasonboard.com |
|---|---|
| State | New |
| Headers | show |
| Series |
|
| Related | show |
2026. 09. 28. 13:13 keltezéssel, Daniel Scally írta: > We want to be able to compare Vectors of gains to see if any of the > vector values are larger / smaller than the other. Add four new > operators for <, >, <= and >=. > > Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com> > --- > include/libcamera/internal/vector.h | 44 +++++++++++++++++++++++++++++++++++++ > 1 file changed, 44 insertions(+) > > diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h > index 4fb610dbc0aec12a934d7f971c8ee62375a6d726..b89239aa9253209726450a63f29af97b8a808cb8 100644 > --- a/include/libcamera/internal/vector.h > +++ b/include/libcamera/internal/vector.h > @@ -343,6 +343,50 @@ bool operator==(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) > return true; > } > > +template<typename T, unsigned int Rows> > +bool operator>(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) > +{ > + for (unsigned int i = 0; i < Rows; i++) { > + if (lhs[i] > rhs[i]) > + return true; > + } > + > + return false; > +} > + > +template<typename T, unsigned int Rows> > +bool operator>=(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) > +{ > + for (unsigned int i = 0; i < Rows; i++) { > + if (lhs[i] >= rhs[i]) > + return true; > + } > + > + return false; > +} > + > +template<typename T, unsigned int Rows> > +bool operator<=(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) > +{ > + for (unsigned int i = 0; i < Rows; i++) { > + if (lhs[i] <= rhs[i]) > + return true; > + } > + > + return false; > +} > + > +template<typename T, unsigned int Rows> > +bool operator<(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) > +{ > + for (unsigned int i = 0; i < Rows; i++) { > + if (lhs[i] < rhs[i]) > + return true; > + } > + > + return false; > +} Could you check if adding constexpr auto operator<=>(const Vector &other) const = default; (and `#include <compare>`) works instead of these four? > + > template<typename T, unsigned int Rows> > bool operator!=(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) > { >
Hi Barnabas On 28/09/2026 12:35, Barnabás Pőcze wrote: > 2026. 09. 28. 13:13 keltezéssel, Daniel Scally írta: >> We want to be able to compare Vectors of gains to see if any of the >> vector values are larger / smaller than the other. Add four new >> operators for <, >, <= and >=. >> >> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com> >> --- >> include/libcamera/internal/vector.h | 44 +++++++++++++++++++++++++++++++++++++ >> 1 file changed, 44 insertions(+) >> >> diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h >> index 4fb610dbc0aec12a934d7f971c8ee62375a6d726..b89239aa9253209726450a63f29af97b8a808cb8 100644 >> --- a/include/libcamera/internal/vector.h >> +++ b/include/libcamera/internal/vector.h >> @@ -343,6 +343,50 @@ bool operator==(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) >> return true; >> } >> +template<typename T, unsigned int Rows> >> +bool operator>(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) >> +{ >> + for (unsigned int i = 0; i < Rows; i++) { >> + if (lhs[i] > rhs[i]) >> + return true; >> + } >> + >> + return false; >> +} >> + >> +template<typename T, unsigned int Rows> >> +bool operator>=(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) >> +{ >> + for (unsigned int i = 0; i < Rows; i++) { >> + if (lhs[i] >= rhs[i]) >> + return true; >> + } >> + >> + return false; >> +} >> + >> +template<typename T, unsigned int Rows> >> +bool operator<=(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) >> +{ >> + for (unsigned int i = 0; i < Rows; i++) { >> + if (lhs[i] <= rhs[i]) >> + return true; >> + } >> + >> + return false; >> +} >> + >> +template<typename T, unsigned int Rows> >> +bool operator<(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) >> +{ >> + for (unsigned int i = 0; i < Rows; i++) { >> + if (lhs[i] < rhs[i]) >> + return true; >> + } >> + >> + return false; >> +} > > Could you check if adding > > constexpr auto operator<=>(const Vector &other) const = default; > > (and `#include <compare>`) works instead of these four? Oooooooh. Thanks! I'll give it a try. Dan > > >> + >> template<typename T, unsigned int Rows> >> bool operator!=(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) >> { >> >
2026. 09. 28. 13:37 keltezéssel, Dan Scally írta: > Hi Barnabas > > On 28/09/2026 12:35, Barnabás Pőcze wrote: >> 2026. 09. 28. 13:13 keltezéssel, Daniel Scally írta: >>> We want to be able to compare Vectors of gains to see if any of the >>> vector values are larger / smaller than the other. Add four new >>> operators for <, >, <= and >=. >>> >>> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com> >>> --- >>> include/libcamera/internal/vector.h | 44 +++++++++++++++++++++++++++++++++++++ >>> 1 file changed, 44 insertions(+) >>> >>> diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h >>> index 4fb610dbc0aec12a934d7f971c8ee62375a6d726..b89239aa9253209726450a63f29af97b8a808cb8 100644 >>> --- a/include/libcamera/internal/vector.h >>> +++ b/include/libcamera/internal/vector.h >>> @@ -343,6 +343,50 @@ bool operator==(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) >>> return true; >>> } >>> +template<typename T, unsigned int Rows> >>> +bool operator>(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) >>> +{ >>> + for (unsigned int i = 0; i < Rows; i++) { >>> + if (lhs[i] > rhs[i]) >>> + return true; >>> + } >>> + >>> + return false; >>> +} >>> + >>> +template<typename T, unsigned int Rows> >>> +bool operator>=(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) >>> +{ >>> + for (unsigned int i = 0; i < Rows; i++) { >>> + if (lhs[i] >= rhs[i]) >>> + return true; >>> + } >>> + >>> + return false; >>> +} >>> + >>> +template<typename T, unsigned int Rows> >>> +bool operator<=(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) >>> +{ >>> + for (unsigned int i = 0; i < Rows; i++) { >>> + if (lhs[i] <= rhs[i]) >>> + return true; >>> + } >>> + >>> + return false; >>> +} >>> + >>> +template<typename T, unsigned int Rows> >>> +bool operator<(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) >>> +{ >>> + for (unsigned int i = 0; i < Rows; i++) { >>> + if (lhs[i] < rhs[i]) >>> + return true; >>> + } >>> + >>> + return false; >>> +} >> >> Could you check if adding >> >> constexpr auto operator<=>(const Vector &other) const = default; >> >> (and `#include <compare>`) works instead of these four? > > Oooooooh. Thanks! I'll give it a try. Hmmm... on second thought, nevermind. Even if it compiles, I don't think it will do what you want. But on that note, these definitions seem quite interesting. a = { 1, 2 } b = { 2, 1 } a > b -> true a < b -> true This seems quite counterintuitive. Maybe we need some other metric? Should we maybe compare the length of the distance vector? E.g. (convergedGains_ - newGains).length() / convergedGains_.length() < ... ? > > Dan > >> >> >>> + >>> template<typename T, unsigned int Rows> >>> bool operator!=(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) >>> { >>> >> >
diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h index 4fb610dbc0aec12a934d7f971c8ee62375a6d726..b89239aa9253209726450a63f29af97b8a808cb8 100644 --- a/include/libcamera/internal/vector.h +++ b/include/libcamera/internal/vector.h @@ -343,6 +343,50 @@ bool operator==(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) return true; } +template<typename T, unsigned int Rows> +bool operator>(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) +{ + for (unsigned int i = 0; i < Rows; i++) { + if (lhs[i] > rhs[i]) + return true; + } + + return false; +} + +template<typename T, unsigned int Rows> +bool operator>=(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) +{ + for (unsigned int i = 0; i < Rows; i++) { + if (lhs[i] >= rhs[i]) + return true; + } + + return false; +} + +template<typename T, unsigned int Rows> +bool operator<=(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) +{ + for (unsigned int i = 0; i < Rows; i++) { + if (lhs[i] <= rhs[i]) + return true; + } + + return false; +} + +template<typename T, unsigned int Rows> +bool operator<(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) +{ + for (unsigned int i = 0; i < Rows; i++) { + if (lhs[i] < rhs[i]) + return true; + } + + return false; +} + template<typename T, unsigned int Rows> bool operator!=(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) {
We want to be able to compare Vectors of gains to see if any of the vector values are larger / smaller than the other. Add four new operators for <, >, <= and >=. Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com> --- include/libcamera/internal/vector.h | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)