-
Notifications
You must be signed in to change notification settings - Fork 0
/
CWrapper.go
68 lines (51 loc) · 1.88 KB
/
CWrapper.go
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import "C"
import (
"encoding/binary"
"./GoChest"
"math"
"unsafe"
)
//export ListEstimator
func ListEstimator(inpSequence unsafe.Pointer, inpLength C.int, inpMinimumDistance C.float) uintptr {
byteSequence := C.GoBytes(inpSequence, inpLength)
length := int(inpLength)
minimumDistance := float64(inpMinimumDistance)
goSequence := make([]float64, length/8)
for i := 0; i < length; i += 8 {
bits := binary.LittleEndian.Uint64(byteSequence[i : i+8])
goSequence[i/8] = math.Float64frombits(bits)
}
changepoints := GoChest.ListEstimator(goSequence, minimumDistance, 1)
// First value of the output is the length of the array
output := make([]byte, (len(changepoints)+1)*8)
bytes := make([]byte, 8)
for index, value := range append([]int{len(changepoints)}, changepoints...) {
binary.LittleEndian.PutUint32(bytes, uint32(value))
copy(output[index*8:(index+1)*8], bytes)
}
return uintptr(unsafe.Pointer(&output[0]))
}
//export FindChangepoints
func FindChangepoints(inpSequence unsafe.Pointer, inpLength C.int, inpMinimumDistance C.float, inpProcessCount C.int) uintptr {
byteSequence := C.GoBytes(inpSequence, inpLength)
length := int(inpLength)
processCount := int(inpProcessCount)
minimumDistance := float64(inpMinimumDistance)
goSequence := make([]float64, length/8)
for i := 0; i < length; i += 8 {
bits := binary.LittleEndian.Uint64(byteSequence[i : i+8])
goSequence[i/8] = math.Float64frombits(bits)
}
changepoints := GoChest.FindChangepoints(goSequence, minimumDistance, processCount, 1)
// First value of the output is the length of the array
output := make([]byte, (len(changepoints)+1)*8)
bytes := make([]byte, 8)
for index, value := range append([]int{len(changepoints)}, changepoints...) {
binary.LittleEndian.PutUint32(bytes, uint32(value))
copy(output[index*8:(index+1)*8], bytes)
}
return uintptr(unsafe.Pointer(&output[0]))
}
func main() {
}