Example #1
0
 def test_struct(self):
     sdata = np.array([(0.5, -1.3, 1, 100.11, 1111111),
                        (2.5, -3.3, 2, 200.22, 2222222),
                        (4.5, -5.3, 2, 350.33, 3333333),
                        (6.5, -7.3, 0, 470.44, 4444444),
                        (8.5, -9.3, 1, 270.55, 55555)],
                       dtype=[('x','f4'), ('y','f4'), ('categ','i4'), ('value','f8'), ('super','i8')])
     hdata = np.array([(0.5, -1.3, 1, 100.11, 1111111),
                        (2.5, -3.3, 2, 200.22, 2222222),
                        (4.5, -5.3, 2, 350.33, 3333333),
                        (6.5, -7.3, 0, 470.44, 4444444),
                        (8.5, -9.3, 1, 270.55, 55555)],
                       dtype = np.float64)
     sr = d4p.cosine_distance().compute(sdata)
     hr = d4p.cosine_distance().compute(hdata)
     self.assertTrue(np.allclose(hr.cosineDistance, sr.cosineDistance))
Example #2
0
def main(readcsv=read_csv, method='defaultDense'):
    data = readcsv(os.path.join('data', 'batch', 'distance.csv'), range(10))

    # Create algorithm to compute cosine distance (no parameters)
    algorithm = d4p.cosine_distance()

    # Computed cosine distance with file or numpy array
    res1 = algorithm.compute(os.path.join('data', 'batch', 'distance.csv'))
    res2 = algorithm.compute(data)

    assert np.allclose(res1.cosineDistance, res2.cosineDistance)

    return res1
Example #3
0
def _daal4py_cosine_distance_dense(X):
    X_fptype = getFPType(X)
    alg = daal4py.cosine_distance(fptype=X_fptype, method='defaultDense')
    res = alg.compute(X)
    return res.cosineDistance
Example #4
0
def cosine(X):
    cos_dist = cosine_distance().compute(X)