congeal

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

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

Examples

//scope(failure) {writefln("Unittest failure :%s(%s)", __FILE__, __LINE__); stdout.flush();}
//scope(success) {writefln("Unittest success :%s(%s)", __FILE__, __LINE__); stdout.flush();}


static struct I{

    size_t opIndex(size_t i, size_t j) inout { return i == j ? 1  : 0;}

    static InferredResult inferSize(Msize_t r, Msize_t c)
    {
        if(r == wild && c == wild)
            return InferredResult(false);
        else if(isEqOrEitherEqX(r, c, wild))
            return InferredResult(true, max(r, c), max(r, c));
        else
            return InferredResult(false);
    }

    mixin(defaultExprOps!(true));
}

static assert(!isNarrowMatrix!I);
static assert(isAbstractMatrix!I);
static assert( I.inferSize(wild, 1).isValid);
static assert( I.inferSize(3, 3).isValid);
static assert(!I.inferSize(1, 3).isValid);

I id;
auto i3x3 = id.congeal!(3, 3)();
static assert(isNarrowMatrix!(typeof(i3x3)));
static assert(hasStaticRows!(typeof(i3x3)));
static assert(hasStaticCols!(typeof(i3x3)));
static assert(i3x3.rows == 3);
static assert(i3x3.cols == 3);
assert(i3x3[0, 0] == 1);assert(i3x3[1, 0] == 0);assert(i3x3[2, 0] == 0);
assert(i3x3[0, 1] == 0);assert(i3x3[1, 1] == 1);assert(i3x3[2, 1] == 0);
assert(i3x3[0, 2] == 0);assert(i3x3[1, 2] == 0);assert(i3x3[2, 2] == 1);
//scope(failure) {writefln("Unittest failure :%s(%s)", __FILE__, __LINE__); stdout.flush();}
//scope(success) {writefln("Unittest success :%s(%s)", __FILE__, __LINE__); stdout.flush();}


static struct I{

    size_t opIndex(size_t i, size_t j) inout { return i == j ? 1  : 0;}

    static InferredResult inferSize(Msize_t r, Msize_t c)
    {
        if(r == wild && c == wild)
            return InferredResult(false);
        else if(isEqOrEitherEqX(r, c, wild))
            return InferredResult(true, max(r, c), max(r, c));
        else
            return InferredResult(false);
    }

    mixin(defaultExprOps!(true));
}

static assert(!isNarrowMatrix!I);
static assert(isAbstractMatrix!I);
static assert( I.inferSize(wild, 1).isValid);
static assert( I.inferSize(3, 3).isValid);
static assert(!I.inferSize(1, 3).isValid);

I id;
auto i3x3 = id.congeal(3, 3);
static assert(isNarrowMatrix!(typeof(i3x3)));
static assert(hasDynamicRows!(typeof(i3x3)));
static assert(hasDynamicColumns!(typeof(i3x3)));
assert(i3x3.rows == 3);
assert(i3x3.cols == 3);
assert(i3x3[0, 0] == 1);assert(i3x3[1, 0] == 0);assert(i3x3[2, 0] == 0);
assert(i3x3[0, 1] == 0);assert(i3x3[1, 1] == 1);assert(i3x3[2, 1] == 0);
assert(i3x3[0, 2] == 0);assert(i3x3[1, 2] == 0);assert(i3x3[2, 2] == 1);

Meta