Is this an okay representation of a dynamically sized Matrix, to be used for HMM matrices m = (A,B)
Enjoys Math
enjoysmath at gmail.com
Thu Dec 28 01:34:10 UTC 2017
Code:
----
module matrix;
import std.array;
struct Matrix(E)
{
private:
E[][];
this() {
}
void deleteRow(int i)
{
E = E[0..i] ~ E[i..$];
}
void deleteColumn(int j)
{
for (int i=0; i < E.length; i++)
{
E[i] = E[i][0..j] ~ E[i][j..$];
}
}
void insertRow(int i, E[] row)
{
if (E.length != 0)
assert(E[0].length == row.length);
E.insertInPlace(i, row);
}
void insertColumn(int j, E[] col)
{
for (int i=0; i < E.length; i++)
{
E[i].insertInPlace(j, col[i]);
}
}
int numRows() { return E.length; }
int numColumns() {
if (E.length == 0)
return 0;
return E[0].length;
}
}
Is there a more efficient way of doing this, knowing that I'll be
inserting columns / rows every time we need to create a new
hidden state so this matrix will be huge, for a good model. By
huge we'll probably use the full capacity of a long[] in D. I've
already tried doing this in MQL5 and we exceeded easily the max
array capacity.
More information about the Digitalmars-d-learn
mailing list