MCPcopy Create free account
hub / github.com/bab2min/tomotopy / tdfLinspace

Method tdfLinspace

src/python/handler/py_GDMR.cpp:197–268  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195}
196
197py::UniqueObj GDMRModelObject::tdfLinspace(PyObject* numericMetadataStart, PyObject* numericMetadataEnd, PyObject* numericMetadataNum, const std::string& metadata, PyObject* multiMetadata, bool endpoint, bool normalize) const
198{
199 auto* inst = getInst<tomoto::IGDMRModel>();
200
201 vector<tomoto::Float> start, stop;
202 if(!py::toCpp(numericMetadataStart, start))
203 {
204 throw py::ValueError{
205 "`metadata_start` must be an iterable of float (but given " + py::repr(numericMetadataStart) + ")"
206 };
207 }
208 if (!py::toCpp(numericMetadataEnd, stop))
209 {
210 throw py::ValueError{
211 "`metadata_stop` must be an iterable of float (but given " + py::repr(numericMetadataEnd) + ")"
212 };
213 }
214
215 vector<std::ptrdiff_t> num;
216 if (!py::toCpp(numericMetadataNum, num))
217 {
218 throw py::ValueError{
219 "`num` must be an iterable of int (but given " + py::repr(numericMetadataNum) + ")"
220 };
221 }
222
223 if (start.size() != inst->getFs().size()) throw py::ValueError{ "`len(metadata_start)` must be equal to `len(degree).`" };
224 if (stop.size() != inst->getFs().size()) throw py::ValueError{ "`len(metadata_stop)` must be equal to `len(degree).`" };
225 if (num.size() != inst->getFs().size()) throw py::ValueError{ "`len(num)` must be equal to `len(degree).`" };
226
227 std::ptrdiff_t tot = 1;
228 for (auto& v : num)
229 {
230 if (v <= 0) v = 1;
231 tot *= v;
232 }
233
234 Eigen::MatrixXf mds{ (Eigen::Index)num.size(), (Eigen::Index)tot };
235 vector<std::ptrdiff_t> idcs(num.size());
236 for (size_t i = 0; i < tot; ++i)
237 {
238 for (size_t j = 0; j < num.size(); ++j)
239 {
240 mds(j, i) = start[j] + (stop[j] - start[j]) * idcs[j] / (endpoint ? max(num[j] - 1, (std::ptrdiff_t)1) : num[j]);
241 }
242
243 idcs.back()++;
244 for (int j = idcs.size() - 1; j >= 0; --j)
245 {
246 if (idcs[j] >= num[j])
247 {
248 idcs[j] = 0;
249 if (j) idcs[j - 1]++;
250 }
251 else break;
252 }
253 }
254

Callers

nothing calls this directly

Calls 9

toCppFunction · 0.85
reprFunction · 0.85
newEmptyArrayFromDimFunction · 0.85
backMethod · 0.80
getTDFBatchMethod · 0.80
emplace_backMethod · 0.80
sizeMethod · 0.45
dataMethod · 0.45
getKMethod · 0.45

Tested by

no test coverage detected