Added a static create helper for Matrix.

This commit is contained in:
Relintai 2023-04-30 12:50:24 +02:00
parent d39291c849
commit 9993bc9d4e
2 changed files with 17 additions and 0 deletions

View File

@ -1999,6 +1999,21 @@ Ref<MLPPMatrix> MLPPMatrix::identity_mat(int d) const {
return identity_mat;
}
Ref<MLPPMatrix> MLPPMatrix::create_identity_mat(int d) {
Ref<MLPPMatrix> identity_mat;
identity_mat.instance();
identity_mat->resize(Size2i(d, d));
identity_mat->fill(0);
real_t *im_ptr = identity_mat->ptrw();
for (int i = 0; i < d; i++) {
im_ptr[identity_mat->calculate_index(i, i)] = 1;
}
return identity_mat;
}
Ref<MLPPMatrix> MLPPMatrix::cov() const {
MLPPStat stat;

View File

@ -248,6 +248,8 @@ public:
Ref<MLPPMatrix> identityn() const;
Ref<MLPPMatrix> identity_mat(int d) const;
static Ref<MLPPMatrix> create_identity_mat(int d);
Ref<MLPPMatrix> cov() const;
void covo(Ref<MLPPMatrix> out) const;