Point chart - two (or more) data rows - powerbi

I would like to add the average Y-axis values for each X-axis value to a point chart. Is there any way to do this please? I would like to achieve a similar result to the second picture.
Expected result is here.
Data example
id
datum
year
month
day
weekday
hour
hourly_steps
cumulative_daily_steps
daily_steps
1
2021-01-01
2021
1
1
5
17
49
49
5837
2
2021-01-01
2021
1
1
5
18
4977
5026
5837
3
2021-01-01
2021
1
1
5
19
692
5718
5837
4
2021-01-01
2021
1
1
5
20
13
5731
5837
5
2021-01-01
2021
1
1
5
22
106
5837
5837
6
2021-01-02
2021
1
2
6
6
48
48
7965
7
2021-01-02
2021
1
2
6
9
97
145
7965
8
2021-01-02
2021
1
2
6
10
1109
1254
7965
9
2021-01-02
2021
1
2
6
11
253
1507
7965
10
2021-01-02
2021
1
2
6
12
126
1633
7965
11
2021-01-02
2021
1
2
6
13
51
1684
7965
12
2021-01-02
2021
1
2
6
14
690
2374
7965
13
2021-01-02
2021
1
2
6
15
3690
6064
7965
14
2021-01-02
2021
1
2
6
16
956
7020
7965
15
2021-01-02
2021
1
2
6
17
667
7687
7965
16
2021-01-02
2021
1
2
6
18
36
7723
7965
17
2021-01-02
2021
1
2
6
19
45
7768
7965
18
2021-01-02
2021
1
2
6
20
38
7806
7965
19
2021-01-02
2021
1
2
6
21
47
7853
7965
20
2021-01-02
2021
1
2
6
22
15
7868
7965
21
2021-01-02
2021
1
2
6
23
97
7965
7965
22
2021-01-03
2021
1
3
7
0
147
147
8007
23
2021-01-03
2021
1
3
7
7
15
162
8007
24
2021-01-03
2021
1
3
7
8
54
216
8007
25
2021-01-03
2021
1
3
7
9
47
263
8007
26
2021-01-03
2021
1
3
7
10
16
279
8007
27
2021-01-03
2021
1
3
7
11
16
295
8007
28
2021-01-03
2021
1
3
7
12
61
356
8007
29
2021-01-03
2021
1
3
7
13
1459
1815
8007
30
2021-01-03
2021
1
3
7
14
2869
4684
8007
31
2021-01-03
2021
1
3
7
15
2670
7354
8007
32
2021-01-03
2021
1
3
7
16
131
7485
8007
33
2021-01-03
2021
1
3
7
17
67
7552
8007
34
2021-01-03
2021
1
3
7
18
27
7579
8007
35
2021-01-03
2021
1
3
7
19
50
7629
8007
36
2021-01-03
2021
1
3
7
20
48
7677
8007
37
2021-01-03
2021
1
3
7
22
119
7796
8007
38
2021-01-03
2021
1
3
7
23
211
8007
8007
39
2021-01-04
2021
1
4
1
4
19
19
6022
40
2021-01-04
2021
1
4
1
6
94
113
6022
41
2021-01-04
2021
1
4
1
10
48
161
6022
42
2021-01-04
2021
1
4
1
11
97
258
6022
43
2021-01-04
2021
1
4
1
12
48
306
6022
44
2021-01-04
2021
1
4
1
13
39
345
6022
45
2021-01-04
2021
1
4
1
14
499
844
6022
46
2021-01-04
2021
1
4
1
15
799
1643
6022
47
2021-01-04
2021
1
4
1
16
180
1823
6022
48
2021-01-04
2021
1
4
1
17
55
1878
6022
49
2021-01-04
2021
1
4
1
18
27
1905
6022
50
2021-01-04
2021
1
4
1
19
2246
4151
6022
51
2021-01-04
2021
1
4
1
20
1518
5669
6022
52
2021-01-04
2021
1
4
1
21
247
5916
6022
53
2021-01-04
2021
1
4
1
22
106
6022
6022
54
2021-01-05
2021
1
5
2
4
18
18
7623
55
2021-01-05
2021
1
5
2
6
44
62
7623
56
2021-01-05
2021
1
5
2
7
51
113
7623
57
2021-01-05
2021
1
5
2
8
450
563
7623
58
2021-01-05
2021
1
5
2
9
385
948
7623
59
2021-01-05
2021
1
5
2
10
469
1417
7623
60
2021-01-05
2021
1
5
2
11
254
1671
7623
61
2021-01-05
2021
1
5
2
12
1014
2685
7623
62
2021-01-05
2021
1
5
2
13
415
3100
7623
63
2021-01-05
2021
1
5
2
14
297
3397
7623
64
2021-01-05
2021
1
5
2
15
31
3428
7623
65
2021-01-05
2021
1
5
2
17
50
3478
7623
66
2021-01-05
2021
1
5
2
18
3771
7249
7623
67
2021-01-05
2021
1
5
2
19
52
7301
7623
68
2021-01-05
2021
1
5
2
20
96
7397
7623
69
2021-01-05
2021
1
5
2
21
59
7456
7623
70
2021-01-05
2021
1
5
2
22
167
7623
7623
71
2021-01-06
2021
1
6
3
6
54
54
7916
72
2021-01-06
2021
1
6
3
7
1223
1277
7916
73
2021-01-06
2021
1
6
3
8
118
1395
7916
74
2021-01-06
2021
1
6
3
10
77
1472
7916
75
2021-01-06
2021
1
6
3
11
709
2181
7916
76
2021-01-06
2021
1
6
3
12
123
2304
7916
77
2021-01-06
2021
1
6
3
13
36
2340
7916
78
2021-01-06
2021
1
6
3
14
14
2354
7916
79
2021-01-06
2021
1
6
3
15
156
2510
7916
80
2021-01-06
2021
1
6
3
16
149
2659
7916
81
2021-01-06
2021
1
6
3
17
995
3654
7916
82
2021-01-06
2021
1
6
3
18
2022
5676
7916
83
2021-01-06
2021
1
6
3
19
34
5710
7916
84
2021-01-06
2021
1
6
3
21
937
6647
7916
85
2021-01-06
2021
1
6
3
22
1208
7855
7916
86
2021-01-06
2021
1
6
3
23
61
7916
7916

Here you go.
Data:
Add Deneb visual and then add the following fields ensuring that don't summarise is selected for each column.
Inside Deneb, paste the following spec.
{
"data": {"name": "dataset"},
"transform": [
{
"calculate": "datum['weekday ']<= 5?'weekday':'weekend'",
"as": "type"
}
],
"layer": [
{"mark": {"type": "point"}},
{
"mark": {"type": "line", "interpolate":"basis"},
"encoding": {
"x": {
"field": "hour"
},
"y": {
"aggregate": "mean",
"field": "cumulative_daily_steps"
}
}
}
],
"encoding": {
"x": {
"field": "hour",
"type": "quantitative",
"axis": {"title": "Hour of Day"}
},
"y": {
"field": "cumulative_daily_steps",
"type": "quantitative",
"axis": {
"title": "Cumulative Step Count"
}
},
"color": {
"field": "type",
"type": "nominal",
"scale": {
"range": ["red", "green"]
},
"legend": {"title": ""}
}
}
}

Related

How to add a row where there is a disruption in series of numbers in Stata

I'm attempting to format a table of 40 different age-race-sex strata to be inputted into R-INLA and noticed that it's important to include all strata (even if they are not present in a county). These should be zeros. However, at this point my table only contains records for strata that are not empty. I can identify places where strata are missing for each county by looking at my strata variable and finding the breaks in the series 1 through 40 (marked with a red x in the image below).
In these places (marked by the red x) I need to add the missing rows and fill in the corresponding county code, strata code, population=0, and the correct corresponding race, sex, age code for the strata.
If I can figure out a way to add an empty row in the spaces with the red Xs from the image, and correctly assign the strata code (and county code) to these empty/missing rows, I am able to populate the rest of the values with the code below:
recode race = 1 & sex= 1 & age =4 if strata = 4
...etc
I'm wondering if there is a way to add the missing rows using an if statement that considers the fact that there are supposed to be forty strata for each county code. It would be ideal if this could populate the correct county code and strata code as well!
Dataex sample data:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float OID str5 fips_statecounty double population byte(race sex age) float strata
1 "" 672 1 1 1 1
2 "" 1048 1 1 2 2
3 "" 883 1 1 3 3
4 "" 1129 1 1 4 4
5 "" 574 1 2 1 5
6 "" 986 1 2 2 6
7 "" 899 1 2 3 7
8 "" 1820 1 2 4 8
9 "" 96 2 1 1 9
10 "" 142 2 1 2 10
11 "" 81 2 1 3 11
12 "" 99 2 1 4 12
13 "" 71 2 2 1 13
14 "" 125 2 2 2 14
15 "" 103 2 2 3 15
16 "" 162 2 2 4 16
17 "" 31 3 1 1 17
18 "" 32 3 1 2 18
19 "" 18 3 1 3 19
20 "" 31 3 1 4 20
21 "" 22 3 2 1 21
22 "" 28 3 2 2 22
23 "" 28 3 2 3 23
24 "" 44 3 2 4 24
25 "" 20 4 1 1 25
26 "" 24 4 1 2 26
27 "" 21 4 1 3 27
28 "" 43 4 1 4 28
29 "" 19 4 2 1 29
30 "" 26 4 2 2 30
31 "" 24 4 2 3 31
32 "" 58 4 2 4 32
33 "" 6 5 1 1 33
34 "" 11 5 1 2 34
35 "" 13 5 1 3 35
36 "" 7 5 1 4 36
37 "" 7 5 2 1 37
38 "" 9 5 2 2 38
39 "" 10 5 2 3 39
40 "" 11 5 2 4 40
41 "01001" 239 1 1 1 1
42 "01001" 464 1 1 2 2
43 "01001" 314 1 1 3 3
44 "01001" 232 1 1 4 4
45 "01001" 284 1 2 1 5
46 "01001" 580 1 2 2 6
47 "01001" 392 1 2 3 7
48 "01001" 440 1 2 4 8
49 "01001" 41 2 1 1 9
50 "01001" 38 2 1 2 10
51 "01001" 23 2 1 3 11
52 "01001" 26 2 1 4 12
53 "01001" 34 2 2 1 13
54 "01001" 52 2 2 2 14
55 "01001" 40 2 2 3 15
56 "01001" 50 2 2 4 16
57 "01001" 4 3 1 1 17
58 "01001" 2 3 1 2 18
59 "01001" 3 3 1 3 19
60 "01001" 6 3 2 1 21
61 "01001" 4 3 2 2 22
62 "01001" 6 3 2 3 23
63 "01001" 4 3 2 4 24
64 "01001" 1 4 1 4 28
65 "01003" 1424 1 1 1 1
66 "01003" 2415 1 1 2 2
67 "01003" 1680 1 1 3 3
68 "01003" 1823 1 1 4 4
69 "01003" 1545 1 2 1 5
70 "01003" 2592 1 2 2 6
71 "01003" 1916 1 2 3 7
72 "01003" 2527 1 2 4 8
73 "01003" 68 2 1 1 9
74 "01003" 82 2 1 2 10
75 "01003" 52 2 1 3 11
76 "01003" 54 2 1 4 12
77 "01003" 72 2 2 1 13
78 "01003" 129 2 2 2 14
79 "01003" 81 2 2 3 15
80 "01003" 106 2 2 4 16
81 "01003" 10 3 1 1 17
82 "01003" 14 3 1 2 18
83 "01003" 8 3 1 3 19
84 "01003" 4 3 1 4 20
85 "01003" 8 3 2 1 21
86 "01003" 14 3 2 2 22
87 "01003" 17 3 2 3 23
88 "01003" 10 3 2 4 24
89 "01003" 4 4 1 1 25
90 "01003" 1 4 1 3 27
91 "01003" 2 4 1 4 28
92 "01003" 2 4 2 1 29
93 "01003" 3 4 2 2 30
94 "01003" 4 4 2 3 31
95 "01003" 10 4 2 4 32
96 "01003" 5 5 1 1 33
97 "01003" 4 5 1 2 34
98 "01003" 3 5 1 3 35
99 "01003" 5 5 1 4 36
100 "01003" 5 5 2 2 38
end
label values race race
label values sex sex
My answer to your previous question
Nested for-loop: error variable already defined
detailed how to create a minimal dataset with all strata present. Therefore you should just merge that with your main dataset and replace missings on the absent strata with whatever your other software expects, zeros it seems.
The complication most obvious at this point is you need to factor in a county variable. I can't see any information on how many counties you have in your dataset, which may affect what is practical. You should be able to break down the preparation into: first, prepare a minimal county dataset with identifiers only; then merge that with a complete strata dataset.

Need help to understand QRegularExpression for my tasks

I have a QTextStream which contain:
Line1: 3 5 7 17 19 23 25
Line2: 3 5 7 17 19 23 26
Line3: 3 5 8 17 19 23 27
Line4: 3 5 9 17 21 35 37
Line5: 3 5 10 17 21 35 38
Line6: 3 5 11 17 21 35 39
Line7: 3 5 12 17 21 36 37
Line8: 3 5 13 17 21 37 38
Line9: 3 5 15 17 21 36 39
Line10: 3 5 16 17 21 37 38
I need to create regular expression to select only lines which contain numbers 3, 17 and 37.
Line4, 7, 8 and 10.
How to setup pattern?
Assuming they are ordered, you might use \b3\b.*\b17\b.*\b37\b.
So in C++, with raw string R"(\b3\b.*\b17\b.*\b37\b)".

Inserting tables with group and subgroup codes in SAS

First please consider the following list of WC variable...
1101 1201 1301 1401 1501 1601
1102 1202 1302 1402 1502 1602
1103 1203 1303 1403 1503 1603
1104 1204 1304 1404 1504 1604
1105 1205 1305 1405 1505 1605
1106 1206 1306 1406 1506 1606
1107 1207 1307 1407 1507 1607
1108 1208 1308 1408 1508 1608
1109 1209 1309 1409 1509 1609
1110 1210 1310 1410 1510 1610
1111 1211 1311 1411 1511 1611
1112 1212 1312 1412 1512 1612
1113 1213 1313 1413 1513 1613
1114 1214 1314 1414 1514 1614
1115 1215 1315 1415 1515 1615
1116 1216 1316 1416 1516 1616
1117 1217 1317 1417 1517 1617
1118 1218 1318 1418 1518 1618
1119
1120
Now understand what I am trying to achieve.
I have a very long dataset where in i have two variables are shown in the below table...
WC ASN
1101 0
1101 1
1101 2
1101 3
1101 4
1101 20
1101 21
1101 22
1101 23
1101 24
1101 25
1101 26
1101 27
1101 28
1101 45
1101 46
1101 47
1101 48
1201 4
1201 5
1201 6
1201 7
1201 8
1201 16
1201 17
1201 18
1201 19
1201 20
1201 28
1201 29
1201 30
1201 31
1201 32
1201 41
1201 42
1201 43
1201 44
1202 4
1202 5
1202 6
1202 7
1202 8
1202 16
1202 17
1202 18
1202 19
1202 20
1202 29
1202 30
1202 31
1202 32
1202 40
1202 41
1202 42
1202 43
1202 44
What I want to do is to add two more columns Group and SubGroup such that I get the final table as shown below:
WC ASN Group SubGroup
1101 0 1 1
1101 1 1 1
1101 2 1 1
1101 3 1 1
1101 4 1 1
1101 20 1 1
1101 21 1 1
1101 22 1 1
1101 23 1 1
1101 24 1 1
1101 25 1 1
1101 26 1 1
1101 27 1 1
1101 28 1 1
1101 45 1 1
1101 46 1 1
1101 47 1 1
1101 48 1 1
1201 4 1 2
1201 5 1 2
1201 6 1 2
1201 7 1 2
1201 8 1 2
1201 16 1 2
1201 17 1 2
1201 18 1 2
1201 19 1 2
1201 20 1 2
1201 28 1 2
1201 29 1 2
1201 30 1 2
1201 31 1 2
1201 32 1 2
1201 41 1 2
1201 42 1 2
1201 43 1 2
1201 44 1 2
1301 8 1 3
1301 9 1 3
1301 10 1 3
1301 11 1 3
1301 12 1 3
1301 13 1 3
1301 14 1 3
1301 15 1 3
1301 16 1 3
1301 32 1 3
1301 33 1 3
1301 34 1 3
1301 35 1 3
1301 36 1 3
1301 37 1 3
1301 38 1 3
1301 39 1 3
1301 40 1 3
1401 8 1 4
1401 9 1 4
1401 10 1 4
1401 11 1 4
1401 12 1 4
1401 13 1 4
1401 14 1 4
1401 15 1 4
1401 16 1 4
1401 33 1 4
1401 34 1 4
1401 35 1 4
1401 36 1 4
1401 37 1 4
1401 38 1 4
1401 39 1 4
1401 40 1 4
1501 4 1 5
1501 5 1 5
1501 6 1 5
1501 7 1 5
1501 8 1 5
1501 16 1 5
1501 17 1 5
1501 18 1 5
1501 19 1 5
1501 20 1 5
1501 29 1 5
1501 30 1 5
1501 31 1 5
1501 32 1 5
1501 40 1 5
1501 41 1 5
1501 42 1 5
1501 43 1 5
1501 44 1 5
1601 0 1 6
1601 1 1 6
1601 2 1 6
1601 3 1 6
1601 4 1 6
1601 20 1 6
1601 21 1 6
1601 22 1 6
1601 23 1 6
1601 24 1 6
1601 25 1 6
1601 26 1 6
1601 27 1 6
1601 28 1 6
1601 44 1 6
1601 45 1 6
1601 46 1 6
1601 47 1 6
1601 48 1 6
I was trying something like this...
select;
when (WC = 1101) group = 1 subgroup=1;
when (WC = 1201) group = 1 subgroup=2;
when (WC = 1301) group = 1 subgroup=3;
when (WC = 1401) group = 1 subgroup=4;
when (WC = 1501) group = 1 subgroup=5;
when (WC = 1601) group = 1 subgroup=6;
when (WC = 1102) group = 2 subgroup=1;
when (WC = 1202) group = 2 subgroup=2;
when (WC = 1302) group = 2 subgroup=3;
when (WC = 1402) group = 2 subgroup=4;
.
.
.
when (WC = 1617) group = 18 subgroup=5;
when (WC = 1618) group = 18 subgroup=6;
when (WC = 1119) group = 1 subgroup=1;
otherwise group = 20 subgroup=1;
end;
This is seriously long, tedious and confusing. I am sure there are better and short ways of doing it.
Please help.
As Joe and Keith suggested, I am adding this explanation.
WC in the table as the appear..
WC1 WC2 WC3 WC4 WC5 WC6 Group
1101 1201 1301 1401 1501 1601 1
1102 1202 1302 1402 1502 1602 2
1103 1203 1303 1403 1503 1603 3
.
.
.
WC ASN Group SubGroup
1101 0 1 1 (because last two digits are 01 and 2nd degit is 1)
.
.
1206 1 6 2
.
.
1201 2 1 2
.
.
1213 3 13 2
.
.
1610 4 10 6
Seems like a case for substr to me.
group = substr(wc,1,1);
subgroup = substr(wc,2,1);
Or whatever your rule is. If your rule is more complicated than that, explain the rule.

How to do _mm256_maskstore_epi8() in C/C++?

The problem
What I am trying to do is, if I have a vector of 27 (not 32!) int8_t:
x = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26}
I want to first cyclic-shift it to the right by n (not a constant), e.g. if n=1:
x2 = {26,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25}
Then this vector is used to perform some very complex calculation, but for simplicity, let's assume that the next step is just to cyclic-shift it back to the left by n, and store it to the memory. So I should have a new vector of 27 int8_t:
y = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26}
So there're thousands of such vectors and performance is very critical here. The CPU that we're using has AVX2 support so we want to use it to speed things up.
My current solution
To get x2, I use two _mm256_loadu_si256() with a _mm256_blendv_epi8():
int8_t x[31+27+31];
for(int i=0; i<27; i++){
x[31+i] = i;
}
__m256i mask = _mm256_set_epi32 (0x0, 0x00800000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0);
__m256i x_second_part = _mm256_loadu_si256((__m256i*)(x+31+1)); //{1,2,...,26}
__m256i x_first_part = _mm256_loadu_si256((__m256i*)(x+31-26)); //{0}
__m256i x2 = _mm256_blendv_epi8(x_second_part, x_first_part, mask); //{1,2,...,26, 0}
int8_t y[31+27+31];
_mm256_storeu_si256((__m256i*)(y+31-26), x2);
_mm256_storeu_si256((__m256i*)(y+31+1), x2);
The reason why the x and y are declared to be of size [31+27+31] is that in this case _mm256_loadu_si256() and _mm256_storeu_si256() won't cause segfault.
And I can get the value of y by:
for(int i=0; i<27; i++){
cout << (int)y[31+i] << ' ';
}
The new problem
Unfortunately all the vectors must be continuous in memory, for example, if there are totally two vectors that need to be processed:
x = {[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26];
[27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53]};
Then I cannot just use _mm256_storeu_si256() to put the value of y back to memory because when the value of the second vector is written to memory it will overwrite some values of the first vector:
int8_t x[31+27+27+31];
int8_t y[31+27+27+31];
for(int i=0; i<27*2; i++){
x[31+i] = i;
}
for(int i=0; i<2; i++){
__m256i mask = _mm256_set_epi32 (0x0, 0x00800000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0);
__m256i x_second_part = _mm256_loadu_si256((__m256i*)(x+31+27*i+1)); //{1,2,...,26}
__m256i x_first_part = _mm256_loadu_si256((__m256i*)(x+31+27*i-26)); //{0}
__m256i x2 = _mm256_blendv_epi8(x_second_part, x_first_part, mask); //{1,2,...,26, 0}
_mm256_storeu_si256((__m256i*)(y+31+27*i-26), x2);
_mm256_storeu_si256((__m256i*)(y+31+27*i+1), x2);
}
for(int i=0; i<27; i++){
cout << (int)y[31+i] << ' ';
}cout << endl;
for(int i=0; i<27; i++){
cout << (int)y[31+27+i] << ' ';
}cout << endl;
will output
0 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
instead of
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
So I was thinking of using maskstore. But in the Intel Intrinsic Guide I couldn't find _mm256_maskstore_epi8. This leads me back to the topic:
How to do _mm256_maskstore_epi8() in C/C++?
There is another implementation of cyclic-shift inside 27-bytes vector with using AVX2:
#include <iostream>
#include <immintrin.h>
const __m256i K0 = _mm256_setr_epi8(
0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0);
const __m256i K1 = _mm256_setr_epi8(
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70);
inline const __m256i Shuffle(const __m256i & value, const __m256i & shuffle)
{
return _mm256_or_si256(_mm256_shuffle_epi8(value, _mm256_add_epi8(shuffle, K0)),
_mm256_shuffle_epi8(_mm256_permute4x64_epi64(value, 0x4E), _mm256_add_epi8(shuffle, K1)));
}
__m256i shuffles[27];
void Init()
{
uint8_t * p = (uint8_t *)shuffles;
for (int s = 0; s < 27; ++s)
for (int i = 0; i < 32; ++i)
p[s*32 + i] = i < 27 ? (27 + i - s)%27 : i;
}
void CyclicShift27(const uint8_t * src, size_t shift, uint8_t * dst)
{
_mm256_storeu_si256((__m256i*)dst, Shuffle(_mm256_loadu_si256((__m256i*)src), shuffles[shift]));
}
int main()
{
Init();
uint8_t src[32] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 }, dst[32];
for (int j = 0; j < 27; ++j)
{
CyclicShift27(src, j, dst);
std::cout << "\t";
for (int i = 0; i < 32; i++)
std::cout << (int)dst[i] << ' ';
std::cout << std::endl;
}
return 0;
}
Output:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 27 28 29 30 31
25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 27 28 29 30 31
24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 27 28 29 30 31
23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 27 28 29 30 31
22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 27 28 29 30 31
21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 27 28 29 30 31
20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 27 28 29 30 31
19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 27 28 29 30 31
18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 27 28 29 30 31
17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 27 28 29 30 31
16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 27 28 29 30 31
15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 27 28 29 30 31
14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 27 28 29 30 31
13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 27 28 29 30 31
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 27 28 29 30 31
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 27 28 29 30 31
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 27 28 29 30 31
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 27 28 29 30 31
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 27 28 29 30 31
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 27 28 29 30 31
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 27 28 29 30 31
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 27 28 29 30 31
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 27 28 29 30 31
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 27 28 29 30 31
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 27 28 29 30 31
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 27 28 29 30 31
It looks more simple than my previous answer.
I have made an implementation of cyclic-shift inside 27-bytes vector with using of SSSE3:
#include <iostream>
#include <tmmintrin.h>
union Shuffle
{
uint8_t s[64];
__m128i v[4];
};
Shuffle shuffles[27];
int Shift(int value)
{
return (value >= 0 && value < 16) ? value : -1;
}
void Init()
{
for (int s = 0; s < 27; ++s)
{
for (int i = 0; i < 16; ++i)
{
shuffles[s].s[0 + i] = s < 16 ? Shift(i - s) : Shift(i - s + 27);
shuffles[s].s[16 + i] = Shift(16 + i - s);
shuffles[s].s[32 + i] = Shift(11 + i - s);
shuffles[s].s[48 + i] = s < 11 ? Shift(i - s) : Shift(i - s + 27);
}
}
}
void CyclicShift27(const uint8_t * src, size_t shift, uint8_t * dst)
{
__m128i srcLo = _mm_loadu_si128((__m128i*)(src + 0));
__m128i srcHi = _mm_loadu_si128((__m128i*)(src + 11));
__m128i dstLo = _mm_or_si128(_mm_shuffle_epi8(srcLo, shuffles[shift].v[0]), _mm_shuffle_epi8(srcHi, shuffles[shift].v[1]));
__m128i dstHi = _mm_or_si128(_mm_shuffle_epi8(srcLo, shuffles[shift].v[2]), _mm_shuffle_epi8(srcHi, shuffles[shift].v[3]));
_mm_storeu_si128((__m128i*)(dst + 0), dstLo);
_mm_storeu_si128((__m128i*)(dst + 11), dstHi);
}
int main()
{
Init();
uint8_t src[27] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26 }, dst[27];
for (int j = 0; j < 27; ++j)
{
CyclicShift27(src, j, dst);
for (int i = 0; i < 27; i++)
std::cout << (int)dst[i] << ' ';
std::cout << std::endl;
}
return 0;
}
It output:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12 13
13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11 12
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10 11
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9 10
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8 9
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7 8
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6 7
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5 6
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4 5
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3 4
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2 3
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1 2
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0
I hope it will be useful.

Regular Expression complex serie with specific pattern

I will try to explain what I need help with.
The numbers in below series that I want to check by the regex, are "2 904", "3 231", "2 653", "2 653", "2 353" and so on. My goal is to only get a match if one of these numbers will be in format "123" (3-digits, between 100-999)
No match:
sö 31 1 2 904 2 3 231 3 2 653 32 4 2 653 5 2 353 6 2 353 7 2 353 8 2 904 9 3 002 10 3 143 33 11 2 615 12 2 353 13 2 353 14 2 353 15 2 353 16 2 653 17 2 353 34 18 2 157 19 1 699 20 1 699
Match:
sö 31 1 2 904 2 3 231 3 653 32 4 2 653 5 2 353 6 2 353 7 2 353 8 2 904 9 3 002 10 3 143 33 11 2 615 12 2 353 13 2 353 14 2 353 15 2 353 16 2 653 17 2 353 34 18 2 157 19 1 699 20 1 699
sö 31 1 2 904 2 3 231 3 2 653 32 4 2 653 5 2 353 6 2 353 7 2 353 8 2 904 9 3 002 10 3 143 33 11 2 615 12 2 353 13 2 353 14 953 15 2 353 16 2 653 17 2 353 34 18 2 157 19 1 699 20 1 699
As you can see from my examples, number "2 653" changed to "653" just after number "3"
And number " 2 353" changed to "953" after number "14".
Numbers between, i.e 1-20, are static numbers and will never change
Possible?
I will try it then at http://rubular.com/