• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang data.Slice类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Image

func Image(f *data.Slice, fmin, fmax string) *image.NRGBA {
	dim := f.NComp()
	switch dim {
	default:
		log.Fatalf("unsupported number of components: %v", dim)
	case 3:
		return drawVectors(f.Vectors())
	case 1:
		min, max := extrema(f.Host()[0])
		if fmin != "auto" {
			m, err := strconv.ParseFloat(fmin, 32)
			util.FatalErr(err)
			min = float32(m)
		}
		if fmax != "auto" {
			m, err := strconv.ParseFloat(fmax, 32)
			util.FatalErr(err)
			max = float32(m)
		}
		return drawFloats(f.Scalars(), min, max)
	}
	panic("unreachable")
}
开发者ID:shenyp09,项目名称:mx3,代码行数:23,代码来源:image.go


示例17: AddAnisoExchange

// Add exchange field to Beff with different exchange constant for X,Y,Z direction.
// m must be normalized to unit length.
func AddAnisoExchange(Beff *data.Slice, m *data.Slice, AexX, AexY, AexZ, Msat float64) {
	// TODO: size check
	mesh := Beff.Mesh()
	N := mesh.Size()
	c := mesh.CellSize()
	w0 := float32(2 * AexX / (Msat * c[0] * c[0]))
	w1 := float32(2 * AexY / (Msat * c[1] * c[1]))
	w2 := float32(2 * AexZ / (Msat * c[2] * c[2]))
	cfg := make2DConfSize(N[2], N[1], STENCIL_BLOCKSIZE)

	str := [3]cu.Stream{stream(), stream(), stream()}
	for c := 0; c < 3; c++ {
		k_addexchange1comp_async(Beff.DevPtr(c), m.DevPtr(c), w0, w1, w2, N[0], N[1], N[2], cfg, str[c])
	}
	syncAndRecycle(str[0])
	syncAndRecycle(str[1])
	syncAndRecycle(str[2])
}
开发者ID:shenyp09,项目名称:mx3,代码行数:20,代码来源:exchange.go


示例18: writeOvf2Header

func writeOvf2Header(out io.Writer, q *data.Slice, time, tstep float64) {
	gridsize := q.Mesh().Size()
	cellsize := q.Mesh().CellSize()

	fmt.Fprintln(out, "# OOMMF OVF 2.0")
	fmt.Fprintln(out, "#")
	hdr(out, "Segment count", "1")
	fmt.Fprintln(out, "#")
	hdr(out, "Begin", "Segment")
	hdr(out, "Begin", "Header")
	fmt.Fprintln(out, "#")

	hdr(out, "Title", q.Tag()) // TODO
	hdr(out, "meshtype", "rectangular")
	hdr(out, "meshunit", "m")

	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]))

	name := q.Tag()
	var labels []interface{}
	if q.NComp() == 1 {
		labels = []interface{}{name}
	} else {
		for i := 0; i < q.NComp(); i++ {
			labels = append(labels, name+"_"+string('x'+i))
		}
	}
	hdr(out, "valuedim", q.NComp())
	hdr(out, "valuelabels", labels...) // TODO
	unit := q.Unit()
	if unit == "" {
		unit = "1"
	}
	if q.NComp() == 1 {
		hdr(out, "valueunits", unit)
	} else {
		hdr(out, "valueunits", unit, unit, unit)
	}

	// We don't really have stages
	fmt.Fprintln(out, "# Desc: Stage simulation time: ", tstep, " s")
	fmt.Fprintln(out, "# Desc: Total simulation time: ", time, " s")

	hdr(out, "xbase", cellsize[Z]/2)
	hdr(out, "ybase", cellsize[Y]/2)
	hdr(out, "zbase", cellsize[X]/2)

	hdr(out, "xnodes", gridsize[Z])
	hdr(out, "ynodes", gridsize[Y])
	hdr(out, "znodes", gridsize[X])

	hdr(out, "xstepsize", cellsize[Z])
	hdr(out, "ystepsize", cellsize[Y])
	hdr(out, "zstepsize", cellsize[X])
	fmt.Fprintln(out, "#")
	hdr(out, "End", "Header")
	fmt.Fprintln(out, "#")
}
开发者ID:shenyp09,项目名称:mx3,代码行数:64,代码来源:ovf2.go


示例19: Madd2

// multiply-add: dst[i] = src1[i] * factor1 + src2[i] * factor2
func Madd2(dst, src1, src2 *data.Slice, factor1, factor2 float32) {
	N := dst.Len()
	nComp := dst.NComp()
	util.Assert(src1.Len() == N && src2.Len() == N)
	util.Assert(src1.NComp() == nComp && src2.NComp() == nComp)
	cfg := make1DConf(N)
	str := stream()
	for c := 0; c < nComp; c++ {
		k_madd2_async(dst.DevPtr(c), src1.DevPtr(c), factor1,
			src2.DevPtr(c), factor2, N, cfg, str)
	}
	syncAndRecycle(str)
}
开发者ID:shenyp09,项目名称:mx3,代码行数:14,代码来源:madd.go


示例20: MaxVecNorm

// Maximum of the norms of all vectors (x[i], y[i], z[i]).
// 	max_i sqrt( x[i]*x[i] + y[i]*y[i] + z[i]*z[i] )
func MaxVecNorm(v *data.Slice) float64 {
	out := reduceBuf(0)
	k_reducemaxvecnorm2(v.DevPtr(0), v.DevPtr(1), v.DevPtr(2), out, 0, v.Len(), reducecfg)
	return math.Sqrt(float64(copyback(out)))
}
开发者ID:shenyp09,项目名称:mx3,代码行数:7,代码来源:reduce.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang plot.New函数代码示例发布时间:2022-05-24
下一篇:
Golang mahonia.NewDecoder函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap