Skip to content
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

add node summary string methods #698

Merged
merged 4 commits into from Feb 6, 2021
Merged

Conversation

cyrush
Copy link
Member

@cyrush cyrush commented Feb 5, 2021

resolves #674

todo:

  • add python interface and tests
  • change python repr to use to_summary_string

@cyrush cyrush requested a review from xjrc February 5, 2021 20:49
@coveralls
Copy link

coveralls commented Feb 5, 2021

Coverage Status

Coverage decreased (-0.05%) to 86.265% when pulling c3feda9 on task/2021_02_node_summary_string into 6dbbe7b on develop.

Copy link
Member

@xjrc xjrc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few comments, but I didn't find any deal-breakers. I'm looking forward to using this for debugging!

std::string pad = " ";
std::string eoe = "\n";

if(opts.has_child("num_children_threshold") &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we're using num_children and num_elements because they're standard Conduit vernacular, but could we use something a bit shorter than threshold since it isn't as standard? Maybe something short, like max?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used threshold b/c that is what I settled on for the DataArray class (mirrors numpy's param name)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


//-----------------------------------------------------------------------------
std::string
Node::to_summary_string(const conduit::Node &opts)const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea that the other conduit::Node::to_* methods are moving to an options conduit::Node approach? This seems like a break from convention otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to move in that direction, number of options is getting large.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added: #700 to track this

// NOTE(cyrush): In this case to_summary_string() is easily callable
// in debugging tools, but still provide the to_summary_string_default()
// variant to present a similar interface to other `to_` methods.
std::string to_summary_string_default() const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an FYI, I found a way to use even the default-parameter conduit::Node::to_* functions in gdb, so I think we can delete these conduit::Node::to_*_default functions in 0.7.X.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, lets discuss further the path post 0.7.0 release. I'll keep this here for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added #702 to track this

num_children_threshold = (index_t)opts["num_children_threshold"].to_int32();
}

if(opts.has_child("num_elements_threshold") &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might it be useful to include a max/threshold on tree depth as well? I could see it being useful to get a broad idea of the basic building blocks of a schema. Not saying we need to do it for this PR, but something to think about.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i agree, we should do that in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added #701 to track this

bb: [1, 1, ..., 8, 9]
... ( skipped 1 child )
dd: [3, 1, ..., 8, 9]
)ST";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If regex doesn't work out, I think I'm going to use this strategy on my output checks as well.

opts.print();
tres = n.to_summary_string(opts);
std::cout << tres << std::endl;
EXPECT_EQ(tres,n.to_yaml());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't considered this case; good coverage of the possible inputs!

bool done = (nchildren == 0);
int idx = 0;

while(!done)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code in these loops is rather hard for me to follow. I think using the lambdas we're afforded by C++11 could make it much more legible, e.g.:

const auto to_summary = [] (const conduit::Node& n, ...)
{
    // ... //
}

for(index_t idx = 0; idx <= bottom; idx++)
{
    to_summary(node);
}

// ... skipped print logic goes here ... //

for(index_t idx = nchildren - top; idx < nchildren; idx++)
{
    to_summary(node);
}

Just my 2 cents here; I don't mind keeping this as is for the sake of expediency.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added #699 to track this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(i think this is great idea)

@cyrush cyrush merged commit a8f1c56 into develop Feb 6, 2021
@cyrush cyrush deleted the task/2021_02_node_summary_string branch February 6, 2021 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add node to_summary_string
3 participants