Exemple #1
0
def test_invalid_code():
    code = '''
    PRO invalid_code
       this_is_invalid
    end
    '''
    with GDLFile(code) as name:
        with pytest.raises(GDL.error):
            GDL.pro(name)
Exemple #2
0
def test_invalid_code():
    code = '''
    PRO invalid_code
       this_is_invalid
    end
    '''
    with GDLFile(code) as name:
        with pytest.raises(GDL.error):
            GDL.pro(name)
Exemple #3
0
def test_invalid_code():
    '''Call a function with some invalid GDL code'''

    code = '''
    PRO invalid_code
       this_is_invalid
    end
    '''
    with GDLFile(code) as name:
        with pytest.raises(GDL.error):
            GDL.pro(name, ret)
Exemple #4
0
def test_invalid_code():
    '''Call a function with some invalid GDL code'''
    
    code = '''
    PRO invalid_code
       this_is_invalid
    end
    '''
    with GDLFile(code) as name:
        with pytest.raises(GDL.error):
            GDL.pro(name)
Exemple #5
0
def test_pro_user():
    '''Call the setenv procedure via a user defined procedure'''

    code = '''
    pro USER_SETENV, key, val
      SETENV, key + '=' + val
      print, GETENV(key)
    end
    '''
    s = 'blabla'
    with GDLFile(code) as name:
        GDL.pro(name, 'T1', s)
Exemple #6
0
def test_pro_user():
    '''Call the setenv procedure via a user defined procedure'''

    code = '''
    pro USER_SETENV, key, val
      SETENV, key + '=' + val
      print, GETENV(key)
    end
    '''
    s = 'blabla'
    with GDLFile(code) as name:
        GDL.pro(name, 'T1', s)
Exemple #7
0
def test_script():
    '''Call a simple script that writes a short file'''

    fname = os.tmpnam()
    scriptname = os.tmpnam()
    arg = 'Hello, world!'
    code = '''openw, 5, '{0}'
    printf, 5, '{1}'
    close, 5
    '''
    with GDLFile(code.format(fname, arg)) as script:
        GDL.script(script)
        ret = open(fname).read().strip()
        os.unlink(fname)
        assert arg == ret
Exemple #8
0
def test_script():
    '''Call a simple script that writes a short file'''
    
    fname = os.tmpnam()
    scriptname = os.tmpnam()
    arg = 'Hello, world!'
    code = '''openw, 5, '{0}'
    printf, 5, '{1}'
    close, 5
    '''
    with GDLFile(code.format(fname, arg)) as script:
        GDL.script(script)
        ret = open(fname).read().strip()
        os.unlink(fname)
        assert arg == ret
Exemple #9
0
def test_pro_setvalue(dtype):
    '''Call a user defined procedure that replaces the values of an array with
    its sinus.

    Note that GDL does not support changes in the arguments, so this test is
    expected to fail'''

    code = '''pro SETVALUE, arg
    arg[*] = sin(arg)
    end
    '''
    with GDLFile(code) as name:
        arg = numpy.arange(-10, 10., 1.1).astype(dtype)
        ret = numpy.copy(arg)
        GDL.pro(name, ret)
        for a, r in zip(numpy.sin(arg), ret):
            assert a == r
Exemple #10
0
def test_script():
    '''Call a simple script that writes a short file'''

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        fname = tempfile.mkstemp()[1]
        scriptname = tempfile.mkstemp()[1]
    arg = 'Hello, world!'
    code = '''openw, 5, '{0}'
    printf, 5, '{1}'
    close, 5
    '''
    with GDLFile(code.format(fname, arg)) as script:
        GDL.script(script)
        ret = open(fname).read().strip()
        os.unlink(fname)
        assert arg == ret
Exemple #11
0
def test_pro_arg_pass(arg):
    '''Call a user defined procedure that stores the value for different
    data types in a file'''
    
    code = '''
    PRO pro_arg_pass, fname, arg
      openw, 5, fname
      printf, 5, arg
      close, 5
    end
    '''
    with GDLFile(code) as name:
        fname = os.tmpnam()
        GDL.pro(name, fname, arg)
        ret = open(fname).read().strip()
        os.unlink(fname)
        assert arg == arg.__class__(ret)
Exemple #12
0
def test_pro_arg_pass(arg):
    '''Call a user defined procedure that stores the value for different
    data types in a file'''

    code = '''
    PRO pro_arg_pass, fname, arg
      openw, 5, fname
      printf, 5, arg
      close, 5
    end
    '''
    with GDLFile(code) as name:
        fname = os.tmpnam()
        GDL.pro(name, fname, arg)
        ret = open(fname).read().strip()
        os.unlink(fname)
        assert arg == arg.__class__(ret)
Exemple #13
0
def test_pro_setvalue(dtype):
    '''Call a user defined procedure that replaces the values of an array with
    its sinus.

    Note that GDL does not support changes in the arguments, so this test is
    expected to fail'''

    
    code = '''pro SETVALUE, arg
    arg[*] = sin(arg)
    end
    '''
    with GDLFile(code) as name:
        arg = numpy.arange(-10, 10., 1.1).astype(dtype)
        ret = numpy.copy(arg)
        GDL.pro(name, ret)
        for a, r in zip(numpy.sin(arg), ret):
            assert a == r
Exemple #14
0
def test_function_arg_pass_return(arg):
    '''Call a function that just returns its argument, with different data types'''

    code = '''
    function ARG_PASS_RETURN, arg
      return, arg
    end
    '''
    with GDLFile(code) as name:
        assert numpy.all(GDL.function(name, arg) == arg)
Exemple #15
0
def test_function_arg_pass_return(arg):
    '''Call a function that just returns its argument, with different data types'''

    code = '''
    function ARG_PASS_RETURN, arg
      return, arg
    end
    '''
    with GDLFile(code) as name:
        assert numpy.all(GDL.function(name, arg) == arg)
Exemple #16
0
def test_function_user():
    '''Call the sinus function via a user defined function'''

    code = '''
    function MYSIN, arg
      return, sin(arg)
    end
    '''
    with GDLFile(code) as name:
        assert GDL.function(name, 1.0) == math.sin(1.0)
Exemple #17
0
def test_function_user():
    '''Call the sinus function via a user defined function'''

    code = '''
    function MYSIN, arg
      return, sin(arg)
    end
    '''
    with GDLFile(code) as name:
        assert GDL.function(name, 1.0) == math.sin(1.0)
Exemple #18
0
def test_pro_arg_pass(arg):
    '''Call a user defined procedure that stores the value for different
    data types in a file'''

    code = '''
    PRO pro_arg_pass, fname, arg
      openw, 5, fname
      printf, 5, arg
      close, 5
    end
    '''
    with GDLFile(code) as name:
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            fname = tempfile.mkstemp()[1]
        GDL.pro(name, fname, arg)
        ret = open(fname).read().strip()
        os.unlink(fname)
        assert arg == arg.__class__(ret)
Exemple #19
0
    fea, labels = loadData.load_coil100()    # K=25 u=100 v=0.1
    print("data_set = COIL100    data.shape =", fea.shape)

    print("------ Normalizing data ------")
    # fea = tool.data_Normalized(fea)
    Normalizer = MinMaxScaler()
    Normalizer.fit(fea)
    fea = Normalizer.transform(fea)

    # u = 100
    # dist = tool.rank_dis_c(fea, u)
    dist = tool.rank_order_dis(fea)

    group_number = len(np.unique(labels))
    K = 25    # the number of nearest neighbors for KNN graph
    v = 0.1

    print("------ Clustering ------")
    start = time.time()
    labels_pred = GDL.gdl(dist, group_number, K, v, True)
    end = time.time()
    print("time =", end - start)

    NMI = measure.NMI(labels, labels_pred)
    print("NMI =", NMI)
    ACC = measure.ACC(labels, labels_pred)
    print("ACC =", ACC)
    precision_score = measure.precision_score(labels, labels_pred)
    print("precision_score =", precision_score)
Exemple #20
0
def test_function_internal():
    '''Call the internal sin() function'''

    assert GDL.function('sin', 1.0) == math.sin(1.0)
Exemple #21
0
def test_function_internal():
    '''Call the internal sin() function'''
    
    assert GDL.function('sin', 1.0) == math.sin(1.0)
Exemple #22
0
def test_pro_internal():
    '''Call the internal setenv procedure'''
    
    s = 'blabla'
    GDL.pro('setenv', 'T1=' + s)
Exemple #23
0
    Normalizer = MinMaxScaler()
    Normalizer.fit(fea)
    fea = Normalizer.transform(fea)

    # dist = tool.rank_dis_c(fea)
    # dist = dist - np.diag(np.diag(dist))
    print("------ Clustering ------")
    start = time.time()
    dist = cdist(fea, fea)
    groupNumber = len(np.unique(labels))
    K = 15  # the number of nearest neighbors for KNN graph
    a = 10
    # a = 10
    # cl = AGDL.AGDL(dist, groupNumber, K, v)

    # cluster = AGDL.AGDL(fea, dist, groupNumber, K, 5, a)
    # labels_pred = np.zeros(len(labels), dtype='i')
    # for i in range(len(cluster)):
    #     for j in range(len(cluster[i])):
    #         labels_pred[cluster[i][j]] = i

    labels_pred = GDL.gdl(dist, groupNumber, K, a, True)
    end = time.time()
    print("time =", end - start)

    print("------ Computing performance measure ------")
    NMI = measure.NMI(labels, labels_pred)
    print("NMI =", NMI)
    ACC = measure.ACC(labels, labels_pred)
    print("ACC =", ACC)
Exemple #24
0
def test_pro_internal():
    '''Call the internal setenv procedure'''

    s = 'blabla'
    GDL.pro('setenv', 'T1=' + s)