Exemple #1
0
        public FloatTensor Pow(FloatTensor x, bool inline = true)
        {
            // Check if both tensors are compatible for sum
            SameSizeDimensionsShapeAndLocation(ref x);

            FloatTensor result = inline ? this : this.emptyTensorCopy();

            if (dataOnGpu)
            {
                result.Gpu(this.shader);
                if (inline)
                {
                    result.PowElemGPU_(x); return(this);
                }
                else
                {
                    return(PowElemGPU(x, result));
                }
            }
            else
            {
                var nCpu = SystemInfo.processorCount;
                Parallel.For(0, nCpu, workerId => {
                    var max = size * (workerId + 1) / nCpu;
                    for (var i = size * workerId / nCpu; i < max; i++)
                    {
                        result.Data [i] = (float)Math.Pow((double)Data [i], x.Data [i]);
                    }
                });
            }
            return(result);
        }
Exemple #2
0
        public FloatTensor Pow(FloatTensor x, bool inline = false, FloatTensor result = null)
        {
            if (!IsContiguous() || !x.IsContiguous())
            {
                throw new InvalidOperationException("All tensors must be contiguous, call Contiguous() to convert");
            }

            // Check if both tensors are compatible for sum
            SameSizeDimensionsShapeAndLocation(ref x);

            result = HookAutograd(ref result, ref x, "pow_elem", inline);

            if (dataOnGpu)
            {
                result.Gpu(shader);
                if (!inline)
                {
                    return(PowElemGPU(x, result));
                }
                result.PowElemGPU_(x);
                return(this);
            }

            result.Data = data.AsParallel().Zip(x.Data.AsParallel(), (a, b) => (float)Math.Pow((double)a, b))
                          .ToArray();

            return(result);
        }
        public FloatTensor Pow(FloatTensor x, bool inline = false)
        {
            // Check if both tensors are compatible for sum
            SameSizeDimensionsShapeAndLocation(ref x);

            if (inline & autograd)
            {
                throw new InvalidOperationException("Cannot call inline functions if you intend to run backprop.");
            }

            FloatTensor result = inline ? this : this.emptyTensorCopy();

            if (dataOnGpu)
            {
                result.Gpu(shader);
                if (inline)
                {
                    result.PowElemGPU_(x);
                    return(this);
                }
                else
                {
                    return(PowElemGPU(x, result));
                }
            }
            else
            {
                var nCpu = SystemInfo.processorCount;
                Parallel.For(0, nCpu, workerId => {
                    var max = size * (workerId + 1) / nCpu;
                    for (var i = size * workerId / nCpu; i < max; i++)
                    {
                        result.Data [i] = (float)Math.Pow((double)Data [i], x.Data [i]);
                    }
                });
            }

            HookAutograd(ref result, ref x, "pow_elem");

            return(result);
        }