当前位置: 首页>>代码示例>>Golang>>正文


Golang data.Slice类代码示例

本文整理汇总了Golang中code/google/com/p/mx3/data.Slice的典型用法代码示例。如果您正苦于以下问题:Golang Slice类的具体用法?Golang Slice怎么用?Golang Slice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Slice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: exec3D

func (c *DemagConvolution) exec3D(outp, inp, vol *data.Slice, Bsat float64) {
	padded := c.kernSize

	// FW FFT
	for i := 0; i < 3; i++ {
		zero1(c.fftRBuf[i], c.stream)
		in := inp.Comp(i)
		copyPadMul(c.fftRBuf[i], in, padded, c.size, vol, Bsat, c.stream)
		c.fwPlan.ExecAsync(c.fftRBuf[i], c.fftCBuf[i])
	}

	// kern mul
	N0, N1, N2 := c.fftKernSize[0], c.fftKernSize[1], c.fftKernSize[2] // TODO: rm these
	kernMulRSymm3D(c.fftCBuf,
		c.gpuFFTKern[0][0], c.gpuFFTKern[1][1], c.gpuFFTKern[2][2],
		c.gpuFFTKern[1][2], c.gpuFFTKern[0][2], c.gpuFFTKern[0][1],
		N0, N1, N2, c.stream)

	// BW FFT
	for i := 0; i < 3; i++ {
		c.bwPlan.ExecAsync(c.fftCBuf[i], c.fftRBuf[i])
		out := outp.Comp(i)
		copyPad(out, c.fftRBuf[i], c.size, padded, c.stream)
	}
	c.stream.Synchronize()
}
开发者ID:shenyp09,项目名称:mx3,代码行数:26,代码来源:conv_symm.go

示例2: kernMulRSymm2Dx

func kernMulRSymm2Dx(fftMx, K00 *data.Slice, N1, N2 int, str cu.Stream) {
	util.Argument(K00.Len() == (N1/2+1)*N2)
	util.Argument(fftMx.NComp() == 1 && K00.NComp() == 1)

	cfg := make2DConf(N1, N2)

	k_kernmulRSymm2Dx_async(fftMx.DevPtr(0), K00.DevPtr(0), N1, N2, cfg, str)
}
开发者ID:shenyp09,项目名称:mx3,代码行数:8,代码来源:conv_kernmul.go

示例3: writeVTKHeader

func writeVTKHeader(out io.Writer, q *data.Slice) (err error) {
	gridsize := q.Mesh().Size()
	_, err = fmt.Fprintln(out, "<?xml version=\"1.0\"?>")
	_, err = fmt.Fprintln(out, "<VTKFile type=\"StructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">")
	_, err = fmt.Fprintf(out, "\t<StructuredGrid WholeExtent=\"0 %d 0 %d 0 %d\">\n", gridsize[Z]-1, gridsize[Y]-1, gridsize[X]-1)
	_, err = fmt.Fprintf(out, "\t\t<Piece Extent=\"0 %d 0 %d 0 %d\">\n", gridsize[Z]-1, gridsize[Y]-1, gridsize[X]-1)
	return
}
开发者ID:shenyp09,项目名称:mx3,代码行数:8,代码来源:vtk.go

示例4: AddConst

// Adds a constant to each element of the slice.
// 	dst[comp][index] += cnst[comp]
func AddConst(dst *data.Slice, cnst ...float32) {
	util.Argument(len(cnst) == dst.NComp())
	N := dst.Len()
	cfg := make1DConf(N)
	str := stream()
	for c := 0; c < dst.NComp(); c++ {
		if cnst[c] != 0 {
			k_madd2_async(dst.DevPtr(c), dst.DevPtr(c), 1, nil, cnst[c], N, cfg, str)
		}
	}
	syncAndRecycle(str)
}
开发者ID:shenyp09,项目名称:mx3,代码行数:14,代码来源:madd.go

示例5: scale

func scale(f *data.Slice, factor float32) {
	a := f.Vectors()
	for i := range a[0] {
		for j := range a[0][i] {
			for k := range a[0][i][j] {
				a[0][i][j][k] *= factor
				a[1][i][j][k] *= factor
				a[2][i][j][k] *= factor

			}
		}
	}
}
开发者ID:shenyp09,项目名称:mx3,代码行数:13,代码来源:normalize.go

示例6: preprocess

func preprocess(f *data.Slice) {
	if *flag_normalize {
		normalize(f, 1)
	}
	if *flag_normpeak {
		normpeak(f)
	}
	if *flag_comp != -1 {
		*f = *f.Comp(swapIndex(*flag_comp, f.NComp()))
	}
	if *flag_resize != "" {
		resize(f, *flag_resize)
	}
	//if *flag_scale != 1{
	//	rescale(f, *flag_scale)
	//}
}
开发者ID:shenyp09,项目名称:mx3,代码行数:17,代码来源:main.go

示例7: writeVTKPoints

func writeVTKPoints(out io.Writer, q *data.Slice, dataformat string) (err error) {
	_, err = fmt.Fprintln(out, "\t\t\t<Points>")
	fmt.Fprintf(out, "\t\t\t\t<DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"%s\">\n\t\t\t\t\t", dataformat)
	gridsize := q.Mesh().Size()
	cellsize := q.Mesh().CellSize()
	switch dataformat {
	case "ascii":
		for k := 0; k < gridsize[X]; k++ {
			for j := 0; j < gridsize[Y]; j++ {
				for i := 0; i < gridsize[Z]; i++ {
					x := (float32)(i) * (float32)(cellsize[Z])
					y := (float32)(j) * (float32)(cellsize[Y])
					z := (float32)(k) * (float32)(cellsize[X])
					_, err = fmt.Fprint(out, x, " ", y, " ", z, " ")
				}
			}
		}
	case "binary":
		buffer := new(bytes.Buffer)
		for k := 0; k < gridsize[X]; k++ {
			for j := 0; j < gridsize[Y]; j++ {
				for i := 0; i < gridsize[Z]; i++ {
					x := (float32)(i) * (float32)(cellsize[Z])
					y := (float32)(j) * (float32)(cellsize[Y])
					z := (float32)(k) * (float32)(cellsize[X])
					binary.Write(buffer, binary.LittleEndian, x)
					binary.Write(buffer, binary.LittleEndian, y)
					binary.Write(buffer, binary.LittleEndian, z)
				}
			}
		}
		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:
		log.Fatalf("Illegal VTK data format: %v. Options are: ascii, binary", dataformat)
	}
	_, err = fmt.Fprintln(out, "\n\t\t\t\t</DataArray>")
	_, err = fmt.Fprintln(out, "\t\t\t</Points>")
	return
}
开发者ID:shenyp09,项目名称:mx3,代码行数:45,代码来源:vtk.go

示例8: 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
}
开发者ID:shenyp09,项目名称:mx3,代码行数:32,代码来源:gnuplot.go

示例9: normpeak

func normpeak(f *data.Slice) {
	a := f.Vectors()
	maxnorm := 0.
	for i := range a[0] {
		for j := range a[0][i] {
			for k := range a[0][i][j] {

				x, y, z := a[0][i][j][k], a[1][i][j][k], a[2][i][j][k]
				norm := math.Sqrt(float64(x*x + y*y + z*z))
				if norm > maxnorm {
					maxnorm = norm
				}

			}
		}
	}
	scale(f, float32(1/maxnorm))
}
开发者ID:shenyp09,项目名称:mx3,代码行数:18,代码来源:normalize.go

示例10: normalize

// normalize vector data to given length
func normalize(f *data.Slice, length float64) {
	a := f.Vectors()
	for i := range a[0] {
		for j := range a[0][i] {
			for k := range a[0][i][j] {
				x, y, z := a[0][i][j][k], a[1][i][j][k], a[2][i][j][k]
				norm := math.Sqrt(float64(x*x + y*y + z*z))
				invnorm := float32(1)
				if norm != 0 {
					invnorm = float32(length / norm)
				}
				a[0][i][j][k] *= invnorm
				a[1][i][j][k] *= invnorm
				a[2][i][j][k] *= invnorm

			}
		}
	}
}
开发者ID:shenyp09,项目名称:mx3,代码行数:20,代码来源:normalize.go

示例11: 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)
				}
			}
		}
	}
}
开发者ID:shenyp09,项目名称:mx3,代码行数:28,代码来源:ovf2.go

示例12: Memset

// Memset sets the Slice's components to the specified values.
func Memset(s *data.Slice, val ...float32) {
	util.Argument(len(val) == s.NComp())
	str := stream()
	for c, v := range val {
		cu.MemsetD32Async(cu.DevicePtr(s.DevPtr(c)), math.Float32bits(v), int64(s.Len()), str)
	}
	syncAndRecycle(str)
}
开发者ID:shenyp09,项目名称:mx3,代码行数:9,代码来源:slice.go

示例13: writeOmfHeader

// Writes the OMF header
func writeOmfHeader(out io.Writer, q *data.Slice) (err error) {
	gridsize := q.Mesh().Size()
	cellsize := q.Mesh().CellSize()

	err = hdr(out, "OOMMF", "rectangular mesh v1.0")
	hdr(out, "Segment count", "1")
	hdr(out, "Begin", "Segment")

	hdr(out, "Begin", "Header")

	dsc(out, "Time", 0) //q.Time) // TODO !!
	hdr(out, "Title", q.Tag())
	hdr(out, "meshtype", "rectangular")
	hdr(out, "meshunit", "m")
	hdr(out, "xbase", cellsize[Z]/2)
	hdr(out, "ybase", cellsize[Y]/2)
	hdr(out, "zbase", cellsize[X]/2)
	hdr(out, "xstepsize", cellsize[Z])
	hdr(out, "ystepsize", cellsize[Y])
	hdr(out, "zstepsize", cellsize[X])
	hdr(out, "xmin", 0)
	hdr(out, "ymin", 0)
	hdr(out, "zmin", 0)
	hdr(out, "xmax", cellsize[Z]*float64(gridsize[Z]))
	hdr(out, "ymax", cellsize[Y]*float64(gridsize[Y]))
	hdr(out, "zmax", cellsize[X]*float64(gridsize[X]))
	hdr(out, "xnodes", gridsize[Z])
	hdr(out, "ynodes", gridsize[Y])
	hdr(out, "znodes", gridsize[X])
	hdr(out, "ValueRangeMinMag", 1e-08) // not so "optional" as the OOMMF manual suggests...
	hdr(out, "ValueRangeMaxMag", 1)     // TODO
	hdr(out, "valueunit", "?")
	hdr(out, "valuemultiplier", 1)

	hdr(out, "End", "Header")
	return
}
开发者ID:shenyp09,项目名称:mx3,代码行数:38,代码来源:omf.go

示例14: 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
}
开发者ID:shenyp09,项目名称:mx3,代码行数:20,代码来源:omf.go

示例15: exec2D

func (c *DemagConvolution) exec2D(outp, inp, vol *data.Slice, Bsat float64) {
	// Convolution is separated into
	// a 1D convolution for x and a 2D convolution for yz.
	// So only 2 FFT buffers are needed at the same time.

	// FFT x
	zero1(c.fftRBuf[0], c.stream)
	in := inp.Comp(0)
	padded := c.kernSize
	copyPadMul(c.fftRBuf[0], in, padded, c.size, vol, Bsat, c.stream)
	c.fwPlan.ExecAsync(c.fftRBuf[0], c.fftCBuf[0])

	// kern mul X
	N1, N2 := c.fftKernSize[1], c.fftKernSize[2] // TODO: rm these
	kernMulRSymm2Dx(c.fftCBuf[0], c.gpuFFTKern[0][0], N1, N2, c.stream)

	// bw FFT x
	c.bwPlan.ExecAsync(c.fftCBuf[0], c.fftRBuf[0])
	out := outp.Comp(0)
	copyPad(out, c.fftRBuf[0], c.size, padded, c.stream)

	// FW FFT yz
	for i := 1; i < 3; i++ {
		zero1(c.fftRBuf[i], c.stream)
		in := inp.Comp(i)
		copyPadMul(c.fftRBuf[i], in, padded, c.size, vol, Bsat, c.stream)
		c.fwPlan.ExecAsync(c.fftRBuf[i], c.fftCBuf[i])
	}

	// kern mul yz
	kernMulRSymm2Dyz(c.fftCBuf[1], c.fftCBuf[2],
		c.gpuFFTKern[1][1], c.gpuFFTKern[2][2], c.gpuFFTKern[1][2],
		N1, N2, c.stream)

	// BW FFT yz
	for i := 1; i < 3; i++ {
		c.bwPlan.ExecAsync(c.fftCBuf[i], c.fftRBuf[i])
		out := outp.Comp(i)
		copyPad(out, c.fftRBuf[i], c.size, padded, c.stream)
	}
	c.stream.Synchronize()
}
开发者ID:shenyp09,项目名称:mx3,代码行数:42,代码来源:conv_symm.go


注:本文中的code/google/com/p/mx3/data.Slice类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。