Beispiel #1
0
def create_scp():
    
    key = ['spk1']+['spk2']*2+['spk3']*3+['spk10']*10
    file_path = np.arange(len(key)).astype('U')
    scp = SCPList(key, file_path)
    scp.sort()
    return scp
Beispiel #2
0
def test_filter():
    filter_key = ['spk2', 'spk10']

    scp1 = create_scp()
    scp2 = scp1.filter(filter_key)
    
    f = np.zeros(len(scp1.key), dtype='bool')
    f[1:13] = True
    scp3 = SCPList(scp1.key[f], scp1.file_path[f])
        
    assert scp2 == scp3

    scp1 = create_scp_with_offset_range()
    scp2 = scp1.filter(filter_key)
    
    f = np.zeros(len(scp1.key), dtype='bool')
    f[1:13] = True
    scp3 = SCPList(scp1.key[f], scp1.file_path[f],
                   scp1.offset[f], scp1.range_spec[f])
    print(scp2.__dict__)
    print(scp3.__dict__)
    assert scp2 == scp3

    
    filter_key=[]
    scp2 = scp1.filter(filter_key)
    scp3 = SCPList([],[])
    assert scp2 == scp3
Beispiel #3
0
def create_scp_with_offset():
    
    key = ['spk1']+['spk2']*2+['spk3']*3+['spk10']*10
    file_path = np.arange(len(key)).astype('U')
    offset = np.arange(len(key), dtype=np.int32)*10
    scp = SCPList(key, file_path, offset)
    scp.sort()
    return scp
Beispiel #4
0
def create_scp_with_offset_range():
    
    key = ['spk1']+['spk2']*2+['spk3']*3+['spk10']*10
    file_path = np.arange(len(key)).astype('U')
    offset = np.arange(len(key), dtype=np.int32)*10
    range_spec = np.zeros((len(key), 2), dtype=np.int32)
    range_spec[3:,0] = 5
    range_spec[10:,1] = 10 
    scp = SCPList(key, file_path, offset, range_spec)
    scp.sort()
    return scp
Beispiel #5
0
def create_dataset():

    if os.path.exists(h5_file):
        return

    file_path = [str(k) for k in xrange(num_seqs)]
    scp = SCPList(file_path, file_path)
    scp.save(key_file, sep='=')

    h = HypDataWriter(h5_file)
    rng = np.random.RandomState(seed=0)

    for i in xrange(num_seqs):
        x_i = rng.randn(seq_length[i], dim)
        h.write(file_path[i], '', x_i)
Beispiel #6
0
def test_cmp():
    scp1 = create_scp()
    scp2 = create_scp()
    assert scp1 == scp2

    scp1 = create_scp_with_offset()
    scp2 = create_scp_with_offset()
    assert scp1 == scp2

    scp1 = create_scp_with_offset_range()
    scp2 = create_scp_with_offset_range()
    assert scp1 == scp2

    scp1 = SCPList([],[])
    scp2 = SCPList([],[])
    assert scp1 == scp2
Beispiel #7
0
def test_split_merge():
    scp1 = create_scp()

    num_parts=3
    scp_list = []
    for i in xrange(num_parts):
        scp_i = scp1.split(i+1, num_parts)
        scp_list.append(scp_i)

    assert scp_list[0].len() == 1
    assert scp_list[1].len() == 10
    assert scp_list[2].len() == 5

    scp2 = SCPList.merge(scp_list)
    assert scp1 == scp2

    
    scp1 = create_scp_with_offset()

    num_parts=3
    scp_list = []
    for i in xrange(num_parts):
        scp_i = scp1.split(i+1, num_parts)
        scp_list.append(scp_i)

    assert scp_list[0].len() == 1
    assert scp_list[1].len() == 10
    assert scp_list[2].len() == 5

    scp2 = SCPList.merge(scp_list)
    assert scp1 == scp2


    scp1 = create_scp_with_offset_range()

    num_parts=3
    scp_list = []
    for i in xrange(num_parts):
        scp_i = scp1.split(i+1, num_parts)
        scp_list.append(scp_i)

    assert scp_list[0].len() == 1
    assert scp_list[1].len() == 10
    assert scp_list[2].len() == 5

    scp2 = SCPList.merge(scp_list)
    assert scp1 == scp2
Beispiel #8
0
def test_save_load():
    file_txt = './tests/data_out/list.scp'
    scp1 = create_scp()
    scp1.save(file_txt)
    scp2 = SCPList.load(file_txt)
    assert scp1 == scp2

    file_txt = './tests/data_out/list_offset.scp'
    scp1 = create_scp_with_offset()
    scp1.save(file_txt)
    scp2 = SCPList.load(file_txt)
    assert scp1 == scp2

    file_txt = './tests/data_out/list_offsetrange.scp'
    scp1 = create_scp_with_offset_range()
    scp1.save(file_txt)
    scp2 = SCPList.load(file_txt)
    assert scp1 == scp2