MRArbGrad 4.0.0__tar.gz → 4.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1/MRArbGrad.egg-info}/PKG-INFO +1 -1
- {mrarbgrad-4.0.0/MRArbGrad.egg-info → mrarbgrad-4.1.1}/PKG-INFO +1 -1
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/Function.py +54 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/__init__.py +1 -1
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/ext/main.cpp +149 -58
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/ext/traj/MrTraj.h +1 -1
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/ext/traj/VDSpiral.h +10 -9
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/ext/traj/Yarnball.h +8 -8
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/ext/utility/global.h +5 -2
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/ext/utility/v3.cpp +79 -1
- mrarbgrad-4.1.1/mrarbgrad_src/ext/utility/v3.h +72 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/pyproject.toml +1 -1
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/setup.py +0 -2
- mrarbgrad-4.0.0/mrarbgrad_src/ext/utility/v3.h +0 -156
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/LICENSE +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/MANIFEST.in +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/MRArbGrad.egg-info/SOURCES.txt +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/MRArbGrad.egg-info/dependency_links.txt +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/MRArbGrad.egg-info/requires.txt +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/MRArbGrad.egg-info/top_level.txt +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/README.md +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/example/example_BuiltInTraj.py +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/example/example_ExternalFunction2D.py +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/example/example_ExternalSamples2D.py +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/example/example_ExternalSamples3D.py +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/Utility.py +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/ext/mag/Mag.cpp +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/ext/mag/Mag.h +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/ext/traj/Cones.h +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/ext/traj/MrTraj_2D.h +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/ext/traj/Rosette.h +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/ext/traj/Seiffert.h +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/ext/traj/Shell3d.h +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/ext/traj/Spiral.h +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/ext/traj/TrajFunc.h +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/ext/utility/Intp.h +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/ext/utility/LinIntp.h +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/ext/utility/SplineIntp.h +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/ext/utility/global.cpp +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/trajfunc/__init__.py +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/mrarbgrad_src/trajfunc/main.py +0 -0
- {mrarbgrad-4.0.0 → mrarbgrad-4.1.1}/setup.cfg +0 -0
|
@@ -376,3 +376,57 @@ def setMagSFS(x): ext.setMagSFS(x)
|
|
|
376
376
|
def setMagGradRep(x): ext.setMagGradRep(x)
|
|
377
377
|
def setMagTrajRep(x): ext.setMagTrajRep(x)
|
|
378
378
|
def setDbgPrint(x): ext.setDbgPrint(x)
|
|
379
|
+
|
|
380
|
+
def saveF64(hdr:str, bin:str, arr:NDArray) -> bool:
|
|
381
|
+
"""
|
|
382
|
+
save vector file (float64)
|
|
383
|
+
|
|
384
|
+
Args:
|
|
385
|
+
hdr (str): header (hdr) file path
|
|
386
|
+
bin (str): bin file path
|
|
387
|
+
arr (NDarray): array to be saved
|
|
388
|
+
|
|
389
|
+
Returns:
|
|
390
|
+
bool: True for success
|
|
391
|
+
"""
|
|
392
|
+
return ext.saveF64(str(hdr), str(bin), arr)
|
|
393
|
+
|
|
394
|
+
def loadF64(hdr:str, bin:str) -> list[NDArray]|None:
|
|
395
|
+
"""
|
|
396
|
+
load vector file (float64)
|
|
397
|
+
|
|
398
|
+
Args:
|
|
399
|
+
hdr (str): header (hdr) file path
|
|
400
|
+
bin (str): bin file path
|
|
401
|
+
|
|
402
|
+
Returns:
|
|
403
|
+
list[NDArray]: list of loaded array
|
|
404
|
+
"""
|
|
405
|
+
return ext.loadF64(str(hdr), str(bin))
|
|
406
|
+
|
|
407
|
+
def saveF32(hdr:str, bin:str, arr:NDArray) -> bool:
|
|
408
|
+
"""
|
|
409
|
+
save vector file (float32)
|
|
410
|
+
|
|
411
|
+
Args:
|
|
412
|
+
hdr (str): header (hdr) file path
|
|
413
|
+
bin (str): bin file path
|
|
414
|
+
arr (NDarray): array to be saved
|
|
415
|
+
|
|
416
|
+
Returns:
|
|
417
|
+
bool: True for success
|
|
418
|
+
"""
|
|
419
|
+
return ext.saveF32(str(hdr), str(bin), arr)
|
|
420
|
+
|
|
421
|
+
def loadF32(hdr:str, bin:str) -> list[NDArray]|None:
|
|
422
|
+
"""
|
|
423
|
+
load vector file (float32)
|
|
424
|
+
|
|
425
|
+
Args:
|
|
426
|
+
hdr (str): header (hdr) file path
|
|
427
|
+
bin (str): bin file path
|
|
428
|
+
|
|
429
|
+
Returns:
|
|
430
|
+
list[NDArray]: list of loaded array
|
|
431
|
+
"""
|
|
432
|
+
return ext.loadF32(str(hdr), str(bin))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from .Function import calGrad4ExFunc, calGrad4ExSamp
|
|
2
2
|
from .Function import getG_Cones, getG_Rosette, getG_Rosette_Trad, getG_Seiffert, getG_Shell3d, getG_Spiral, getG_VDSpiral, getG_VDSpiral_RT, getG_Yarnball, getG_Yarnball_RT
|
|
3
|
-
from .Function import setSolverMtg, setTrajRev, setGoldAng, setShuf, setMaxG0, setMaxG1, setMagOverSamp, setMagSFS, setMagGradRep, setMagTrajRep, setDbgPrint
|
|
3
|
+
from .Function import setSolverMtg, setTrajRev, setGoldAng, setShuf, setMaxG0, setMaxG1, setMagOverSamp, setMagSFS, setMagGradRep, setMagTrajRep, setDbgPrint, saveF64, loadF64, saveF32, loadF32
|
|
4
4
|
from .Utility import _calDiaphony, rotate, _calJacElip, _calCompElipInt, _calSphFibPt, cvtGrad2Traj, getGoldang, getGoldrat, rand3d, gradClip
|
|
5
5
|
|
|
6
6
|
from . import trajfunc
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
#include "traj/Cones.h"
|
|
18
18
|
#include "utility/SplineIntp.h"
|
|
19
19
|
|
|
20
|
+
typedef std::list<vv3> lvv3;
|
|
21
|
+
|
|
20
22
|
bool gMain_enTrajRev (0);
|
|
21
23
|
bool gMain_enGoldAng (0);
|
|
22
24
|
bool gMain_enShuffle (0);
|
|
@@ -133,14 +135,9 @@ bool cvtNpa2Vf64(PyObject* pNumpyArray, vf64* pvf64Out)
|
|
|
133
135
|
return true;
|
|
134
136
|
}
|
|
135
137
|
|
|
136
|
-
bool inline
|
|
138
|
+
bool inline chkNarg(i64 nArg, i64 nArgExp)
|
|
137
139
|
{
|
|
138
|
-
|
|
139
|
-
{
|
|
140
|
-
printf("wrong num. of arg, narg=%ld, %ld expected\n", nArg, nArgExp);
|
|
141
|
-
abort();
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
140
|
+
ASSERT (nArg == nArgExp);
|
|
144
141
|
return true;
|
|
145
142
|
}
|
|
146
143
|
|
|
@@ -187,18 +184,13 @@ public:
|
|
|
187
184
|
PyObject* _pPyObj_v3 = pPyObj_v3;
|
|
188
185
|
pPyObj_v3 = PyArray_FROM_OTF(pPyObj_v3, NPY_FLOAT64, NPY_ARRAY_CARRAY);
|
|
189
186
|
Py_DECREF(_pPyObj_v3);
|
|
190
|
-
|
|
191
|
-
{
|
|
192
|
-
PyErr_SetString(PyExc_RuntimeError, "the return value of getK / getDkDp / getD2kDp2 must be size-3.\n");
|
|
193
|
-
PyErr_PrintEx(-1);
|
|
194
|
-
std::abort();
|
|
195
|
-
return false;
|
|
196
|
-
}
|
|
187
|
+
ASSERT (PyArray_SIZE((PyArrayObject*)pPyObj_v3) == 3);
|
|
197
188
|
|
|
198
189
|
k->x = *(f64*)PyArray_GETPTR1((PyArrayObject*)pPyObj_v3, 0);
|
|
199
190
|
k->y = *(f64*)PyArray_GETPTR1((PyArrayObject*)pPyObj_v3, 1);
|
|
200
191
|
k->z = *(f64*)PyArray_GETPTR1((PyArrayObject*)pPyObj_v3, 2);
|
|
201
|
-
|
|
192
|
+
|
|
193
|
+
Py_DECREF(pPyObj_v3);
|
|
202
194
|
return true;
|
|
203
195
|
}
|
|
204
196
|
|
|
@@ -215,18 +207,13 @@ public:
|
|
|
215
207
|
PyObject* _pPyObj_v3 = pPyObj_v3;
|
|
216
208
|
pPyObj_v3 = PyArray_FROM_OTF(pPyObj_v3, NPY_FLOAT64, NPY_ARRAY_CARRAY);
|
|
217
209
|
Py_DECREF(_pPyObj_v3);
|
|
218
|
-
|
|
219
|
-
{
|
|
220
|
-
PyErr_SetString(PyExc_RuntimeError, "the return value of getK / getDkDp / getD2kDp2 must be size-3.\n");
|
|
221
|
-
PyErr_PrintEx(-1);
|
|
222
|
-
std::abort();
|
|
223
|
-
return false;
|
|
224
|
-
}
|
|
210
|
+
ASSERT (PyArray_SIZE((PyArrayObject*)pPyObj_v3) == 3);
|
|
225
211
|
|
|
226
212
|
k->x = *(f64*)PyArray_GETPTR1((PyArrayObject*)pPyObj_v3, 0);
|
|
227
213
|
k->y = *(f64*)PyArray_GETPTR1((PyArrayObject*)pPyObj_v3, 1);
|
|
228
214
|
k->z = *(f64*)PyArray_GETPTR1((PyArrayObject*)pPyObj_v3, 2);
|
|
229
215
|
|
|
216
|
+
Py_DECREF(pPyObj_v3);
|
|
230
217
|
return true;
|
|
231
218
|
}
|
|
232
219
|
|
|
@@ -243,18 +230,13 @@ public:
|
|
|
243
230
|
PyObject* _pPyObj_v3 = pPyObj_v3;
|
|
244
231
|
pPyObj_v3 = PyArray_FROM_OTF(pPyObj_v3, NPY_FLOAT64, NPY_ARRAY_CARRAY);
|
|
245
232
|
Py_DECREF(_pPyObj_v3);
|
|
246
|
-
|
|
247
|
-
{
|
|
248
|
-
PyErr_SetString(PyExc_RuntimeError, "the return value of getK / getDkDp / getD2kDp2 must be size-3.\n");
|
|
249
|
-
PyErr_PrintEx(-1);
|
|
250
|
-
std::abort();
|
|
251
|
-
return false;
|
|
252
|
-
}
|
|
233
|
+
ASSERT (PyArray_SIZE((PyArrayObject*)pPyObj_v3) != 3);
|
|
253
234
|
|
|
254
235
|
k->x = *(f64*)PyArray_GETPTR1((PyArrayObject*)pPyObj_v3, 0);
|
|
255
236
|
k->y = *(f64*)PyArray_GETPTR1((PyArrayObject*)pPyObj_v3, 1);
|
|
256
237
|
k->z = *(f64*)PyArray_GETPTR1((PyArrayObject*)pPyObj_v3, 2);
|
|
257
238
|
|
|
239
|
+
Py_DECREF(pPyObj_v3);
|
|
258
240
|
return true;
|
|
259
241
|
}
|
|
260
242
|
protected:
|
|
@@ -325,7 +307,7 @@ private:
|
|
|
325
307
|
|
|
326
308
|
PyObject* calGrad4ExFunc(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
327
309
|
{
|
|
328
|
-
|
|
310
|
+
chkNarg(narg, 10);
|
|
329
311
|
|
|
330
312
|
MrTraj::GeoPara objGeoPara;
|
|
331
313
|
MrTraj::GradPara objGradPara;
|
|
@@ -353,7 +335,7 @@ PyObject* calGrad4ExSamp(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
|
353
335
|
{
|
|
354
336
|
try
|
|
355
337
|
{
|
|
356
|
-
|
|
338
|
+
chkNarg(narg, 6);
|
|
357
339
|
|
|
358
340
|
MrTraj::GeoPara objGeoPara;
|
|
359
341
|
MrTraj::GradPara objGradPara;
|
|
@@ -389,7 +371,7 @@ bool getG(MrTraj* pmt, vv3* pvv3M0PE, vvv3* pvvv3GRO)
|
|
|
389
371
|
pvvv3GRO->resize(nAcq);
|
|
390
372
|
|
|
391
373
|
bool& enShuf = gMain_enShuffle;
|
|
392
|
-
vi64 vi64ShufSeq; MrTraj::
|
|
374
|
+
vi64 vi64ShufSeq; MrTraj::genPermTab(&vi64ShufSeq, nAcq);
|
|
393
375
|
for (i64 i = 0; i < nAcq; ++i)
|
|
394
376
|
{
|
|
395
377
|
i64 _i = enShuf?vi64ShufSeq[i]:i;
|
|
@@ -410,7 +392,7 @@ bool getG(MrTraj* pmt, vv3* pvv3M0PE, vvv3* pvvv3GRO)
|
|
|
410
392
|
|
|
411
393
|
PyObject* getG_Spiral(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
412
394
|
{
|
|
413
|
-
|
|
395
|
+
chkNarg(narg, 7);
|
|
414
396
|
|
|
415
397
|
MrTraj::GeoPara objGeoPara;
|
|
416
398
|
MrTraj::GradPara objGradPara;
|
|
@@ -430,7 +412,7 @@ PyObject* getG_Spiral(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
|
430
412
|
|
|
431
413
|
PyObject* getG_VDSpiral(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
432
414
|
{
|
|
433
|
-
|
|
415
|
+
chkNarg(narg, 8);
|
|
434
416
|
|
|
435
417
|
MrTraj::GeoPara objGeoPara;
|
|
436
418
|
MrTraj::GradPara objGradPara;
|
|
@@ -451,7 +433,7 @@ PyObject* getG_VDSpiral(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
|
451
433
|
|
|
452
434
|
PyObject* getG_VDSpiral_RT(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
453
435
|
{
|
|
454
|
-
|
|
436
|
+
chkNarg(narg, 7);
|
|
455
437
|
|
|
456
438
|
MrTraj::GeoPara objGeoPara;
|
|
457
439
|
MrTraj::GradPara objGradPara;
|
|
@@ -470,7 +452,7 @@ PyObject* getG_VDSpiral_RT(PyObject* self, PyObject* const* args, Py_ssize_t nar
|
|
|
470
452
|
|
|
471
453
|
PyObject* getG_Rosette(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
472
454
|
{
|
|
473
|
-
|
|
455
|
+
chkNarg(narg, 9);
|
|
474
456
|
|
|
475
457
|
MrTraj::GeoPara objGeoPara;
|
|
476
458
|
MrTraj::GradPara objGradPara;
|
|
@@ -494,7 +476,7 @@ PyObject* getG_Rosette(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
|
494
476
|
|
|
495
477
|
PyObject* getG_Rosette_Trad(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
496
478
|
{
|
|
497
|
-
|
|
479
|
+
chkNarg(narg, 10);
|
|
498
480
|
|
|
499
481
|
MrTraj::GeoPara objGeoPara;
|
|
500
482
|
MrTraj::GradPara objGradPara;
|
|
@@ -518,7 +500,7 @@ PyObject* getG_Rosette_Trad(PyObject* self, PyObject* const* args, Py_ssize_t na
|
|
|
518
500
|
|
|
519
501
|
PyObject* getG_Shell3d(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
520
502
|
{
|
|
521
|
-
|
|
503
|
+
chkNarg(narg, 6);
|
|
522
504
|
|
|
523
505
|
MrTraj::GeoPara objGeoPara;
|
|
524
506
|
MrTraj::GradPara objGradPara;
|
|
@@ -536,7 +518,7 @@ PyObject* getG_Shell3d(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
|
536
518
|
|
|
537
519
|
PyObject* getG_Yarnball(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
538
520
|
{
|
|
539
|
-
|
|
521
|
+
chkNarg(narg, 6);
|
|
540
522
|
|
|
541
523
|
MrTraj::GeoPara objGeoPara;
|
|
542
524
|
MrTraj::GradPara objGradPara;
|
|
@@ -554,7 +536,7 @@ PyObject* getG_Yarnball(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
|
554
536
|
|
|
555
537
|
PyObject* getG_Yarnball_RT(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
556
538
|
{
|
|
557
|
-
|
|
539
|
+
chkNarg(narg, 6);
|
|
558
540
|
|
|
559
541
|
MrTraj::GeoPara objGeoPara;
|
|
560
542
|
MrTraj::GradPara objGradPara;
|
|
@@ -572,7 +554,7 @@ PyObject* getG_Yarnball_RT(PyObject* self, PyObject* const* args, Py_ssize_t nar
|
|
|
572
554
|
|
|
573
555
|
PyObject* getG_Seiffert(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
574
556
|
{
|
|
575
|
-
|
|
557
|
+
chkNarg(narg, 7);
|
|
576
558
|
|
|
577
559
|
MrTraj::GeoPara objGeoPara;
|
|
578
560
|
MrTraj::GradPara objGradPara;
|
|
@@ -591,7 +573,7 @@ PyObject* getG_Seiffert(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
|
591
573
|
|
|
592
574
|
PyObject* getG_Cones(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
593
575
|
{
|
|
594
|
-
|
|
576
|
+
chkNarg(narg, 6);
|
|
595
577
|
|
|
596
578
|
MrTraj::GeoPara objGeoPara;
|
|
597
579
|
MrTraj::GradPara objGradPara;
|
|
@@ -610,7 +592,7 @@ PyObject* getG_Cones(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
|
610
592
|
PyObject* setSolverMtg(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
611
593
|
{
|
|
612
594
|
extern bool gMrTraj_enMtg;
|
|
613
|
-
|
|
595
|
+
chkNarg(narg, 1);
|
|
614
596
|
gMrTraj_enMtg = PyLong_AsLong(args[0]);
|
|
615
597
|
Py_INCREF(Py_None);
|
|
616
598
|
return Py_None;
|
|
@@ -618,7 +600,7 @@ PyObject* setSolverMtg(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
|
618
600
|
|
|
619
601
|
PyObject* setTrajRev(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
620
602
|
{
|
|
621
|
-
|
|
603
|
+
chkNarg(narg, 1);
|
|
622
604
|
gMain_enTrajRev = PyLong_AsLong(args[0]);
|
|
623
605
|
Py_INCREF(Py_None);
|
|
624
606
|
return Py_None;
|
|
@@ -626,7 +608,7 @@ PyObject* setTrajRev(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
|
626
608
|
|
|
627
609
|
PyObject* setGoldAng(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
628
610
|
{
|
|
629
|
-
|
|
611
|
+
chkNarg(narg, 1);
|
|
630
612
|
gMain_enGoldAng = PyLong_AsLong(args[0]);
|
|
631
613
|
Py_INCREF(Py_None);
|
|
632
614
|
return Py_None;
|
|
@@ -634,7 +616,7 @@ PyObject* setGoldAng(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
|
634
616
|
|
|
635
617
|
PyObject* setShuf(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
636
618
|
{
|
|
637
|
-
|
|
619
|
+
chkNarg(narg, 1);
|
|
638
620
|
gMain_enShuffle = PyLong_AsLong(args[0]);
|
|
639
621
|
Py_INCREF(Py_None);
|
|
640
622
|
return Py_None;
|
|
@@ -643,7 +625,7 @@ PyObject* setShuf(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
|
643
625
|
PyObject* setMaxG0(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
644
626
|
{
|
|
645
627
|
extern f64 gMrTraj_g0Norm;
|
|
646
|
-
|
|
628
|
+
chkNarg(narg, 1);
|
|
647
629
|
bool enMaxG0 = PyLong_AsLong(args[0]);
|
|
648
630
|
if (enMaxG0) gMrTraj_g0Norm = 1e6;
|
|
649
631
|
else gMrTraj_g0Norm = 0e0;
|
|
@@ -654,7 +636,7 @@ PyObject* setMaxG0(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
|
654
636
|
PyObject* setMaxG1(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
655
637
|
{
|
|
656
638
|
extern f64 gMrTraj_g1Norm;
|
|
657
|
-
|
|
639
|
+
chkNarg(narg, 1);
|
|
658
640
|
bool enMaxG1 = PyLong_AsLong(args[0]);
|
|
659
641
|
if (enMaxG1) gMrTraj_g1Norm = 1e6;
|
|
660
642
|
else gMrTraj_g1Norm = 0e0;
|
|
@@ -665,7 +647,7 @@ PyObject* setMaxG1(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
|
665
647
|
PyObject* setMagOverSamp(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
666
648
|
{
|
|
667
649
|
extern i64 gMag_oversamp;
|
|
668
|
-
|
|
650
|
+
chkNarg(narg, 1);
|
|
669
651
|
gMag_oversamp = PyLong_AsLong(args[0]);
|
|
670
652
|
Py_INCREF(Py_None);
|
|
671
653
|
return Py_None;
|
|
@@ -674,7 +656,7 @@ PyObject* setMagOverSamp(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
|
674
656
|
PyObject* setMagSFS(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
675
657
|
{
|
|
676
658
|
extern bool gMag_enSFS;
|
|
677
|
-
|
|
659
|
+
chkNarg(narg, 1);
|
|
678
660
|
gMag_enSFS = PyLong_AsLong(args[0]);
|
|
679
661
|
Py_INCREF(Py_None);
|
|
680
662
|
return Py_None;
|
|
@@ -683,7 +665,7 @@ PyObject* setMagSFS(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
|
683
665
|
PyObject* setMagGradRep(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
684
666
|
{
|
|
685
667
|
extern bool gMag_enGradRep;
|
|
686
|
-
|
|
668
|
+
chkNarg(narg, 1);
|
|
687
669
|
gMag_enGradRep = PyLong_AsLong(args[0]);
|
|
688
670
|
Py_INCREF(Py_None);
|
|
689
671
|
return Py_None;
|
|
@@ -692,7 +674,7 @@ PyObject* setMagGradRep(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
|
692
674
|
PyObject* setMagTrajRep(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
693
675
|
{
|
|
694
676
|
extern bool gMag_enTrajRep;
|
|
695
|
-
|
|
677
|
+
chkNarg(narg, 1);
|
|
696
678
|
gMag_enTrajRep = PyLong_AsLong(args[0]);
|
|
697
679
|
Py_INCREF(Py_None);
|
|
698
680
|
return Py_None;
|
|
@@ -701,17 +683,123 @@ PyObject* setMagTrajRep(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
|
701
683
|
PyObject* setDbgPrint(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
702
684
|
{
|
|
703
685
|
extern bool glob_enDbgPrint;
|
|
704
|
-
|
|
686
|
+
chkNarg(narg, 1);
|
|
705
687
|
glob_enDbgPrint = PyLong_AsLong(args[0]);
|
|
706
688
|
Py_INCREF(Py_None);
|
|
707
689
|
return Py_None;
|
|
708
690
|
}
|
|
709
691
|
|
|
710
|
-
|
|
711
|
-
|
|
692
|
+
PyObject* saveF64(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
693
|
+
{
|
|
694
|
+
chkNarg(narg, 3);
|
|
695
|
+
const char* strHdr = PyUnicode_AsUTF8(args[0]);
|
|
696
|
+
const char* strBin = PyUnicode_AsUTF8(args[1]);
|
|
697
|
+
FILE* fHdr = fopen(strHdr, "w");
|
|
698
|
+
FILE* fBin = fopen(strBin, "wb");
|
|
699
|
+
if (fHdr==NULL || fBin==NULL)
|
|
700
|
+
{
|
|
701
|
+
if (fHdr) fclose(fHdr);
|
|
702
|
+
if (fBin) fclose(fBin);
|
|
703
|
+
Py_INCREF(Py_False);
|
|
704
|
+
return Py_False;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
vv3 vv3Data;
|
|
708
|
+
i64 n = PyList_GET_SIZE(args[2]);
|
|
709
|
+
for (i64 i=0; i<n; ++i)
|
|
710
|
+
{
|
|
711
|
+
cvtNpa2Vv3(PyList_GET_ITEM(args[2], i), &vv3Data);
|
|
712
|
+
v3::saveF64(fHdr, fBin, vv3Data);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
Py_INCREF(Py_True);
|
|
716
|
+
return Py_True;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
PyObject* loadF64(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
720
|
+
{
|
|
721
|
+
chkNarg(narg, 2);
|
|
722
|
+
const char* strHdr = PyUnicode_AsUTF8(args[0]);
|
|
723
|
+
const char* strBin = PyUnicode_AsUTF8(args[1]);
|
|
724
|
+
FILE* fHdr = fopen(strHdr, "r");
|
|
725
|
+
FILE* fBin = fopen(strBin, "rb");
|
|
726
|
+
if (fHdr==NULL || fBin==NULL)
|
|
727
|
+
{
|
|
728
|
+
if (fHdr) fclose(fHdr);
|
|
729
|
+
if (fBin) fclose(fBin);
|
|
730
|
+
Py_INCREF(Py_None);
|
|
731
|
+
return Py_None;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
lvv3 lvv3Data;
|
|
735
|
+
bool ret; vv3 vv3Data;
|
|
736
|
+
while (1)
|
|
737
|
+
{
|
|
738
|
+
ret = v3::loadF64(fHdr, fBin, &vv3Data);
|
|
739
|
+
if (vv3Data.empty() || !ret) break;
|
|
740
|
+
lvv3Data.push_back(vv3Data);
|
|
741
|
+
}
|
|
742
|
+
if (fHdr) fclose(fHdr);
|
|
743
|
+
if (fBin) fclose(fBin);
|
|
744
|
+
vvv3 vvv3Data(lvv3Data.begin(), lvv3Data.end());
|
|
745
|
+
return cvtVvv3toList(vvv3Data);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
PyObject* saveF32(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
712
749
|
{
|
|
713
|
-
|
|
714
|
-
|
|
750
|
+
chkNarg(narg, 3);
|
|
751
|
+
const char* strHdr = PyUnicode_AsUTF8(args[0]);
|
|
752
|
+
const char* strBin = PyUnicode_AsUTF8(args[1]);
|
|
753
|
+
FILE* fHdr = fopen(strHdr, "w");
|
|
754
|
+
FILE* fBin = fopen(strBin, "wb");
|
|
755
|
+
if (fHdr==NULL || fBin==NULL)
|
|
756
|
+
{
|
|
757
|
+
if (fHdr) fclose(fHdr);
|
|
758
|
+
if (fBin) fclose(fBin);
|
|
759
|
+
Py_INCREF(Py_False);
|
|
760
|
+
return Py_False;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
vv3 vv3Data;
|
|
764
|
+
i64 n = PyList_GET_SIZE(args[2]);
|
|
765
|
+
for (i64 i=0; i<n; ++i)
|
|
766
|
+
{
|
|
767
|
+
cvtNpa2Vv3(PyList_GET_ITEM(args[2], i), &vv3Data);
|
|
768
|
+
v3::saveF32(fHdr, fBin, vv3Data);
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
Py_INCREF(Py_True);
|
|
772
|
+
return Py_True;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
PyObject* loadF32(PyObject* self, PyObject* const* args, Py_ssize_t narg)
|
|
776
|
+
{
|
|
777
|
+
chkNarg(narg, 2);
|
|
778
|
+
const char* strHdr = PyUnicode_AsUTF8(args[0]);
|
|
779
|
+
const char* strBin = PyUnicode_AsUTF8(args[1]);
|
|
780
|
+
typedef std::list<vv3> lvv3;
|
|
781
|
+
FILE* fHdr = fopen(strHdr, "r");
|
|
782
|
+
FILE* fBin = fopen(strBin, "rb");
|
|
783
|
+
if (fHdr==NULL || fBin==NULL)
|
|
784
|
+
{
|
|
785
|
+
if (fHdr) fclose(fHdr);
|
|
786
|
+
if (fBin) fclose(fBin);
|
|
787
|
+
Py_INCREF(Py_None);
|
|
788
|
+
return Py_None;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
lvv3 lvv3Data;
|
|
792
|
+
bool ret; vv3 vv3Data;
|
|
793
|
+
while (1)
|
|
794
|
+
{
|
|
795
|
+
ret = v3::loadF32(fHdr, fBin, &vv3Data);
|
|
796
|
+
if (vv3Data.empty() || !ret) break;
|
|
797
|
+
lvv3Data.push_back(vv3Data);
|
|
798
|
+
}
|
|
799
|
+
if (fHdr) fclose(fHdr);
|
|
800
|
+
if (fBin) fclose(fBin);
|
|
801
|
+
vvv3 vvv3Data(lvv3Data.begin(), lvv3Data.end());
|
|
802
|
+
return cvtVvv3toList(vvv3Data);
|
|
715
803
|
}
|
|
716
804
|
|
|
717
805
|
static PyMethodDef aMeth[] =
|
|
@@ -734,12 +822,15 @@ static PyMethodDef aMeth[] =
|
|
|
734
822
|
{"setShuf", (PyCFunction)setShuf, METH_FASTCALL, ""},
|
|
735
823
|
{"setMaxG0", (PyCFunction)setMaxG0, METH_FASTCALL, ""},
|
|
736
824
|
{"setMaxG1", (PyCFunction)setMaxG1, METH_FASTCALL, ""},
|
|
737
|
-
{"getTestVal", (PyCFunction)getTestVal, METH_FASTCALL, ""},
|
|
738
825
|
{"setMagOverSamp", (PyCFunction)setMagOverSamp, METH_FASTCALL, ""},
|
|
739
826
|
{"setMagSFS", (PyCFunction)setMagSFS, METH_FASTCALL, ""},
|
|
740
827
|
{"setMagGradRep", (PyCFunction)setMagGradRep, METH_FASTCALL, ""},
|
|
741
828
|
{"setMagTrajRep", (PyCFunction)setMagTrajRep, METH_FASTCALL, ""},
|
|
742
829
|
{"setDbgPrint", (PyCFunction)setDbgPrint, METH_FASTCALL, ""},
|
|
830
|
+
{"saveF64", (PyCFunction)saveF64, METH_FASTCALL, ""},
|
|
831
|
+
{"loadF64", (PyCFunction)loadF64, METH_FASTCALL, ""},
|
|
832
|
+
{"saveF32", (PyCFunction)saveF32, METH_FASTCALL, ""},
|
|
833
|
+
{"loadF32", (PyCFunction)loadF32, METH_FASTCALL, ""},
|
|
743
834
|
{NULL, NULL, 0, NULL} /* Sentinel */
|
|
744
835
|
};
|
|
745
836
|
|
|
@@ -78,14 +78,13 @@ public:
|
|
|
78
78
|
{
|
|
79
79
|
m_kRhoPhi0 = kRhoPhi0;
|
|
80
80
|
m_kRhoPhi1 = kRhoPhi1;
|
|
81
|
-
|
|
82
|
-
m_dRotAng = 2e0*M_PI/
|
|
83
|
-
|
|
84
|
-
m_nAcq = m_nRot;
|
|
81
|
+
m_nAcq = calNRot(kRhoPhi1, objGeoPara.nPix);
|
|
82
|
+
m_dRotAng = 2e0*M_PI/m_nAcq;
|
|
83
|
+
genPermTab(&m_vi64PermTab, m_nAcq);
|
|
85
84
|
|
|
86
85
|
VDSpiral_TrajFunc tf(m_kRhoPhi0, m_kRhoPhi1, 0);
|
|
87
|
-
vv3 vv3GRO; calGrad(NULL, &vv3GRO, NULL, tf, m_objGradPara,
|
|
88
|
-
m_nSampMax = vv3GRO.size();
|
|
86
|
+
vv3 vv3GRO; calGrad(NULL, &vv3GRO, NULL, tf, m_objGradPara, 4);
|
|
87
|
+
m_nSampMax = vv3GRO.size() + 0;
|
|
89
88
|
}
|
|
90
89
|
|
|
91
90
|
virtual ~VDSpiral_RT()
|
|
@@ -95,7 +94,9 @@ public:
|
|
|
95
94
|
{
|
|
96
95
|
bool ret = true;
|
|
97
96
|
ASSERT(iAcq >= 0);
|
|
98
|
-
|
|
97
|
+
i64 iPhi = m_vi64PermTab[iAcq%m_nAcq];
|
|
98
|
+
f64 phi = iPhi*m_dRotAng;
|
|
99
|
+
VDSpiral_TrajFunc tf(m_kRhoPhi0, m_kRhoPhi1, phi);
|
|
99
100
|
ret &= calGrad(pv3M0PE, pvv3GRO, NULL, tf, m_objGradPara, 2);
|
|
100
101
|
return ret;
|
|
101
102
|
}
|
|
@@ -103,6 +104,6 @@ public:
|
|
|
103
104
|
protected:
|
|
104
105
|
f64 m_kRhoPhi0;
|
|
105
106
|
f64 m_kRhoPhi1;
|
|
106
|
-
|
|
107
|
-
vi64
|
|
107
|
+
f64 m_dRotAng;
|
|
108
|
+
vi64 m_vi64PermTab;
|
|
108
109
|
};
|
|
@@ -115,12 +115,12 @@ public:
|
|
|
115
115
|
m_kRhoPhi = kRhoPhi;
|
|
116
116
|
m_nRot = calNRot(kRhoPhi, objGeoPara.nPix);
|
|
117
117
|
m_dRotAng = 2e0*M_PI/m_nRot;
|
|
118
|
-
genRandIdx(&m_vi64Idx, m_nRot);
|
|
119
118
|
m_nAcq = m_nRot*m_nRot;
|
|
119
|
+
genPermTab(&m_vi64PermTab, m_nAcq);
|
|
120
120
|
|
|
121
121
|
Yarnball_TrajFunc tf(m_kRhoPhi, M_PI/2e0, 0);
|
|
122
|
-
vv3 vv3GRO; calGrad(NULL, &vv3GRO, NULL, tf, m_objGradPara,
|
|
123
|
-
m_nSampMax = vv3GRO.size();
|
|
122
|
+
vv3 vv3GRO; calGrad(NULL, &vv3GRO, NULL, tf, m_objGradPara, 4);
|
|
123
|
+
m_nSampMax = vv3GRO.size() + 1; // 1 for redundance
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
virtual ~Yarnball_RT()
|
|
@@ -130,10 +130,10 @@ public:
|
|
|
130
130
|
{
|
|
131
131
|
bool ret = true;
|
|
132
132
|
ASSERT(iAcq >= 0);
|
|
133
|
-
i64 iPhi = iAcq%m_nRot;
|
|
134
|
-
i64 iTht = iAcq/m_nRot
|
|
135
|
-
f64 phi = m_dRotAng*
|
|
136
|
-
f64 tht = m_dRotAng*
|
|
133
|
+
i64 iPhi = m_vi64PermTab[iAcq%m_nAcq]%m_nRot;
|
|
134
|
+
i64 iTht = m_vi64PermTab[iAcq%m_nAcq]/m_nRot;
|
|
135
|
+
f64 phi = m_dRotAng*iPhi;
|
|
136
|
+
f64 tht = m_dRotAng*iTht;
|
|
137
137
|
Yarnball_TrajFunc tf(m_kRhoPhi, tht, phi);
|
|
138
138
|
ret &= calGrad(pv3M0PE, pvv3GRO, NULL, tf, m_objGradPara, 2);
|
|
139
139
|
return ret;
|
|
@@ -142,5 +142,5 @@ public:
|
|
|
142
142
|
protected:
|
|
143
143
|
f64 m_kRhoPhi;
|
|
144
144
|
i64 m_nRot; f64 m_dRotAng;
|
|
145
|
-
vi64
|
|
145
|
+
vi64 m_vi64PermTab;
|
|
146
146
|
};
|
|
@@ -24,6 +24,10 @@ typedef std::vector<i64> vi64;
|
|
|
24
24
|
typedef std::vector<f64> vf64;
|
|
25
25
|
typedef std::list<i64> li64;
|
|
26
26
|
typedef std::list<f64> lf64;
|
|
27
|
+
typedef std::vector<i32> vi32;
|
|
28
|
+
typedef std::vector<f32> vf32;
|
|
29
|
+
typedef std::list<i32> li32;
|
|
30
|
+
typedef std::list<f32> lf32;
|
|
27
31
|
|
|
28
32
|
typedef std::string str;
|
|
29
33
|
|
|
@@ -49,7 +53,7 @@ inline T gcd(T x, T y)
|
|
|
49
53
|
#define GOLDRAT (1.6180339887498949e0) // ((1e0+std::sqrt(5e0))/2e0)
|
|
50
54
|
#define GOLDANG (2.3999632297286531e0) // ((3e0-std::sqrt(5e0))*M_PI)
|
|
51
55
|
|
|
52
|
-
#define PRINT(X) {printf("%s: %ld\n", #X, (
|
|
56
|
+
#define PRINT(X) {printf("%s: %ld\n", #X, (long)(X));}
|
|
53
57
|
#define PRINT_F(X) {printf("%s: %.3lf\n", #X, (f64)(X));}
|
|
54
58
|
#define PRINT_E(X) {printf("%s: %.3e\n", #X, (f64)(X));}
|
|
55
59
|
#define ASSERT(X) {if(!(X)) throw std::runtime_error(#X);}
|
|
@@ -62,4 +66,3 @@ inline T gcd(T x, T y)
|
|
|
62
66
|
if (glob_enDbgPrint) printf("Elapsed time: %.3lf ms\n", 1e3*cTick/CLOCKS_PER_SEC);
|
|
63
67
|
|
|
64
68
|
extern bool glob_enDbgPrint;
|
|
65
|
-
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#include "v3.h"
|
|
2
2
|
#include <array>
|
|
3
|
+
#include <cinttypes>
|
|
4
|
+
#include <cstring> // test
|
|
3
5
|
|
|
4
6
|
v3::v3() :x(0e0), y(0e0), z(0e0) {}
|
|
5
7
|
v3::v3(f64 _) :x(_), y(_), z(_) {}
|
|
@@ -362,4 +364,80 @@ v3 v3::axisroll(const v3& v3In, i64 nShift)
|
|
|
362
364
|
break;
|
|
363
365
|
}
|
|
364
366
|
return v3Ot;
|
|
365
|
-
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
bool v3::saveF64(FILE* pfHdr, FILE* pfBin, const vv3& vv3Data)
|
|
370
|
+
{
|
|
371
|
+
bool ret = true;
|
|
372
|
+
i64 lenData = vv3Data.size();
|
|
373
|
+
fprintf(pfHdr, "float64[%ld][3];\n", (long)lenData);
|
|
374
|
+
|
|
375
|
+
f64* bufFile = (f64*)malloc(lenData*3*sizeof(f64));
|
|
376
|
+
for(i64 i=0; i<(i64)lenData; ++i)
|
|
377
|
+
{
|
|
378
|
+
for(i64 j=0; j<3; ++j)
|
|
379
|
+
{ bufFile[3*i+j] = (f64)vv3Data[i][j]; }
|
|
380
|
+
}
|
|
381
|
+
ret &= (i64)fwrite(bufFile, sizeof(f64), lenData*3, pfBin)==lenData*3;
|
|
382
|
+
free(bufFile);
|
|
383
|
+
return ret;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
bool v3::loadF64(FILE* pfHdr, FILE* pfBin, vv3* pvv3Data)
|
|
387
|
+
{
|
|
388
|
+
bool ret = true;
|
|
389
|
+
i64 lenData = 0;
|
|
390
|
+
pvv3Data->clear();
|
|
391
|
+
int nRead = fscanf(pfHdr, "float64[%" SCNi64 "][3];\n", &lenData);
|
|
392
|
+
if (nRead==EOF) return true; // EOF
|
|
393
|
+
else if (nRead!=1) return false;
|
|
394
|
+
pvv3Data->resize(lenData);
|
|
395
|
+
|
|
396
|
+
f64* bufFile = (f64*)malloc(lenData*3*sizeof(f64));
|
|
397
|
+
ret &= (i64)fread(bufFile, sizeof(f64), lenData*3, pfBin)==lenData*3;
|
|
398
|
+
for(i64 i=0; i<lenData; ++i)
|
|
399
|
+
{
|
|
400
|
+
for(i64 j=0; j<3; ++j)
|
|
401
|
+
{ (*pvv3Data)[i][j] = (f64)bufFile[3*i+j]; }
|
|
402
|
+
}
|
|
403
|
+
free(bufFile);
|
|
404
|
+
return ret;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
bool v3::saveF32(FILE* pfHdr, FILE* pfBin, const vv3& vv3Data)
|
|
408
|
+
{
|
|
409
|
+
bool ret = true;
|
|
410
|
+
i64 lenData = vv3Data.size();
|
|
411
|
+
fprintf(pfHdr, "float32[%ld][3];\n", (long)lenData);
|
|
412
|
+
|
|
413
|
+
f32* bufFile = (f32*)malloc(lenData*3*sizeof(f32));
|
|
414
|
+
for(i64 i=0; i<(i64)lenData; ++i)
|
|
415
|
+
{
|
|
416
|
+
for(i64 j=0; j<3; ++j)
|
|
417
|
+
{ bufFile[3*i+j] = (f32)vv3Data[i][j]; }
|
|
418
|
+
}
|
|
419
|
+
ret &= (i64)fwrite(bufFile, sizeof(f32), lenData*3, pfBin)==lenData*3;
|
|
420
|
+
free(bufFile);
|
|
421
|
+
return ret;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
bool v3::loadF32(FILE* pfHdr, FILE* pfBin, vv3* pvv3Data)
|
|
425
|
+
{
|
|
426
|
+
bool ret = true;
|
|
427
|
+
i64 lenData = 0;
|
|
428
|
+
pvv3Data->clear();
|
|
429
|
+
int nRead = fscanf(pfHdr, "float32[%" SCNi64 "][3];\n", &lenData);
|
|
430
|
+
if (nRead==EOF) return true; // EOF
|
|
431
|
+
else if (nRead!=1) return false;
|
|
432
|
+
pvv3Data->resize(lenData);
|
|
433
|
+
|
|
434
|
+
f32* bufFile = (f32*)malloc(lenData*3*sizeof(f32));
|
|
435
|
+
ret &= (i64)fread(bufFile, sizeof(f32), lenData*3, pfBin)==lenData*3;
|
|
436
|
+
for(i64 i=0; i<lenData; ++i)
|
|
437
|
+
{
|
|
438
|
+
for(i64 j=0; j<3; ++j)
|
|
439
|
+
{ (*pvv3Data)[i][j] = (f64)bufFile[3*i+j]; }
|
|
440
|
+
}
|
|
441
|
+
free(bufFile);
|
|
442
|
+
return ret;
|
|
443
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <cmath>
|
|
4
|
+
#include <list>
|
|
5
|
+
#include <array>
|
|
6
|
+
#include "global.h"
|
|
7
|
+
|
|
8
|
+
class v3;
|
|
9
|
+
|
|
10
|
+
typedef std::vector<v3> vv3;
|
|
11
|
+
typedef std::vector<vv3> vvv3;
|
|
12
|
+
typedef std::list<v3> lv3;
|
|
13
|
+
|
|
14
|
+
class v3
|
|
15
|
+
{
|
|
16
|
+
public:
|
|
17
|
+
f64 x, y, z;
|
|
18
|
+
|
|
19
|
+
v3();
|
|
20
|
+
v3(f64 _);
|
|
21
|
+
v3(f64 x, f64 y, f64 z);
|
|
22
|
+
~v3();
|
|
23
|
+
v3 operator+(const v3 &rhs) const;
|
|
24
|
+
v3& operator+=(const v3 &rhs);
|
|
25
|
+
v3 operator+(const f64 &rhs) const;
|
|
26
|
+
v3& operator+=(const f64 &rhs);
|
|
27
|
+
v3 operator-(const v3 &rhs) const;
|
|
28
|
+
v3& operator-=(const v3 &rhs);
|
|
29
|
+
v3 operator-(const f64 &rhs) const;
|
|
30
|
+
v3& operator-=(const f64 &rhs);
|
|
31
|
+
v3 operator*(const v3 &rhs) const;
|
|
32
|
+
v3& operator*=(const v3 &rhs);
|
|
33
|
+
v3 operator*(const f64 &rhs) const;
|
|
34
|
+
v3& operator*=(const f64 &rhs);
|
|
35
|
+
v3 operator/(const v3 &rhs) const;
|
|
36
|
+
v3& operator/=(const v3 &rhs);
|
|
37
|
+
v3 operator/(const f64 &rhs) const;
|
|
38
|
+
v3& operator/=(const f64 &rhs);
|
|
39
|
+
bool operator==(const v3 &rhs) const;
|
|
40
|
+
bool operator!=(const v3 &rhs) const;
|
|
41
|
+
f64& operator[](i64 idx);
|
|
42
|
+
f64 operator[](i64 idx) const;
|
|
43
|
+
static f64 norm(const v3& v3In);
|
|
44
|
+
static v3 cross(const v3& v3In0, const v3& v3In1);
|
|
45
|
+
static f64 inner(const v3& v3In0, const v3& v3In1);
|
|
46
|
+
static v3 pow(const v3& v3In, f64 exp);
|
|
47
|
+
static bool rotate
|
|
48
|
+
(
|
|
49
|
+
v3* pv3Dst,
|
|
50
|
+
int iAx, f64 ang,
|
|
51
|
+
const v3& v3Src
|
|
52
|
+
);
|
|
53
|
+
static bool rotate
|
|
54
|
+
(
|
|
55
|
+
vv3* pvv3Dst,
|
|
56
|
+
int iAx, f64 ang,
|
|
57
|
+
const vv3& vv3Src
|
|
58
|
+
);
|
|
59
|
+
static bool rotate
|
|
60
|
+
(
|
|
61
|
+
lv3* plv3Dst,
|
|
62
|
+
int iAx, f64 ang,
|
|
63
|
+
const lv3& lv3Src
|
|
64
|
+
);
|
|
65
|
+
static v3 axisroll(const v3& v3In, i64 lShift);
|
|
66
|
+
static bool saveF64(FILE* pfHdr, FILE* pfBin, const vv3& vv3Data);
|
|
67
|
+
static bool loadF64(FILE* pfHdr, FILE* pfBin, vv3* pvv3Data);
|
|
68
|
+
static bool saveF32(FILE* pfHdr, FILE* pfBin, const vv3& vv3Data);
|
|
69
|
+
static bool loadF32(FILE* pfHdr, FILE* pfBin, vv3* pvv3Data);
|
|
70
|
+
private:
|
|
71
|
+
static bool genRotMat(std::array<v3,3>* pav3RotMat, int iAx, f64 ang);
|
|
72
|
+
};
|
|
@@ -4,7 +4,6 @@ from os.path import exists
|
|
|
4
4
|
from ctypes.util import find_library
|
|
5
5
|
|
|
6
6
|
useMtg = exists("./mrarbgrad_src/ext/mtg/")
|
|
7
|
-
useJemalloc = find_library("jemalloc") is not None
|
|
8
7
|
|
|
9
8
|
_sources = \
|
|
10
9
|
[
|
|
@@ -23,7 +22,6 @@ modExt = Extension\
|
|
|
23
22
|
(
|
|
24
23
|
"mrarbgrad.ext",
|
|
25
24
|
sources = _sources,
|
|
26
|
-
libraries = ['jemalloc'] if useJemalloc else [],
|
|
27
25
|
include_dirs = ["./mrarbgrad_src/ext/", numpy.get_include()],
|
|
28
26
|
define_macros = [("USE_MTG", None)] if useMtg else None,
|
|
29
27
|
language = 'c++'
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <cmath>
|
|
4
|
-
#include <list>
|
|
5
|
-
#include <array>
|
|
6
|
-
#include "global.h"
|
|
7
|
-
|
|
8
|
-
class v3;
|
|
9
|
-
|
|
10
|
-
typedef std::vector<v3> vv3;
|
|
11
|
-
typedef std::vector<vv3> vvv3;
|
|
12
|
-
typedef std::list<v3> lv3;
|
|
13
|
-
|
|
14
|
-
class v3
|
|
15
|
-
{
|
|
16
|
-
public:
|
|
17
|
-
f64 x, y, z;
|
|
18
|
-
|
|
19
|
-
v3();
|
|
20
|
-
v3(f64 _);
|
|
21
|
-
v3(f64 x, f64 y, f64 z);
|
|
22
|
-
~v3();
|
|
23
|
-
v3 operator+(const v3 &rhs) const;
|
|
24
|
-
v3& operator+=(const v3 &rhs);
|
|
25
|
-
v3 operator+(const f64 &rhs) const;
|
|
26
|
-
v3& operator+=(const f64 &rhs);
|
|
27
|
-
v3 operator-(const v3 &rhs) const;
|
|
28
|
-
v3& operator-=(const v3 &rhs);
|
|
29
|
-
v3 operator-(const f64 &rhs) const;
|
|
30
|
-
v3& operator-=(const f64 &rhs);
|
|
31
|
-
v3 operator*(const v3 &rhs) const;
|
|
32
|
-
v3& operator*=(const v3 &rhs);
|
|
33
|
-
v3 operator*(const f64 &rhs) const;
|
|
34
|
-
v3& operator*=(const f64 &rhs);
|
|
35
|
-
v3 operator/(const v3 &rhs) const;
|
|
36
|
-
v3& operator/=(const v3 &rhs);
|
|
37
|
-
v3 operator/(const f64 &rhs) const;
|
|
38
|
-
v3& operator/=(const f64 &rhs);
|
|
39
|
-
bool operator==(const v3 &rhs) const;
|
|
40
|
-
bool operator!=(const v3 &rhs) const;
|
|
41
|
-
f64& operator[](i64 idx);
|
|
42
|
-
f64 operator[](i64 idx) const;
|
|
43
|
-
static f64 norm(const v3& v3In);
|
|
44
|
-
static v3 cross(const v3& v3In0, const v3& v3In1);
|
|
45
|
-
static f64 inner(const v3& v3In0, const v3& v3In1);
|
|
46
|
-
static v3 pow(const v3& v3In, f64 exp);
|
|
47
|
-
static bool rotate
|
|
48
|
-
(
|
|
49
|
-
v3* pv3Dst,
|
|
50
|
-
int iAx, f64 ang,
|
|
51
|
-
const v3& v3Src
|
|
52
|
-
);
|
|
53
|
-
static bool rotate
|
|
54
|
-
(
|
|
55
|
-
vv3* pvv3Dst,
|
|
56
|
-
int iAx, f64 ang,
|
|
57
|
-
const vv3& vv3Src
|
|
58
|
-
);
|
|
59
|
-
static bool rotate
|
|
60
|
-
(
|
|
61
|
-
lv3* plv3Dst,
|
|
62
|
-
int iAx, f64 ang,
|
|
63
|
-
const lv3& lv3Src
|
|
64
|
-
);
|
|
65
|
-
static v3 axisroll(const v3& v3In, i64 lShift);
|
|
66
|
-
template<typename cv3>
|
|
67
|
-
static bool saveF64(FILE* pfBHdr, FILE* pfBin, const cv3& cv3Data);
|
|
68
|
-
template<typename cv3>
|
|
69
|
-
static bool loadF64(FILE* pfBHdr, FILE* pfBin, cv3* pcv3Data);
|
|
70
|
-
template<typename cv3>
|
|
71
|
-
static bool saveF32(FILE* pfBHdr, FILE* pfBin, const cv3& cv3Data);
|
|
72
|
-
template<typename cv3>
|
|
73
|
-
static bool loadF32(FILE* pfBHdr, FILE* pfBin, cv3* pcv3Data);
|
|
74
|
-
private:
|
|
75
|
-
static bool genRotMat(std::array<v3,3>* pav3RotMat, int iAx, f64 ang);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
template<typename cv3>
|
|
79
|
-
bool v3::saveF64(FILE* pfBHdr, FILE* pfBin, const cv3& cv3Data)
|
|
80
|
-
{
|
|
81
|
-
bool ret = true;
|
|
82
|
-
fprintf(pfBHdr, "float64[%ld][3];\n", (i64)cv3Data.size());
|
|
83
|
-
typename cv3::const_iterator icv3Data = cv3Data.begin();
|
|
84
|
-
while (icv3Data!=cv3Data.end())
|
|
85
|
-
{
|
|
86
|
-
ret &= (fwrite(&icv3Data->x, sizeof(f64), 1, pfBin) == 1);
|
|
87
|
-
ret &= (fwrite(&icv3Data->y, sizeof(f64), 1, pfBin) == 1);
|
|
88
|
-
ret &= (fwrite(&icv3Data->z, sizeof(f64), 1, pfBin) == 1);
|
|
89
|
-
++icv3Data;
|
|
90
|
-
}
|
|
91
|
-
return ret;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
template<typename cv3>
|
|
95
|
-
bool v3::loadF64(FILE* pfBHdr, FILE* pfBin, cv3* pcv3Data)
|
|
96
|
-
{
|
|
97
|
-
bool ret = true;
|
|
98
|
-
i64 lenData = 0;
|
|
99
|
-
int nByte = fscanf(pfBHdr, "float64[%ld][3];\n", &lenData);
|
|
100
|
-
if (nByte!=1) ret = false;
|
|
101
|
-
pcv3Data->resize(lenData);
|
|
102
|
-
typename cv3::iterator icv3Data = pcv3Data->begin();
|
|
103
|
-
while (icv3Data!=pcv3Data->end())
|
|
104
|
-
{
|
|
105
|
-
ret &= (fread(&icv3Data->x, sizeof(f64), 1, pfBin) == 1);
|
|
106
|
-
ret &= (fread(&icv3Data->y, sizeof(f64), 1, pfBin) == 1);
|
|
107
|
-
ret &= (fread(&icv3Data->z, sizeof(f64), 1, pfBin) == 1);
|
|
108
|
-
++icv3Data;
|
|
109
|
-
}
|
|
110
|
-
return ret;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
template<typename cv3>
|
|
114
|
-
bool v3::saveF32(FILE* pfBHdr, FILE* pfBin, const cv3& cv3Data)
|
|
115
|
-
{
|
|
116
|
-
bool ret = true;
|
|
117
|
-
fprintf(pfBHdr, "float32[%ld][3];\n", (i64)cv3Data.size());
|
|
118
|
-
typename cv3::const_iterator icv3Data = cv3Data.begin();
|
|
119
|
-
float f32X, f32Y, f32Z;
|
|
120
|
-
while (icv3Data!=cv3Data.end())
|
|
121
|
-
{
|
|
122
|
-
f32X = (float)icv3Data->x;
|
|
123
|
-
f32Y = (float)icv3Data->y;
|
|
124
|
-
f32Z = (float)icv3Data->z;
|
|
125
|
-
ret &= (fwrite(&f32X, sizeof(float), 1, pfBin) == 1);
|
|
126
|
-
ret &= (fwrite(&f32Y, sizeof(float), 1, pfBin) == 1);
|
|
127
|
-
ret &= (fwrite(&f32Z, sizeof(float), 1, pfBin) == 1);
|
|
128
|
-
++icv3Data;
|
|
129
|
-
}
|
|
130
|
-
return ret;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
template<typename cv3>
|
|
134
|
-
bool v3::loadF32(FILE* pfBHdr, FILE* pfBin, cv3* pcv3Data)
|
|
135
|
-
{
|
|
136
|
-
bool ret = true;
|
|
137
|
-
i64 lenData = 0;
|
|
138
|
-
int nByte = fscanf(pfBHdr, "float32[%ld][3];\n", &lenData);
|
|
139
|
-
if (nByte!=1) ret = false;
|
|
140
|
-
pcv3Data->resize(lenData);
|
|
141
|
-
typename cv3::iterator icv3Data = pcv3Data->begin();
|
|
142
|
-
float f32X, f32Y, f32Z;
|
|
143
|
-
while (icv3Data!=pcv3Data->end())
|
|
144
|
-
{
|
|
145
|
-
ret &= (fread(&f32X, sizeof(float), 1, pfBin) == 1);
|
|
146
|
-
ret &= (fread(&f32Y, sizeof(float), 1, pfBin) == 1);
|
|
147
|
-
ret &= (fread(&f32Z, sizeof(float), 1, pfBin) == 1);
|
|
148
|
-
|
|
149
|
-
icv3Data->x = (f64)f32X;
|
|
150
|
-
icv3Data->y = (f64)f32Y;
|
|
151
|
-
icv3Data->z = (f64)f32Z;
|
|
152
|
-
|
|
153
|
-
++icv3Data;
|
|
154
|
-
}
|
|
155
|
-
return ret;
|
|
156
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|