createDeviceEngine

Note: This function is not supported by Community Edition. You can get a trial of Shark from DolphinDB official website.

Syntax

createDeviceEngine(name, metrics, dummyTable, outputTable, keyColumn,[keepOrder])

Arguments

name is a string of the engine name. It is the only identifier of a reactive state engine on a data/compute node. It can have letter, number and "_" and must start with a letter.

metrics is metacode specifying the formulas for calculation. For more information about metacode refer to Metaprogramming.

dummyTable is a table object whose schema must be the same as the subscribed stream table. Whether dummyTable contains data does not matter.

outputTable is the output table for the results. It can be an in-memory table or a DFS table. Create an empty table and specify the column names and types before calling the function.

keyColumn is a STRING scalar/vector indicating the grouping column(s).

keepOrder (optional) specifies whether to preserve the insertion order of the records in the output table. The default value is false, meaning data is sorted by keyColumn.

Details

Create a device engine which conducts the calculations defined in the metrics with GPU acceleration.

The following functions can be accelerated using GPUs:

  • Basic unary operation: not, neg, cast, log, log2, log10, log1p, abs, sign

  • Basic binary operation: add, sub, mul, div, ratio, pow, lt, gt, eq, ne, and, or

  • Binary operation on integers: mod, bitAnd, bitOr, bitXor, lshift, rshift

  • Ternary operation: iif

  • Unary moving function: mavg, msum, mcount, mprod, mvar, mvarp, mstd, mstdp, mmin, mmax, mimin, mimax, sma, wma, mfirst, mlast, mrank, mmaxPositiveStreak, mmed, mpercentile, mmad

  • Binary moving function: mcorr, mbeta, mcovar, mwsum, mwavg

  • Other moving function: linearTimeTrend, mslr

  • Unary cumulative function: cumsum, cumprod, cummin, cummax, cumvar, cumvarp, cumstd, cumstdp

  • Order-sensitive function: deltas, ratios, ffill, move, prev, percentChange, iterate, prevState

Details

// create a device engine
dummyTb = table(1:0, `sym`id`value, [SYMBOL,INT,DOUBLE])
result = table(100:0, `sym`id`value`factor, [SYMBOL,INT,DOUBLE,DOUBLE])
de = createDeviceEngine(name="myDe", metrics=[<id>,<value>,<mavg(value,5)>], dummyTable=dummyTb, outputTable=result, keyColumn="sym")


// simulate data
data1 = table(take("A", 100) as sym, 1..100 as id, double(10+1..100) as value)
data2 = table(take("B", 100) as sym, 1..100 as id, double(20+1..100) as value)
data3 = table(take("C", 100) as sym, 1..100 as id, double(30+1..100) as value)
data = data1.unionAll(data2).unionAll(data3).sortBy!(`id)

// write data
de.append!(data)
select top 10 * from result
sym id value factor
A 1 11
A 2 12
A 3 13
A 4 14
A 5 15 13
A 6 16 14
A 7 17 15
A 8 18 16
A 9 19 17
A 10 20 18