10 #ifndef LLVM_CODEGEN_PBQP_MATH_H
11 #define LLVM_CODEGEN_PBQP_MATH_H
37 std::fill(Data.get(), Data.get() + Length, InitVal);
43 std::copy(V.Data.get(), V.Data.get() + Length, Data.get());
48 : Length(V.Length), Data(std::move(V.Data)) {
54 assert(Length != 0 && Data &&
"Invalid vector");
55 if (Length != V.Length)
57 return std::equal(Data.get(), Data.get() + Length, V.Data.get());
62 assert(Length != 0 && Data &&
"Invalid vector");
68 assert(Length != 0 && Data &&
"Invalid vector");
69 assert(Index < Length &&
"Vector element access out of bounds.");
75 assert(Length != 0 && Data &&
"Invalid vector");
76 assert(Index < Length &&
"Vector element access out of bounds.");
82 assert(Length != 0 && Data &&
"Invalid vector");
83 assert(Length == V.Length &&
"Vector length mismatch.");
84 std::transform(Data.get(), Data.get() + Length, V.Data.get(), Data.get(),
85 std::plus<PBQPNum>());
91 assert(Length != 0 && Data &&
"Invalid vector");
92 return std::min_element(Data.get(), Data.get() + Length) - Data.get();
97 std::unique_ptr<PBQPNum []> Data;
102 unsigned *VBegin =
reinterpret_cast<unsigned*
>(V.Data.get());
103 unsigned *VEnd =
reinterpret_cast<unsigned*
>(V.Data.get() + V.Length);
109 template <
typename OStream>
114 for (
unsigned i = 1; i < V.getLength(); ++i)
135 : Rows(Rows), Cols(Cols),
137 std::fill(Data.get(), Data.get() + (Rows * Cols), InitVal);
142 : Rows(M.Rows), Cols(M.Cols),
144 std::copy(M.Data.get(), M.Data.get() + (Rows * Cols), Data.get());
149 : Rows(M.Rows), Cols(M.Cols), Data(std::move(M.Data)) {
155 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
156 if (Rows != M.Rows || Cols != M.Cols)
158 return std::equal(Data.get(), Data.get() + (Rows * Cols), M.Data.get());
163 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
169 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
175 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
176 assert(R < Rows &&
"Row out of bounds.");
177 return Data.get() + (R * Cols);
182 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
183 assert(R < Rows &&
"Row out of bounds.");
184 return Data.get() + (R * Cols);
189 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
191 for (
unsigned C = 0;
C < Cols; ++
C)
192 V[
C] = (*
this)[R][
C];
198 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
200 for (
unsigned R = 0; R < Rows; ++R)
201 V[R] = (*
this)[R][
C];
207 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
209 for (
unsigned r = 0; r < Rows; ++r)
210 for (
unsigned c = 0; c < Cols; ++c)
211 M[c][r] = (*
this)[r][c];
217 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
218 assert(Rows == M.Rows && Cols == M.Cols &&
219 "Matrix dimensions mismatch.");
220 std::transform(Data.get(), Data.get() + (Rows * Cols), M.Data.get(),
221 Data.get(), std::plus<PBQPNum>());
226 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
234 std::unique_ptr<PBQPNum []> Data;
239 unsigned *MBegin =
reinterpret_cast<unsigned*
>(M.Data.get());
241 reinterpret_cast<unsigned*
>(M.Data.get() + (M.Rows * M.Cols));
247 template <
typename OStream>
250 for (
unsigned i = 0; i < M.
getRows(); ++i)
255 template <
typename Metadata>
267 template <
typename Metadata>
269 return hash_value(static_cast<const Vector&>(V));
272 template <
typename Metadata>
284 template <
typename Metadata>
286 return hash_value(static_cast<const Matrix&>(M));
292 #endif // LLVM_CODEGEN_PBQP_MATH_H
OStream & operator<<(OStream &OS, const Vector &V)
Output a textual representation of the given vector on the given output stream.
unsigned getCols() const
Return the number of cols in this matrix.
unsigned minIndex() const
Returns the index of the minimum value in this vector.
friend hash_code hash_value(const Matrix &)
Return a hash_code for the given matrix.
PBQPNum * operator[](unsigned R)
Matrix element access.
PBQPNum & operator[](unsigned Index)
Element access.
MDMatrix(const Matrix &m)
Matrix(unsigned Rows, unsigned Cols, PBQPNum InitVal)
Construct a PBQP Matrix with the given dimensions and initial value.
Matrix(unsigned Rows, unsigned Cols)
Construct a PBQP Matrix with the given dimensions.
bool operator==(const Matrix &M) const
Comparison operator.
Vector getRowAsVector(unsigned R) const
Returns the given row as a vector.
Vector getColAsVector(unsigned C) const
Returns the given column as a vector.
const PBQPNum & operator[](unsigned Index) const
Const element access.
Vector(unsigned Length)
Construct a PBQP vector of the given size.
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&...args)
Constructs a new T() with the given args and returns a unique_ptr<T> which owns the object...
Matrix & operator+=(const Matrix &M)
Add the given matrix to this one.
friend hash_code hash_value(const Vector &)
Return a hash_value for the given vector.
unsigned getLength() const
Return the length of the vector.
Matrix(Matrix &&M)
Move construct a PBQP matrix.
const Metadata & getMetadata() const
Vector(const Vector &V)
Copy construct a PBQP vector.
hash_code hash_value(const Vector &V)
Return a hash_value for the given vector.
bool operator==(const Vector &V) const
Comparison operator.
const PBQPNum * operator[](unsigned R) const
Matrix element access.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Matrix operator+(const Matrix &M)
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
An opaque object representing a hash code.
const Metadata & getMetadata() const
unsigned getRows() const
Return the number of rows in this matrix.
Vector(Vector &&V)
Move construct a PBQP vector.
Vector & operator+=(const Vector &V)
Add another vector to this one.
OutputIt transform(R &&Range, OutputIt d_first, UnaryPredicate P)
Wrapper function around std::transform to apply a function to a range and store the result elsewhere...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Matrix(const Matrix &M)
Copy construct a PBQP matrix.
Matrix transpose() const
Matrix transpose.
Vector(unsigned Length, PBQPNum InitVal)
Construct a PBQP vector with initializer.
MDVector(const Vector &v)