Giter Club home page Giter Club logo

Comments (8)

goldsborough avatar goldsborough commented on July 30, 2024 9

@rusty1s you can now pass None if you use at::optional<at::Tensor> in C++ (and at::nullopt or nullptr as the C++ default type)

from extension-cpp.

goldsborough avatar goldsborough commented on July 30, 2024

Hi, we don't currently provide a way of creating a "void"/"None" Tensor in our C++ extension API. Would it be enough for you to use something like at::empty(torch::CPU(at::kDouble), {0})); as the default argument and then check with .numel() == 0 whether or not it is empty? This would work both in the function prototype and for the py::arg() = ... .

Let me know whether this would be sufficient for you.

from extension-cpp.

rusty1s avatar rusty1s commented on July 30, 2024

Thanks! python setup.py install now works perfectly.

However, calling the function in Python with a None argument gives the following error message:

incompatible function arguments. The following argument types are supported:
1. (tensor1: at::Tensor, tensor2 = tensor([], dtype=torch.float64)) -> at::Tensor

Invoked with: tensor([2, 2]), None

from extension-cpp.

goldsborough avatar goldsborough commented on July 30, 2024

from extension-cpp.

rusty1s avatar rusty1s commented on July 30, 2024

Yeah, I see. Actually, I wanted to pass None, but I guess I'm fine with the proposed solution (unless you know of an easy way to allow for None arguments). Thanks again!

from extension-cpp.

goldsborough avatar goldsborough commented on July 30, 2024

I will keep the possibility of None converting to an undefined Tensor in mind as we expand the extension API. Thanks for posting the issue! I'll mark it as resolved.

from extension-cpp.

apaszke avatar apaszke commented on July 30, 2024

@goldsborough how about we expose torch::optional and let Nones bind to that?

from extension-cpp.

goldsborough avatar goldsborough commented on July 30, 2024

Yes that's a good idea, I'll do that

from extension-cpp.

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.