MCPcopy Create free account
hub / github.com/NGT-labs/NGT / appendText

Method appendText

lib/NGT/ObjectRepository.h:121–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119 }
120
121 void appendText(std::istream &is, size_t dataSize = 0) {
122 if (dimension == 0) {
123 NGTThrowException("ObjectSpace::readText: Dimension is not specified.");
124 }
125 if (size() == 0) {
126 // First entry should be always a dummy entry.
127 // If it is empty, the dummy entry should be inserted.
128 push_back((PersistentObject *)0);
129 }
130 size_t prevDataSize = size();
131 if (dataSize > 0) {
132 reserve(size() + dataSize);
133 }
134 size_t dim = innerProduct ? dimension - 1 : dimension;
135 std::string line;
136 size_t lineNo = 0;
137 while (getline(is, line)) {
138 lineNo++;
139 if (dataSize > 0 && (dataSize <= size() - prevDataSize)) {
140 std::cerr << "The size of data reached the specified size. The remaining data in the file are not "
141 "inserted. "
142 << dataSize << std::endl;
143 break;
144 }
145 std::vector<double> object;
146 object.reserve(dim);
147 try {
148 extractObjectFromText(line, "\t, ", object);
149#ifdef NGT_DISABLE_NORMALIZATION_ERROR_CHECK
150 PersistentObject *obj = 0;
151 try {
152 obj = allocateNormalizedPersistentObject(object);
153 } catch (Exception &err) {
154 std::cerr << err.what() << " continue..." << std::endl;
155 obj = allocatePersistentObject(object);
156 }
157#else
158 auto *obj = allocateNormalizedPersistentObject(object);
159#endif
160 push_back(obj);
161 } catch (Exception &err) {
162 std::cerr << "ObjectSpace::readText: Warning! Invalid line. " << err.what() << " [" << line
163 << "] Skip the line " << lineNo << " and continue." << std::endl;
164 }
165 }
166 }
167
168 template <typename T> void append(T *data, size_t objectCount) {
169 if (dimension == 0) {

Callers

nothing calls this directly

Calls 2

whatMethod · 0.80
reserveMethod · 0.45

Tested by

no test coverage detected