本文整理汇总了Golang中code/google/com/p/mx3/data.Slice.Tensors方法的典型用法代码示例。如果您正苦于以下问题:Golang Slice.Tensors方法的具体用法?Golang Slice.Tensors怎么用?Golang Slice.Tensors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code/google/com/p/mx3/data.Slice
的用法示例。
在下文中一共展示了Slice.Tensors方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: writeOvf2Binary4
func writeOvf2Binary4(out io.Writer, array *data.Slice) {
data := array.Tensors()
gridsize := array.Mesh().Size()
var bytes []byte
// OOMMF requires this number to be first to check the format
var controlnumber float32 = OMF_CONTROL_NUMBER
// Conversion form float32 [4]byte in big-endian
// encoding/binary is too slow
// Inlined for performance, terabytes of data will pass here...
bytes = (*[4]byte)(unsafe.Pointer(&controlnumber))[:]
out.Write(bytes)
// Here we loop over X,Y,Z, not Z,Y,X, because
// internal in C-order == external in Fortran-order
ncomp := array.NComp()
for i := 0; i < gridsize[X]; i++ {
for j := 0; j < gridsize[Y]; j++ {
for k := 0; k < gridsize[Z]; k++ {
for c := 0; c < ncomp; c++ {
bytes = (*[4]byte)(unsafe.Pointer(&data[swapIndex(c, ncomp)][i][j][k]))[:]
out.Write(bytes)
}
}
}
}
}
示例2: dumpGnuplot
func dumpGnuplot(out io.Writer, f *data.Slice) (err error) {
buf := bufio.NewWriter(out)
defer buf.Flush()
data := f.Tensors()
gridsize := f.Mesh().Size()
cellsize := f.Mesh().CellSize()
// If no cell size is set, use generic cell index.
if cellsize == [3]float64{0, 0, 0} {
cellsize = [3]float64{1, 1, 1}
}
ncomp := f.NComp()
// Here we loop over X,Y,Z, not Z,Y,X, because
// internal in C-order == external in Fortran-order
for i := 0; i < gridsize[0]; i++ {
x := float64(i) * cellsize[0]
for j := 0; j < gridsize[1]; j++ {
y := float64(j) * cellsize[1]
for k := 0; k < gridsize[2]; k++ {
z := float64(k) * cellsize[2]
_, err = fmt.Fprint(buf, z, " ", y, " ", x, "\t")
for c := 0; c < ncomp; c++ {
_, err = fmt.Fprint(buf, data[swapIndex(c, ncomp)][i][j][k], " ") // converts to user space.
}
_, err = fmt.Fprint(buf, "\n")
}
_, err = fmt.Fprint(buf, "\n")
}
}
return
}
示例3: writeOmfText
// Writes data in OMF Text format
func writeOmfText(out io.Writer, tens *data.Slice) (err error) {
data := tens.Tensors()
gridsize := tens.Mesh().Size()
// Here we loop over X,Y,Z, not Z,Y,X, because
// internal in C-order == external in Fortran-order
for i := 0; i < gridsize[X]; i++ {
for j := 0; j < gridsize[Y]; j++ {
for k := 0; k < gridsize[Z]; k++ {
for c := 0; c < tens.NComp(); c++ {
_, err = fmt.Fprint(out, data[swapIndex(c, tens.NComp())][i][j][k], " ") // converts to user space.
}
_, err = fmt.Fprint(out, "\n")
}
}
}
return
}
示例4: writeVTKCellData
func writeVTKCellData(out io.Writer, q *data.Slice, dataformat string) (err error) {
N := q.NComp()
data := q.Tensors()
switch N {
case 1:
fmt.Fprintf(out, "\t\t\t<PointData Scalars=\"%s\">\n", q.Tag())
fmt.Fprintf(out, "\t\t\t\t<DataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" format=\"%s\">\n\t\t\t\t\t", q.Tag(), N, dataformat)
case 3:
fmt.Fprintf(out, "\t\t\t<PointData Vectors=\"%s\">\n", q.Tag())
fmt.Fprintf(out, "\t\t\t\t<DataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" format=\"%s\">\n\t\t\t\t\t", q.Tag(), N, dataformat)
case 6, 9:
fmt.Fprintf(out, "\t\t\t<PointData Tensors=\"%s\">\n", q.Tag())
fmt.Fprintf(out, "\t\t\t\t<DataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" format=\"%s\">\n\t\t\t\t\t", q.Tag(), 9, dataformat) // must be 9!
default:
log.Fatalf("vtk: cannot handle %v components", N)
}
gridsize := q.Mesh().Size()
switch dataformat {
case "ascii":
for i := 0; i < gridsize[X]; i++ {
for j := 0; j < gridsize[Y]; j++ {
for k := 0; k < gridsize[Z]; k++ {
// if symmetric tensor manage it appart to write the full 9 components
if N == 6 {
fmt.Fprint(out, data[swapIndex(0, 9)][i][j][k], " ")
fmt.Fprint(out, data[swapIndex(1, 9)][i][j][k], " ")
fmt.Fprint(out, data[swapIndex(2, 9)][i][j][k], " ")
fmt.Fprint(out, data[swapIndex(1, 9)][i][j][k], " ")
fmt.Fprint(out, data[swapIndex(3, 9)][i][j][k], " ")
fmt.Fprint(out, data[swapIndex(4, 9)][i][j][k], " ")
fmt.Fprint(out, data[swapIndex(2, 9)][i][j][k], " ")
fmt.Fprint(out, data[swapIndex(4, 9)][i][j][k], " ")
fmt.Fprint(out, data[swapIndex(5, 9)][i][j][k], " ")
} else {
for c := 0; c < N; c++ {
fmt.Fprint(out, data[swapIndex(c, N)][i][j][k], " ")
}
}
}
}
}
case "binary":
// Inlined for performance, terabytes of data will pass here...
buffer := new(bytes.Buffer)
for i := 0; i < gridsize[X]; i++ {
for j := 0; j < gridsize[Y]; j++ {
for k := 0; k < gridsize[Z]; k++ {
// if symmetric tensor manage it appart to write the full 9 components
if N == 6 {
binary.Write(buffer, binary.LittleEndian, data[swapIndex(0, 9)][i][j][k])
binary.Write(buffer, binary.LittleEndian, data[swapIndex(1, 9)][i][j][k])
binary.Write(buffer, binary.LittleEndian, data[swapIndex(2, 9)][i][j][k])
binary.Write(buffer, binary.LittleEndian, data[swapIndex(1, 9)][i][j][k])
binary.Write(buffer, binary.LittleEndian, data[swapIndex(3, 9)][i][j][k])
binary.Write(buffer, binary.LittleEndian, data[swapIndex(4, 9)][i][j][k])
binary.Write(buffer, binary.LittleEndian, data[swapIndex(2, 9)][i][j][k])
binary.Write(buffer, binary.LittleEndian, data[swapIndex(4, 9)][i][j][k])
binary.Write(buffer, binary.LittleEndian, data[swapIndex(5, 9)][i][j][k])
} else {
for c := 0; c < N; c++ {
binary.Write(buffer, binary.LittleEndian, data[swapIndex(c, N)][i][j][k])
}
}
}
}
}
b64len := uint32(len(buffer.Bytes()))
bufLen := new(bytes.Buffer)
binary.Write(bufLen, binary.LittleEndian, b64len)
base64out := base64.NewEncoder(base64.StdEncoding, out)
base64out.Write(bufLen.Bytes())
base64out.Write(buffer.Bytes())
base64out.Close()
default:
panic(fmt.Errorf("vtk: illegal data format " + dataformat + ". Options are: ascii, binary"))
}
fmt.Fprintln(out, "\n\t\t\t\t</DataArray>")
fmt.Fprintln(out, "\t\t\t</PointData>")
return
}