-
Notifications
You must be signed in to change notification settings - Fork 2
/
readtensor.cpp
67 lines (58 loc) · 1.33 KB
/
readtensor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "readtensor.h"
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <stdlib.h>
using std::ifstream;
using std::istringstream;
using std::endl;
using std::cout;
using std::string;
/**
* @param
* @param
* @param
* @param
* @return
*/
int precess(int &dim_i, int &dim_j, int &dim_k, char *file) {
ifstream in_stream(file);
string line;
int total_nnz = 0;
int i, j, k;
float value;
while (getline(in_stream, line)) {
istringstream liness(line);
liness >> i >> j >> k >> value;
dim_i = i > dim_i ? i : dim_i;
dim_j = j > dim_j ? j : dim_j;
dim_k = k > dim_k ? k : dim_k;
total_nnz++;
}
return total_nnz;
}
void tensor_malloc(tensor *data, int nnz) {
*data = (tensor)malloc(sizeof(item) * nnz);
}
void tensor_free(tensor data) {
free(data);
}
int readtensor(tensor data, char *file) {
ifstream in_stream(file);
string line;
int index = 0;
// int i,j,k;
cout << "in readtensor" << endl;
while (getline(in_stream, line)) {
// cout<<"in readtensor"<<endl;
istringstream liness(line);
liness >> data[index].coord[0] >> data[index].coord[1] >> data[index].coord[2] >> data[index].val;
// cout<<"in readtensor2"<<endl;
index++;
if (index % 1000000 == 0) {
cout << "Total lines read: " << index << endl;
}
}
return index;
}