當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Frame.Tensors方法代碼示例

本文整理匯總了Golang中nimble-cube/dump.Frame.Tensors方法的典型用法代碼示例。如果您正苦於以下問題:Golang Frame.Tensors方法的具體用法?Golang Frame.Tensors怎麽用?Golang Frame.Tensors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在nimble-cube/dump.Frame的用法示例。


在下文中一共展示了Frame.Tensors方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: writeOmfBinary4

// Writes data in OMF Binary 4 format
func writeOmfBinary4(out io.Writer, array *dump.Frame) {
	data := array.Tensors()
	gridsize := array.Size()[1:]

	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
	// Inlined for performance, terabytes of data will pass here...
	bytes = (*[4]byte)(unsafe.Pointer(&controlnumber))[:]
	bytes[0], bytes[1], bytes[2], bytes[3] = bytes[3], bytes[2], bytes[1], bytes[0] // swap endianess
	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.Size()[0]
	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++ {
					// dirty conversion from float32 to [4]byte
					bytes = (*[4]byte)(unsafe.Pointer(&data[core.SwapIndex(c, ncomp)][i][j][k]))[:]
					bytes[0], bytes[1], bytes[2], bytes[3] = bytes[3], bytes[2], bytes[1], bytes[0]
					out.Write(bytes)
				}
			}
		}
	}
}
開發者ID:barnex,項目名稱:nimble-tools,代碼行數:31,代碼來源:omf.go

示例2: dumpGnuplotGZip

func dumpGnuplotGZip(f *dump.Frame, file string) {

	out, err := os.OpenFile(file, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
	core.Fatal(err)

	out_gzip, err1 := gzip.NewWriterLevel(out, gzip.BestSpeed)
	core.Fatal(err1)

	out_buffered := bufio.NewWriter(out_gzip)

	defer func() {
		out_buffered.Flush()
		out_gzip.Close()
		out.Close()
	}()

	data := f.Tensors()
	gridsize := f.Size()[1:]
	cellsize := f.MeshStep
	ncomp := len(data)

	// 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++ {
		x := float64(i) * cellsize[X]
		for j := 0; j < gridsize[Y]; j++ {
			y := float64(j) * cellsize[Y]
			for k := 0; k < gridsize[Z]; k++ {
				z := float64(k) * cellsize[Z]
				_, err := fmt.Fprint(out_buffered, z, " ", y, " ", x, "\t")
				core.Fatal(err)
				for c := 0; c < ncomp; c++ {
					_, err := fmt.Fprint(out_buffered, data[core.SwapIndex(c, ncomp)][i][j][k], " ") // converts to user space.
					core.Fatal(err)
				}
				_, err = fmt.Fprint(out_buffered, "\n")
				core.Fatal(err)
			}
			_, err := fmt.Fprint(out_buffered, "\n")
			core.Fatal(err)
		}
		core.Fatal(err)
	}
	out_buffered.Flush()
}
開發者ID:barnex,項目名稱:nimble-tools,代碼行數:45,代碼來源:gnuplotgzip.go

示例3: dumpGnuplot

func dumpGnuplot(f *dump.Frame, file string) {

	out_, err := os.OpenFile(file, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
	core.Fatal(err)
	defer out_.Close()

	out_buffered := bufio.NewWriter(out_)
	defer out_buffered.Flush()

	data := f.Tensors()
	gridsize := f.Size()[1:]
	cellsize := f.MeshStep
	// 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.Components
	core.Assert(ncomp > 0)

	// 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++ {
		x := float64(i) * cellsize[X]
		for j := 0; j < gridsize[Y]; j++ {
			y := float64(j) * cellsize[Y]
			for k := 0; k < gridsize[Z]; k++ {
				z := float64(k) * cellsize[Z]
				_, err := fmt.Fprint(out_buffered, z, " ", y, " ", x, "\t")
				core.Fatal(err)
				for c := 0; c < ncomp; c++ {
					_, err := fmt.Fprint(out_buffered, data[core.SwapIndex(c, ncomp)][i][j][k], " ") // converts to user space.
					core.Fatal(err)
				}
				_, err = fmt.Fprint(out_buffered, "\n")
				core.Fatal(err)
			}
			_, err := fmt.Fprint(out_buffered, "\n")
			core.Fatal(err)
		}
		core.Fatal(err)
	}
}
開發者ID:barnex,項目名稱:nimble-tools,代碼行數:42,代碼來源:gnuplot.go

示例4: writeOmfText

// Writes data in OMF Text format
func writeOmfText(out io.Writer, tens *dump.Frame) {

	data := tens.Tensors()
	gridsize := tens.Size()[1:]

	// 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.Size()[0]; c++ {
					_, err := fmt.Fprint(out, data[core.SwapIndex(c, tens.Size()[0])][i][j][k], " ") // converts to user space.
					core.Fatal(err)
				}
				_, err := fmt.Fprint(out, "\n")
				core.Fatal(err)
			}
		}
	}
}
開發者ID:barnex,項目名稱:nimble-tools,代碼行數:21,代碼來源:omf.go

示例5: writeVTKCellData

func writeVTKCellData(out io.Writer, q *dump.Frame, dataformat string) {
	N := q.Size()[0]
	data := q.Tensors()
	switch N {
	case 1:
		fmt.Fprintf(out, "\t\t\t<PointData Scalars=\"%s\">\n", q.DataLabel)
		fmt.Fprintf(out, "\t\t\t\t<DataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" format=\"%s\">\n", q.DataLabel, N, dataformat)
	case 3:
		fmt.Fprintf(out, "\t\t\t<PointData Vectors=\"%s\">\n", q.DataLabel)
		fmt.Fprintf(out, "\t\t\t\t<DataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" format=\"%s\">\n", q.DataLabel, N, dataformat)
	case 6, 9:
		fmt.Fprintf(out, "\t\t\t<PointData Tensors=\"%s\">\n", q.DataLabel)
		fmt.Fprintf(out, "\t\t\t\t<DataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" format=\"%s\">\n", q.DataLabel, 9, dataformat) // must be 9!
	default:
		core.Fatal(fmt.Errorf("vtk: cannot handle %v components"))
	}
	gridsize := q.MeshSize
	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[core.SwapIndex(0, 9)][i][j][k], " ")
						fmt.Fprint(out, data[core.SwapIndex(1, 9)][i][j][k], " ")
						fmt.Fprint(out, data[core.SwapIndex(2, 9)][i][j][k], " ")
						fmt.Fprint(out, data[core.SwapIndex(1, 9)][i][j][k], " ")
						fmt.Fprint(out, data[core.SwapIndex(3, 9)][i][j][k], " ")
						fmt.Fprint(out, data[core.SwapIndex(4, 9)][i][j][k], " ")
						fmt.Fprint(out, data[core.SwapIndex(2, 9)][i][j][k], " ")
						fmt.Fprint(out, data[core.SwapIndex(4, 9)][i][j][k], " ")
						fmt.Fprint(out, data[core.SwapIndex(5, 9)][i][j][k], " ")
					} else {
						for c := 0; c < N; c++ {
							fmt.Fprint(out, data[core.SwapIndex(c, N)][i][j][k], " ")
						}
					}
				}
			}
		}
	case "binary":
		// Inlined for performance, terabytes of data will pass here...
		var bytes []byte
		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 {
						bytes = (*[4]byte)(unsafe.Pointer(&data[core.SwapIndex(0, 9)][i][j][k]))[:]
						out.Write(bytes)
						bytes = (*[4]byte)(unsafe.Pointer(&data[core.SwapIndex(1, 9)][i][j][k]))[:]
						out.Write(bytes)
						bytes = (*[4]byte)(unsafe.Pointer(&data[core.SwapIndex(2, 9)][i][j][k]))[:]
						out.Write(bytes)
						bytes = (*[4]byte)(unsafe.Pointer(&data[core.SwapIndex(1, 9)][i][j][k]))[:]
						out.Write(bytes)
						bytes = (*[4]byte)(unsafe.Pointer(&data[core.SwapIndex(3, 9)][i][j][k]))[:]
						out.Write(bytes)
						bytes = (*[4]byte)(unsafe.Pointer(&data[core.SwapIndex(4, 9)][i][j][k]))[:]
						out.Write(bytes)
						bytes = (*[4]byte)(unsafe.Pointer(&data[core.SwapIndex(2, 9)][i][j][k]))[:]
						out.Write(bytes)
						bytes = (*[4]byte)(unsafe.Pointer(&data[core.SwapIndex(4, 9)][i][j][k]))[:]
						out.Write(bytes)
						bytes = (*[4]byte)(unsafe.Pointer(&data[core.SwapIndex(5, 9)][i][j][k]))[:]
						out.Write(bytes)
					} else {
						for c := 0; c < N; c++ {
							bytes = (*[4]byte)(unsafe.Pointer(&data[core.SwapIndex(c, N)][i][j][k]))[:]
							out.Write(bytes)
						}
					}
				}
			}
		}
	default:
		core.Fatal(fmt.Errorf("vtk: illegal data format " + dataformat + ". Options are: ascii, binary"))
	}
	fmt.Fprintln(out, "</DataArray>")
	fmt.Fprintln(out, "\t\t\t</PointData>")
}
開發者ID:barnex,項目名稱:nimble-tools,代碼行數:82,代碼來源:vtk.go


注:本文中的nimble-cube/dump.Frame.Tensors方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。