-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Soma a single class used by both mutable and immutable #366
Open
eleftherioszisis
wants to merge
13
commits into
master
Choose a base branch
from
zisis/remove-soma-friend
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9d0ac2b
Merge mut/readonly somata.
eleftherioszisis df6815f
Fixes
eleftherioszisis 48b2449
Add soma testing
eleftherioszisis 9f5300f
Remove mut soma files
eleftherioszisis 9bff517
Fix soma bindings
eleftherioszisis 366b1c4
clang
eleftherioszisis a07313d
Remove unused include
eleftherioszisis 4faaae3
Return NaN from empty soma computation methods
eleftherioszisis 7ff0fb8
Add cpp tests for soma
eleftherioszisis a70457c
clang
eleftherioszisis eda4350
Revert to using the soma exceptions
eleftherioszisis 741b5b7
Remove unused function
eleftherioszisis 0be6665
Use double in initializer lists
eleftherioszisis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
|
||
#include <catch2/catch.hpp> | ||
#include <cmath> | ||
|
||
#include <morphio/enums.h> | ||
#include <morphio/soma.h> | ||
|
||
#include <morphio/morphology.h> | ||
#include <morphio/mut/morphology.h> | ||
|
||
|
||
TEST_CASE("soma-default-constructor", "[soma]") { | ||
const morphio::Soma soma; | ||
|
||
REQUIRE(soma.type() == morphio::enums::SomaType::SOMA_UNDEFINED); | ||
REQUIRE(soma.points().empty()); | ||
REQUIRE(soma.diameters().empty()); | ||
|
||
REQUIRE(soma.properties()._points.empty()); | ||
REQUIRE(soma.properties()._diameters.empty()); | ||
REQUIRE(soma.properties()._perimeters.empty()); | ||
|
||
morphio::Point center = soma.center(); | ||
|
||
REQUIRE(std::isnan(center[0])); | ||
REQUIRE(std::isnan(center[1])); | ||
REQUIRE(std::isnan(center[2])); | ||
REQUIRE(std::isnan(soma.surface())); | ||
REQUIRE(std::isnan(soma.volume())); | ||
REQUIRE(std::isnan(soma.maxDistance())); | ||
} | ||
|
||
|
||
TEST_CASE("soma-point-properties-constructor", "[soma]") { | ||
auto properties = morphio::Property::PointLevel(); | ||
|
||
properties._points = {{0., 1., 2.}, {3., 4., 5.}}; | ||
properties._diameters = {0.2, 0.3}; | ||
|
||
morphio::Soma soma(properties); | ||
|
||
REQUIRE(soma.points() == properties._points); | ||
REQUIRE(soma.diameters() == properties._diameters); | ||
REQUIRE(soma.type() == morphio::enums::SomaType::SOMA_UNDEFINED); | ||
|
||
REQUIRE(soma.center() == morphio::Point({1.5, 2.5, 3.5})); | ||
REQUIRE_THAT(soma.maxDistance(), Catch::WithinAbs(2.598076, 1e-6)); | ||
} | ||
|
||
|
||
TEST_CASE("soma-properties-constructor", "[soma]") { | ||
auto properties = morphio::Property::Properties(); | ||
|
||
std::vector<morphio::Point> expected_points = {{0., 1., 2.}, {3., 4., 5.}, {6., 7., 8.}}; | ||
std::vector<morphio::floatType> expected_diameters = {0.2, 0.3, 0.4}; | ||
morphio::enums::SomaType expected_soma_type = morphio::enums::SomaType::SOMA_SIMPLE_CONTOUR; | ||
|
||
properties._somaLevel._points = expected_points; | ||
properties._somaLevel._diameters = expected_diameters; | ||
properties._cellLevel._somaType = expected_soma_type; | ||
|
||
morphio::Soma soma(properties); | ||
|
||
REQUIRE(soma.points() == expected_points); | ||
REQUIRE(soma.diameters() == expected_diameters); | ||
REQUIRE(soma.type() == expected_soma_type); | ||
} | ||
|
||
|
||
TEST_CASE("soma-copy-constructor", "[soma]") { | ||
auto properties = morphio::Property::PointLevel(); | ||
|
||
properties._points = {{0., 1., 2.}, {3., 4., 5.}}; | ||
properties._diameters = {0.2, 0.3}; | ||
|
||
// allocate a soma in the heap to delete it afterwards | ||
// and check if the copy maintains its data | ||
morphio::Soma* soma = new morphio::Soma(properties); | ||
morphio::Soma soma_copy(*soma); | ||
|
||
auto expected_points = soma->points(); | ||
auto expected_diameters = soma->diameters(); | ||
auto expected_type = soma->type(); | ||
|
||
REQUIRE(expected_points == soma_copy.points()); | ||
REQUIRE(expected_diameters == soma_copy.diameters()); | ||
REQUIRE(expected_type == soma_copy.type()); | ||
|
||
delete soma; | ||
|
||
REQUIRE(expected_points == soma_copy.points()); | ||
REQUIRE(expected_diameters == soma_copy.diameters()); | ||
REQUIRE(expected_type == soma_copy.type()); | ||
} | ||
|
||
|
||
TEST_CASE("soma-immutable-morphology-constructor", "[soma]") { | ||
const auto soma = morphio::Morphology("data/h5/v1/Neuron.h5").soma(); | ||
|
||
REQUIRE(soma.type() == morphio::SomaType::SOMA_SIMPLE_CONTOUR); | ||
|
||
std::vector<morphio::Point> expected_soma_points = {{0.0f, 0.0f, 0.0f}, | ||
{0.0f, 0.2f, 0.0f}, | ||
{0.1f, 0.1f, 0.0f}}; | ||
REQUIRE(soma.points() == expected_soma_points); | ||
|
||
std::vector<morphio::floatType> expected_soma_diameters = {0.2f, 0.2f, 0.2f}; | ||
REQUIRE(soma.diameters() == expected_soma_diameters); | ||
} | ||
|
||
|
||
TEST_CASE("soma-mutable-morphology-constructor", "[soma]") { | ||
auto morph = morphio::mut::Morphology("data/h5/v1/Neuron.h5"); | ||
|
||
const auto soma = *morph.soma(); | ||
|
||
REQUIRE(soma.type() == morphio::SomaType::SOMA_SIMPLE_CONTOUR); | ||
|
||
std::vector<morphio::Point> expected_soma_points = {{0.0f, 0.0f, 0.0f}, | ||
{0.0f, 0.2f, 0.0f}, | ||
{0.1f, 0.1f, 0.0f}}; | ||
REQUIRE(soma.points() == expected_soma_points); | ||
|
||
std::vector<morphio::floatType> expected_soma_diameters = {0.2f, 0.2f, 0.2f}; | ||
REQUIRE(soma.diameters() == expected_soma_diameters); | ||
} | ||
|
||
|
||
TEST_CASE("soma-mutable-morphology-mutation", "[soma]") { | ||
auto morph = morphio::mut::Morphology("data/h5/v1/Neuron.h5"); | ||
|
||
std::vector<morphio::Point> expected_soma_points = {{0.1f, 0.1f, 0.0f}}; | ||
morph.soma()->points() = expected_soma_points; | ||
REQUIRE(morph.soma()->points() == expected_soma_points); | ||
|
||
std::vector<morphio::floatType> expected_soma_diameters = {3.0f}; | ||
morph.soma()->diameters() = expected_soma_diameters; | ||
REQUIRE(morph.soma()->diameters() == expected_soma_diameters); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do people check for NaN? If I use Python, I would just expect this to return
None
, and by now, in compiled languages, expectstd::optional
(or language equivalent)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I removed them after thinking twice and also realizing that the volume/surface functions already raise exceptions.