Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Random op can't be casted to tensor_t #728

Closed
HugoPhibbs opened this issue Aug 21, 2024 · 2 comments
Closed

[BUG] Random op can't be casted to tensor_t #728

HugoPhibbs opened this issue Aug 21, 2024 · 2 comments

Comments

@HugoPhibbs
Copy link
Contributor

Describe the Bug
Build and IDE complains when I try put in a RandomOp into a function that expects a tensor_t type

To Reproduce

template <typename T>
        inline auto  performProjectionsMatX(matx::tensor_t<T, 2> X, int D) {
            int d = X.Shape()[1];
            auto Y = matx::random<T>({d, D}, matx::UNIFORM);
            auto res = matx::make_tensor<T>({X.shape(0), D});
            (res = matx::matmul(X, Y)).run();
            return res;
        }

auto X = matx::random<float>({10, 3}, matx::UNIFORM);

auto projections = GsDBSCAN::projections::performProjectionsMatX(X, 3);

Tells me:

error: no instance of function template "GsDBSCAN::projections::performProjectionsMatX" matches the argument list
            argument types are: (matx::detail::RandomOp<float, cuda::std::__4::array<matx::index_t, 2UL>>, int)
      auto projections = GsDBSCAN::projections::performProjectionsMatX(X, 3);
                         ^

I'm honestly also a little lost as to how to copy an operator to a tensor such that this issue may be circumvented.

Expected Behavior
No error being thrown

System Details:

  • OS: Ubuntu 20.04
  • CUDA version: 12.6
  • g++ version: 9.3.4
@cliffburdick
Copy link
Collaborator

Hi @HugoPhibbs, a random operator, or any operator in general, cannot be cast to a tensor_t. The reason is that a random operator is a generator, and the values in that generator don't actually exist until they're fetched. A tensor_t needs memory backing it, and the random operator doesn't necessarily have anything backing it. To accomplish this you need a temporary tensor to hold the random numbers if you're trying to get a tensor with random data, or you can modify your function like the following to take an operator instead of a tensor:

template <typename Op>
        inline auto  performProjectionsMatX(Op X, int D) {
            int d = Shape(X)[1];
            auto Y = matx::random<typename X::value_type>({d, D}, matx::UNIFORM);
            auto res = matx::make_tensor<typename X::value_type>({Shape(X)[0], D});
            (res = matx::matmul(X, Y)).run();
            return res;
        }

@HugoPhibbs
Copy link
Contributor Author

ok thx for your help

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

No branches or pull requests

2 participants