63 if int32(dim) ~= dim || dim <= 0
64 error(
" Dimension d must be a positive integer. ");
68 this.rnd= RandStream(
" mt19937ar ",
" Seed ",2);
69 this.expidx= int32(1);
70 this.incidx= int32(1);
81 alpha = zeros(this.
Dim,1);
92 function [colvec<double>alpha , int32deg , exps ] =
nextMonomial() {
97 alpha = histc(this.expidx, 1:this.
Dim)^
t;
102 if this.expidx(this.incidx) == this.
Dim && this.incidx > 1
104 this.incidx= this.incidx - 1;
107 this.expidx(this.incidx) = this.expidx(this.incidx) + 1;
110 if this.expidx(this.incidx) < this.
Dim
112 this.expidx(this.incidx+1:this.deg) = this.expidx(this.incidx);
113 this.incidx= this.deg;
116 this.expidx(this.incidx) = this.expidx(this.incidx) + 1;
120 if this.incidx == 0 || this.expidx(this.incidx) > this.
Dim
122 this.deg= this.deg + 1;
123 this.expidx= int32(ones(1,this.deg));
125 this.incidx= this.deg;
142 alpha = zeros(this.
Dim,1);
145 idx = this.rnd.randi(this.
Dim);
146 alpha(idx) = alpha(idx) + this.rnd.randi(deg-s);
166 fprintf(
" Dim=%d:\n ",
Dim)
170 [alpha, deg, exps] = mi.nextMonomial;
171 fprintf(
" p=%d, exps=[%s], alpha=[%s]\n ",deg,
Utils.
implode(exps,
" , ",
" %d "),...
179 [alpha, deg, exps] = mi.nextMonomial;
181 res = res && alpha == i && deg == i &&
all(exps==1);
186 cmpp1 = [1; 2; 3; 4];
187 cmpp2 = [1 1; 1 2; 1 3; 1 4; 2 2; 2 3; 2 4; 3 3; 3 4; 4 4];
188 cmpp3 = [1 1 1; 1 1 2; 1 1 3; 1 1 4; 1 2 2; 1 2 3; 1 2 4; 1 3 3; 1 3 4; 1 4 4; 2 2 2;...
189 2 2 3; 2 2 4; 2 3 3; 2 3 4; 2 4 4; 3 3 3; 3 3 4; 3 4 4; 4 4 4];
190 for i = 1:size(cmpp1,1)
191 [~, deg, exps] = mi.nextMonomial;
192 res = res && deg == 1 &&
all(exps==cmpp1(i,:));
194 for i = 1:size(cmpp2,1)
195 [~, deg, exps] = mi.nextMonomial;
196 res = res && deg == 2 &&
all(exps==cmpp2(i,:));
198 for i = 1:size(cmpp3,1)
199 [~, deg, exps] = mi.nextMonomial;
200 res = res && deg == 3 &&
all(exps==cmpp3(i,:));
static function logical res = test_MonomialIterator()
Tests the MonomialIterator for two test cases.
Collection of generally useful functions.
function colvec< int32 > alpha = getRandMonomial(int32 deg)
Returns a random monomial.
MonomialIterator(integer dim)
Creates a new monomial iterator.
Matlab's base handle class (documentation generation substitute)
MonomialIterator: Create list of d-dim monomials.
function colvec< double > alpha = getNullMonomial()
Get the monomial of degree zero.
static function char str = implode(char|rowvec data,char glue,char format)
Implodes the elements of data using glue.
function [ colvec< double > alpha , int32 deg , exps ] = nextMonomial()
Returns the next monomial in the sequence.