Code Monkey home page Code Monkey logo

Comments (4)

yorkshireandrew avatar yorkshireandrew commented on September 24, 2024

Here is a breaking test file seems to error for
Release v0.150.0 based on tensorflowv v2.15.0.


using Microsoft.VisualStudio.TestTools.UnitTesting;
using Tensorflow.NumPy;
using System.Linq;
using Tensorflow;
using static Tensorflow.Binding;

namespace TensorFlowNET.UnitTest.Basics
{	
    [TestClass]
    public class TensorTest
    {
		 [TestMethod]
        public void TensorIndexingTest()
        {
			var elements = new int[3]{1, 2 , 3};
			var tensor = new Tensor(elements);
			var firstElement = (int) tensor[0];
			var secondElement = (int) tensor[1];
                        Assert.AreEqual(1, firstElement);
			Assert.AreEqual(2, secondElement);
        }
    }
}

from tensorflow.net.

Wanglongzhi2001 avatar Wanglongzhi2001 commented on September 24, 2024

Hello, please create tensor from NDArray in your case. For more information about how to create a tensor, you can refer to the source code.
https://github.com/SciSharp/TensorFlow.NET/blob/master/src/TensorFlowNET.Core/Tensors/Tensor.Creation.cs

from tensorflow.net.

yorkshireandrew avatar yorkshireandrew commented on September 24, 2024

I was writing unit tests around a method that takes a 1D Tensor then extracts each element from it (each one still as a Tensor) I think the code above fails because the Tensor has not yet been calculated in a graph.

If I make this replacement in the test above it then passes:

var tensor = tf.constant(elements);

from tensorflow.net.

yorkshireandrew avatar yorkshireandrew commented on September 24, 2024

@Wanglongzhi2001 your right constructing the Tensor from NDArray also works fine, thankyou.

	var raw_elements = new int[3]{1, 2 , 3};
        var elements = np.array(raw_elements);
        var tensor = new Tensor(elements);

I'll close the issue. What a great project. I'm finding using BARD rather than ChatGPT to help with coding works better as the code examples it generates are more up to date.

from tensorflow.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.