congeal

InferableMatrixをある大きさの行列へ固定します。

  1. auto congeal(A mat)
    congeal
    (
    Msize_t rs
    Msize_t cs
    A
    )
    (
    A mat
    )
    if (
    A.inferSize(rs, cs).isValid
    )
  2. auto congeal(auto ref A mat, size_t r, size_t c)
  3. auto congeal(auto ref A mat)

Examples

1 scope(failure) {writefln("Unittest failure :%s(%s)", __FILE__, __LINE__); stdout.flush();}
2 scope(success) {writefln("Unittest success :%s(%s)", __FILE__, __LINE__); stdout.flush();}
3 
4 
5 static struct I{
6 
7     size_t opIndex(size_t i, size_t j) inout { return i == j ? 1  : 0;}
8 
9     static InferredResult inferSize(Msize_t r, Msize_t c)
10     {
11         if(r == wild && c == wild)
12             return InferredResult(false);
13         else if(isEqOrEitherEqX(r, c, wild))
14             return InferredResult(true, max(r, c), max(r, c));
15         else
16             return InferredResult(false);
17     }
18 
19     mixin(defaultExprOps!(true));
20 }
21 
22 static assert(!isNarrowMatrix!I);
23 static assert(isAbstractMatrix!I);
24 static assert( I.inferSize(wild, 1).isValid);
25 static assert( I.inferSize(3, 3).isValid);
26 static assert(!I.inferSize(1, 3).isValid);
27 
28 I id;
29 auto i3x3 = id.congeal!(3, 3)();
30 static assert(isNarrowMatrix!(typeof(i3x3)));
31 static assert(hasStaticRows!(typeof(i3x3)));
32 static assert(hasStaticCols!(typeof(i3x3)));
33 static assert(i3x3.rows == 3);
34 static assert(i3x3.cols == 3);
35 assert(i3x3[0, 0] == 1);assert(i3x3[1, 0] == 0);assert(i3x3[2, 0] == 0);
36 assert(i3x3[0, 1] == 0);assert(i3x3[1, 1] == 1);assert(i3x3[2, 1] == 0);
37 assert(i3x3[0, 2] == 0);assert(i3x3[1, 2] == 0);assert(i3x3[2, 2] == 1);
1 scope(failure) {writefln("Unittest failure :%s(%s)", __FILE__, __LINE__); stdout.flush();}
2 scope(success) {writefln("Unittest success :%s(%s)", __FILE__, __LINE__); stdout.flush();}
3 
4 
5 static struct I{
6 
7     size_t opIndex(size_t i, size_t j) inout { return i == j ? 1  : 0;}
8 
9     static InferredResult inferSize(Msize_t r, Msize_t c)
10     {
11         if(r == wild && c == wild)
12             return InferredResult(false);
13         else if(isEqOrEitherEqX(r, c, wild))
14             return InferredResult(true, max(r, c), max(r, c));
15         else
16             return InferredResult(false);
17     }
18 
19     mixin(defaultExprOps!(true));
20 }
21 
22 static assert(!isNarrowMatrix!I);
23 static assert(isAbstractMatrix!I);
24 static assert( I.inferSize(wild, 1).isValid);
25 static assert( I.inferSize(3, 3).isValid);
26 static assert(!I.inferSize(1, 3).isValid);
27 
28 I id;
29 auto i3x3 = id.congeal(3, 3);
30 static assert(isNarrowMatrix!(typeof(i3x3)));
31 static assert(hasDynamicRows!(typeof(i3x3)));
32 static assert(hasDynamicColumns!(typeof(i3x3)));
33 assert(i3x3.rows == 3);
34 assert(i3x3.cols == 3);
35 assert(i3x3[0, 0] == 1);assert(i3x3[1, 0] == 0);assert(i3x3[2, 0] == 0);
36 assert(i3x3[0, 1] == 0);assert(i3x3[1, 1] == 1);assert(i3x3[2, 1] == 0);
37 assert(i3x3[0, 2] == 0);assert(i3x3[1, 2] == 0);assert(i3x3[2, 2] == 1);

Meta