Esempio n. 1
0
void MnistDataSet<M>::read() {

	std::string path = "/home/local/datasets/MNIST";
	ifstream ftraind((path + "/train-images.idx3-ubyte").c_str());
	ifstream ftrainl((path + "/train-labels.idx1-ubyte").c_str());
	ifstream ftestd ((path + "/t10k-images.idx3-ubyte").c_str());
	ifstream ftestl ((path + "/t10k-labels.idx1-ubyte").c_str());

	char buf[16];
	ftraind.read(buf,16); ftrainl.read(buf, 8);
	ftestd.read(buf,16); ftestl.read(buf, 8);
	tensor<unsigned char, host_memory_space> traind(extents[n_trainData][n_dim]);
	tensor<unsigned char, host_memory_space> trainl(extents[n_trainData]);
	tensor<unsigned char, host_memory_space> testd(extents[n_testData][n_dim]);
	tensor<unsigned char, host_memory_space> testl(extents[n_testData]);
	ftraind.read((char*)traind.ptr(), traind.size());
	assert(ftraind.good());
	ftrainl.read((char*)trainl.ptr(), trainl.size());
	assert(ftrainl.good());
	ftestd.read((char*)testd.ptr(), testd.size());
	assert(ftestd.good());
	ftestl.read((char*)testl.ptr(), testl.size());
	assert(ftestl.good());

	tensor<unsigned char, M> train_d(extents[n_trainData][n_dim]);
	tensor<unsigned char, M> train_l(extents[n_trainData]);
	tensor<unsigned char, M> test_d(extents[n_testData][n_dim]);
	tensor<unsigned char, M> test_l(extents[n_testData]);

	train_d = traind;
	train_l = trainl;
	test_d = testd;
	test_l = testl;

	// conversion to float:
	convert(this->X_train, train_d);
	convert(this->Y_train, train_l);
	convert(this->X_test, test_d);
	convert(this->Y_test, test_l);

}
Esempio n. 2
0
static void TestL(void)
{
    static PRInt32 nums[] = {
	0,
	1,
	-1,
	10,
	-10,
	32767,
	-32768,
	PR_INT32(0x7fffffff), /* 2147483647L */
	-1 - PR_INT32(0x7fffffff)  /* -2147483648L */
    };
    static char *signs[] = {
	"",
	"0",	"-",	"+", " ",
	"0-",	"0+",	"0 ",	"-0",	"-+",	"- ",
	"+0",	"+-",	"+ ",	" 0",	" -",	" +",
	"0-+",	"0- ",	"0+-",	"0+ ",	"0 -",	"0 +",
	"-0+",	"-0 ",	"-+0",	"-+ ",	"- 0",	"- +",
	"+0-",	"+0 ",	"+-0",	"+- ",	"+ 0",	"+ -",
	" 0-",	" 0+",	" -0",	" -+",	" +0",	" +-",
	"0-+ ",	"0- +",	"0+- ",	"0+ -",	"0 -+",	"0 +-",
	"-0+ ",	"-0 +",	"-+0 ",	"-+ 0",	"- 0+",	"- +0",
	"+0- ",	"+0 -",	"+-0 ",	"+- 0",	"+ 0-",	"+ -0",
	" 0-+",	" 0+-",	" -0+",	" -+0",	" +0-",	" +-0",
    };
    static char *precs[] = {
	"", "3", "5", "43",
	".3", ".43",
	"7.3", "7.5", "7.11", "7.43",
    };
    static char *formats[] = { "ld", "lo", "lx", "lu" };

#if PR_BYTES_PER_INT == 4
    static char *sformats[] = { "d", "o", "x", "u" };
#elif PR_BYTES_PER_LONG == 4
    static char *sformats[] = { "ld", "lo", "lx", "lu" };
#else
#error Neither int nor long is 4 bytes on this platform
#endif

    int f, s, n, p;
    char fmt[40], sfmt[40];

    for (f = 0; f < countof(formats); f++) {
	for (s = 0; s < countof(signs); s++) {
	    for (p = 0; p < countof(precs); p++) {
		fmt[0] = '%';
		fmt[1] = 0;
		if (signs[s]) strcat(fmt, signs[s]);
		if (precs[p]) strcat(fmt, precs[p]);
		strcpy(sfmt, fmt);
		if (formats[f]) strcat(fmt, formats[f]);
		if (sformats[f]) strcat(sfmt, sformats[f]);
		for (n = 0; n < countof(nums); n++) {
		    test_l(fmt, sfmt, nums[n]);
		}
	    }
	}
    }
}