c ++ – Accelerated string splitting in Rcpp / Cpp

I want to speed up an Rcpp function I wrote.

The function records a called string vcfieldthat takes the format od x:y:z, This string contains 3 fields if you separate them with the :, It takes an int DSfield This tells us the index field (0-based) of vcfield Which is the dosage. The dosage is always a double value.

It also takes 2 intcalled s aa and bb

The program then returns the value of abs((aa + bb) - dosage),

So call ReturnUncertainty("1/1:1.88:0,0.12,0.88", 1, 1, 1) should return 0.12 as abs((1+1) - 1.88) = 0.12

We should assume that the number of characters in the different fields of vcfield may vary. So it should also be able to take on a value like "1/1/1/1:1.88999:0,0.12,0.88",


using namespace Rcpp;
using namespace std;

// ((Rcpp::export))
double ReturnUncertainty(String vcfield, int DSfield, int aa, int bb) {

    string stdfield = vcfield; 
    vector  tokensMain;
    stringstream checkMain(stdfield);
    string intermediate;  

    while (getline(checkMain, intermediate, ':')) { 

    std::string DS = tokensMain(DSfield);
    double DSf;
    std::istringstream(DS) >> DSf;

    double aaD = static_cast(aa);
    double bbD = static_cast(bb);

    double genoSum = aaD + bbD;
    return abs(genoSum - DSf);

QUESTION: As an absolute novice in C ++, I wondered if I was doing something that was very inefficient / unnecessary and could slow down my code.

Functional analysis – operator standard bound by splitting the operator

To let ($ M $. $ mu $) be a measure space. Consider the operator $ T: L ^ {2} (M, mu) to L ^ {2} (M, mu) $ With $$ Tf (x) = int_ {M} {k (x, y) f (y) d mu}, $$ Where $ k (x, y) geq 0 $ and $ k (x, y) = k (y, x) $ satisfying $$ k (x, y) leq h_ {1} (x, y) + h_ {2} (x, y) $$ Where $ h_ {i} (x, y) = h_ {i} (y, x) $ and $ h_ {i} (x, y) geq 0 $, Suppose this is for the operator $ H_ {i}: L ^ {2} (M, mu) to L ^ {2} (M, mu) $ With $$ H_ {i} f (x) = int_ {M} {h_ {i} (x, y) f (y) d mu}, $$ we have $$ || H_ {1} || _ {2 to 2} leq lambda_ {1} $$ and $$ || H_ {2} || _ {2 to 2} leq lambda_ {2}. $$ Does this follow? $$ || T || _ {2 to 2} leq C ( lambda_ {1} + lambda_ {2})? $$
Thank you in advance!

Clustering – splitting strings into groups of similar strings

I want to group a list of strings into groups of strings that differ by a maximum of 1 character:

Given for example:

[John, Alibaba, Johny, Alidaba, Mary]

I would expect three groups:

[John, Johny],
[Alibaba, Alidaba],

My first thought was to use a Levenshtein removal clustering algorithm, but that seems like an overkill to me.

Is there a better approach?

Apache Spark – Splitting a feature vector into columns using Java

I have a data frame like this:

|IndexedArtistID|     recommendations|
|           1580|[[919, 0.00249262...|
|           4900|[[41749, 7.143963...|
|           5300|[[0, 2.0147272E-4...|
|           6620|[[208780, 9.81092...|

I want to split the recommendation column as follows to get a data frame:

|IndexedArtistID|     recommendations|
|           1580|919                 |
|           1580|0.00249262          |
|           4900|41749               |
|           4900|7.143963            |
|           5300|0                   |
|           5300|2.0147272E-4        |
|           6620|208780              |
|           6620|9.81092             |

Basically, I want to split the feature vector into columns and then merge those columns into a single column. The merge section is described in: Splitting a Single Row into Multiple Lines in Spark DataFrame Using Java.
How do you do the sharing with Java?
For Scala it is explained here: Spark Scala: How do I convert DataFrame [vector] to DataFrame [F1: Double, …, FN: Double]], but I cannot proceed as stated in the link.

KVM virtualization – splitting the network between VPN and KVM guest

I'm pretty sure that's stupid, but has anyone tried this?

I have 2 WiFi cards, one of which I want to use to connect to a VPN over WiFi and the other to connect to normal WiFi, using the VM as a host. I can't torrent over the VPN.

I've been researching all day and saw people doing that for different gatways, but my router gateway is the same.

The VPN creates a tun device and adds a route. How can I do this? Instructions on how to understand the network in this regard or how it should be would be very helpful.

I can create a bridge network on KVM, but the routing confuses me and the VM cannot access the Internet.

I have a standard network that is a bridge device. (Please correct me if I'm wrong.)



The output of:
Show IP address

1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp2s0:  mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
    link/ether 58:8a:5a:3c:fa:ef brd ff:ff:ff:ff:ff:ff
3: wlp3s0:  mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:e1:8c:5d:c3:66 brd ff:ff:ff:ff:ff:ff
    inet brd scope global dynamic noprefixroute wlp3s0
       valid_lft 42702sec preferred_lft 42702sec
    inet6 fe80::2e1:8cff:fe5d:c366/64 scope link 
       valid_lft forever preferred_lft forever
44: virbr0:  mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:d6:45:03 brd ff:ff:ff:ff:ff:ff
    inet brd scope global virbr0
       valid_lft forever preferred_lft forever
45: virbr0-nic:  mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:d6:45:03 brd ff:ff:ff:ff:ff:ff

The result of brctl

brctl show
bridge name     bridge id               STP enabled     interfaces
virbr0          8000.525400d64503       yes             virbr0-nic

This is passed on to all interfaces in a NAT mode (I only advise this). I only have to forward the connection of the VM directly to the network card and not to the Tun device (when I am in the VPN).

I know that bridging on a wireless interface is not possible. I'm just wondering what the above means.

I would be grateful for any help. I would also like to learn networking. I'm stuck because of my networking skills.

python – splitting the date (day, month, year) into new columns – DataFrame Pandas

I have a DataFrame and had to take one split in its date field to add month and day columns later.

The problem is that the field data DataFrame is not of type str, so I cannot use it split,

Data frame structure

data        usuarios
2018-01-01  215.0


data          usuarios      ano      mes
2018-01-01    215.0         2018     01


# df.data.apply(str)
# df("data").apply(str)
# df("data").astype(basestring)

I tried these ways, but none of them solved my problem.

I also tried to use the official documentation but was unable to resolve it.

Error displayed

AttributeError: Can only use .str accessors with string values!

Data Structures – Splitting a node into a B + tree with an odd number of keys

This and some other sources suggest Msgstr "Always a knot that receives the middle key from the lower divisions should drop an item for a new middle key",

To illustrate an example.

For 5-way B + tree

(24, 25, 44, 79) is one of the leaf nodes with its root (.., 24,80, …)

       (24, 25, 44, 79)

After insertion 40.

The knot (24, 25, 40, 44, 79) is overloaded and has to split up (even if the siblings are full).

In such a case, is there an advantage in dividing it as

(24, 25) (40, 44, 79)
Over (24, 25, 40) (44, 79)

Is this split A?

(..,24, 40, 80,...)           
    (24, 25)  (40,44, 79)

better than this split b?

 (..,24, 44, 80,...)           
 (24, 25, 40)  (44, 79)

If so, what does A do right and B do wrong, considering that both fulfill the rules of the B + tree.

I could not find a resource to substantiate my argument that B is just as correct as A.

dnd 5e – How do I determine my known / prepared spells when splitting several classes into two or more spell classes?

The rules for the Multilevel Spell Checker in the PHB (p. 175) or the Basic Rules clearly state how known and prepared spells work when subdivided into two or more classes (or subclasses) using the Spell Check feature:

Your ability to spellcast depends in part on your combined language levels in all your spellcasting classes, and partly on your individual language levels in those classes. If you have the magic function of more than one class, apply the following rules. If you have multiple classes but only use the magic function of a class, follow the rules described in this class.

Spells known and prepared. You decide which spells you know, and you can prepare for each class individually as if you were a one-time member of that class. For example, if you're a Ranger 4 / Wizard 3, you know three first-rank Ranger sayings based on your Ranger-level tiers. As a third-level wizard, you know three Wizard Cantrips, and your spellbook contains ten spells, of which two (the two you received when you reached the third level as a sorcerer) may be second-level spells. If your Intellect is 16, you can prepare six spells from your spellbook.

Each spell you know and prepare is linked to one of your classes, and you use the spell casting abilities of that class when casting the spell. Similarly, a magic effect focus, such as a sacred symbol, can only be used for the spells of the class associated with that focus.

As your Cantrip increases in strength at higher levels, the increase is based on your character level rather than your level in a particular class.

As explained above, if you create multiple spell classes, you will determine your known and prepared spells as if they were classified as a single class in each of these classes.

Note that some class / subclass features (such as the extra magical secrets of the Overlord Barber, Cleric Domain Charms, or Paladin Oath Spells) may contain additional known or prepared spells that are not counted against your number of known / prepared spells for that class , In this case, you can use the class / subclass function description to determine whether these spells are counted against your known / prepared spell limit.

What about sorcerers?

You may notice that the rules I quoted above mention the spell-casting function in particular, so you might wonder how they interact with sorcerers who use the pact magic function instead of the spell-casting function. On this topic, the rules for the multiclass spell checker only specify:

Pact spells. If you have both the Spellcasting class feature and the Pact Magic class function of the Warlock class, you can use the spell slots gained through the Pact Magic feature to cast spells you know or prepare from classes using the Spellcasting class feature You can cast known sorcerer spells on the spell slots you receive with the Spellcasting class feature.

Technically speaking, it is not mentioned how well-known spells are determined for sorcerers who are multi-classified with another class, but only how multi-classes interact with their pact magic slots and which slots can be used to cast hexes. However, based on the given logic and the lack of rules to the contrary, it seems clear that their known sorcerer spells are determined as if they were single-level warlocks, just like any other spell class.

Rule designer Jeremy Crawford unofficially acknowledges that this is also the intention of the rules in a series of tweets in December 2017:

The Cleric Spell feature states that you can cast spells up to your spell slot. Pact Magic gives you higher tier magic slots. Can a 1/5 cleric prepare an animated death? Because Warlock does not have a spell function, it does not use preprocessing rules for multiple classes

Spellchecker for multiple classes. You choose the spells you know / prepare for each class individually and pretend that you have only that class. The slots you receive from the multiclassing rules do not apply. You have 1 level in clerics? They prepare cleric spells as first-level clerics.

"If you have multiple classes, but the magic feature is only available for one class, follow the rules described in this class." Warlocks do not grant spellcasting, so she would follow the clerics. "Spells must have a level for which you have spells." Is that still wrong?

Continue reading and start with the next sentence: "Spells known and prepared. …"

"If you have the magic function of more than one class, apply the following rules." In this case, I would not have the magic function of more than one class, so the following rules for known and prepared spells would not apply.

Keep going until the end of the page. You will be redirected to the "Pact Magic" section, which explains how Pact Magic interacts with the spell. It does not affect what you can prepare.

The spell function does not mention where the spell fields originate from.

After rereading the rules for several classes, we turn to the cleric. The first sentence of "Preparing and Casting Spells" reads: "The cleric table shows how many spell bracelets you must use to cast your spells …" This original text forms the basis for what follows in this rule.

"The spells must have a level for which you have spells." However, the text in Preparing and Casting Spells does not explicitly state that it applies only to Cleric Spellworks. I do not feel that the first line restricts you this way.

When I wrote this rule, I started it with this sentence for a reason: putting everything you read about it in that rule into context. Phrases in our rules should not be interpreted in isolation from each other.

Thus, it is clear that determining known / prepared spells should work the same way in a sorcerer as in any other combination of spell classes.

Back to example:

How do I determine which spells I know / prepare, for example when I play a character in several classes with 1 level in the Warlock, 2 levels in the Bard and 3 levels in the Paladin?

We need to look at the magic functions and the class table of each class to see how many spells are known or prepared for each class:

  • The Warlock table shows that a first-level Warlock knows 2 Cantrips and 2 more spells. And according to the Pact Magic feature, "In the first level, you know two first-level spells of your choice from the Warlock spell list." (If you learn a new spell or swap an existing spell in higher Warlock levels for a new one, your new spell does not have to be higher than your Pact magic slots.)

  • Per Bard table, a 2nd level Bard knows 2 cantrips and 5 more spells. Like the sorcerer's pact magic feature, the bard's spell-casting ability states that your non-cantrip spells must be a level for which you have spell slots. As the Bard table shows, a 2nd level bard has only 1st level spells, so all 5 spells must be 1st level spells.

  • Finally, paladins prepare their spells instead of knowing / learning them. Paladin's Spellcasting feature states that you can "prepare a set of Paladin spells that match your Charisma modifier + half of your Paladin level, rounded down (at least one spell)." It is added that the spells must have a level for which you have spell slots. According to the Paladin Table, a third-tier paladin has only first-tier spells. For example, your paladin has a charisma value of 16 and a charisma modifier of +3. This means that you can prepare a number of spells equal to your Charisma Mod (3) plus half of your Paladin Level (3/2, rounded to 1) for a total of 4 spells.

    That's not all. In the third level Paladins receive the function "Holy Oath". Each oath grants them oath spells in predetermined levels. Your Oath spells are always automatically prepared and do not count toward the number of Paladin spells prepared (and always counted as Paladin spells). The oath of surrender Paladin's Eid spells at Paladin level 3 are Protection from good and evil and sanctuary, This raises your actual number of prepared Paladin spells 6.

As Warlock 1 / Bard 2 / Paladin 3 with a Charisma Score of 16:

  • Know 2 Warlock Cantrips and 2 Level 1 Witchcraft spells
  • Get to know 2 bard cantrips and 5 first-level bard spells and
  • Have prepared 4 Paladin spells of the first level and 2 always prepared Oaths
    Spells specified in the subclass description (e.g. protection against
    bad and good
    and sanctuary for a devotional paladin)

You would Not You have access to 2nd level or higher spells in any of these classes, unless you have at least 3 total sorcerer or bard levels, or at least 5 total paladin levels.

Pattern matching – splitting a list by cumulative sum when the accumulator reaches a fixed value

I have a list dat = {10, 10, 10, 10, 10, 40} ,

If the cumulative sum of dat reached >= 25, the cumulative sum is stopped, the difference between 25 and the cumulative sum up to this point is added to the next element of FIG dat and the cumulative sum will be restarted until another 25 is reached and so on.

The desired result should be {{10, 20, 25}, { 15, 25}, {25}, {15}}

I can not figure out how to perform this task, either procedurally or functionally

Thank you in advance.