예제 #1
0
void Transpose::scalar(const var& iVar, var& oVar) const
{
    // Note that we need to transpose the view too.  If it's allocated, it's
    // transposed at allocation; if it's supplied it's assumed to be correct
    // already.  This leaves the in-place case; this happens after the
    // operation.

    // Transpose always broadcasts to array()
    broadcast(iVar, oVar);

    // Transpose view if necessary
    if (iVar.is(oVar))
    {
        // Swap the trailing dimensions
        int d = iVar.dim();
        Heap* h = iVar.heap();
        int& str1 = h->stride(d-1);
        int& shp1 = h->shape(d-1);
        int& str2 = h->stride(d-2);
        int& shp2 = h->shape(d-2);
        int tmp = shp1;
        shp1 = shp2;
        shp2 = tmp;
        str2 = shp1 * str1;
    }
}
예제 #2
0
void Transpose::vector(var iVar, ind iOffsetI, var& oVar, ind iOffsetO) const
{
    assert(oVar);
    int dim = iVar.dim();
    ind rows = iVar.shape(dim-2);
    ind cols = iVar.shape(dim-1);
    if (iVar.is(oVar))
        // In place transpose
        switch (iVar.atype())
        {
        case TYPE_FLOAT:
            inPlace<float>(oVar.ptr<float>(iOffsetO), rows, cols);
            break;
        case TYPE_DOUBLE:
            inPlace<double>(oVar.ptr<double>(iOffsetO), rows, cols);
            break;
        default:
            throw error("Transpose::vector(): unknown type");            
        }
    else
        // Transpose to new location
        switch (iVar.atype())
        {
        case TYPE_FLOAT:
            outOfPlace<float>(iVar.ptr<float>(iOffsetI), rows, cols,
                              oVar.ptr<float>(iOffsetO));
            break;
        case TYPE_DOUBLE:
            outOfPlace<double>(iVar.ptr<double>(iOffsetI), rows, cols,
                               oVar.ptr<double>(iOffsetO));
            break;
        default:
            throw error("Transpose::vector(): unknown type");
        }
}