GNU DC displays the stack vertically, (f displays the stack)
1 2 3 4
f # to display the stack
4
3
2
1
Is there a way to change this to be more like FORTH? While GNU FORTH displays the stack horizontally, (.s displays the stack)
1 2 3 4 ok
.s <4> 1 2 3 4 ok
You can create custom function in ~/.dcrc which is read each time dc start.
cat ~/.dcrc
[
# if the stack is empty
[ 2 + [stack empty] p 0 :- Q ]s-
z d 0 =- 0 :-
# keep the stack in indexed array -
[ z :- z 0 <- ]s-
l-x
# restore the stack
[ 0 ;- 1 + d ;- ;- r d ;- 1 + r :- 0 ;- d 1 + ;- r !<- ]s-
1 0 ;- 1 + :-
l-x
# displays the stack horizontally
[ 0 ;- d 1 + d ;- ;- n [ ] n d d ;- 1 + r :- ;- !>- ]s-
1 0 ;- 1 + :- l-x [ ok] p 0 :-
]s-
You call it this way :
echo '7 16 8 9' | dc -f - -e 'l-x f'
and you get :
7 16 8 9 ok
9
8
16
7
You cannot use register -
Related
In this table it's easy to find that column E is the first match for the value 3.
How do I find the column of the last match of 3 which will be column I
A B C D E F G H I J K L
6 6 9 9 3 3 2 2 3 1 1 1
Use this formula
=ArrayFormula(Substitute(Address(1,MAX(IF(REGEXMATCH(A1:L1,3&"")<>TRUE,,COLUMN(A1:L1))),4),"1",""))
try:
=SUBSTITUTE(ADDRESS(2, XMATCH(3, A2:P2,, -1), 4), 2, )
=ADDRESS(2, XMATCH(3, A2:P2,, -1), 4)
=XLOOKUP(3, A2:P2, A1:P1,,, -1)
XMATCH has a reverse search feature. Set search_mode top -1 to activate:
=INDEX(1:1,XMATCH(3,2:2,,-1))
(A1)A
B
C
D
E
F
G
H
I
J
K
L
6
6
9
9
3
3
2
2
3
1
1
1
Result:
I
I have this data frame
AutoStat_1 AutoStat_2 Mode_1 Mode_2 Setpoint_1 Setpoint_2
0 -> 0 0 1 1 23 24
1 -> 0 1 1 0 23 27
2 -> 1 1 3 0 26 27
3 -> 1 0 3 1 26 24
4 -> 0 0 1 2 24 24
5 -> 0 0 1 2 24 24
6 -> 2 3 0 4 24 26
7 -> 2 3 0 4 25 26
The requirement is that if AutoStat_i is not 0 then Mode_i and Setpoint_i will be the value of the above (in-front) of which AutoStat_i is 0
The result should be (notice the column Setpoint_i and Mode_i are different than above)
AutoStat_1 AutoStat_2 Mode_1 Mode_2 Setpoint_1 Setpoint_2
0 -> 0 0 1 1 23 24
1 -> 0 1 1 1 23 24
2 -> 1 1 1 1 23 24
3 -> 1 0 1 1 23 24
4 -> 0 0 1 2 24 24
5 -> 0 0 1 2 24 24
6 -> 2 3 1 2 24 24
7 -> 2 3 1 2 24 24
What've I tried:
My idea is for each set i of (AutoStat_i, Mode_i, Setpoint_i), scan each row if AutoStat_i is <> 0 then set the other values to NaN, after that I will just do the fillMissing with Direction.Forward. Below is the impementation
let calculateNonSFi (df:Frame<_,string>) idx =
let autoStatusName = sprintf "AutoStat_%d" idx
let setpointName = sprintf "Setpoint_%d" idx
let modeName = sprintf "Mode_%d" idx
let setMissingOnMode (s:ObjectSeries<string>) =
let s2 = s.As<float>()
if s2.[autoStatusName] <> 0. then
Series.replaceArray [|setpointName;modeName|] Double.NaN s2
else
s2
df.Rows
|> Series.mapValues setMissingOnMode
|> Frame.ofRows
|> Frame.fillMissing Direction.Forward
|> Frame.fillMissing Direction.Backward
// for each set i do the folding
[0..150]
|> List.fold calculateNonSFi df
It gave me the expected results, however, for 150sets of 8000rows, it took more than 30 minutes to complete. I kinda see where it's wrong as for every set it acts on the whole dataset but I cannot think of a better way.
The logic is quite simple. I believe there should be a better way, do advice, thanks.
UPDATE
Here is the code for reproduction
open Deedle
open System
let df =
[
{| AutoStat_1=0;Setpoint_1=23;Mode_1=1;AutoStat_2=0;Setpoint_2=24;Mode_2=1|}
{| AutoStat_1=0;Setpoint_1=23;Mode_1=1;AutoStat_2=1;Setpoint_2=24;Mode_2=1|}
{| AutoStat_1=1;Setpoint_1=23;Mode_1=1;AutoStat_2=1;Setpoint_2=24;Mode_2=1|}
{| AutoStat_1=1;Setpoint_1=23;Mode_1=1;AutoStat_2=0;Setpoint_2=24;Mode_2=1|}
{| AutoStat_1=0;Setpoint_1=24;Mode_1=1;AutoStat_2=0;Setpoint_2=24;Mode_2=2|}
{| AutoStat_1=0;Setpoint_1=24;Mode_1=1;AutoStat_2=0;Setpoint_2=24;Mode_2=2|}
{| AutoStat_1=2;Setpoint_1=24;Mode_1=1;AutoStat_2=3;Setpoint_2=24;Mode_2=2|}
{| AutoStat_1=2;Setpoint_1=24;Mode_1=1;AutoStat_2=3;Setpoint_2=24;Mode_2=2|}
] |> Frame.ofRecords
df.Print()
let calculateNonSFi (df:Frame<_,string>) idx =
let autoStatusName = sprintf "AutoStat_%d" idx
let setpointName = sprintf "Setpoint_%d" idx
let modeName = sprintf "Mode_%d" idx
let setMissingOnMode (s:ObjectSeries<string>) =
let s2 = s.As<float>()
if s2.[autoStatusName] <> 0. then
Series.replaceArray [|setpointName;modeName|] Double.NaN s2
else
s2
df.Rows
|> Series.mapValues setMissingOnMode
|> Frame.ofRows
|> Frame.fillMissing Direction.Forward
let df1 =
[1..2]
|> List.fold calculateNonSFi df
df1.Print()
Advice/Answer from Tomas
df
|> Frame.mapRows (fun _ o ->
[ for i in 0 .. 150 do
let au = o.GetAs<float>("AutoStat_" + string i)
yield "AutoStat_" + string i, au
yield "Mode_" + string i, if au <> 0. then nan else o.GetAs("Mode_" + string i)
yield "Setpoint_" + string i, if au <> 0. then nan else o.GetAs("Setpoint_" + string i) ]
|> series )
|> Frame.ofRows
|> Frame.fillMissing Direction.Forward
which yields correct result but in different column order hence my mistake in the earlier edit
AutoStat_1 Mode_1 Setpoint_1 AutoStat_2 Mode_2 Setpoint_2
0 -> 0 1 23 0 1 24
1 -> 0 1 23 1 1 24
2 -> 1 1 23 1 1 24
3 -> 1 1 23 0 1 24
4 -> 0 1 24 0 2 24
5 -> 0 1 24 0 2 24
6 -> 2 1 24 3 2 24
7 -> 2 1 24 3 2 24
First of all, I think your strategy of setting Mode_i and Setpoint_i to NA when AutoStat_i is not 0 and then filling the missing values is a nice approach.
You can certainly make it a bit faster by moving the fillMissing call outside of the calculateNonSFi function - the fillMissing operation will run on the whole frame, so you need to run this once at the end.
The second thing would be to find a way of setting the NA values that only iterates over the frame once. One option (I have not tested this) would be to use Frame.mapRows and, inside the function, iterate over all the columns (rather than iterating over all the columns and calling mapRows repeatedly). Something like:
df
|> Frame.mapRows (fun _ o ->
[ for i in 0 .. 150 do
let au = o.GetAs<float>("AutoStat_" + string i)
yield "AutoStat_" + string i, au
yield "Mode_" + string i, if au = 0. then nan else o.GetAs("Mode_" + string i)
yield "Setpoint_" + string i, if au = 0. then nan else o.GetAs("Setpoint_" + string i) ]
|> series )
|> Frame.ofRows
I have an matrix in Maxima, let´s say (for simplification of the problem):
A: matrix([2*(a^2+b^2+c^2)])
But I know that:
a^2+b^2+c^2 = 1
How do I simplify that matrix in Maxima in terms of that equation, in order to obtain A = [2]?
I found the solution:
A: matrix([2*(a^2+b^2+c^2)]);
eq: a^2+b^2+c^2 = 1;
scsimp(A, eq);
You can use tellrat.
(%i1) A:matrix([2*(a^2+b^2+c^2)])
(%o1) [ 2 2 2 ]
[ 2 (c + b + a ) ]
(%i2) a^2+b^2+c^2 = 1
2 2 2
(%o2) c + b + a = 1
(%i3) solve(%,a^2)
2 2 2
(%o3) [a = (- c ) - b + 1]
(%i4) tellrat(%[1])
2 2 2
(%o4) [c + b + a - 1]
(%i5) algebraic:true
(%o5) true
(%i6) rat(A)
(%o6)/R/ [ 2 ]
(%i7) untellrat(a)
(%o7) []
blktrace version v2.0.0
note: in blkparse output, the m in the sixth column indicate the line is scheduler information.
On Ubuntu 16.04 ext4 I can see the IO Scheduler message, blktrace -d /dev/sda -o - | blkparse -i -
8,0 3 1 0.000000000 24714 A WS 76519424 + 2048 <- (8,1) 76517376
8,0 3 2 0.000000861 24714 Q WS 76519424 + 2048 [TaskSchedulerFo]
8,0 3 3 0.000005084 24714 X WS 76519424 / 76520768 [TaskSchedulerFo]
8,0 3 4 0.000008962 24714 G WS 76519424 + 1344 [TaskSchedulerFo]
8,0 3 5 0.000009379 24714 P N [TaskSchedulerFo]
8,0 3 6 0.000012021 24714 G WS 76520768 + 704 [TaskSchedulerFo]
8,0 3 7 0.000012622 24714 I WS 76519424 + 1344 [TaskSchedulerFo]
8,0 3 0 0.000015209 0 m N cfq24714SN /user.slice insert_request
8,0 3 0 0.000016074 0 m N cfq24714SN /user.slice add_to_rr
8,0 3 0 0.000017548 0 m N cfq24714SN /user.slice preempt
8,0 3 0 0.000018184 0 m N cfq25055SN /user.slice slice expired t=1
8,0 3 0 0.000018982 0 m N cfq25055SN /user.slice resid=-2643710186
8,0 3 0 0.000020125 0 m N /user.slice served: vt=247310740068 min_vt=247310580285
8,0 3 0 0.000021297 0 m N cfq25055SN /user.slice sl_used=33325195 disp=13 charge=13 iops=1 sect=1088
8,0 3 0 0.000021822 0 m N cfq25055SN /user.slice del_from_rr
8,0 3 0 0.000023767 0 m N cfq workload slice:100000000
8,0 3 0 0.000024496 0 m N cfq24714SN /user.slice set_active wl_class:0 wl_type:1
8,0 3 0 0.000025395 0 m N cfq24714SN /user.slice dispatch_insert
8,0 3 0 0.000026232 0 m N cfq24714SN /user.slice dispatched a request
8,0 3 0 0.000026818 0 m N cfq24714SN /user.slice activate rq, drv=1
8,0 3 8 0.000027030 24714 D WS 76519424 + 1344 [TaskSchedulerFo]
8,0 3 9 0.000037848 24714 U N [TaskSchedulerFo] 1
8,0 3 10 0.000038118 24714 P N [TaskSchedulerFo]
8,0 3 11 0.000048153 24714 A WS 76521472 + 264 <- (8,1) 76519424
8,0 3 12 0.000048340 24714 Q WS 76521472 + 264 [TaskSchedulerFo]
8,0 3 13 0.000049444 24714 M WS 76521472 + 264 [TaskSchedulerFo]
8,0 3 14 0.000050486 24714 I WS 76520768 + 968 [TaskSchedulerFo]
8,0 3 0 0.000051332 0 m N cfq24714SN /user.slice insert_request
8,0 3 15 0.000051755 24714 U N [TaskSchedulerFo] 1
8,0 3 0 0.000052418 0 m N cfq24714SN /user.slice dispatch_insert
8,0 3 0 0.000053068 0 m N cfq24714SN /user.slice dispatched a request
8,0 3 0 0.000053604 0 m N cfq24714SN /user.slice activate rq, drv=2
8,0 3 16 0.000053721 24714 D WS 76520768 + 968 [TaskSchedulerFo]
8,0 2 1 0.001844211 0 C WS 76519424 + 1344 [0]
8,0 2 0 0.001849143 0 m N cfq24714SN /user.slice complete rqnoi
on CentOS 7.4 xfs,I can not see the IO Scheduler message, blktrace -d /dev/sdb -o - | blkparse -i -
8,16 25 1 0.000000000 11966 Q R 73400472 + 128 [fio]
8,16 25 2 0.000006237 11966 G R 73400472 + 128 [fio]
8,16 25 3 0.000007806 11966 P N [fio]
8,16 25 4 0.000010836 11966 I R 73400472 + 128 [fio]
8,16 25 5 0.000011878 11966 U N [fio] 1
8,16 25 6 0.000013900 11966 D R 73400472 + 128 [fio]
8,16 10 1 0.008284979 0 C R 73400472 + 128 [0]
8,16 10 2 0.008343574 11966 Q R 73400600 + 128 [fio]
8,16 10 3 0.008345976 11966 G R 73400600 + 128 [fio]
8,16 10 4 0.008346908 11966 P N [fio]
8,16 10 5 0.008348926 11966 I R 73400600 + 128 [fio]
8,16 10 6 0.008349651 11966 U N [fio] 1
8,16 10 7 0.008350694 11966 D R 73400600 + 128 [fio]
8,16 8 1 0.008771249 0 C R 73400600 + 128 [0]
While there are program version differences between the setups (in CentOS 7 blktrace is version 1.0.5 and the kernel is based off 3.10 whereas in Ubuntu 16.04 blktrace is version 1.1.0 and the kernel may be between 4.4 - 4.10) the real point may be down to what was asked (but unfortunately went unanswered) in one of the comments:
what [I/O] scheduler was in use
If we look at one of your m lines:
8,0 3 0 0.000015209 0 m N cfq24714SN /user.slice insert_request
we can see that it is a textual message (hence the m) and that it likely came from the CFQ I/O scheduler (hence the cfq prefix on the message itself). If the I/O scheduler being used for the /dev/sdb device on the CentOS 7 setup was not CFQ (e.g. because the noop I/O scheduler was being used) then we cannot expect similar messages to be present.
So bringing this back to the title of the question:
blkparse how to show IO Scheduler message
If an I/O scheduler wants to it can send free form blktrace text (e.g. see block/cfq-iosched.c which has calls to blk_add_trace_msg() in it) but not all I/O schedulers do (e.g. see block/noop-iosched.c which doesn't even include the linux/blktrace_api.h header). By default blkparse will show all messages present unless you use the -M option to suppress them.
I would like to implement a bandpass filter using GPUImageColorMatrixFilter. Basically, blue would equal floor(blue - (k*red)) and both red and green would just end up being zero. Where can I find documentation indicating what the columns and rows of the matrix mean?
My intuition would suggest that the 4x4 matrix is following the standard RGBA order and judging by the examples (see for instance GPUImageSepiaFilter) it looks like I'm right.
For instance, this is the identity GPUMatrix4x4
R G B A
| 1 0 0 0 | red
| 0 1 0 0 | green
| 0 0 1 0 | blue
| 0 0 0 1 | alpha
Let's name each coefficient
R G B A
| a b c d | red
| e f g h | green
| i j k l | blue
| m n o p | alpha
Applying the matrix to a RGBA color will result in the following R'G'B'A' color where the components are computed as
R' = a*R + b*G + c*B + d*A
G' = e*R + f*G + g*B + h*A
B' = i*R + j*G + k*B + l*A
A' = m*R + n*G + o*B + p*A
which is nothing but the following matrix multiplication
| a b c d | |R| |R'|
| e f g h | x |G| = |G'|
| i j k l | |B| |B'|
| m n o p | |A| |A'|