Esempio n. 1
0
def test_nauty(verbose=0):
    if verbose:
        print('test_nauty: test reduction to normal form')
    al = oalib.exampleArray(1, verbose)
    alr = al.randomperm()
    tr = oalib.reduceOAnauty(alr)
    alx = tr.apply(alr)
    assert (alx == al)
Esempio n. 2
0
def pytest7(verbose=1):
    """ Reduced array with random transformtion to LMC form """
    al = oalib.exampleArray(3)
    adata = oalib.arraylink2arraydata(al)
    reduction = oalib.LMCreduction_t(adata)

    for ii in range(10):
        if verbose >= 2:
            print('pytest7: randomized reduction of array %d' % ii)
        reduction.transformation.randomize()
        al2 = reduction.transformation.apply(al)

        alr = al2.reduceLMC()
        c = al == alr
        if not c:
            print('pytest7: error: reduction of randomized array failed!')
Esempio n. 3
0
def miscunittest(verbose=1):
    """ Perform some unit testing, return True if succesfull """
    if verbose:
        print('oapackage: unittest: oalib version %s' % oalib.version())
    al = oalib.array_link()
    ii = 0
    al = oalib.exampleArray(ii, 0)

    arrayclass = oalib.arraydata_t(2, 16, 2, 6)  # fine
    alist = [arrayclass.create_root()]
    r = oalib.extend_arraylist(alist, arrayclass)
    if len(r) != 3:
        raise Exception('extension generation for %s failed' % (arrayclass, ))

    if not isinstance(al.getarray(), np.ndarray):
        print(
            'oapackage: unittest: error: array interface not working properly')
    else:
        if not al[2, 0] == al.getarray()[2, 0]:
            print(
                'oapackage: unittest: error: array interface not working properly'
            )

    arrayclass = oalib.arraylink2arraydata(al)

    if verbose >= 2:
        print('unittest: calculate efficiencies')
    Deff = al.Defficiency()
    aa = oalib.Aefficiencies(al)
    assert (aa[0] == 1.0)
    assert (aa[1] == 1.0)
    assert (aa[2] == 1.0)

    if verbose >= 2:
        print('## oapackage test: example array %d: Deff %.3f' % (ii, Deff))

    # DOP reduction
    if verbose >= 2:
        print('unittest: test delete-one-factor GWLP reduction')
    al = oalib.exampleArray(5, verbose)
    al2 = al.randomperm()

    alr = al.reduceDOP()
    al2r = al2.reduceDOP()
    if not alr == al2r:
        print('error: DOP reduced arrays unequal!: %d' % (alr == al2r))
        print('alr')
        alr.showarraycompact()
        print('al2r')
        al2r.showarraycompact()
        return False

    transformation = oalib.reductionDOP(al)
    check = transformation.apply(al) == al.reduceDOP()
    if not check:
        print('error: DOP reduction transformation is invalid')

    # test graphtools
    if verbose >= 2:
        print('unittest: test graphtools')
    from oapackage.graphtools import oa2graph
    arrayclass = oalib.arraylink2arraydata(al)
    _ = oa2graph(al, arrayclass)

    test_numpy_interface()
    test_nauty()

    return True
Esempio n. 4
0
def unittest(verbose=1):
    """ Perform some unit testing, return True if succesfull """
    if verbose:
        print('oapackage: unittest: oalib version %s' % oalib.version())
    al = oalib.array_link()
    ii = 0
    al = oalib.exampleArray(ii, 0)

    #test_numpy_interface()

    if not isinstance(al.getarray(), np.ndarray):
        print(
            'oapackage: unittest: error: array interface not working properly')
    else:
        if not al[2, 0] == al.getarray()[2, 0]:
            print(
                'oapackage: unittest: error: array interface not working properly'
            )

    arrayclass = oalib.arraylink2arraydata(al)
    #    print(arrayclass)

    if verbose >= 2:
        print('unittest: calculate efficiencies')
    Deff = al.Defficiency()
    aa = oalib.Aefficiencies(al)
    if verbose >= 2:
        print('## oapackage test: example array %d: Deff %.3f' % (ii, Deff))

    # DOP reduction
    if verbose >= 2:
        print('unittest: test delete-one-factor GWLP reduction')
    al = oalib.exampleArray(5, 1)
    al2 = al.randomperm()

    alr = al.reduceDOP()
    al2r = al2.reduceDOP()
    if not alr == al2r:
        print('error: DOP reduced arrays unequal!: %d' % (alr == al2r))
        print('alr')
        alr.showarraycompact()
        print('al2r')
        al2r.showarraycompact()
        return False

    at = oalib.reductionDOP(al)
    check = at.apply(al) == al.reduceDOP()
    if not check:
        print('error: DOP reduction transformation is invalid')

    # test graphtools
    if verbose >= 2:
        print('unittest: test graphtools')
    # import . graphtools
    from .graphtools import oa2graph
    arrayclass = oalib.arraylink2arraydata(al)
    _ = oa2graph(al, arrayclass)

    test_numpy_interface()
    test_nauty()

    return True
print('Extend to 3 columns')
newsols = oalib.extend_array(al, adata, oaoptions)
print(newsols)

print('Extend to 4 columns')
newsols2 = oalib.extend_arraylist(newsols, adata, oaoptions)
print(newsols2)

print('-- Analysing properties of arrays --')
for ii in range(0, 10):
    al = newsols2[ii]
    print('array %d: generalized word length pattern: %s' %
          (ii, str(al.GWLP())))
    print('          D-efficiency: %.3f' % ((al.Defficiency())))

al = oalib.exampleArray()
al.showarray()
print('D-efficiency %f, rank %d' % (al.Defficiency(), al.rank()))

#%% Write al array to disk
al = oalib.exampleArray()
r = oalib.writearrayfile('test.oa', al)
oahelper.oainfo('test.oa')

#%% Convert to Numpy array
al = oalib.exampleArray(0)
al.showarray()
al[2, 1]
X = al.getarray()
X