gopherdata / gophernotes

The Go kernel for Jupyter notebooks and nteract.
MIT License
3.84k stars 265 forks source link

reflect convert unimplemented #204

Closed ajinwu closed 4 years ago

ajinwu commented 4 years ago

hello, I have a problem. In jupyter go, I use pointers to convert types, but the prompt does not implement pointer conversion, but I have no problem in vscode. Please refer to the official compiled implementation

my platform: ubuntu 19.10 go version: cat VERSION go1.14 install method: in my pc, use my jupyter

this is code

System.out.println("Hello to see U!");
var a = []float64{4, 2, 5, 7, 2, 1, 88, 1}

func SortFloat64FastV1(a []float64) {
// 强制类型转换
    var b []int = ((*[1 << 20]int)(unsafe.Pointer(&a[0])))[:len(a):cap(a)]

    // 以int方式给float64排序
    sort.Ints(b)
}

func SortFloat64FastV2(a []float64) {
    // 通过 reflect.SliceHeader 更新切片头部信息实现转换
    var c []int
    aHdr := (*reflect.SliceHeader)(unsafe.Pointer(&a))
    cHdr := (*reflect.SliceHeader)(unsafe.Pointer(&c))
    *cHdr = *aHdr

    // 以int方式给float64排序
    sort.Ints(c)
}

errors: repl.go:5:54: unimplemented conversion from <float64> to with reflect.Type <float64> to

thanks very much

cosmos72 commented 4 years ago

Yes, it's a limitation of the interpreter.

Unluckily it's basically impossible to implement unsafe.Pointer in an interpreter which is written itself in Go - any reasonable implementation would need many more (unsafe) features than the ones provided by the Go language

ajinwu commented 4 years ago

Yes, it's a limitation of the interpreter.

Unluckily it's basically impossible to implement unsafe.Pointer in an interpreter which is written itself in Go - any reasonable implementation would need many more (unsafe) features than the ones provided by the Go language

thanks very much