コード例 #1
0
ファイル: fc_rnn.cpp プロジェクト: kamrann/workbase
	void fc_rnn::initialize_connection_map()
	{
		connection_id id = 0;

		// Input->Hidden
		for(neuron_id in = 0; in < input_layer_count(); ++in)
		{
			for(neuron_id hid = 0; hid < hidden_count(); ++hid)
			{
				m_connections.insert({ id, std::make_pair(input_offset() + in, hidden_offset() + hid) });
				++id;
			}
		}

		// Hidden->Hidden
		for(neuron_id hid1 = 0; hid1 < hidden_count(); ++hid1)
		{
			for(neuron_id hid2 = 0; hid2 < hidden_count(); ++hid2)
			{
				m_connections.insert({ id, std::make_pair(hidden_offset() + hid1, hidden_offset() + hid2) });
				++id;
			}
		}

		// Input,Hidden->Output
		for(neuron_id ih = 0; ih < input_layer_count() + hidden_count(); ++ih)
		{
			for(neuron_id out = 0; out < output_count(); ++out)
			{
				m_connections.insert({ id, std::make_pair(input_offset() + ih, output_offset() + out) });
				++id;
			}
		}
	}
コード例 #2
0
ファイル: fc_rnn.cpp プロジェクト: kamrann/workbase
	size_t fc_rnn::layer_offset(LayerType ly) const
	{
		switch(ly)
		{
			case LayerType::Input:		return 0;
			case LayerType::Hidden:		return hidden_offset();
			case LayerType::Output:		return output_offset();
			default:					throw std::runtime_error("invalid layer type");
		}
	}
コード例 #3
0
ファイル: stack-gen.c プロジェクト: anttisalonen/lvm
int main(int argc, char **argv)
{
	char buf[1024];
	int fundef = 0;
	interactive = argc > 1 && !strncmp(argv[1], "-i", 2);
	reset_labels();
	if(!interactive) {
		int lib_index = 1;
		output_magic();
		output_version();
		for(lib_index = 1; lib_index < MAX_NUM_LIBS && lib_index < argc;
				lib_index++) {
			output_until_space(argv[lib_index], 1);
			output_header(' ');
		}
		output_header('\0');
	}
	while(1) {
		int emptyline;
		if(interactive) {
			printf(">>> ");
			fflush(stdout);
		}
		emptyline = (fgets(buf, 1024, stdin) == NULL);
		if(!interactive && emptyline)
			break;
		if(buf[0] == ':') {
			if(buf[1] >= 'a' && buf[1] <= 'z') {
				labels[buf[1] - 'a'] = current_addr;
			}
		}
		else if(!strncmp(buf, "ADD", 3)) {
			output(OPCODE_ADD);
		}
		else if(!strncmp(buf, "SUB", 3)) {
			output(OPCODE_SUB);
		}
		else if(!strncmp(buf, "MUL", 3)) {
			output(OPCODE_MUL);
		}
		else if(!strncmp(buf, "DIV", 3)) {
			output(OPCODE_DIV);
		}
		else if(!strncmp(buf, "LT", 2)) {
			output(OPCODE_LT);
		}
		else if(!strncmp(buf, "LE", 2)) {
			output(OPCODE_LE);
		}
		else if(!strncmp(buf, "EQ", 2)) {
			output(OPCODE_EQ);
		}
		else if(!strncmp(buf, "DUP", 3)) {
			output(OPCODE_DUP);
		}
		else if(!strncmp(buf, "DROP", 4)) {
			output(OPCODE_DROP);
		}
		else if(!strncmp(buf, "NOP", 3)) {
			output(OPCODE_NOP);
		}
		else if(!strncmp(buf, "SWAP", 4)) {
			output(OPCODE_SWAP);
		}
		else if(!strncmp(buf, "NEW", 3)) {
			output(OPCODE_NEW);
		}
		else if(!strncmp(buf, "RSTORE", 6)) {
			output(OPCODE_RSTORE);
		}
		else if(!strncmp(buf, "RLOAD", 4)) {
			output(OPCODE_RLOAD);
		}
		else if(!strncmp(buf, "END_THUNK", 9)) {
			output(OPCODE_END_THUNK);
		}
		else if(output_offset(buf, "BR", OPCODE_BRANCH));
		else if(output_offset(buf, "BRNZ", OPCODE_BRANCHNZ));
		else if(output_offset(buf, "THUNK", OPCODE_START_THUNK));
		else if(!strncmp(buf, "FUNCALL ", 8)) {
			int succ;
			long int parsed_num = getnum(buf + 8, &succ);
			if(!succ)
				fprintf(stderr, "?\n");
			else {
				output_num(OPCODE_CALLFUN, parsed_num);
			}
		}
		else if(!strncmp(buf, "FUNPCALL", 8)) {
			output(OPCODE_CALLPFUN);
		}
		else if(!strncmp(buf, "FUNDEF ", 7)) {
			if(fundef) {
				fprintf(stderr, "?\n");
			}
			else {
				int parsed_funnum, parsed_params;
				int succ = get_two_nums(buf + 7, &parsed_funnum, &parsed_params);
				if(!succ)
					fprintf(stderr, "?\n");
				else {
					output_nums(OPCODE_DEFUN_START, parsed_params, parsed_funnum);
					fundef = 1;
					reset_labels();
				}
			}
		}
		else if(!strncmp(buf, "FUNEND", 6)) {
			fundef = funend(OPCODE_DEFUN_END, fundef);
		}
		else if(!strncmp(buf, "RET0", 4)) {
			fundef = funend(OPCODE_RET0, fundef);
		}
		else if(!strncmp(buf, "RET1", 4)) {
			fundef = funend(OPCODE_RET1, fundef);
		}
		else if(!strncmp(buf, "LOAD ", 5)) {
			int succ;
			long int parsed_num = getnum(buf + 5, &succ);
			if(!succ)
				fprintf(stderr, "?\n");
			else
				output_num(OPCODE_LOAD, parsed_num);
		}
		else if(!strncmp(buf, "FFIDEF ", 7)) {
			if(fundef) {
				fprintf(stderr, "?\n");
			}
			else {
				int succ = handle_ffidef(buf + 7);
				if(!succ) {
					fprintf(stderr, "FFIDEF?\n");
				}
			}
		}
		else if(buf[0] == 'f') {
			int succ;
			long int parsed_num = getnum(buf + 1, &succ);
			if(!succ)
				fprintf(stderr, "?\n");
			else
				output_num(OPCODE_PFUN_ID, parsed_num);
		}
		else if(buf[0] == '-' || isdigit(buf[0])) {
			int succ;
			long int parsed_num = getnum(buf, &succ);
			if(!succ)
				fprintf(stderr, "?\n");
			else
				output_num(OPCODE_INT, parsed_num);
		}
		else if(interactive && !strncmp(buf, "run", 3)) {
			parse_buffer(interactive_buffer,
					interactive_bufferpos);
		}
		else if(buf[0]) {
			fprintf(stderr, "?\n");
		}
	}
	return 0;
}