/ reference / nim / proof_input / src / dataset.nim
dataset.nim
 1  
 2  #import sugar
 3  
 4  #import std/streams
 5  #import std/sequtils
 6  
 7  import types
 8  import slot
 9  #import blocks
10  
11  #-------------------------------------------------------------------------------
12  # Example slot configuration
13  #
14  
15  const exDataSetCfg* = 
16    DataSetConfig( nCells:   256  # 1024
17                 , nSamples: 7    # 20
18                 , nSlots:   5
19                 , dataSrc:  DataSource(kind: FakeData, seed: 12345)
20                 )
21  
22  const exGlobalCfg* = 
23    GlobalConfig( maxDepth:       16
24                , maxLog2NSlots:  5     
25                , cellSize:       256
26                , blockSize:      4096          
27                )
28  
29  #-------------------------------------------------------------------------------
30  
31  {.overflowChecks: off.}
32  func parametricSlotSeed( seed: Seed, k: SlotIdx): Seed = (seed + 72 + 1001*uint64(k))
33  
34  func parametricSlotFileName( basefile: string, k: SlotIdx): string = basefile & ($k) & ".dat"
35  
36  func parametricSlotDataSource( src: DataSource, k: SlotIdx): DataSource = 
37    case src.kind
38      of FakeData:
39        return DataSource(kind: FakeData, seed: parametricSlotSeed(src.seed, k))
40      of SlotFile:
41        return DataSource(kind: SlotFile, filename: parametricSlotFileName(src.filename, k))
42  
43  #-------------------------------------------------------------------------------
44  
45  func slotCfgFromDataSetCfg*( dsetcfg: DataSetConfig, idx: SlotIdx ): SlotConfig =
46    assert( idx >= 0 and idx < dsetcfg.nSlots )
47    let newDataSrc = parametricSlotDataSource( dsetcfg.dataSrc, idx )
48    return SlotConfig( nCells:   dsetcfg.nCells
49                     , nSamples: dsetcfg.nSamples
50                     , dataSrc:  newDataSrc
51                     )
52  
53  #-------------------------------------------------------------------------------
54  
55  proc dataSetLoadCellData*(globCfg: GlobalConfig, dsetCfg: DataSetConfig, slotIdx: SlotIdx, cellIdx: CellIdx): Cell =
56    let slotCfg = slotCfgFromDataSetCfg( dsetCfg, slotIdx )
57    return slotLoadCellData(globCfg, slotCfg, cellIdx)
58  
59  proc dataSetLoadBlockData*(globCfg: GlobalConfig, dsetCfg: DataSetConfig, slotIdx: SlotIdx, blockIdx: BlockIdx): Block =
60    let slotCfg = slotCfgFromDataSetCfg( dsetCfg, slotIdx )
61    return slotLoadBlockData(globCfg, slotCfg, blockIdx)
62  
63  #-------------------------------------------------------------------------------