Browse Source

np.expand_dims

tags/TensorFlowOpLayer
Oceania2018 4 years ago
parent
commit
e859b20d09
4 changed files with 32 additions and 8 deletions
  1. +2
    -3
      src/TensorFlowNET.Core/APIs/tf.array.cs
  2. +1
    -1
      src/TensorFlowNET.Core/NumPy/Numpy.Manipulation.cs
  3. +1
    -4
      src/TensorFlowNET.Core/Operations/array_ops.cs
  4. +28
    -0
      test/TensorFlowNET.UnitTest/NumPy/Manipulation.Test.cs

+ 2
- 3
src/TensorFlowNET.Core/APIs/tf.array.cs View File

@@ -99,13 +99,12 @@ namespace Tensorflow
/// <param name="input"></param>
/// <param name="axis"></param>
/// <param name="name"></param>
/// <param name="dim"></param>
/// <returns>
/// A `Tensor` with the same data as `input`, but its shape has an additional
/// dimension of size 1 added.
/// </returns>
public Tensor expand_dims(Tensor input, int axis = -1, string name = null, int dim = -1)
=> array_ops.expand_dims(input, axis, name, dim);
public Tensor expand_dims(Tensor input, int axis = -1, string name = null)
=> array_ops.expand_dims(input, axis, name);

/// <summary>
/// Creates a tensor filled with a scalar value.


+ 1
- 1
src/TensorFlowNET.Core/NumPy/Numpy.Manipulation.cs View File

@@ -15,7 +15,7 @@ namespace Tensorflow.NumPy
public static NDArray dstack(params NDArray[] tup) => throw new NotImplementedException("");

[AutoNumPy]
public static NDArray expand_dims(NDArray a, Axis? axis = null) => throw new NotImplementedException("");
public static NDArray expand_dims(NDArray a, Axis? axis = null) => new NDArray(array_ops.expand_dims(a, axis: axis ?? -1));

[AutoNumPy]
public static NDArray reshape(NDArray x1, Shape newshape) => x1.reshape(newshape);


+ 1
- 4
src/TensorFlowNET.Core/Operations/array_ops.cs View File

@@ -300,10 +300,7 @@ namespace Tensorflow
return result;
}

public static Tensor expand_dims(Tensor input, int axis = -1, string name = null, int dim = -1)
=> expand_dims_v2(input, axis, name);

private static Tensor expand_dims_v2(Tensor input, int axis, string name = null)
public static Tensor expand_dims(Tensor input, int axis = -1, string name = null)
=> gen_array_ops.expand_dims(input, axis, name);

/// <summary>


+ 28
- 0
test/TensorFlowNET.UnitTest/NumPy/Manipulation.Test.cs View File

@@ -0,0 +1,28 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tensorflow;
using Tensorflow.NumPy;

namespace TensorFlowNET.UnitTest.NumPy
{
/// <summary>
/// https://numpy.org/doc/stable/reference/routines.array-manipulation.html
/// </summary>
[TestClass]
public class ManipulationTest : EagerModeTestBase
{
[TestMethod]
public void expand_dims()
{
var x = np.array(new[] { 1, 2 });
var y = np.expand_dims(x, axis: 0);
Assert.AreEqual(y.shape, (1, 2));

y = np.expand_dims(x, axis: 1);
Assert.AreEqual(y.shape, (2, 1));
}
}
}

Loading…
Cancel
Save