From 9f70780291e705d76a4b12f2a3058c0966c6d942 Mon Sep 17 00:00:00 2001 From: yueyinqiu Date: Fri, 26 Apr 2024 17:12:29 +0800 Subject: [PATCH] leaf normal --- RELEASENOTES.md | 1 + src/TorchSharp/Tensor/Factories/Tensor.Factories.cs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index ac759131b..a2f89060a 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -10,6 +10,7 @@ __API Changes__: __Bug Fixes__: +- `torch.normal` will now correctly return a leaf tensor. # NuGet Version 0.102.4 diff --git a/src/TorchSharp/Tensor/Factories/Tensor.Factories.cs b/src/TorchSharp/Tensor/Factories/Tensor.Factories.cs index 87e26b58c..133bf8b47 100644 --- a/src/TorchSharp/Tensor/Factories/Tensor.Factories.cs +++ b/src/TorchSharp/Tensor/Factories/Tensor.Factories.cs @@ -116,7 +116,8 @@ public static Tensor eye(long rows, long columns = -1L, ScalarType? dtype = null /// public static Tensor normal(double mean, double std, ReadOnlySpan size, ScalarType? dtype = null, Device? device = null, bool requires_grad = false, Generator? generator = null, string[]? names = null) { - return randn(size, dtype: dtype, device: device, requires_grad: requires_grad, generator: generator) * std + mean; + return randn(size, dtype, device, requires_grad: false, generator, names) + .mul_(std).add_(mean).requires_grad_(requires_grad); } ///