问:
Neo4j - apoc.algo.dijkstra - shortest path from a to b, but via c, d, e etc
Hi I am experimenting with routing using neo4j but I am struggling with adapting apoc.algo.dijkstra. I don’t just want to go from A to B, but actually go from A to B via C, whilst taking into account a weighting on the link.

The A-B query is...

```<code>MATCH  (startNode:road_node {id:'59030214550942348742a27d'}), (endNode:road_node {id:'59030215550942348742a610'})
call apoc.algo.dijkstra(startNode, endNode, 'ROADLINK', 'min_travel_time') YIELD path, weight
return path, weight/60
</code>```

I tried a few ways of including a via c but can't get it to work... for example

```<code>MATCH  (startNode:road_node {id:'59030214550942348742a27d'}), (endNode:road_node {id:'59030215550942348742a610'})
call apoc.algo.dijkstra(startNode, endNode, 'ROADLINK', 'min_travel_time')
with path, weight
MATCH (startNode)-[*]-(via:road_node {id:'59030215550942348742a666'})-[*]-(endNode)
return path, weight
</code>```

Any ideas or suggestions on how to route from A to B via C, whilst taking into a count a weighting on the links, would be very helpful.

答:
You can just invoke the Dijkstra algorithm twice, using via as the end node in the first invocation, and then as the start node in the second. The result will have 2 sub-paths and 2 sub-weights (divided by 60).

```<code>MATCH (start:road_node {id:'59030214550942348742a27d'}), (end:road_node {id:'59030215550942348742a610'}), (via:road_node {id:'59030215550942348742a666'})
CALL apoc.algo.dijkstra(start, via, 'ROADLINK', 'min_travel_time') YIELD path, weight
WITH end, via, path AS p1, weight/60 AS w1
CALL apoc.algo.dijkstra(via, end, 'ROADLINK', 'min_travel_time') YIELD path, weight
return p1, path AS p2, w1, weight/60 AS w2;
</code>```

Body:
Hi I am experimenting with routing using neo4j but I am struggling with adapting apoc.algo.dijkstra. I don’t just want to go from A to B, but actually go from A to B via C, whilst taking into account a weighting on the link.

The A-B query is...

MATCH  (startNode:road_node {id:'59030214550942348742a27d'}), (endNode:road_node {id:'59030215550942348742a610'})
call apoc.algo.dijkstra(startNode, endNode, 'ROADLINK', 'min_travel_time') YIELD path, weight
return path, weight/60

I tried a few ways of including a via c but can't get it to work... for example

MATCH  (startNode:road_node {id:'59030214550942348742a27d'}), (endNode:road_node {id:'59030215550942348742a610'})
call apoc.algo.dijkstra(startNode, endNode, 'ROADLINK', 'min_travel_time')
with path, weight
MATCH (startNode)-[*]-(via:road_node {id:'59030215550942348742a666'})-[*]-(endNode)
return path, weight

Any ideas or suggestions on how to route from A to B via C, whilst taking into a count a weighting on the links, would be very helpful.

Body:
You can just invoke the Dijkstra algorithm twice, using via as the end node in the first invocation, and then as the start node in the second. The result will have 2 sub-paths and 2 sub-weights (divided by 60).

MATCH (start:road_node {id:'59030214550942348742a27d'}), (end:road_node {id:'59030215550942348742a610'}), (via:road_node {id:'59030215550942348742a666'})
CALL apoc.algo.dijkstra(start, via, 'ROADLINK', 'min_travel_time') YIELD path, weight
WITH end, via, path AS p1, weight/60 AS w1
CALL apoc.algo.dijkstra(via, end, 'ROADLINK', 'min_travel_time') YIELD path, weight
return p1, path AS p2, w1, weight/60 AS w2;


来源: stackexchange

问:
cohort analysis in R
I have a dataset test of user ids and the quarter in which user ids made a transaction:

```<code>> test
   id quarter
1   7      Q1
2   7      Q1
3   5      Q1
4   8      Q1
5   3      Q1
6   6      Q1
7  10      Q1
8   3      Q2
9  10      Q2
10  8      Q2
11  2      Q2
12  7      Q2
13  6      Q2
14  6      Q3
15  9      Q3
16  6      Q3
17  4      Q3
18  9      Q3
19  2      Q3
20  5      Q4
21  8      Q4
22 10      Q4
23  7      Q4
24  1      Q4
25  8      Q4
</code>```

My objective is to find the number of unique users that were active in Quarter 1 and, of those users, get the number of users that made transactions in subsequent quarters.

The output from the above sample should be:

```<code>> output
  quarter unique_cohort_ids
1      Q1                 6
2      Q2                 5
3      Q3                 1
4      Q4                 4
</code>```

The following code works, but it is verbose and repetitive, and is not ideal for a larger dataset with dozens of quarters.  Any suggestions on how to improve it would be appreciated:

```<code>subsets <-split(test, test$quarter, drop=TRUE)

for (i in 1:length(subsets)) {
  assign(paste0("Q", i), as.data.frame(subsets[[i]]))
}

Q1_ids <- sum(uniqueQ1$id)
Q2_ids <- sum(unique(Q1$id) %in% unique(Q2$id))
Q3_ids <- sum(unique(Q1$id) %in% unique(Q3$id))
Q4_ids <- sum(unique(Q1$id) %in% unique(Q4$id))
</code>```

Cohort analysis also includes counting the number of new users
per quarter.  As opposed to manually counting the unique user ids that appear per quarter that had not appeared in any previous quarters, I am seeking a programmatic solution.  In this case, the output would be the following list:

```<code>> mylist
[[1]]
[1]  7  5  8  3  6 10

[[2]]
[1] 2

[[3]]
[1] 9 4

[[4]]
[1] 1
</code>```

Any suggestions would be appreciated

Here is the sample data:

```<code>> dput(test)
structure(list(id = c(7, 7, 5, 8, 3, 6, 10, 3, 10, 8, 2, 7, 6,
6, 9, 6, 4, 9, 2, 5, 8, 10, 7, 1, 8), quarter = c("Q1", "Q1",
"Q1", "Q1", "Q1", "Q1", "Q1", "Q2", "Q2", "Q2", "Q2", "Q2", "Q2",
"Q3", "Q3", "Q3", "Q3", "Q3", "Q3", "Q4", "Q4", "Q4", "Q4", "Q4",
"Q4")), .Names = c("id", "quarter"), row.names = c(NA, -25L), class = "data.frame")
</code>```

答:
How about this approach?</p>

```<code>library(tidyverse)
test %>%
distinct() %>%
mutate(value = T) %>%
spread(quarter, value) %>%
filter(!is.na(Q1)) %>%
select(-id) %>%
colSums(na.rm = T)
# Q1 Q2 Q3 Q4
# 6  5  1  4
</code>```

ContentLicense: CC BY-SA 3.0

Title: cohort analysis in R

Body:
I have a dataset test of user ids and the quarter in which user ids made a transaction:

> test
   id quarter
1   7      Q1
2   7      Q1
3   5      Q1
4   8      Q1
5   3      Q1
6   6      Q1
7  10      Q1
8   3      Q2
9  10      Q2
10  8      Q2
11  2      Q2
12  7      Q2
13  6      Q2
14  6      Q3
15  9      Q3
16  6      Q3
17  4      Q3
18  9      Q3
19  2      Q3
20  5      Q4
21  8      Q4
22 10      Q4
23  7      Q4
24  1      Q4
25  8      Q4

My objective is to find the number of unique users that were active in Quarter 1 and, of those users, get the number of users that made transactions in subsequent quarters.

The output from the above sample should be:

> output
  quarter unique_cohort_ids
1      Q1                 6
2      Q2                 5
3      Q3                 1
4      Q4                 4

The following code works, but it is verbose and repetitive, and is not ideal for a larger dataset with dozens of quarters.  Any suggestions on how to improve it would be appreciated:

subsets <-split(test, test$quarter, drop=TRUE)

for (i in 1:length(subsets)) {
  assign(paste0("Q", i), as.data.frame(subsets[[i]]))
}

Q1_ids <- sum(uniqueQ1$id)
Q2_ids <- sum(unique(Q1$id) %in% unique(Q2$id))
Q3_ids <- sum(unique(Q1$id) %in% unique(Q3$id))
Q4_ids <- sum(unique(Q1$id) %in% unique(Q4$id))

Cohort analysis also includes counting the number of new users
per quarter.  As opposed to manually counting the unique user ids that appear per quarter that had not appeared in any previous quarters, I am seeking a programmatic solution.  In this case, the output would be the following list:

> mylist
[[1]]
[1]  7  5  8  3  6 10

[[2]]
[1] 2

[[3]]
[1] 9 4

[[4]]
[1] 1

Any suggestions would be appreciated

Here is the sample data:

> dput(test)
structure(list(id = c(7, 7, 5, 8, 3, 6, 10, 3, 10, 8, 2, 7, 6,
6, 9, 6, 4, 9, 2, 5, 8, 10, 7, 1, 8), quarter = c("Q1", "Q1",
"Q1", "Q1", "Q1", "Q1", "Q1", "Q2", "Q2", "Q2", "Q2", "Q2", "Q2",
"Q3", "Q3", "Q3", "Q3", "Q3", "Q3", "Q4", "Q4", "Q4", "Q4", "Q4",
"Q4")), .Names = c("id", "quarter"), row.names = c(NA, -25L), class = "data.frame")

Body:
How about this approach?

library(tidyverse)
test %>%
distinct() %>%
mutate(value = T) %>%
spread(quarter, value) %>%
filter(!is.na(Q1)) %>%
select(-id) %>%
colSums(na.rm = T)
# Q1 Q2 Q3 Q4
# 6  5  1  4


问:
Convert protoc generated java files to .proto
I have a .java file created by protoc from a .proto file.

The .proto file no longer exists, is there an existing tool to recreate it from the generated .java file?

答:
In the bottom of the file, you should see a field called descriptorData which includes the original descriptor of the proto.   You cannot directly turn this back into a proto file, but it does contain all the information about how to parse the proto.

If you were so inclined, the format of this data is itself a proto, representing a descriptor.proto.   You can parse this data yourself and reconstruct it, though I don't think there are any tools to do so automatically.


问:
Div floating left in another div onclick to fill screen
I have looked for a solution to this for ages, but have not been able to find an answer. I have some divs inside another div which all float left. I want it so when one is clicked it expands to fill the entire screen and then when a close button that appears in the top right is clicked it goes back to normal, without pushing any of the other divs around. I HAVE been able to achieve this but when i click the div again after the close button is pressed it wont re-expand. Help!

/* We need to create dynamic keyframes to show the animation from full-screen to normal. So we create a stylesheet in which we can insert CSS keyframe rules */

/* Click on the container */
$("#box1").on('click', function() {
  $("body").append('');
 /* The position of the container will be set to fixed, so set the top & left properties of the container */
 var bounding_box = $("#box1").get(0).getBoundingClientRect();
 $(this).css({ top: bounding_box.top + 'px', left: bounding_box.left + 'px' });
  $('#twitter').hide();
   $('#googlebadge').hide();

 /* Set container to fixed position. Add animation */
 $(this).addClass('in-animation');

 /* An empty container has to be added in place of the lightbox container so that the elements below don't come up
 Dimensions of this empty container is the same as the original container */
 $('

').insertAfter("#box1");

 /* To animate the container from full-screen to normal, we need dynamic keyframes */
 var styles = '';
 styles = '@keyframes outlightbox {';
  styles += '0% {';
  styles += 'height: 100%;';
  styles += 'width: 100%;';
  styles += 'top: 0px;';
  styles += 'left: 0px;';
  styles += '}';
  styles += '50% {';
  styles += 'height: 200px;';
  styles += 'top: ' + bounding_box.y + 'px;';
  styles += '}';
  styles += '100% {';
  styles += 'height: 200px;';
  styles += 'width: 500px;';
  styles += 'top: ' + bounding_box.y + 'px;';
  styles += 'left: ' + bounding_box.x + 'px;';
  styles += '}';
 styles += '}';

 /* Add keyframe to CSS */
 $("#lightbox-animations").get(0).sheet.insertRule(styles, 0);

 /* Hide the window scrollbar */
 $("body").css('overflow', 'hidden');
});

/* Click on close button when full-screen */
$("#close").on('click', function(e) {
 $("#close").hide();
    $('#twitter').show();
   $('#googlebadge').show();
     $('#empty-container').remove();

 /* Window scrollbar normal */
 $("body").css('overflow', 'auto');

 /* Show animation */
$("#box1").replaceWith(divClone.clone());
  $("#box2").replaceWith(divClone1.clone());
  $("#box3").replaceWith(divClone2.clone());
  $("#box4").replaceWith(divClone3.clone());

 e.stopPropagation();
});

/* On animationend : from normal to full screen & full screen to normal */
$("#box1").on('animationend', function(e) {
 /* On animation end from normal to full-screen */
 if(e.originalEvent.animationName == 'inlightbox') {
  $("#close").show();
 }
 /* On animation end from full-screen to normal */
 else if(e.originalEvent.animationName == 'outlightbox') {
  /* Remove fixed positioning, remove animation rules */
  $("#box1").removeClass('in-animation').removeClass('out-animation');

  /* Remove the empty container that was earlier added */
  $("#empty-container").remove();

  /* Delete the dynamic keyframe rule that was earlier created */
  $("#lightbox-animations").get(0).sheet.deleteRule(0);
 }
});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>#wrapper {
  position: absolute;
  top: 15%;
  left: 25%;
  width: 50%;
  height: 100%;
  z-index: 888;
}

.box {
  position: relative;
  background: #5C97FF;
  overflow: hidden;
  float: left;
  border: 0.1px solid white;
  box-shadow: 0px 0px 10px 1px white;
  margin: 2%;
  z-index: 777;
  opacity: 1;
}

.box:first-child {
  margin-left: 0;
}

.box:before {
  content: ' ';
  display: block;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 777;
  opacity: 0.6;
  background-image: url('http://wiki.dpconline.org/images/f/f3/Template_clipboard.png');
  background-repeat: no-repeat;
  background-position: 50% 50%;
  -ms-background-size: cover;
  -o-background-size: cover;
  -moz-background-size: cover;
  -webkit-background-size: cover;
  background-size: cover;
}

.box h2 {
  padding: 25px;
  text-align: center;
  z-index: 2;
  position: relative;
  color: #fff;
  top: 0;
  left: 0;
}

article {
  background: #fff;
  padding: 15px;
  top: 0;
  left: 0;
}</code>```

I am Template minus One!

This is a template, works pretty well, right?

              <button id="close">Close</button>

I am Template 0!

This is a template, works pretty well, right?

I am Template One!

This is a template, works pretty well, right?

I am Template Two!

This is a template, works pretty well, right?

```

EDIT:

It appears my javascript does not work in snippets. here is the link to my project : https://codepen.io/TechTime/pen/ZKdxQK

答:
If you want a single div per row, you can use a display: block property to each such divs or display: inline-block if you want them one after another.

When one div is clicked, you can hide the other divs, and give the current div a 100% height and width. And when clicking the close button, restore the original states of the divs. Since, you will be use this feature, it will be probably be better to achieve it using adding and removing a class, rather than hardcoding the css into js.

Body:
I have looked for a solution to this for ages, but have not been able to find an answer. I have some divs inside another div which all float left. I want it so when one is clicked it expands to fill the entire screen and then when a close button that appears in the top right is clicked it goes back to normal, without pushing any of the other divs around. I HAVE been able to achieve this but when i click the div again after the close button is pressed it wont re-expand. Help!

/* We need to create dynamic keyframes to show the animation from full-screen to normal. So we create a stylesheet in which we can insert CSS keyframe rules */

/* Click on the container */
$("#box1").on('click', function() {
  $("body").append('');
 /* The position of the container will be set to fixed, so set the top & left properties of the container */
 var bounding_box = $("#box1").get(0).getBoundingClientRect();
 $(this).css({ top: bounding_box.top + 'px', left: bounding_box.left + 'px' });
  $('#twitter').hide();
   $('#googlebadge').hide();

 /* Set container to fixed position. Add animation */
 $(this).addClass('in-animation');

 /* An empty container has to be added in place of the lightbox container so that the elements below don't come up
 Dimensions of this empty container is the same as the original container */
 $('

').insertAfter("#box1");

 /* To animate the container from full-screen to normal, we need dynamic keyframes */
 var styles = '';
 styles = '@keyframes outlightbox {';
  styles += '0% {';
  styles += 'height: 100%;';
  styles += 'width: 100%;';
  styles += 'top: 0px;';
  styles += 'left: 0px;';
  styles += '}';
  styles += '50% {';
  styles += 'height: 200px;';
  styles += 'top: ' + bounding_box.y + 'px;';
  styles += '}';
  styles += '100% {';
  styles += 'height: 200px;';
  styles += 'width: 500px;';
  styles += 'top: ' + bounding_box.y + 'px;';
  styles += 'left: ' + bounding_box.x + 'px;';
  styles += '}';
 styles += '}';

 /* Add keyframe to CSS */
 $("#lightbox-animations").get(0).sheet.insertRule(styles, 0);

 /* Hide the window scrollbar */
 $("body").css('overflow', 'hidden');
});

/* Click on close button when full-screen */
$("#close").on('click', function(e) {
 $("#close").hide();
    $('#twitter').show();
   $('#googlebadge').show();
     $('#empty-container').remove();

 /* Window scrollbar normal */
 $("body").css('overflow', 'auto');

 /* Show animation */
$("#box1").replaceWith(divClone.clone());
  $("#box2").replaceWith(divClone1.clone());
  $("#box3").replaceWith(divClone2.clone());
  $("#box4").replaceWith(divClone3.clone());

 e.stopPropagation();
});

/* On animationend : from normal to full screen & full screen to normal */
$("#box1").on('animationend', function(e) {
 /* On animation end from normal to full-screen */
 if(e.originalEvent.animationName == 'inlightbox') {
  $("#close").show();
 }
 /* On animation end from full-screen to normal */
 else if(e.originalEvent.animationName == 'outlightbox') {
  /* Remove fixed positioning, remove animation rules */
  $("#box1").removeClass('in-animation').removeClass('out-animation');

  /* Remove the empty container that was earlier added */
  $("#empty-container").remove();

  /* Delete the dynamic keyframe rule that was earlier created */
  $("#lightbox-animations").get(0).sheet.deleteRule(0);
 }
});

#wrapper {
  position: absolute;
  top: 15%;
  left: 25%;
  width: 50%;
  height: 100%;
  z-index: 888;
}

.box {
  position: relative;
  background: #5C97FF;
  overflow: hidden;
  float: left;
  border: 0.1px solid white;
  box-shadow: 0px 0px 10px 1px white;
  margin: 2%;
  z-index: 777;
  opacity: 1;
}

.box:first-child {
  margin-left: 0;
}

.box:before {
  content: ' ';
  display: block;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 777;
  opacity: 0.6;
  background-image: url('http://wiki.dpconline.org/images/f/f3/Template_clipboard.png');
  background-repeat: no-repeat;
  background-position: 50% 50%;
  -ms-background-size: cover;
  -o-background-size: cover;
  -moz-background-size: cover;
  -webkit-background-size: cover;
  background-size: cover;
}

.box h2 {
  padding: 25px;
  text-align: center;
  z-index: 2;
  position: relative;
  color: #fff;
  top: 0;
  left: 0;
}

article {
  background: #fff;
  padding: 15px;
  top: 0;
  left: 0;
}

I am Template minus One!

This is a template, works pretty well, right?

              <button id="close">Close</button>

I am Template 0!

This is a template, works pretty well, right?

I am Template One!

This is a template, works pretty well, right?

I am Template Two!

This is a template, works pretty well, right?

EDIT:

It appears my javascript does not work in snippets. here is the link to my project : https://codepen.io/TechTime/pen/ZKdxQK


问:
Designing models with multiple (optional?) inheritance in Entity Framework
I am struggling for the last couple of days on an idea of how to model these entities in EF. So I decided to ask the community to lend a hand. :-) The core classes are given below.

```<code>class BaseEntity
{
   long Id;
   DateTime DateCreated;
}

class Person : BaseEntity
{
   string Name;
   string Address;
}

class Taxpayer : Person
{
    string TaxpayerIdentificationNumber;
    double Income;
    Taxpayer(or Person) Spouse;
}

class Client : BaseEntity
{
    string CustomerId;
    string ContactNumber;
}

class Partnership : Client
{
    List<Taxpayer (or Person)> Partners;
}

class Company : Client
{
    string CompanyRegistrationNumber;
}
</code>```

The scenario is, a Client can be one of the 3 types i.e. Taxpayer, Partnership, Company (Specialization/IsA).

The problem is, in the case of the Taxpayer class he should inherit both the properties of Client and Person classes. (UPDATE: A taxpayer can be a client but not necessarily) Also in the other places Taxpayer class is used, most of the time it can be either a Person class or Taxpayer class.

Any ideas on how to proceed?

Thanks.

答:
thinking out loud:

People are a lot of things, but always people. A person does not morph into a new species with different DNA just because (s)he is unemployed, in a business partnership, or plays professional tiddily-winks.

This leads me to thinking about composition not inheritance. A client might have a person reference to tell who (s)he is. Likewise for a taxpayer or partner.

Partnerships is an engagement in particular behavior. For the purpose of a partnership class I don't care who you are, only that you can function in a partnership. So now I'm thinking how there is explicit, specific functionality with a focus on taxpaying, partnering.

This gets me thinking about 2 design patterns, visitor and decorator. Decorator adds functionality to an existing class dynamically; essentially extends a class via composition, not inheritance. A visitor performs its functionality against a given object (or set of said objects). Visitor can solve the "double dispatch" problem - i.e the lack multiple inheritance.

I get two things from design patterns. First is inspiration. How to think about what my problem is. The inspiration and perspective has proven far more helpful than patterns as mere recipes. Second is specific Object Oriented design. That is design, revise, and extend without resorting to amateurish code hack-n-slash. But don't take that design too literally. These are patterns, not inflexible dictats. Features of your particular programming language can work within these patterns. I'm thinking of how i've used delegates in C# in lieu of "command" subclasses as called for in the command pattern.

Body:
I am struggling for the last couple of days on an idea of how to model these entities in EF. So I decided to ask the community to lend a hand. :-) The core classes are given below.

class BaseEntity
{
   long Id;
   DateTime DateCreated;
}

class Person : BaseEntity
{
   string Name;
   string Address;
}

class Taxpayer : Person
{
    string TaxpayerIdentificationNumber;
    double Income;
    Taxpayer(or Person) Spouse;
}

class Client : BaseEntity
{
    string CustomerId;
    string ContactNumber;
}

class Partnership : Client
{
    List<Taxpayer (or Person)> Partners;
}

class Company : Client
{
    string CompanyRegistrationNumber;
}

The scenario is, a Client can be one of the 3 types i.e. Taxpayer, Partnership, Company (Specialization/IsA).

The problem is, in the case of the Taxpayer class he should inherit both the properties of Client and Person classes. (UPDATE: A taxpayer can be a client but not necessarily) Also in the other places Taxpayer class is used, most of the time it can be either a Person class or Taxpayer class.

Any ideas on how to proceed?

Thanks.


问:
Sampling a list with linq
I need a helper method for adding axis labels to a chart. I don't want to add a label at every point along the axis that has values in the chart because that would get too busy. So I need to extract samples at regular intervals. So far I've come up with the following method which meets the requirements but I think there must be a neater way of accomplishing this with Linq. Can anyone think of how this could be made more concise (n represents the total number of samples I want back)?</p>

```<code>public static List<T> Sample<T>(this List<T> list, int n)
{
  var samples = new List<T>();
  var divisor = list.Count/n;
  for (var i = 0; i < list.Count; i++)
    if (samples.Count == i/divisor)
      samples.Add(list[i]);
  return samples;
}
</code>```

答:
```<code>    public static List<T> Sample<T>(this List<T> list, int n)
    {
        Int32 count = list.Count;
        Int32 interval = count / n;

        return list.Where((item, index) => index % interval == 0).ToList();
    }
</code>```

ContentLicense: CC BY-SA 2.5

Title: Sampling a list with linq

Body:
I need a helper method for adding axis labels to a chart. I don't want to add a label at every point along the axis that has values in the chart because that would get too busy. So I need to extract samples at regular intervals. So far I've come up with the following method which meets the requirements but I think there must be a neater way of accomplishing this with Linq. Can anyone think of how this could be made more concise (n represents the total number of samples I want back)?

public static List<T> Sample<T>(this List<T> list, int n)
{
  var samples = new List<T>();
  var divisor = list.Count/n;
  for (var i = 0; i < list.Count; i++)
    if (samples.Count == i/divisor)
      samples.Add(list[i]);
  return samples;
}


答:
It looks like rather than including r(indicate_fe) you want to include displayName = coefficientName, so in the example above and below, the return list shows:

r(indicate_fe) : " "headroom=0.headroom" "foreign=0.foreign""

so we indicate foo = 0.headroom

Using your example:

```<code>sysuse auto, clear
eststo m: reghdfe price weight, a(headroom foreign)
estfe m
return list
esttab m, keep(weight) indicate("foo = 0.headroom")
</code>```

this will output:

```<code>----------------------------
                      (1)
                    price
----------------------------
weight              3.581***
                   (8.03)

foo                   Yes
----------------------------
N                      73
----------------------------
t statistics in parentheses
* p<0.05, ** p<0.01, *** p<0.001
</code>```

Title: Drop indicators with estfe

Body:
When using estfe and subsequently indicate(r(indicate_fe)), the regression table contains all of the fixed-effects set up, even if I have not specified them in estfe, and there appears no way to drop them.

In the following example, I'd like to control for headroom and foreign, but only display headroom, which I rename to foo:

. sysuse auto, clear
(1978 Automobile Data)

. reghdfe price weight, a(headroom foreign)
(dropped 1 singleton observations)
(converged in 4 iterations)

HDFE Linear regression                            Number of obs   =         73
Absorbing 2 HDFE groups                           F(   1,     64) =      64.50
                                                  Prob > F        =     0.0000
                                                  R-squared       =     0.5542
                                                  Adj R-squared   =     0.4985
                                                  Within R-sq.    =     0.5020
                                                  Root MSE        =  2095.7886

------------------------------------------------------------------------------
       price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      weight |    3.58106   .4458786     8.03   0.000     2.690315    4.471805
-------------+----------------------------------------------------------------
    Absorbed |          F(7, 64) =      5.272   0.000             (Joint test)
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     |
-------------+-------------------------------------------------|
    headroom |            7               7              0     |
     foreign |            1               2              1     |
---------------------------------------------------------------+

. eststo m: reghdfe price weight, a(headroom foreign)
(dropped 1 singleton observations)
(converged in 4 iterations)

HDFE Linear regression                            Number of obs   =         73
Absorbing 2 HDFE groups                           F(   1,     64) =      64.50
                                                  Prob > F        =     0.0000
                                                  R-squared       =     0.5542
                                                  Adj R-squared   =     0.4985
                                                  Within R-sq.    =     0.5020
                                                  Root MSE        =  2095.7886

------------------------------------------------------------------------------
       price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      weight |    3.58106   .4458786     8.03   0.000     2.690315    4.471805
-------------+----------------------------------------------------------------
    Absorbed |          F(7, 64) =      5.272   0.000             (Joint test)
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     |
-------------+-------------------------------------------------|
    headroom |            7               7              0     |
     foreign |            1               2              1     |
---------------------------------------------------------------+

. estfe m, labels(headroom "foo")

. return list

macros:
        r(indicate_fe) : " "foo=0.headroom"  "foreign=0.foreign""

. esttab m, keep(weight) indicate(`r(indicate_fe)')

----------------------------
                      (1)
                    price
----------------------------
weight              3.581***
                   (8.03)

foo                   Yes

foreign               Yes
----------------------------
N                      73
----------------------------
t statistics in parentheses
* p<0.05, ** p<0.01, *** p<0.001

. esttab m, keep(weight) indicate(`r(indicate_fe)') drop(foreign)
coefficient foreign not found

Clearly, foreign is still in the regression table, despite my hardest efforts to drop it or not show it. help estfe is not being of any use, so I'm afraid I'm stuck.

Body:
It looks like rather than including r(indicate_fe) you want to include displayName = coefficientName, so in the example above and below, the return list shows:

r(indicate_fe) : " "headroom=0.headroom" "foreign=0.foreign""

so we indicate foo = 0.headroom

Using your example:

sysuse auto, clear
eststo m: reghdfe price weight, a(headroom foreign)
estfe m
return list
esttab m, keep(weight) indicate("foo = 0.headroom")

this will output:

----------------------------
                      (1)
                    price
----------------------------
weight              3.581***
                   (8.03)

foo                   Yes
----------------------------
N                      73
----------------------------
t statistics in parentheses
* p<0.05, ** p<0.01, *** p<0.001


问:
Not able to find controls in UserControl from parent page set in accordion
aspx page layout is as below

```<code><asp:Content ID="PageContent" ContentPlaceHolderID="PageContent" runat="Server">
<div id="checkout_onePage" class="mainContentWrapper opcOverlayWrapper">
    <script language="javascript" type="text/javascript">
        Page_ClientValidate();
    </script>
    <div id="PageOverlay" runat="server" visible="false" class="opcOverlay"></div>
 <ajax:Accordion ID="UserAccordion" runat="server" SelectedIndex="0" HeaderCssClass="accordionHeader"
        HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent" FadeTransitions="true" SuppressHeaderPostbacks="true" TransitionDuration="250" FramesPerSecond="40" RequireOpenedPane="true" AutoSize="None">
        <Panes>
            <ajax:AccordionPane ID="BillingInformation" runat="server">
                <Header>
                    <div id="billingAddr" class="widget billingAddressWidget aboveOpcOverlay">
                        <div class="header">
                            <h2>Billing Information</h2>
                        </div>
                    </div>
                </Header>
                <Content>
                    <div class="aboveOpcOverlay">
                        <asp:UpdatePanel ID="UPBilling" runat="server">
                            <ContentTemplate>
                                <div class="content floatleft">
                                    <asp:PlaceHolder ID="LoginPanel" runat="server" EnableViewState="False" Visible="false">
                                        <p class="LoginMessage">
                                            If you have previously created an account, you can
                        <asp:HyperLink ID="LoginLink" runat="server" Text="log in" EnableViewState="false" CssClass="button"></asp:HyperLink>
                                            to retrieve your saved addresses.
                                        </p>
                                    </asp:PlaceHolder>
                                </div>
                            </ContentTemplate>
                        </asp:UpdatePanel>
                    </div>
                </Content>
            </ajax:AccordionPane>
            <ajax:AccordionPane ID="ShippingInformation" runat="server">
                <Header>
                    <div class="widget shippingAddressWidget aboveOpcOverlay">
                        <div class="header">
                            <h2>Shipping Information</h2>
                        </div>
                    </div>
                </Header>
                <Content>
                    <asp:Panel ID="ShippingAddressPanel" runat="server" Visible="true">
                        <div class="aboveOpcOverlay">
                            <div class="content" runat="server" id="Div_Main_Shipping_Information">

                            </div>
                        </div>
                     <table>
                     <tr id="trShippingAddress" runat="server" visible="false">
                                            <td>
                                                <uc2:AddressDetails ID="ShippingAddress" runat="server" ValidationGroupName="Shipping" />
                                            </td>
                                        </tr>
                                    </table>
                    </asp:Panel>
                </Content>
            </ajax:AccordionPane>
        </Panes>
    </ajax:Accordion>
</code>```

I have one usercontrol assigned in above page from there I am not able to find my div control named as Div_Main_Shipping_Information

My usercontrol code is as Below

```<code> Content PageContent = (Content)this.Parent.FindControl("PageContent");
 Accordion UserAccordion = (Accordion)PageContent.FindControl("UserAccordion");
 AccordionPane shipInfoPane = UserAccordion.Panes["ShippingInformation"];
 Panel ShippingAddressPanel = (Panel)shipInfoPane.FindControl("ShippingAddressPanel");
 System.Web.UI.HtmlControls.HtmlGenericControl Div_Main_Shipping_Information = (System.Web.UI.HtmlControls.HtmlGenericControl)ShippingAddressPanel.FindControl("Div_Main_Shipping_Information");
</code>```

But I am not able to find my control Accordion control, panel control or my div control.

答:
```<code>using AjaxControlToolkit;

Accordion userAccordion = (Accordion)this.Page.FindControl("UserAccordion");
AccordionPane shipInfoPane = userAccordion.Panes["ShippingInformation"];
Panel ShippingAddressPanel = (Panel)shipInfoPane.FindControl("ShippingAddressPanel");
System.Web.UI.HtmlControls.HtmlGenericControl Div_Main_Shipping_Information = (System.Web.UI.HtmlControls.HtmlGenericControl)ShippingAddressPanel.FindControl("Div_Main_Shipping_Information");
</code>```

Body:
aspx page layout is as below

<asp:Content ID="PageContent" ContentPlaceHolderID="PageContent" runat="Server">

 <ajax:Accordion ID="UserAccordion" runat="server" SelectedIndex="0" HeaderCssClass="accordionHeader"
        HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent" FadeTransitions="true" SuppressHeaderPostbacks="true" TransitionDuration="250" FramesPerSecond="40" RequireOpenedPane="true" AutoSize="None">
        <Panes>
            <ajax:AccordionPane ID="BillingInformation" runat="server">

Billing Information

                <Content>

                        <asp:UpdatePanel ID="UPBilling" runat="server">
                            <ContentTemplate>

                                    <asp:PlaceHolder ID="LoginPanel" runat="server" EnableViewState="False" Visible="false">

                                            If you have previously created an account, you can
                        <asp:HyperLink ID="LoginLink" runat="server" Text="log in" EnableViewState="false" CssClass="button"></asp:HyperLink>
                                            to retrieve your saved addresses.

                                    </asp:PlaceHolder>

                            </ContentTemplate>
                        </asp:UpdatePanel>

                </Content>
            </ajax:AccordionPane>
            <ajax:AccordionPane ID="ShippingInformation" runat="server">

Shipping Information

                <Content>
                    <asp:Panel ID="ShippingAddressPanel" runat="server" Visible="true">

                                                <uc2:AddressDetails ID="ShippingAddress" runat="server" ValidationGroupName="Shipping" />

                    </asp:Panel>
                </Content>
            </ajax:AccordionPane>
        </Panes>
    </ajax:Accordion>

I have one usercontrol assigned in above page from there I am not able to find my div control named as Div_Main_Shipping_Information

My usercontrol code is as Below

 Content PageContent = (Content)this.Parent.FindControl("PageContent");
 Accordion UserAccordion = (Accordion)PageContent.FindControl("UserAccordion");
 AccordionPane shipInfoPane = UserAccordion.Panes["ShippingInformation"];
 Panel ShippingAddressPanel = (Panel)shipInfoPane.FindControl("ShippingAddressPanel");
 System.Web.UI.HtmlControls.HtmlGenericControl Div_Main_Shipping_Information = (System.Web.UI.HtmlControls.HtmlGenericControl)ShippingAddressPanel.FindControl("Div_Main_Shipping_Information");

But I am not able to find my control Accordion control, panel control or my div control.


问:
Extract json in an array in Jmeter
How do I extract the json object name from the below json data in Jmeter

```<code>[
:   {
:   :   "name":"x",
:   :   "age":"50",
:   :   "gender":"Female"
:   }
]
</code>```

I am doing this $..name in the JsonPath Extractor which is giving me this in the variable I extracted to

```<code>name=["x"]
</code>```

Is there a way I could just get name=x without the array format

Or is there a way I can extract just the x from ["x"]?

Thanks

答:
Using this in a bean shell post processor worked

```<code> String newName = vars.get("name"). replace([","").replace("]","").replace("\"","");
log.info("name is: " +newName);
</code>```

which gives name is: x

Title: Extract json in an array in Jmeter

Body:
How do I extract the json object name from the below json data in Jmeter

[
:   {
:   :   "name":"x",
:   :   "age":"50",
:   :   "gender":"Female"
:   }
]

I am doing this $..name in the JsonPath Extractor which is giving me this in the variable I extracted to

name=["x"]

Is there a way I could just get name=x without the array format

Or is there a way I can extract just the x from ["x"]?

Thanks

Body:
Using this in a bean shell post processor worked

 String newName = vars.get("name"). replace([","").replace("]","").replace("\"","");
log.info("name is: " +newName);

which gives name is: x


问:
I do *not* want correct rounding for function exp
The GCC implementation of the C mathematical library on Debian systems has apparently an (IEEE 754-2008)-compliant implementation of the function exp, implying that rounding shall always be correct:

(from Wikipedia) The IEEE floating point standard guarantees that add, subtract, multiply, divide, fused multiply–add, square root, and floating point remainder will give the correctly rounded result of the infinite precision operation. No such guarantee was given in the 1985 standard for more complex functions and they are typically only accurate to within the last bit at best. However, the 2008 standard guarantees that conforming implementations will give correctly rounded results which respect the active rounding mode; implementation of the functions, however, is optional.

It turns out that I am encountering a case where this feature is actually hindering, because the exact result of the exp function is often nearly exactly at the middle between two consecutive double values (1), and then the program carries plenty of several further computations, losing up to a factor 400 (!) in speed: this was actually the explanation to my (ill-asked :-S) Question #43530011.

(1) More precisely, this happens when the argument of exp turns out to be of the form (2 k + 1) × 2-53 with k a rather small integer (like 242 for instance). In particular, the computations involved by pow (1. + x, 0.5) tend to call exp with such an argument when x is of the order of magnitude of 2-44.

Since implementations of correct rounding can be so much time-consuming in certain circumstances, I guess that the developers will also have devised a way to get a slightly less precise result (say, only up to 0.6 ULP or something like this) in a time which is (roughly) bounded for every value of the argument in a given range… (2)

… But how to do this??

(2) What I mean is that I just do not want that some exceptional values of the argument like (2 k + 1) × 2-53 would be much more time-consuming than most values of the same order of magnitude; but of course I do not mind if some exceptional values of the argument go much faster, or if large arguments (in absolute value) need a larger computation time.

Here is a minimal program showing the phenomenon:

```<code>#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>

int main (void)
 {
  int i;
  double a, c;
  c = 0;
  clock_t start = clock ();
  for (i = 0; i < 1e6; ++i) // Doing a large number of times the same type of computation with different values, to smoothen random fluctuations.
   {
    a = (double) (1 + 2 * (rand () % 0x400)) / 0x20000000000000; // "a" has only a few significant digits, and its last non-zero digit is at (fixed-point) position 53.
    c += exp (a); // Just to be sure that the compiler will actually perform the computation of exp (a).
   }
  clock_t stop = clock ();
  printf ("%e\n", c); // Just to be sure that the compiler will actually perform the computation.
  printf ("Clock time spent: %d\n", stop - start);
  return 0;
 }
</code>```

Now after gcc -std=c99 program53.c -lm -o program53:

$ ./program53
1.000000e+06
Clock time spent: 13470008
$ ./program53
1.000000e+06
Clock time spent: 13292721
$ ./program53
1.000000e+06
Clock time spent: 13201616
```

<p>On the other hand, with <code>program52</code> and <code>program54</code> (got by replacing <code>0x20000000000000</code> by resp. <code>0x10000000000000</code> and <code>0x40000000000000</code>):</p>

<pre class="lang-none prettyprint-override"><code>$ ./program52
1.000000e+06
Clock time spent: 83594
$ ./program52
1.000000e+06
Clock time spent: 69095
$ ./program52
1.000000e+06
Clock time spent: 54694
$ ./program54
1.000000e+06
Clock time spent: 86151
$ ./program54
1.000000e+06
Clock time spent: 74209
$ ./program54
1.000000e+06
Clock time spent: 78612
</code>```

Beware, the phenomenon is implementation-dependent! Apparently, among the common implementations, only those of the Debian systems (including Ubuntu) show this phenomenon.

P.-S.: I hope that my question is not a duplicate: I searched for a similar question thoroughly without success, but maybe I did note use the relevant keywords… :-/

答:
Regarding your comment to @EOF 's answer, the "write your own" remark from @NominalAnimal seems simple enough here, even trivial, as follows.

Your original code above seems to have a max possible argument for exp() of a=(1+2*0x400)/0x2000...=4.55e-13 (that should really be 2*0x3FF, and I'm counting 13 zeroes after your 0x2000... which makes it 2x16^13). So that 4.55e-13 max argument is very, very small.

And then the trivial taylor expansion is exp(a)=1+a+(a^2)/2+(a^3)/6+... which already gives you all double's precision for such small arguments. Now, you'll have to discard the 1 part, as explained above, and then that just reduces to expm1(a)=a*(1.+a*(1.+a/3.)/2.) And that should go pretty darn quick! Just make sure a stays small. If it gets a little bigger, just add the next term, a^4/24 (you see how to do that?).

>>EDIT<<

I modified the OP's test program as follows to test a little more stuff (discussion follows code)

```<code>/* https://stackoverflow.com/questions/44346371/
   i-do-not-want-correct-rounding-for-function-exp/44397261 */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define BASE 16               /*denominator will be (multiplier)xBASE^EXPON*/
#define EXPON 13
#define taylorm1(a) (a*(1.+a*(1.+a/3.)/2.)) /*expm1() approx for small args*/

int main (int argc, char *argv[]) {
  int N          = (argc>1?atoi(argv[1]):1e6),
      multiplier = (argc>2?atoi(argv[2]):2),
      isexp      = (argc>3?atoi(argv[3]):1); /* flags to turn on/off exp() */
  int isexpm1    = 1;                        /* and expm1() for timing tests*/
  int i, n=0;
  double denom = ((double)multiplier)*pow((double)BASE,(double)EXPON);
  double a, c=0.0, cm1=0.0, tm1=0.0;
  clock_t start = clock();
  n=0;  c=cm1=tm1=0.0;
  /* --- to smooth random fluctuations, do the same type of computation
         a large number of (N) times with different values --- */
  for (i=0; i<N; i++) {
    n++;
    a = (double)(1 + 2*(rand()%0x400)) / denom; /* "a" has only a few
                                 significant digits, and its last non-zero
                                 digit is at (fixed-point) position 53. */
    if ( isexp ) c += exp(a); /* turn this off to time expm1() alone */
    if ( isexpm1 ) {          /* you can turn this off to time exp() alone, */
      cm1 += expm1(a);        /* but difference is negligible */
      tm1 += taylorm1(a); }
    } /* --- end-of-for(i) --- */
  int nticks = (int)(clock()-start);
  printf ("N=%d, denom=%dx%d^%d, Clock time: %d (%.2f secs)\n",
         n, multiplier,BASE,EXPON,
         nticks, ((double)nticks)/((double)CLOCKS_PER_SEC));
  printf ("\t c=%.20e,\n\t c-n=%e, cm1=%e, tm1=%e\n",
           c,c-(double)n,cm1,tm1);
  return 0;
  } /* --- end-of-function main() --- */
</code>```

Compile and run it as test to reproduce OP's 0x2000... scenario, or run it with (up to three) optional args test  #trials  multiplier  timeexp where #trials defaults to the OP's 1000000, and multipler defaults to 2 for the OP's 2x16^13 (change it to 4, etc, for her other tests). For the last arg, timeexp, enter a 0 to do only the expm1() (and my unnecessary taylor-like) calculation. The point of that is to show that the bad-timing-cases displayed by the OP disappear with expm1(), which takes "no time at all" regardless of multiplier.

So default runs, test and test 1000000 4, produce (okay, I called the program rounding)...

```<code>bash-4.3$ ./rounding
N=1000000, denom=2x16^13, Clock time: 11155070 (11.16 secs)
         c=1.00000000000000023283e+06,
         c-n=2.328306e-10, cm1=1.136017e-07, tm1=1.136017e-07
bash-4.3$ ./rounding 1000000 4
N=1000000, denom=4x16^13, Clock time: 200211 (0.20 secs)
         c=1.00000000000000011642e+06,
         c-n=1.164153e-10, cm1=5.680083e-08, tm1=5.680083e-08
</code>```

So the first thing you'll note is that the OP's c-n using exp() differs substantially from both cm1==tm1 using expm1() and my taylor approx. If you reduce N they come into agreement, as follows...

```<code>N=10, denom=2x16^13, Clock time: 941 (0.00 secs)
         c=1.00000000000007140954e+01,
         c-n=7.140954e-13, cm1=7.127632e-13, tm1=7.127632e-13
bash-4.3$ ./rounding 100
N=100, denom=2x16^13, Clock time: 5506 (0.01 secs)
         c=1.00000000000010103918e+02,
         c-n=1.010392e-11, cm1=1.008393e-11, tm1=1.008393e-11
bash-4.3$ ./rounding 1000
N=1000, denom=2x16^13, Clock time: 44196 (0.04 secs)
         c=1.00000000000011345946e+03,
         c-n=1.134595e-10, cm1=1.140730e-10, tm1=1.140730e-10
bash-4.3$ ./rounding 10000
N=10000, denom=2x16^13, Clock time: 227215 (0.23 secs)
         c=1.00000000000002328306e+04,
         c-n=2.328306e-10, cm1=1.131288e-09, tm1=1.131288e-09
bash-4.3$ ./rounding 100000
N=100000, denom=2x16^13, Clock time: 1206348 (1.21 secs)
         c=1.00000000000000232831e+05,
         c-n=2.328306e-10, cm1=1.133611e-08, tm1=1.133611e-08
</code>```

And as far as timing of exp() versus expm1() is concerned, see for yourself...

```<code>bash-4.3$ ./rounding 1000000 2
N=1000000, denom=2x16^13, Clock time: 11168388 (11.17 secs)
         c=1.00000000000000023283e+06,
         c-n=2.328306e-10, cm1=1.136017e-07, tm1=1.136017e-07
bash-4.3$ ./rounding 1000000 2 0
N=1000000, denom=2x16^13, Clock time: 24064 (0.02 secs)
         c=0.00000000000000000000e+00,
         c-n=-1.000000e+06, cm1=1.136017e-07, tm1=1.136017e-07
</code>```

Question: you'll note that once the exp() calculation reaches N=10000 trials, its sum remains constant regardless of larger N. Not sure why that would be happening.

>>__SECOND EDIT__<<

Okay, @EOF , "you made me look" with your "heirarchical accumulation" comment. And that indeed works to bring the exp() sum closer (much closer) to the (presumably correct) expm1() sum. The modified code's immediately below followed by a discussion. But one discussion note here: recall multiplier from above. That's gone, and in its same place is expon so that denominator is now 2^expon where the default is 53, matching OP's default (and I believe better matching how she was thinking about it). Okay, and here's the code...

```<code>/* https://stackoverflow.com/questions/44346371/
   i-do-not-want-correct-rounding-for-function-exp/44397261 */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define BASE 2                /*denominator=2^EXPON, 2^53=2x16^13 default */
#define EXPON 53
#define taylorm1(a) (a*(1.+a*(1.+a/3.)/2.)) /*expm1() approx for small args*/

int main (int argc, char *argv[]) {
  int N          = (argc>1?atoi(argv[1]):1e6),
      expon      = (argc>2?atoi(argv[2]):EXPON),
      isexp      = (argc>3?atoi(argv[3]):1), /* flags to turn on/off exp() */
      ncparts    = (argc>4?atoi(argv[4]):1), /* #partial sums for c */
      binsize    = (argc>5?atoi(argv[5]):10);/* #doubles to sum in each bin */
  int isexpm1    = 1;                        /* and expm1() for timing tests*/
  int i, n=0;
  double denom = pow((double)BASE,(double)expon);
  double a, c=0.0, cm1=0.0, tm1=0.0;
  double csums[10], cbins[10][65537]; /* c partial sums and heirarchy */
  int nbins[10], ibin=0;      /* start at lowest level */
  clock_t start = clock();
  n=0;  c=cm1=tm1=0.0;
  if ( ncparts > 65536 ) ncparts=65536;  /* array size check */
  if ( ncparts > 1 ) for(i=0;i<ncparts;i++) cbins[0][i]=0.0; /*init bin#0*/
  /* --- to smooth random fluctuations, do the same type of computation
         a large number of (N) times with different values --- */
  for (i=0; i<N; i++) {
    n++;
    a = (double)(1 + 2*(rand()%0x400)) / denom; /* "a" has only a few
                                 significant digits, and its last non-zero
                                 digit is at (fixed-point) position 53. */
    if ( isexp ) {            /* turn this off to time expm1() alone */
      double expa = exp(a);   /* exp(a) */
      c += expa;              /* just accumulate in a single "bin" */
      if ( ncparts > 1 ) cbins[0][n%ncparts] += expa; } /* accum in ncparts */
    if ( isexpm1 ) {          /* you can turn this off to time exp() alone, */
      cm1 += expm1(a);        /* but difference is negligible */
      tm1 += taylorm1(a); }
    } /* --- end-of-for(i) --- */
  int nticks = (int)(clock()-start);
  if ( ncparts > 1 ) {        /* need to sum the partial-sum bins */
    nbins[ibin=0] = ncparts;  /* lowest-level has everything */
    while ( nbins[ibin] > binsize ) { /* need another heirarchy level */
      if ( ibin >= 9 ) break; /* no more bins */
      ibin++;                 /* next available heirarchy bin level */
      nbins[ibin] = (nbins[ibin-1]+(binsize-1))/binsize; /*#bins this level*/
      for(i=0;i<nbins[ibin];i++) cbins[ibin][i]=0.0; /* init bins */
      for(i=0;i<nbins[ibin-1];i++) {
        cbins[ibin][(i+1)%nbins[ibin]] += cbins[ibin-1][i]; /*accum in nbins*/
        csums[ibin-1] += cbins[ibin-1][i]; } /* accumulate in "one bin" */
      } /* --- end-of-while(nprevbins>binsize) --- */
    for(i=0;i<nbins[ibin];i++) csums[ibin] += cbins[ibin][i]; /*highest level*/
    } /* --- end-of-if(ncparts>1) --- */
  printf ("N=%d, denom=%d^%d, Clock time: %d (%.2f secs)\n", n, BASE,expon,
         nticks, ((double)nticks)/((double)CLOCKS_PER_SEC));
  printf ("\t c=%.20e,\n\t c-n=%e, cm1=%e, tm1=%e\n",
           c,c-(double)n,cm1,tm1);
  if ( ncparts > 1 ) { printf("\t binsize=%d...\n",binsize);
    for (i=0;i<=ibin;i++) /* display heirarchy */
      printf("\t level#%d: #bins=%5d, c-n=%e\n",
      i,nbins[i],csums[i]-(double)n); }
  return 0;
  } /* --- end-of-function main() --- */
</code>```

Okay, and now you can notice two additional command-line args following the old timeexp. They are ncparts for the initial number of bins into which the entire #trials will be distributed. So at the lowest level of the heirarchy, each bin should (modulo bugs:) have the sum of #trials/ncparts doubles. The argument after that is binsize, which will be the number of doubles summed in each bin at every successive level, until the last level has fewer (or equal) #bins as binsize. So here's an example dividing 1000000 trials into 50000 bins, meaning 20doubles/bin at the lowest level, and 5doubles/bin thereafter...

```<code>bash-4.3$ ./rounding 1000000 53 1 50000 5
N=1000000, denom=2^53, Clock time: 11129803 (11.13 secs)
         c=1.00000000000000465661e+06,
         c-n=4.656613e-09, cm1=1.136017e-07, tm1=1.136017e-07
         binsize=5...
         level#0: #bins=50000, c-n=4.656613e-09
         level#1: #bins=10002, c-n=1.734588e-08
         level#2: #bins= 2002, c-n=7.974450e-08
         level#3: #bins=  402, c-n=1.059379e-07
         level#4: #bins=   82, c-n=1.133885e-07
         level#5: #bins=   18, c-n=1.136214e-07
         level#6: #bins=    5, c-n=1.138542e-07
</code>```

Note how the c-n for exp() converges pretty nicely towards the expm1() value. But note how it's best at level#5, and isn't converging uniformly at all. And note if you break the #trials into only 5000 initial bins, you get just as good a result,

```<code>bash-4.3$ ./rounding 1000000 53 1 5000 5
N=1000000, denom=2^53, Clock time: 11165924 (11.17 secs)
         c=1.00000000000003527384e+06,
         c-n=3.527384e-08, cm1=1.136017e-07, tm1=1.136017e-07
         binsize=5...
         level#0: #bins= 5000, c-n=3.527384e-08
         level#1: #bins= 1002, c-n=1.164153e-07
         level#2: #bins=  202, c-n=1.158332e-07
         level#3: #bins=   42, c-n=1.136214e-07
         level#4: #bins=   10, c-n=1.137378e-07
         level#5: #bins=    4, c-n=1.136214e-07
</code>```

In fact, playing with ncparts and binsize doesn't seem to show much sensitivity, and it's not always "more is better" (i.e., less for binsize) either. So I'm not sure exactly what's going on. Could be a bug (or two), or could be yet another question for @EOF ...???

>>EDIT -- example showing pair addition "binary tree" heirarchy<<

Example below added as per @EOF 's comment
(Note: re-copy preceding code. I had to edit nbins[ibin] calculation for each next level to nbins[ibin]=(nbins[ibin-1]+(binsize-1))/binsize; from nbins[ibin]=(nbins[ibin-1]+2*binsize)/binsize; which was "too conservative" to create ...16,8,4,2 sequence)

```<code>bash-4.3$ ./rounding 1024 53 1 512 2
N=1024, denom=2^53, Clock time: 36750 (0.04 secs)
         c=1.02400000000011573320e+03,
         c-n=1.157332e-10, cm1=1.164226e-10, tm1=1.164226e-10
         binsize=2...
         level#0: #bins=  512, c-n=1.159606e-10
         level#1: #bins=  256, c-n=1.166427e-10
         level#2: #bins=  128, c-n=1.166427e-10
         level#3: #bins=   64, c-n=1.161879e-10
         level#4: #bins=   32, c-n=1.166427e-10
         level#5: #bins=   16, c-n=1.166427e-10
         level#6: #bins=    8, c-n=1.166427e-10
         level#7: #bins=    4, c-n=1.166427e-10
         level#8: #bins=    2, c-n=1.164153e-10
</code>```

>>EDIT -- to show @EOF's elegant solution in comment below<<

"Pair addition" can be elegantly accomplished recursively, as per @EOF's comment below, which I'm reproducing here. (Note case 0/1 at end-of-recursion to handle n even/odd.)

```<code>  /* Quoting from EOF's comment...
   What I (EOF) proposed is effectively a binary tree of additions:
   a+b+c+d+e+f+g+h as ((a+b)+(c+d))+((e+f)+(g+h)).
   Like this: Add adjacent pairs of elements, this produces
   a new sequence of n/2 elements.
   Recurse until only one element is left.
   (Note that this will require n/2 elements of storage,
   rather than a fixed number of bins like your implementation) */
  double trecu(double *vals, double sum, int n) {
      int midn = n/2;
      switch (n) {
        case  0: break;
        case  1: sum += *vals; break;
        default: sum = trecu(vals+midn, trecu(vals,sum,midn), n-midn); break; }
      return(sum);
      }
</code>```

Body:
The GCC implementation of the C mathematical library on Debian systems has apparently an (IEEE 754-2008)-compliant implementation of the function exp, implying that rounding shall always be correct:

(from Wikipedia) The IEEE floating point standard guarantees that add, subtract, multiply, divide, fused multiply–add, square root, and floating point remainder will give the correctly rounded result of the infinite precision operation. No such guarantee was given in the 1985 standard for more complex functions and they are typically only accurate to within the last bit at best. However, the 2008 standard guarantees that conforming implementations will give correctly rounded results which respect the active rounding mode; implementation of the functions, however, is optional.

It turns out that I am encountering a case where this feature is actually hindering, because the exact result of the exp function is often nearly exactly at the middle between two consecutive double values (1), and then the program carries plenty of several further computations, losing up to a factor 400 (!) in speed: this was actually the explanation to my (ill-asked :-S) Question #43530011.

(1) More precisely, this happens when the argument of exp turns out to be of the form (2 k + 1) × 2-53 with k a rather small integer (like 242 for instance). In particular, the computations involved by pow (1. + x, 0.5) tend to call exp with such an argument when x is of the order of magnitude of 2-44.

Since implementations of correct rounding can be so much time-consuming in certain circumstances, I guess that the developers will also have devised a way to get a slightly less precise result (say, only up to 0.6 ULP or something like this) in a time which is (roughly) bounded for every value of the argument in a given range… (2)

… But how to do this??

(2) What I mean is that I just do not want that some exceptional values of the argument like (2 k + 1) × 2-53 would be much more time-consuming than most values of the same order of magnitude; but of course I do not mind if some exceptional values of the argument go much faster, or if large arguments (in absolute value) need a larger computation time.

Here is a minimal program showing the phenomenon:

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>

int main (void)
 {
  int i;
  double a, c;
  c = 0;
  clock_t start = clock ();
  for (i = 0; i < 1e6; ++i) // Doing a large number of times the same type of computation with different values, to smoothen random fluctuations.
   {
    a = (double) (1 + 2 * (rand () % 0x400)) / 0x20000000000000; // "a" has only a few significant digits, and its last non-zero digit is at (fixed-point) position 53.
    c += exp (a); // Just to be sure that the compiler will actually perform the computation of exp (a).
   }
  clock_t stop = clock ();
  printf ("%e\n", c); // Just to be sure that the compiler will actually perform the computation.
  printf ("Clock time spent: %d\n", stop - start);
  return 0;
 }

Now after gcc -std=c99 program53.c -lm -o program53:

$ ./program53
1.000000e+06
Clock time spent: 13470008
$ ./program53
1.000000e+06
Clock time spent: 13292721
$ ./program53
1.000000e+06
Clock time spent: 13201616

On the other hand, with program52 and program54 (got by replacing 0x20000000000000 by resp. 0x10000000000000 and 0x40000000000000):

$ ./program52
1.000000e+06
Clock time spent: 83594
$ ./program52
1.000000e+06
Clock time spent: 69095
$ ./program52
1.000000e+06
Clock time spent: 54694
$ ./program54
1.000000e+06
Clock time spent: 86151
$ ./program54
1.000000e+06
Clock time spent: 74209
$ ./program54
1.000000e+06
Clock time spent: 78612

Beware, the phenomenon is implementation-dependent! Apparently, among the common implementations, only those of the Debian systems (including Ubuntu) show this phenomenon.

P.-S.: I hope that my question is not a duplicate: I searched for a similar question thoroughly without success, but maybe I did note use the relevant keywords… :-/

Body:
Regarding your comment to @EOF 's answer, the "write your own" remark from @NominalAnimal seems simple enough here, even trivial, as follows.

Your original code above seems to have a max possible argument for exp() of a=(1+2*0x400)/0x2000...=4.55e-13 (that should really be 2*0x3FF, and I'm counting 13 zeroes after your 0x2000... which makes it 2x16^13). So that 4.55e-13 max argument is very, very small.

And then the trivial taylor expansion is exp(a)=1+a+(a^2)/2+(a^3)/6+... which already gives you all double's precision for such small arguments. Now, you'll have to discard the 1 part, as explained above, and then that just reduces to expm1(a)=a*(1.+a*(1.+a/3.)/2.) And that should go pretty darn quick! Just make sure a stays small. If it gets a little bigger, just add the next term, a^4/24 (you see how to do that?).

>>EDIT<<

I modified the OP's test program as follows to test a little more stuff (discussion follows code)

/* https://stackoverflow.com/questions/44346371/
   i-do-not-want-correct-rounding-for-function-exp/44397261 */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define BASE 16               /*denominator will be (multiplier)xBASE^EXPON*/
#define EXPON 13
#define taylorm1(a) (a*(1.+a*(1.+a/3.)/2.)) /*expm1() approx for small args*/

int main (int argc, char *argv[]) {
  int N          = (argc>1?atoi(argv[1]):1e6),
      multiplier = (argc>2?atoi(argv[2]):2),
      isexp      = (argc>3?atoi(argv[3]):1); /* flags to turn on/off exp() */
  int isexpm1    = 1;                        /* and expm1() for timing tests*/
  int i, n=0;
  double denom = ((double)multiplier)*pow((double)BASE,(double)EXPON);
  double a, c=0.0, cm1=0.0, tm1=0.0;
  clock_t start = clock();
  n=0;  c=cm1=tm1=0.0;
  /* --- to smooth random fluctuations, do the same type of computation
         a large number of (N) times with different values --- */
  for (i=0; i<N; i++) {
    n++;
    a = (double)(1 + 2*(rand()%0x400)) / denom; /* "a" has only a few
                                 significant digits, and its last non-zero
                                 digit is at (fixed-point) position 53. */
    if ( isexp ) c += exp(a); /* turn this off to time expm1() alone */
    if ( isexpm1 ) {          /* you can turn this off to time exp() alone, */
      cm1 += expm1(a);        /* but difference is negligible */
      tm1 += taylorm1(a); }
    } /* --- end-of-for(i) --- */
  int nticks = (int)(clock()-start);
  printf ("N=%d, denom=%dx%d^%d, Clock time: %d (%.2f secs)\n",
         n, multiplier,BASE,EXPON,
         nticks, ((double)nticks)/((double)CLOCKS_PER_SEC));
  printf ("\t c=%.20e,\n\t c-n=%e, cm1=%e, tm1=%e\n",
           c,c-(double)n,cm1,tm1);
  return 0;
  } /* --- end-of-function main() --- */

Compile and run it as test to reproduce OP's 0x2000... scenario, or run it with (up to three) optional args test  #trials  multiplier  timeexp where #trials defaults to the OP's 1000000, and multipler defaults to 2 for the OP's 2x16^13 (change it to 4, etc, for her other tests). For the last arg, timeexp, enter a 0 to do only the expm1() (and my unnecessary taylor-like) calculation. The point of that is to show that the bad-timing-cases displayed by the OP disappear with expm1(), which takes "no time at all" regardless of multiplier.

So default runs, test and test 1000000 4, produce (okay, I called the program rounding)...

bash-4.3$ ./rounding
N=1000000, denom=2x16^13, Clock time: 11155070 (11.16 secs)
         c=1.00000000000000023283e+06,
         c-n=2.328306e-10, cm1=1.136017e-07, tm1=1.136017e-07
bash-4.3$ ./rounding 1000000 4
N=1000000, denom=4x16^13, Clock time: 200211 (0.20 secs)
         c=1.00000000000000011642e+06,
         c-n=1.164153e-10, cm1=5.680083e-08, tm1=5.680083e-08

So the first thing you'll note is that the OP's c-n using exp() differs substantially from both cm1==tm1 using expm1() and my taylor approx. If you reduce N they come into agreement, as follows...

N=10, denom=2x16^13, Clock time: 941 (0.00 secs)
         c=1.00000000000007140954e+01,
         c-n=7.140954e-13, cm1=7.127632e-13, tm1=7.127632e-13
bash-4.3$ ./rounding 100
N=100, denom=2x16^13, Clock time: 5506 (0.01 secs)
         c=1.00000000000010103918e+02,
         c-n=1.010392e-11, cm1=1.008393e-11, tm1=1.008393e-11
bash-4.3$ ./rounding 1000
N=1000, denom=2x16^13, Clock time: 44196 (0.04 secs)
         c=1.00000000000011345946e+03,
         c-n=1.134595e-10, cm1=1.140730e-10, tm1=1.140730e-10
bash-4.3$ ./rounding 10000
N=10000, denom=2x16^13, Clock time: 227215 (0.23 secs)
         c=1.00000000000002328306e+04,
         c-n=2.328306e-10, cm1=1.131288e-09, tm1=1.131288e-09
bash-4.3$ ./rounding 100000
N=100000, denom=2x16^13, Clock time: 1206348 (1.21 secs)
         c=1.00000000000000232831e+05,
         c-n=2.328306e-10, cm1=1.133611e-08, tm1=1.133611e-08

And as far as timing of exp() versus expm1() is concerned, see for yourself...

bash-4.3$ ./rounding 1000000 2
N=1000000, denom=2x16^13, Clock time: 11168388 (11.17 secs)
         c=1.00000000000000023283e+06,
         c-n=2.328306e-10, cm1=1.136017e-07, tm1=1.136017e-07
bash-4.3$ ./rounding 1000000 2 0
N=1000000, denom=2x16^13, Clock time: 24064 (0.02 secs)
         c=0.00000000000000000000e+00,
         c-n=-1.000000e+06, cm1=1.136017e-07, tm1=1.136017e-07

Question: you'll note that once the exp() calculation reaches N=10000 trials, its sum remains constant regardless of larger N. Not sure why that would be happening.

>>__SECOND EDIT__<<

Okay, @EOF , "you made me look" with your "heirarchical accumulation" comment. And that indeed works to bring the exp() sum closer (much closer) to the (presumably correct) expm1() sum. The modified code's immediately below followed by a discussion. But one discussion note here: recall multiplier from above. That's gone, and in its same place is expon so that denominator is now 2^expon where the default is 53, matching OP's default (and I believe better matching how she was thinking about it). Okay, and here's the code...

/* https://stackoverflow.com/questions/44346371/
   i-do-not-want-correct-rounding-for-function-exp/44397261 */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define BASE 2                /*denominator=2^EXPON, 2^53=2x16^13 default */
#define EXPON 53
#define taylorm1(a) (a*(1.+a*(1.+a/3.)/2.)) /*expm1() approx for small args*/

int main (int argc, char *argv[]) {
  int N          = (argc>1?atoi(argv[1]):1e6),
      expon      = (argc>2?atoi(argv[2]):EXPON),
      isexp      = (argc>3?atoi(argv[3]):1), /* flags to turn on/off exp() */
      ncparts    = (argc>4?atoi(argv[4]):1), /* #partial sums for c */
      binsize    = (argc>5?atoi(argv[5]):10);/* #doubles to sum in each bin */
  int isexpm1    = 1;                        /* and expm1() for timing tests*/
  int i, n=0;
  double denom = pow((double)BASE,(double)expon);
  double a, c=0.0, cm1=0.0, tm1=0.0;
  double csums[10], cbins[10][65537]; /* c partial sums and heirarchy */
  int nbins[10], ibin=0;      /* start at lowest level */
  clock_t start = clock();
  n=0;  c=cm1=tm1=0.0;
  if ( ncparts > 65536 ) ncparts=65536;  /* array size check */
  if ( ncparts > 1 ) for(i=0;i<ncparts;i++) cbins[0][i]=0.0; /*init bin#0*/
  /* --- to smooth random fluctuations, do the same type of computation
         a large number of (N) times with different values --- */
  for (i=0; i<N; i++) {
    n++;
    a = (double)(1 + 2*(rand()%0x400)) / denom; /* "a" has only a few
                                 significant digits, and its last non-zero
                                 digit is at (fixed-point) position 53. */
    if ( isexp ) {            /* turn this off to time expm1() alone */
      double expa = exp(a);   /* exp(a) */
      c += expa;              /* just accumulate in a single "bin" */
      if ( ncparts > 1 ) cbins[0][n%ncparts] += expa; } /* accum in ncparts */
    if ( isexpm1 ) {          /* you can turn this off to time exp() alone, */
      cm1 += expm1(a);        /* but difference is negligible */
      tm1 += taylorm1(a); }
    } /* --- end-of-for(i) --- */
  int nticks = (int)(clock()-start);
  if ( ncparts > 1 ) {        /* need to sum the partial-sum bins */
    nbins[ibin=0] = ncparts;  /* lowest-level has everything */
    while ( nbins[ibin] > binsize ) { /* need another heirarchy level */
      if ( ibin >= 9 ) break; /* no more bins */
      ibin++;                 /* next available heirarchy bin level */
      nbins[ibin] = (nbins[ibin-1]+(binsize-1))/binsize; /*#bins this level*/
      for(i=0;i<nbins[ibin];i++) cbins[ibin][i]=0.0; /* init bins */
      for(i=0;i<nbins[ibin-1];i++) {
        cbins[ibin][(i+1)%nbins[ibin]] += cbins[ibin-1][i]; /*accum in nbins*/
        csums[ibin-1] += cbins[ibin-1][i]; } /* accumulate in "one bin" */
      } /* --- end-of-while(nprevbins>binsize) --- */
    for(i=0;i<nbins[ibin];i++) csums[ibin] += cbins[ibin][i]; /*highest level*/
    } /* --- end-of-if(ncparts>1) --- */
  printf ("N=%d, denom=%d^%d, Clock time: %d (%.2f secs)\n", n, BASE,expon,
         nticks, ((double)nticks)/((double)CLOCKS_PER_SEC));
  printf ("\t c=%.20e,\n\t c-n=%e, cm1=%e, tm1=%e\n",
           c,c-(double)n,cm1,tm1);
  if ( ncparts > 1 ) { printf("\t binsize=%d...\n",binsize);
    for (i=0;i<=ibin;i++) /* display heirarchy */
      printf("\t level#%d: #bins=%5d, c-n=%e\n",
      i,nbins[i],csums[i]-(double)n); }
  return 0;
  } /* --- end-of-function main() --- */

Okay, and now you can notice two additional command-line args following the old timeexp. They are ncparts for the initial number of bins into which the entire #trials will be distributed. So at the lowest level of the heirarchy, each bin should (modulo bugs:) have the sum of #trials/ncparts doubles. The argument after that is binsize, which will be the number of doubles summed in each bin at every successive level, until the last level has fewer (or equal) #bins as binsize. So here's an example dividing 1000000 trials into 50000 bins, meaning 20doubles/bin at the lowest level, and 5doubles/bin thereafter...

bash-4.3$ ./rounding 1000000 53 1 50000 5
N=1000000, denom=2^53, Clock time: 11129803 (11.13 secs)
         c=1.00000000000000465661e+06,
         c-n=4.656613e-09, cm1=1.136017e-07, tm1=1.136017e-07
         binsize=5...
         level#0: #bins=50000, c-n=4.656613e-09
         level#1: #bins=10002, c-n=1.734588e-08
         level#2: #bins= 2002, c-n=7.974450e-08
         level#3: #bins=  402, c-n=1.059379e-07
         level#4: #bins=   82, c-n=1.133885e-07
         level#5: #bins=   18, c-n=1.136214e-07
         level#6: #bins=    5, c-n=1.138542e-07

Note how the c-n for exp() converges pretty nicely towards the expm1() value. But note how it's best at level#5, and isn't converging uniformly at all. And note if you break the #trials into only 5000 initial bins, you get just as good a result,

bash-4.3$ ./rounding 1000000 53 1 5000 5
N=1000000, denom=2^53, Clock time: 11165924 (11.17 secs)
         c=1.00000000000003527384e+06,
         c-n=3.527384e-08, cm1=1.136017e-07, tm1=1.136017e-07
         binsize=5...
         level#0: #bins= 5000, c-n=3.527384e-08
         level#1: #bins= 1002, c-n=1.164153e-07
         level#2: #bins=  202, c-n=1.158332e-07
         level#3: #bins=   42, c-n=1.136214e-07
         level#4: #bins=   10, c-n=1.137378e-07
         level#5: #bins=    4, c-n=1.136214e-07

In fact, playing with ncparts and binsize doesn't seem to show much sensitivity, and it's not always "more is better" (i.e., less for binsize) either. So I'm not sure exactly what's going on. Could be a bug (or two), or could be yet another question for @EOF ...???

>>EDIT -- example showing pair addition "binary tree" heirarchy<<

Example below added as per @EOF 's comment
(Note: re-copy preceding code. I had to edit nbins[ibin] calculation for each next level to nbins[ibin]=(nbins[ibin-1]+(binsize-1))/binsize; from nbins[ibin]=(nbins[ibin-1]+2*binsize)/binsize; which was "too conservative" to create ...16,8,4,2 sequence)

bash-4.3$ ./rounding 1024 53 1 512 2
N=1024, denom=2^53, Clock time: 36750 (0.04 secs)
         c=1.02400000000011573320e+03,
         c-n=1.157332e-10, cm1=1.164226e-10, tm1=1.164226e-10
         binsize=2...
         level#0: #bins=  512, c-n=1.159606e-10
         level#1: #bins=  256, c-n=1.166427e-10
         level#2: #bins=  128, c-n=1.166427e-10
         level#3: #bins=   64, c-n=1.161879e-10
         level#4: #bins=   32, c-n=1.166427e-10
         level#5: #bins=   16, c-n=1.166427e-10
         level#6: #bins=    8, c-n=1.166427e-10
         level#7: #bins=    4, c-n=1.166427e-10
         level#8: #bins=    2, c-n=1.164153e-10

>>EDIT -- to show @EOF's elegant solution in comment below<<

"Pair addition" can be elegantly accomplished recursively, as per @EOF's comment below, which I'm reproducing here. (Note case 0/1 at end-of-recursion to handle n even/odd.)

  /* Quoting from EOF's comment...
   What I (EOF) proposed is effectively a binary tree of additions:
   a+b+c+d+e+f+g+h as ((a+b)+(c+d))+((e+f)+(g+h)).
   Like this: Add adjacent pairs of elements, this produces
   a new sequence of n/2 elements.
   Recurse until only one element is left.
   (Note that this will require n/2 elements of storage,
   rather than a fixed number of bins like your implementation) */
  double trecu(double *vals, double sum, int n) {
      int midn = n/2;
      switch (n) {
        case  0: break;
        case  1: sum += *vals; break;
        default: sum = trecu(vals+midn, trecu(vals,sum,midn), n-midn); break; }
      return(sum);
      }


问:
Why Web Page is showing a horizontal scroll bar even it fits on the screen
I have create this web page and It fits  in the browser perfectly. But There is this horizontal scroll bar to navigate horizontally. There cannot be horizontal bar if the site fits to the screen properly.

I checked if I have accidentally zoomed webpage by browser. I checked even with different browsers. But it all shows the same...

Here's the screenshot of the web page:

Here's my code sample:

```<code><!DOCTYPE html>
<html>
<head>
    <title>Omicron.com</title>

    <link rel="stylesheet" type="text/css" href="css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="css/custom.css">

<style>

/*#MostUpperGreyLine img{
    width: 100%;
    min-width: 10px;
    height:auto;
}*/
#Header-New img{
    width: 100%;
    min-width: 10px;
    height: auto;
    position: relative;
    top:-5px;
}

</style>

</head>
<body>

    <!--<div id="MostUpperGreyLine">
        <img src="MostUpperGreyLine.png" alt="No Green Header Found!">
    </div>-->

    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="HomePage.html" style="font-family:N-Gage;font-size:15px;">Omicron.Inc</a>
            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

                <ul class="nav navbar-nav">
                    <li class="active"><a href="#">Home<span class="sr-only">(current)</span></a></li>
                    <li><a href="#">About Us</a></li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Our Softwares <span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Software 1</a></li>
                            <li><a href="#">Software 2</a></li>
                            <li><a href="#">Software 3</a></li>
                            <!--<li role="separator" class="divider"></li>
                            <li><a href="#">Separated link</a></li>
                            <li role="separator" class="divider"></li>
                            <li><a href="#">One more separated link</a></li>-->
                        </ul>
                    </li>
                </ul>

                <form class="navbar-form navbar-left">
                    <div class="form-group">
                        <input type="text" class="form-control" placeholder="Search">
                    </div>
                    <button type="submit" class="btn btn-default">Search</button>
                </form>

                <ul class="nav navbar-nav navbar-right">
                    <li><a href="#">Contact Us</a></li>
                    <!--<li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Contact Us <span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Facebook</a></li>
                            <li><a href="#">Another action</a></li>
                            <li><a href="#">Something else here</a></li>
                            <li role="separator" class="divider"></li>
                            <li><a href="#">Separated link</a></li>
                        </ul>
                    </li>-->
                </ul>
            </div><!-- /.navbar-collapse -->
        </div><!-- /.container-fluid -->
    </nav>

    <div id="Header-New">
        <img src="Header-New.png" alt="Header not Found!">
    </div>

<div class="row">
  <div class="col-sm-6 col-md-4">
    <div class="thumbnail">
      <img src="square.png" alt="...">
      <div class="caption">
        <h3 style="font-size:16px;position:relative;left:35px;top:-27px;font-family:Myriad Pro;color:white;">Software Name</h3>
        <p>...</p>
        <p><a href="#" class="btn btn-primary btn-ok" role="button">Read More</a></p>
      </div>
    </div>
  </div>
</div>

<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>

</body>
</html>
</code>```

答: Remove margin-left and margin-right for .row and it well be fixed.</p>

Body:
I have create this web page and It fits  in the browser perfectly. But There is this horizontal scroll bar to navigate horizontally. There cannot be horizontal bar if the site fits to the screen properly.

I checked if I have accidentally zoomed webpage by browser. I checked even with different browsers. But it all shows the same...

Here's the screenshot of the web page:

Here's my code sample:

<!DOCTYPE html>

    <title>Omicron.com</title>

    <link rel="stylesheet" type="text/css" href="css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="css/custom.css">

                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                    Toggle navigation

                </button>
                Omicron.Inc

Home(current)

About Us

                        Our Softwares

Software 1

Software 2

Software 3

                <form class="navbar-form navbar-left">

                        <input type="text" class="form-control" placeholder="Search">

                    <button type="submit" class="btn btn-default">Search</button>
                </form>

Contact Us

Software Name

...

Read More


问:
Can I use asterisk * in config file variable name?
I am using Config Parser to specify a list of variables, and the values for those variables are then pulled from a larger file. The variables/lines in the larger file all look like this:

```<code>callCount.1.cell=2
callCount.2.cell=10
callCount.3.cell=12
</code>```

Rather than listing all these variables specifically, would I be able to use an '*' as a wildcard character, in place of the number, like this:

```<code>[variablesToPull]
callCount.*.cell
</code>```

I can't change the formatting of the larger file I'm pulling values from, and I don't always know what the numbers that are apart of the variables will be.

EDIT: I'm using Python 2.7 to do all my Config Parsing

答:
After looking around for a while I don't think it's possible. I ended up using just the first part of the desired variable name in the config file

```<code>[variablesToPull]
callCount
</code>```

Then I created a dictionary from the file I was storing the full list of variable names and values in (All the following code is for Python 2.7, it probably works for Python 3, but might need some syntax changes)

```<code>f = open(variable_names_and_values_file, 'r')
dict_of_vars= {}
for line in f:
    k, v = line.strip().split('=')
    dict_of_vars[k.strip()] = v.strip()
f.close()
</code>```

Then I looped over this dictionary and created a new list of the specific variables to pull (like callCount.1.cell, callCount.2.cell, ect...)

```<code>new_variables= []
for var in partial_variable_names_from_config_file:
    for data in dict_of_vars:
        if var in data:
            new_variables.append(data)
</code>```

Initially I didn't want to do so much looping for fear of performance decrease (my file of variables has like 10000 lines), but it doesn't seem to have slowed down my script by a noticeable amount.

Hope this helps someone out there

Body:
I am using Config Parser to specify a list of variables, and the values for those variables are then pulled from a larger file. The variables/lines in the larger file all look like this:

callCount.1.cell=2
callCount.2.cell=10
callCount.3.cell=12

Rather than listing all these variables specifically, would I be able to use an '*' as a wildcard character, in place of the number, like this:

[variablesToPull]
callCount.*.cell

I can't change the formatting of the larger file I'm pulling values from, and I don't always know what the numbers that are apart of the variables will be.

EDIT: I'm using Python 2.7 to do all my Config Parsing

Body:
After looking around for a while I don't think it's possible. I ended up using just the first part of the desired variable name in the config file

[variablesToPull]
callCount

Then I created a dictionary from the file I was storing the full list of variable names and values in (All the following code is for Python 2.7, it probably works for Python 3, but might need some syntax changes)

f = open(variable_names_and_values_file, 'r')
dict_of_vars= {}
for line in f:
    k, v = line.strip().split('=')
    dict_of_vars[k.strip()] = v.strip()
f.close()

Then I looped over this dictionary and created a new list of the specific variables to pull (like callCount.1.cell, callCount.2.cell, ect...)

new_variables= []
for var in partial_variable_names_from_config_file:
    for data in dict_of_vars:
        if var in data:
            new_variables.append(data)

Initially I didn't want to do so much looping for fear of performance decrease (my file of variables has like 10000 lines), but it doesn't seem to have slowed down my script by a noticeable amount.

Hope this helps someone out there


问:
Android intent to check/view emails
I am looking for a way to fire the email-app on device from my app to check emails. Note: I do not want to 'send' any email, just want to 'check' emails. The following code crashes for the gmail app -

```<code>          Intent intent = new Intent(Intent.ACTION_VIEW);
          intent.setType("message/rfc822");
          startActivity(intent);
</code>```

The stack-trace being -

```<code>06-06 23:26:20.313 27703-27731/? E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
                                                   Process: com.google.android.gm, PID: 27703
                                                   java.lang.RuntimeException: An error occurred while executing doInBackground()
                                                       at android.os.AsyncTask$3.done(AsyncTask.java:309)
                                                       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
                                                       at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
                                                       at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                                                       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                       at java.lang.Thread.run(Thread.java:818)
                                                    Caused by: java.lang.NullPointerException: uri
                                                       at com.android.internal.util.Preconditions.checkNotNull(Preconditions.java:60)
                                                       at android.content.ContentResolver.openInputStream(ContentResolver.java:645)
                                                       at clk.a(SourceFile:8)
                                                       at clk.loadInBackground(SourceFile:74)
                                                       at android.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:312)
                                                       at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:69)
                                                       at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:66)
                                                       at android.os.AsyncTask$2.call(AsyncTask.java:295)
                                                       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                       at java.lang.Thread.run(Thread.java:818)
</code>```

Is there no way to fire email app just to check emails?

答:
You can do this using the makeMainSelectorActivity method from the Intent class.

```<code>Intent intent = Intent.makeMainSelectorActivity(
                     Intent.ACTION_MAIN,
                     Intent.CATEGORY_APP_EMAIL);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(intent, "Email"));
</code>```

Intent makeMainSelectorActivity (String selectorAction,
                String selectorCategory)

Make an Intent for the main activity of an application, without specifying a specific activity to run but giving a selector to find the activity. This results in a final Intent that is structured the same as when the application is launched from Home. For anything else that wants to launch an application in the same way, it is important that they use an Intent structured the same way, and can use this function to ensure this is the case.

CATEGORY_APP_EMAIL

Title: Android intent to check/view emails

Body:
I am looking for a way to fire the email-app on device from my app to check emails. Note: I do not want to 'send' any email, just want to 'check' emails. The following code crashes for the gmail app -

          Intent intent = new Intent(Intent.ACTION_VIEW);
          intent.setType("message/rfc822");
          startActivity(intent);

The stack-trace being -

06-06 23:26:20.313 27703-27731/? E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
                                                   Process: com.google.android.gm, PID: 27703
                                                   java.lang.RuntimeException: An error occurred while executing doInBackground()
                                                       at android.os.AsyncTask$3.done(AsyncTask.java:309)
                                                       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
                                                       at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
                                                       at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                                                       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                       at java.lang.Thread.run(Thread.java:818)
                                                    Caused by: java.lang.NullPointerException: uri
                                                       at com.android.internal.util.Preconditions.checkNotNull(Preconditions.java:60)
                                                       at android.content.ContentResolver.openInputStream(ContentResolver.java:645)
                                                       at clk.a(SourceFile:8)
                                                       at clk.loadInBackground(SourceFile:74)
                                                       at android.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:312)
                                                       at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:69)
                                                       at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:66)
                                                       at android.os.AsyncTask$2.call(AsyncTask.java:295)
                                                       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                       at java.lang.Thread.run(Thread.java:818)

Is there no way to fire email app just to check emails?

Body:
You can do this using the makeMainSelectorActivity method from the Intent class.

Intent intent = Intent.makeMainSelectorActivity(
                     Intent.ACTION_MAIN,
                     Intent.CATEGORY_APP_EMAIL);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(intent, "Email"));

Intent makeMainSelectorActivity (String selectorAction,
                String selectorCategory)

Make an Intent for the main activity of an application, without specifying a specific activity to run but giving a selector to find the activity. This results in a final Intent that is structured the same as when the application is launched from Home. For anything else that wants to launch an application in the same way, it is important that they use an Intent structured the same way, and can use this function to ensure this is the case.

CATEGORY_APP_EMAIL


问:
Read every note from a MIDI file (note, velocity, length) using DryWetMidi
I'm making a C# program that should read every note from a MIDI file and get the length and the velocity of the note, but I don't know how to do that...

I'm using the DryWetMidi library, but is there some other library?

答:
Please have a look at this Stack Overflow question.

Further information can be grabbed here.

DryWetMidi isn't really clear about the chunk sizes, apart from reading these notes out of the chunk, as far as I've looked into it.

ContentLicense: CC BY-SA 4.0