Beispiel #1
0
def construct_oa(al):
    """ Transform one Hadamard matrix into several OAs """

    oalist = []
    nfactors = al.n_columns
    altwo = al * 2 - 1
    for ii in range(nfactors):
        Hadmat = altwo.getarray()
        norm_col = Hadmat[:, ii]
        OAtwo = np.multiply(norm_col.reshape((-1, 1)), Hadmat)
        OAtwo = np.delete(OAtwo, ii, 1)
        A = oapackage.makearraylink((OAtwo + 1) / 2)
        oalist.append(oapackage.makearraylink(A))

    return (oalist)
Beispiel #2
0
def _get_array(f, N=32, k=32, verbose=1):
    """ Return array from file """
    A = np.zeros((N, k), dtype=int)
    row = 0
    al = None
    while True:
        l = f.readline()
        if verbose >= 2:
            print(l)
            print('len(l) %d' % len(l))
        if len(l) == 0:
            break
        if l == '\n':
            continue

        if 0:
            for c in l:
                print(c)
        if len(l) == (k / 4) + 1:
            l = l.strip()
            if verbose:
                print(f'row {row}: {l}')
            x = bin(int(l, 16))[2:]
            A[row, :] = [int(y) for y in list(x)]
            row = row + 1
            if row == N:
                break

    al = oapackage.makearraylink(A[:row, :])
    return al
Beispiel #3
0
def test_numpy_interface(verbose=0):
    A = np.eye(3, 4).astype(int)
    A[0, :] = [10, 20, 30, 50]
    A[2, :] = [-3, -4, -5, -6]

    if verbose:
        print('makearraylink')
    al = oapackage.makearraylink(A)

    np.testing.assert_array_equal(np.array(al), A)

    if verbose:
        al.showarray()

    if verbose:
        print('direct')
    al = oapackage.array_link(A)
    if verbose:
        al.showarray()
    Ax = np.array(al)
    if verbose:
        print(A)
        print(Ax)

    with np.testing.assert_raises(TypeError):
        # not possible right now...
        if verbose:
            print('direct float')
        A = np.eye(3).astype(float)
        al = oapackage.array_link(A)
        if verbose:
            al.showarray()
Beispiel #4
0
def selectIsomorphismClasses(sols, verbose=1):
    """ Select isomorphism classes from a list of designs 

    Args:
        sols (list of arrays)
        verbose (int)
    Return:
        indices (list of integers): indices of the isomorphism classes
        mm (list of arrays): the arrays in normal form


    Example:
        >>> sols=[oapackage.exampleArray(i) for i in [26,26,27,26]]
        >>> idx, mm = selectIsomorphismClasses(sols)

    To select one representative array from each isomorphism class one can use:
        >>> _, ui = np.unique(idx, return_index=True)
        >>> representatives = [sols[i] for i in ui]

    """

    # perform check on array data type
    mm = []
    for ii, al in enumerate(sols):
        if verbose:
            oapackage.tprint('selectIsomorphismClasses: process aray %d/%d' %
                             (ii, len(sols)))
        al = oapackage.makearraylink(al)

        tt = oapackage.reduceOAnauty(al, verbose >= 2)

        #pp, tt = reduceBliss(al, arrayclass, verbose >= 2)
        #tt = graph2arrayTransformation(pp, arrayclass)
        alx = tt.apply(al)
        mm.append(np.array(alx))
        pass

    # perform uniqueness check
    nn = len(mm)
    qq = np.array([None] * nn, dtype=object)
    for ii in range(nn):
        qq[ii] = mm[ii].flatten()

    # Trick to make unique work...
    nx = qq[0].size
    dt = qq[0].dtype.descr * nx
    qqq = np.array(qq, dtype=dt)

    a, indices = np.unique(qqq, return_inverse=True)

    if verbose >= 1:
        print('selectIsomorphismClasses: reduce %d to %d' %
              (len(sols), np.unique(indices).size))

    return indices, mm
Beispiel #5
0
def selectIsomorphismClasses(sols, verbose=1):
    """ Select isomorphism classes from a list of designs 
    
    Args:
        sols (list of arrays)
        verbose (int)
    Return:
        indices (list of integers): indices of the isomorphism classes
        mm (list of arrays): the arrays in normal form

        
    """

    # perform check on array data type
    mm = []
    for ii, al in enumerate(sols):
        if verbose:
            oapackage.tprint('selectIsomorphismClasses: process aray %d/%d' %
                             (ii, len(sols)),
                             dt=4)
        al = oapackage.makearraylink(al)

        tt = oapackage.reduceOAnauty(al, verbose >= 2)

        #pp, tt = reduceBliss(al, arrayclass, verbose >= 2)
        #tt = graph2arrayTransformation(pp, arrayclass)
        alx = tt.apply(al)
        mm.append(np.array(alx))
        pass

    # perform uniqueness check
    nn = len(mm)
    qq = np.array([None] * nn, dtype=object)
    for ii in range(nn):
        qq[ii] = mm[ii].flatten()

    if 0:
        # Trick to make unique work...
        # old code
        nx = qq[0].size
        dt = qq[0].dtype.descr * nx
        qqq = [np.array(q, dtype=dt) for q in qq]
        qqq = np.array(qq, dtype=dt)
        a, indices = np.unique(qqq, return_inverse=True)

    # Trick to make unique work...
    a, indices = np.unique(np.vstack(qq), axis=0, return_inverse=True)

    if verbose >= 1:
        print('selectIsomorphismClasses: %d reduced to %d' %
              (len(sols), np.unique(indices).size))

    return indices, mm
Beispiel #6
0
    def test_arraylink_slicing(self):
        numpy_array = np.arange(0, 6 * 10).reshape((6, 10))

        al = oapackage.makearraylink(numpy_array)
        self.assertTrue(al[0] == numpy_array.flatten()[0])
        self.assertTrue(al[0, 1] == numpy_array[0, 1])
        self.assertTrue(al[4, 2] == numpy_array[4, 2])
        np.testing.assert_equal(al[0:4, 1:5], np.array(al)[0:4, 1:5])
        np.testing.assert_equal(al[0:1, 0:10:2], np.array(al)[0:1, 0:10:2])
        np.testing.assert_equal(al[3, 3::], np.array(al)[3:4, 3::])
        np.testing.assert_equal(al[2, :8:2], np.array(al)[2:3, :8:2])
        np.testing.assert_equal(al[2:3, :8:2], np.array(al)[2:3, :8:2])

        with self.assertRaises(IndexError):
            _ = al[-1, 1]
Beispiel #7
0
def selectIsomorphismClasses(sols, verbose=1):
    """ Select isomorphism classes from a list of designs

    Args:
        sols (list of arrays): list of arrays from which to determine the unique ones
        verbose (int): verbosity level
    Return:
        indices (list of integers): indices of the isomorphism classes
        mm (list of arrays): the arrays in normal form


    Example:
        >>> import oapackage.graphtools; import numpy as np
        >>> sols=[oapackage.exampleArray(idx) for idx in [26,26,27,26]]
        >>> idx, mm = oapackage.graphtools.selectIsomorphismClasses(sols, verbose=0)
        >>> _, unique_indices = np.unique(idx, return_index=True)
        >>> print('found %d isomorphism classes from %d arrays' % (len(unique_indices), len(sols)) )
        found 2 isomorphism classes from 4 arrays
        >>> representatives = [sols[idx] for idx in unique_indices]

    """

    mm = []
    for ii, al in enumerate(sols):
        if verbose:
            oapackage.tprint(
                'selectIsomorphismClasses: process aray %d/%d' % (ii, len(sols)))
        al = oapackage.makearraylink(al)

        tt = oapackage.reduceOAnauty(al, verbose >= 2)

        alx = tt.apply(al)
        mm.append(np.array(alx))

    # perform uniqueness check
    nn = len(mm)
    qq = np.array([None] * nn, dtype=object)
    for ii in range(nn):
        qq[ii] = mm[ii].flatten()

    # Trick to make unique work...
    _, indices = np.unique(np.vstack(qq), axis=0, return_inverse=True)

    if verbose >= 1:
        print('selectIsomorphismClasses: reduce %d to %d' %
              (len(sols), np.unique(indices).size))

    return indices, mm
Beispiel #8
0
def selectIsomorphismClasses(sols, verbose=1):
    """ Select isomorphism classes from a list of designs

    Args:
        sols (list of arrays): list of arrays from which to determine the unique ones
        verbose (int): verbosity level
    Return:
        indices (list of integers): indices of the isomorphism classes
        mm (list of arrays): the arrays in normal form


    Example:
        >>> import oapackage.graphtools; import numpy as np
        >>> sols=[oapackage.exampleArray(idx) for idx in [26,26,27,26]]
        >>> idx, mm = oapackage.graphtools.selectIsomorphismClasses(sols, verbose=0)
        >>> _, unique_indices = np.unique(idx, return_index=True)
        >>> print('found %d isomorphism classes from %d arrays' % (len(unique_indices), len(sols)) )
        found 2 isomorphism classes from 4 arrays
        >>> representatives = [sols[idx] for idx in unique_indices]

    """

    mm = []
    for ii, al in enumerate(sols):
        if verbose:
            oapackage.tprint('selectIsomorphismClasses: process aray %d/%d' %
                             (ii, len(sols)))
        al = oapackage.makearraylink(al)

        tt = oapackage.reduceOAnauty(al, verbose >= 2)

        alx = tt.apply(al)
        mm.append(np.array(alx))

    # perform uniqueness check
    nn = len(mm)
    qq = np.array([None] * nn, dtype=object)
    for ii in range(nn):
        qq[ii] = mm[ii].flatten()

    # Trick to make unique work...
    _, indices = np.unique(np.vstack(qq), axis=0, return_inverse=True)

    if verbose >= 1:
        print('selectIsomorphismClasses: reduce %d to %d' %
              (len(sols), np.unique(indices).size))

    return indices, mm