llgo/ssa: PyList
This commit is contained in:
@@ -6,24 +6,17 @@ import (
|
||||
"github.com/goplus/llgo/py/numpy"
|
||||
)
|
||||
|
||||
func matrix(row, col int, vals ...float64) *py.Object {
|
||||
if len(vals) != row*col {
|
||||
panic("invalid matrix size")
|
||||
}
|
||||
rows := py.NewList(uintptr(row))
|
||||
for i := 0; i < row; i++ {
|
||||
cols := py.NewList(uintptr(col))
|
||||
for j := 0; j < col; j++ {
|
||||
cols.ListSetItem(uintptr(j), py.Float(vals[i*col+j]))
|
||||
}
|
||||
rows.ListSetItem(uintptr(i), cols)
|
||||
}
|
||||
return numpy.Array(rows, nil)
|
||||
}
|
||||
|
||||
func main() {
|
||||
a := matrix(3, 3, 1, 2, 3, 4, 5, 6, 7, 8, 9)
|
||||
b := matrix(3, 3, 9, 8, 7, 6, 5, 4, 3, 2, 1)
|
||||
a := py.List(
|
||||
py.List(1.0, 2.0, 3.0),
|
||||
py.List(4.0, 5.0, 6.0),
|
||||
py.List(7.0, 8.0, 9.0),
|
||||
)
|
||||
b := py.List(
|
||||
py.List(9.0, 8.0, 7.0),
|
||||
py.List(6.0, 5.0, 4.0),
|
||||
py.List(3.0, 2.0, 1.0),
|
||||
)
|
||||
x := numpy.Add(a, b)
|
||||
c.Printf(c.Str("a = %s\n"), a.Str().CStr())
|
||||
c.Printf(c.Str("a = %s\n"), b.Str().CStr())
|
||||
|
||||
Reference in New Issue
Block a user