|
1 | | -import std / [math, algorithm, tables, sequtils] |
| 1 | +import std / [math, algorithm, tables, sequtils, strutils] |
2 | 2 | import arraymancer |
3 | 3 | import ./utils |
4 | 4 |
|
@@ -34,18 +34,13 @@ iterator neighbours*[T](grid: RbfGrid[T], k: int): int = |
34 | 34 | var kNeigh = k |
35 | 35 | for i, x in dir: |
36 | 36 | let step = grid.gridSize ^ (grid.gridDim - i - 1) |
37 | | - if i == dir.high and k mod grid.gridSize == 0 and x == -1: |
| 37 | + if (k div step) mod grid.gridSize == 0 and x == -1: |
38 | 38 | break loopBody |
39 | | - elif i == dir.high and k mod grid.gridSize == grid.gridSize - 1 and x == 1: |
40 | | - break loopBody |
41 | | - elif k div step == 0 and x == -1: |
42 | | - break loopBody |
43 | | - elif k div step == grid.gridSize - 1 and x == 1: |
| 39 | + elif (k div step) mod grid.gridSize == grid.gridSize - 1 and x == 1: |
44 | 40 | break loopBody |
45 | 41 | else: |
46 | 42 | kNeigh += x * step |
47 | 43 | if kNeigh >= 0 and kNeigh < grid.gridSize ^ grid.gridDim: |
48 | | - echo kNeigh, ": ", dir |
49 | 44 | yield kNeigh |
50 | 45 |
|
51 | 46 |
|
@@ -147,7 +142,7 @@ proc newRbfPu*[T](points: Tensor[float], values: Tensor[T], gridSize: int = 0, r |
147 | 142 | for i in 0 ..< nPatches: |
148 | 143 | let indices = dataGrid.findAllWithin(patchPoints[i, _], dataGrid.gridDelta) |
149 | 144 | if indices.len > 0: |
150 | | - patchRbfs.add newRbf(dataGrid.points[indices,_], values[indices, _], epsilon=dataGrid.gridDelta) |
| 145 | + patchRbfs.add newRbf(dataGrid.points[indices,_], values[indices, _], epsilon=epsilon) |
151 | 146 | patchIndices.add i |
152 | 147 |
|
153 | 148 | let patchGrid = newRbfGrid(patchPoints[patchIndices, _], patchRbfs.toTensor.unsqueeze(1), gridSize) |
@@ -194,8 +189,8 @@ when isMainModule: |
194 | 189 |
|
195 | 190 | #echo rbfPu.eval(sqrt x1) |
196 | 191 | echo "----------------" |
197 | | - let xGrid = [[0.1, 0.1], [0.2, 0.3], [0.9, 0.9], [0.4, 0.4]].toTensor |
| 192 | + #[ let xGrid = [[0.1, 0.1], [0.2, 0.3], [0.9, 0.9], [0.4, 0.4]].toTensor |
198 | 193 | let valuesGrid = @[0, 1, 9, 5].toTensor.reshape(4, 1) |
199 | | - let grid = newRbfGrid(xGrid, valuesGrid, 3) |
| 194 | + let grid = newRbfGrid(xGrid, valuesGrid, 2) |
200 | 195 | echo grid |
201 | | - echo grid.neighbours(8).toSeq |
| 196 | + echo grid.neighbours(3).toSeq ]# |
0 commit comments