Git Product home page Git Product logo

Comments (4)

andreaskoepf avatar andreaskoepf commented on April 28, 2024

It would be great to support basic cross-type auto-converting arithmetic operations for floating point types as well.

Copy/Assignment operations are already supported (VERY permissive):

f = torch.FloatTensor(5)
d = torch.DoubleTensor(5).fill_(float('nan')) # fill with nan to challenge double->int...
i = torch.IntTensor(5)
d.copy_(f)
f.copy_(d)    # ok, maybe I accept this as explicit cast...
f[:] = d[:]   # implicit conversion to smaller type? data-scientists world...
d[:] = f[:]
i[:] = d[:]   # wow, even double to int without complaints...

Things become strange/normal (depending on whether you are data or computer scientist) when you try to assign a SINGLE float to an int:

>>> i[1] = d[1]
RuntimeError: can't assign a float to a scalar value of type int

A nice feature I would like to see in the future are relatively save cross-type arithmetic ops for +,-,*,/ ... e.g.

r = d[:] + f[:]
# currently only possible with explicit conversion (-> additional copy), e.g.
r = d[:] + f[:].double()

Currently yields:

    return self.add(other)
TypeError: add received an invalid combination of arguments - got (torch.FloatTensor), but expected one of:
 * (float value)
      didn't match because some of the arguments have invalid types: (torch.FloatTensor)
 * (torch.DoubleTensor other)
      didn't match because some of the arguments have invalid types: (torch.FloatTensor)
 * (float value, torch.DoubleTensor other)
 * (torch.DoubleTensor mat1, torch.SparseDoubleTensor mat2)
 * (torch.DoubleTensor mat1, float value, torch.SparseDoubleTensor mat2)

from pytorch.

fmassa avatar fmassa commented on April 28, 2024

@soumith this issue was accidentally closed I believe

from pytorch.

ezyang avatar ezyang commented on April 28, 2024

This still does not work

from pytorch.

gchanan avatar gchanan commented on April 28, 2024

This works now after type promotion.

from pytorch.

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.