Skip to content

Commit b9ab84c

Browse files
authored
Add (in)equality operators for nnet array (#1337)
* Add (in)equality operators * Changes for linter * Add (in)equality operators * Return false if array sizes differ
1 parent f794928 commit b9ab84c

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

hls4ml/templates/catapult/nnet_utils/nnet_types.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ template <typename T, unsigned N> struct array {
3030
}
3131
return *this;
3232
}
33+
34+
bool operator==(const array &other) const {
35+
if (N != other.size) {
36+
return false;
37+
}
38+
39+
for (unsigned i = 0; i < N; i++) {
40+
if (data[i] != other[i]) {
41+
return false;
42+
}
43+
}
44+
45+
return true;
46+
}
47+
48+
bool operator!=(const array &other) const { return !(*this == other); }
3349
};
3450

3551
// Generic lookup-table implementation, for use in approximations of math functions

hls4ml/templates/vivado/nnet_utils/nnet_types.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ template <typename T, unsigned N> struct array {
3030
}
3131
return *this;
3232
}
33+
34+
bool operator==(const array &other) const {
35+
if (N != other.size) {
36+
return false;
37+
}
38+
39+
for (unsigned i = 0; i < N; i++) {
40+
if (data[i] != other[i]) {
41+
return false;
42+
}
43+
}
44+
45+
return true;
46+
}
47+
48+
bool operator!=(const array &other) const { return !(*this == other); }
3349
};
3450

3551
// Generic lookup-table implementation, for use in approximations of math functions

0 commit comments

Comments
 (0)