Skip to content

Conversation

@jamesr66a
Copy link
Collaborator

Closes #10631

Copy link
Contributor

@zdevito zdevito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool fix -- I suggest a simplification where we don't have a separate SugaredValue and just handle the name mapping inside of the SimpleValue::attr function.

std::shared_ptr<SugaredValue> SimpleValue::attr(SourceRange loc, Method & m, const std::string& field) {
// Allow method-style casts on Tensor types. e.g. x.int()
if (value->type()->isSubtypeOf(DynamicType::get()) && ScalarTypeCastValue::method_to_type_map().count(field)) {
return std::make_shared<ScalarTypeCastValue>(field, NamedValue(loc, "self", value));

This comment was marked as off-topic.

at::ArrayRef<NamedValue> inputs,
at::ArrayRef<NamedValue> attributes,
size_t n_binders) override {
if (!attributes.empty())

This comment was marked as off-topic.

@jamesr66a jamesr66a force-pushed the method_casts_script branch from a0936af to 4044e13 Compare August 20, 2018 18:15
@apaszke
Copy link
Contributor

apaszke commented Aug 20, 2018

Wouldn't it be simpler to add those methods as native functions? They don't seem to be implemented for C++ tensors, but would be useful too.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jamesr66a has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

petrex pushed a commit to petrex/pytorch that referenced this pull request Aug 21, 2018
* upstream/master: (147 commits)
  Support Loading to GPU (pytorch#10710)
  More changes for hidden visibility (pytorch#10692)
  Add arguments __repr__ in Distribution base class
  Add util function from core type to dtype (pytorch#10716)
  Make ONNX_ATEN_FALLBACK as internal default option
  Set the BUILD_ENVIRONMENT variable before installing sccache. (pytorch#10640)
  Avoid shadowing i, j vars in GeneralProposals test (pytorch#10721)
  Move THNN Reduction to ATen/core. (pytorch#10703)
  Completely remove build_aten and use_aten (pytorch#10469)
  Make empty list literals construct empty Tensor[] (pytorch#10705)
  Soumith's last few patches to v0.4.1
  Fix issues link in Caffe2 readme (pytorch#10711)
  Update the onnx Gemm op to FC/FCTransposed logic in caffe2 onnx backend (pytorch#10108)
  Adding ATEN_NO_TEST option to root level cmake for propogation to aten
  Allow method-style casts on tensors (pytorch#10641)
  Fix pytorch#10698 build failure (pytorch#10704)
  Add support for Log()
  Add a bisect percentile operator (pytorch#10563)
  Fix EnsureCPUOutputOp (pytorch#10651)
  Nomnigraph - rename some APIs that invole Subtree to Subgraph (pytorch#10551)
  ...
PenghuiCheng pushed a commit to PenghuiCheng/pytorch that referenced this pull request Sep 11, 2018
Summary:
Closes pytorch#10631
Pull Request resolved: pytorch#10641

Differential Revision: D9407598

Pulled By: jamesr66a

fbshipit-source-id: a0331f4e9e55d92718cde7a1112fe8c705206b1f
@ezyang ezyang added the merged label Jun 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JIT][script] Support method-style casts in script

5 participants