Skip to content

Commit

Permalink
initial support of negative source and negative-patterns
Browse files Browse the repository at this point in the history
some test still fails, but feature is mostly working, need more work
  • Loading branch information
fangq committed Aug 3, 2023
1 parent 0619332 commit 198cd34
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 76 deletions.
2 changes: 1 addition & 1 deletion pymcx
118 changes: 58 additions & 60 deletions src/mcx_core.cu

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/mcx_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ void mcx_initcfg(Config* cfg) {
cfg->detectedcount = 0;
cfg->runtime = 0;
cfg->faststep = 0;
cfg->srcpos.w = 1.f;
cfg->srcdir.w = 0.f;
cfg->issaveref = 0;
cfg->isspecular = 0;
Expand Down Expand Up @@ -2480,6 +2481,8 @@ int mcx_loadjson(cJSON* root, Config* cfg) {
cfg->srcpos.z = subitem->child->next->next->valuedouble;
}

cfg->srcpos.w = FIND_JSON_KEY("Weight", "Optode.Source.Weight", src, 1.f, valuedouble);

subitem = FIND_JSON_OBJ("Dir", "Optode.Source.Dir", src);

if (subitem) {
Expand Down
28 changes: 21 additions & 7 deletions src/mcxlab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,15 +392,29 @@ void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
fieldlen = fielddim[0] * fielddim[1] * fielddim[2] * fielddim[3] * fielddim[4] * fielddim[5];

if (cfg.issaveref) {
int highdim = fielddim[3] * fielddim[4] * fielddim[5];
int voxellen = cfg.dim.x * cfg.dim.y * cfg.dim.z;
float* dref = (float*)malloc(fieldlen * sizeof(float));
memcpy(dref, cfg.exportfield, fieldlen * sizeof(float));

for (int i = 0; i < fieldlen; i++) {
if (dref[i] < 0.f) {
dref[i] = -dref[i];
cfg.exportfield[i] = 0.f;
} else {
dref[i] = 0.f;
for (int ix = 0; ix < cfg.dim.x; ix++) {
for (int iy = 0; iy < cfg.dim.y; iy++) {
for (int iz = 0; iz < cfg.dim.z; iz++) {
int voxelid = iz * (cfg.dim.x * cfg.dim.y) + iy * cfg.dim.x + ix;

if (cfg.vol[voxelid]) {
for (int gate = 0; gate < highdim; gate++)
for (int srcid = 0; srcid < cfg.srcnum; srcid++) {
dref[(gate * voxellen + voxelid) * cfg.srcnum + srcid] = 0.f;
}
} else {
for (int gate = 0; gate < highdim; gate++)
for (int srcid = 0; srcid < cfg.srcnum; srcid++) {
dref[(gate * voxellen + voxelid) * cfg.srcnum + srcid] = -dref[(gate * voxellen + voxelid) * cfg.srcnum + srcid];
cfg.exportfield[(gate * voxellen + voxelid) * cfg.srcnum + srcid] = 0.f;
}
}
}
}
}

Expand Down Expand Up @@ -551,7 +565,7 @@ void mcx_set_field(const mxArray* root, const mxArray* item, int idx, Config* cf
GET_ONE_FIELD(cfg, omega)
GET_ONE_FIELD(cfg, issave2pt)
GET_ONE_FIELD(cfg, lambda)
GET_VEC3_FIELD(cfg, srcpos)
GET_VEC34_FIELD(cfg, srcpos)
GET_VEC34_FIELD(cfg, srcdir)
GET_VEC3_FIELD(cfg, steps)
GET_VEC3_FIELD(cfg, crop0)
Expand Down
28 changes: 21 additions & 7 deletions src/pmcx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ void parse_config(const py::dict& user_cfg, Config& mcx_config) {
GET_SCALAR_FIELD(user_cfg, mcx_config, srcnum, py::int_);
GET_SCALAR_FIELD(user_cfg, mcx_config, omega, py::float_);
GET_SCALAR_FIELD(user_cfg, mcx_config, lambda, py::float_);
GET_VEC3_FIELD(user_cfg, mcx_config, srcpos, float);
GET_VEC34_FIELD(user_cfg, mcx_config, srcpos, float);
GET_VEC34_FIELD(user_cfg, mcx_config, srcdir, float);
GET_VEC3_FIELD(user_cfg, mcx_config, steps, float);
GET_VEC3_FIELD(user_cfg, mcx_config, crop0, uint);
Expand Down Expand Up @@ -1037,15 +1037,29 @@ py::dict pmcx_interface(const py::dict& user_cfg) {
auto dref_array = py::array_t<float, py::array::f_style>(array_dims);

if (mcx_config.issaveref) {
int highdim = fielddim[3] * fielddim[4] * fielddim[5];
int voxellen = cfg.dim.x * cfg.dim.y * cfg.dim.z;
auto* dref = static_cast<float*>(dref_array.mutable_data());
memcpy(dref, mcx_config.exportfield, field_len * sizeof(float));

for (int i = 0; i < field_len; i++) {
if (dref[i] < 0.f) {
dref[i] = -dref[i];
mcx_config.exportfield[i] = 0.f;
} else {
dref[i] = 0.f;
for (int ix = 0; ix < mcx_config.dim.x; ix++) {
for (int iy = 0; iy < mcx_config.dim.y; iy++) {
for (int iz = 0; iz < mcx_config.dim.z; iz++) {
int voxelid = iz * (mcx_config.dim.x * mcx_config.dim.y) + iy * mcx_config.dim.x + ix;

if (mcx_config.vol[voxelid]) {
for (int gate = 0; gate < highdim; gate++)
for (int srcid = 0; srcid < mcx_config.srcnum; srcid++) {
dref[(gate * voxellen + voxelid) * mcx_config.srcnum + srcid] = 0.f;
}
} else {
for (int gate = 0; gate < highdim; gate++)
for (int srcid = 0; srcid < mcx_config.srcnum; srcid++) {
dref[(gate * voxellen + voxelid) * mcx_config.srcnum + srcid] = -dref[(gate * voxellen + voxelid) * mcx_config.srcnum + srcid];
mcx_config.exportfield[(gate * voxellen + voxelid) * mcx_config.srcnum + srcid] = 0.f;
}
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/pybind11
Submodule pybind11 updated 79 files
+65 −61 .clang-tidy
+5 −3 .github/CONTRIBUTING.md
+0 −4 .github/dependabot.yml
+40 −23 .github/workflows/ci.yml
+1 −1 .github/workflows/configure.yml
+6 −4 .github/workflows/format.yml
+7 −5 .github/workflows/pip.yml
+3 −3 .github/workflows/upstream.yml
+14 −11 .pre-commit-config.yaml
+13 −0 CMakeLists.txt
+3 −0 docs/_static/css/custom.css
+0 −11 docs/_static/theme_overrides.css
+2 −2 docs/advanced/cast/custom.rst
+3 −3 docs/advanced/cast/stl.rst
+2 −2 docs/advanced/classes.rst
+2 −2 docs/advanced/pycpp/numpy.rst
+1 −1 docs/advanced/smart_ptrs.rst
+160 −12 docs/changelog.rst
+1 −1 docs/classes.rst
+6 −17 docs/conf.py
+ docs/pybind11-logo.png
+4 −3 docs/requirements.txt
+5 −3 include/pybind11/attr.h
+5 −5 include/pybind11/cast.h
+23 −30 include/pybind11/detail/class.h
+21 −2 include/pybind11/detail/common.h
+1 −1 include/pybind11/detail/init.h
+1 −0 include/pybind11/detail/internals.h
+0 −66 include/pybind11/detail/type_caster_base.h
+9 −3 include/pybind11/detail/typeid.h
+17 −6 include/pybind11/eigen.h
+56 −32 include/pybind11/embed.h
+2 −2 include/pybind11/functional.h
+1 −1 include/pybind11/iostream.h
+19 −8 include/pybind11/numpy.h
+44 −26 include/pybind11/pybind11.h
+338 −64 include/pybind11/pytypes.h
+6 −6 include/pybind11/stl.h
+16 −6 noxfile.py
+2 −1 pybind11/__init__.py
+8 −1 pybind11/__main__.py
+1 −1 pybind11/_version.py
+12 −0 pybind11/commands.py
+2 −1 setup.cfg
+1 −0 setup.py
+1 −0 tests/CMakeLists.txt
+14 −1 tests/conftest.py
+51 −0 tests/cross_module_interleaved_error_already_set.cpp
+68 −58 tests/extra_python_package/test_files.py
+25 −0 tests/pybind11_tests.cpp
+1 −1 tests/requirements.txt
+8 −2 tests/test_builtin_casters.cpp
+2 −2 tests/test_constants_and_functions.cpp
+7 −7 tests/test_custom_type_casters.cpp
+5 −2 tests/test_eigen.cpp
+7 −0 tests/test_eigen.py
+1 −1 tests/test_embed/CMakeLists.txt
+47 −2 tests/test_exceptions.cpp
+99 −3 tests/test_exceptions.py
+10 −1 tests/test_kwargs_and_defaults.cpp
+21 −9 tests/test_methods_and_attributes.py
+2 −0 tests/test_modules.cpp
+30 −0 tests/test_modules.py
+1 −1 tests/test_numpy_array.cpp
+1 −1 tests/test_numpy_dtypes.cpp
+1 −1 tests/test_numpy_vectorize.cpp
+183 −0 tests/test_pytypes.cpp
+129 −0 tests/test_pytypes.py
+2 −2 tests/test_smart_ptr.cpp
+15 −8 tests/test_stl.cpp
+2 −2 tests/test_tagbased_polymorphic.cpp
+2 −3 tests/test_virtual_functions.cpp
+21 −11 tools/FindPythonLibsNew.cmake
+23 −0 tools/JoinPaths.cmake
+7 −0 tools/pybind11.pc.in
+3 −1 tools/pybind11NewTools.cmake
+32 −11 tools/pybind11Tools.cmake
+2 −0 tools/setup_global.py.in
+2 −0 tools/setup_main.py.in

0 comments on commit 198cd34

Please sign in to comment.