Exemple #1
0
def printTensors(dataTable1,
                 dataTable2,
                 title1="",
                 title2="",
                 message="",
                 nPrintedRows=0,
                 interval=15):
    dims1 = dataTable1.getDimensions()
    nRows1 = int(dims1[0])

    if nPrintedRows != 0:
        nPrintedRows = min(nRows1, nPrintedRows)
    else:
        nPrintedRows = nRows1

    block1 = SubtensorDescriptor()
    dataTable1.getSubtensor([], 0, nPrintedRows, readOnly, block1)
    nCols1 = int(block1.getSize() / nPrintedRows)

    dims2 = dataTable2.getDimensions()
    nRows2 = int(dims2[0])

    if nPrintedRows != 0:
        nPrintedRows = min(nRows2, nPrintedRows)
    else:
        nPrintedRows = nRows2

    block2 = SubtensorDescriptor()
    dataTable2.getSubtensor([], 0, nPrintedRows, readOnly, block2)
    nCols2 = int(block2.getSize() / nPrintedRows)

    dataType1 = block1.getArray().flatten()
    dataType2 = block2.getArray().flatten()

    print(message)
    print("{:<{width}}".format(title1, width=(interval * nCols1)), end='')
    print("{:<{width}}".format(title2, width=(interval * nCols2)))

    for i in range(nPrintedRows):
        for j in range(nCols1):
            print("{v:<{width}.0f}".format(v=dataType1[i * nCols1 + j],
                                           width=interval),
                  end='')

        for j in range(nCols2):
            print("{:<{width}.3f}".format(dataType2[i * nCols2 + j],
                                          width=int(interval / 2)),
                  end='')
        print()
    print()

    dataTable1.releaseSubtensor(block1)
    dataTable2.releaseSubtensor(block2)
Exemple #2
0
def printTensor3d(dataTable,
                  message="",
                  nFirstDim=0,
                  nSecondDim=0,
                  interval=10):
    dims = dataTable.getDimensions()
    nRows = int(dims[0])
    nCols = int(dims[1])

    if nFirstDim != 0:
        nFirstDim = min(nRows, nFirstDim)
    else:
        nFirstDim = nRows

    if nSecondDim != 0:
        nSecondDim = min(nCols, nSecondDim)
    else:
        nSecondDim = nCols

    block = SubtensorDescriptor()

    print(message)
    for i in range(nFirstDim):
        dataTable.getSubtensor([i], 0, nSecondDim, readOnly, block)

        nThirdDim = block.getSize() / nSecondDim

        printArray(block.getArray(), int(nThirdDim), int(nSecondDim),
                   int(nThirdDim), "", interval)

        dataTable.releaseSubtensor(block)
Exemple #3
0
def printTensor(dataTable,
                message="",
                nPrintedRows=0,
                nPrintedCols=0,
                interval=10):
    dims = dataTable.getDimensions()
    nRows = int(dims[0])

    if nPrintedRows != 0:
        nPrintedRows = min(nRows, nPrintedRows)
    else:
        nPrintedRows = nRows

    block = SubtensorDescriptor()

    dataTable.getSubtensor([], 0, nPrintedRows, readOnly, block)

    nCols = int(block.getSize() / nPrintedRows)

    if nPrintedCols != 0:
        nPrintedCols = min(nCols, nPrintedCols)
    else:
        nPrintedCols = nCols

    printArray(block.getArray(), int(nPrintedCols), int(nPrintedRows),
               int(nCols), message, interval)
    dataTable.releaseSubtensor(block)
Exemple #4
0
def findClasses(dataTable):
    dims1 = dataTable.getDimensions()
    nRows1 = int(dims1[0])
    block1 = SubtensorDescriptor()
    dataTable.getSubtensor([], 0, nRows1, readOnly, block1)
    nCols1 = int(block1.getSize() / nRows1)
    dataType = block1.getArray().flatten()
    dataType = np.reshape(dataType, (nRows1, nCols1))
    classes = np.argmax(dataType, axis=1)
    dataTable.releaseSubtensor(block1)
    return classes