def test_nnet_decodable(self):
    gen_config = NnetGenerationOptions()
    configs = generate_config_sequence(gen_config)
    nnet = Nnet()
    for (j, config) in enumerate(configs):
        istrm = istringstream.from_str(config)
        nnet.read_config(istrm)
    num_frames = (5 + random.randint(1, 100))
    input_dim = nnet.input_dim('input')
    output_dim = nnet.output_dim('output')
    ivector_dim = max(0, nnet.input_dim('ivector'))
    input = Matrix(num_frames, input_dim)
    set_batchnorm_test_mode(True, nnet)
    set_dropout_test_mode(True, nnet)
    input.set_randn_()
    ivector = Vector(ivector_dim)
    ivector.set_randn_()
    priors = Vector((output_dim if random.choice([True, False]) else 0))
    if (len(priors) != 0):
        priors.set_randn_()
        priors.apply_exp_()
    output1 = Matrix(num_frames, output_dim)
    output2 = Matrix(num_frames, output_dim)
    opts = NnetSimpleComputationOptions()
    opts.frames_per_chunk = random.randint(5, 25)
    compiler = CachingOptimizingCompiler(nnet)
    decodable = DecodableNnetSimple(opts, nnet, priors, input, compiler, (ivector if ivector_dim else None))
    for t in range(num_frames):
        decodable.get_output_for_frame(t, output1[t])
    opts = NnetSimpleLoopedComputationOptions()
    info = DecodableNnetSimpleLoopedInfo.from_priors(opts, priors, nnet)
    decodable = DecodableNnetSimpleLooped(info, input, (ivector if ivector_dim else None))
    for t in range(num_frames):
        decodable.get_output_for_frame(t, output2[t])
    if ((not nnet_is_recurrent(nnet)) and (nnet.info().find('statistics-extraction') == (- 1)) and (nnet.info().find('TimeHeightConvolutionComponent') == (- 1)) and (nnet.info().find('RestrictedAttentionComponent') == (- 1))):
        for t in range(num_frames):
            self.assertTrue(approx_equal(output1[t], output2[t]))
def test_nnet_decodable(self):
    gen_config = NnetGenerationOptions()
    configs = generate_config_sequence(gen_config)
    nnet = Nnet()
    for (j, config) in enumerate(configs):
        istrm = istringstream.from_str(config)
        nnet.read_config(istrm)
    num_frames = (5 + random.randint(1, 100))
    input_dim = nnet.input_dim('input')
    output_dim = nnet.output_dim('output')
    ivector_dim = max(0, nnet.input_dim('ivector'))
    input = Matrix(num_frames, input_dim)
    set_batchnorm_test_mode(True, nnet)
    set_dropout_test_mode(True, nnet)
    input.set_randn_()
    ivector = Vector(ivector_dim)
    ivector.set_randn_()
    priors = Vector((output_dim if random.choice([True, False]) else 0))
    if (len(priors) != 0):
        priors.set_randn_()
        priors.apply_exp_()
    output1 = Matrix(num_frames, output_dim)
    output2 = Matrix(num_frames, output_dim)
    opts = NnetSimpleComputationOptions()
    opts.frames_per_chunk = random.randint(5, 25)
    compiler = CachingOptimizingCompiler(nnet)
    decodable = DecodableNnetSimple(opts, nnet, priors, input, compiler, (ivector if ivector_dim else None))
    for t in range(num_frames):
        decodable.get_output_for_frame(t, output1[t])
    opts = NnetSimpleLoopedComputationOptions()
    info = DecodableNnetSimpleLoopedInfo.from_priors(opts, priors, nnet)
    decodable = DecodableNnetSimpleLooped(info, input, (ivector if ivector_dim else None))
    for t in range(num_frames):
        decodable.get_output_for_frame(t, output2[t])
    if ((not nnet_is_recurrent(nnet)) and (nnet.info().find('statistics-extraction') == (- 1)) and (nnet.info().find('TimeHeightConvolutionComponent') == (- 1)) and (nnet.info().find('RestrictedAttentionComponent') == (- 1))):
        for t in range(num_frames):
            self.assertTrue(approx_equal(output1[t], output2[t]))