Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7874433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:48:19+00:00 2026-06-03T02:48:19+00:00

I’m implementing the outer product using a templated representation of a Tensor. The basic

  • 0

I’m implementing the outer product using a templated representation of a Tensor.

The basic prototype of the tensor looks like:

template <int N>
struct Tensor
{
    Tensor<N - 1> x;
    Tensor<N - 1> y;
    Tensor<N - 1> z;
};

With a specialization for Tensor<1> to degrade to a simple vector. My Outer function is defined as:

template <int N, int M>
Tensor<N + M> Outer(const Tensor<N> &lhs, const Tensor<M> &rhs)
{
    Tensor<N + M> result;

    result.x = Outer(lhs.x, rhs);
    result.y = Outer(lhs.y, rhs);
    result.z = Outer(lhs.z, rhs);

    return result;
}

template <int N>
Tensor<N + 1> Outer(const Tensor<N> &lhs, const Tensor<1> &rhs)
{
    Tensor<N + 1> result;

    result.x = Outer(lhs.x, rhs);
    result.y = Outer(lhs.y, rhs);
    result.z = Outer(lhs.z, rhs);

    return result;
}

template <>
Tensor<2> Outer(const Tensor<1> &lhs, const Tensor<1> &rhs)
{
    Tensor<2> result;

    result.x.x = lhs.x * rhs.x;
    result.x.y = lhs.x * rhs.y;
    result.x.z = lhs.x * rhs.z;

    // and so on

    return result;
}

The outer product of a tensor A of order N and of a tensor B of order M is simply the outer product of each element of A with the B tensor. The outer product of any tensor of order N with a tensor of order 1 is defined similarly.

The base case is simply the outer product of two order 1 tensors (vectors). Except, as defined above I’m getting a C1202 error in MSVC:

error C1202: recursive type or function dependency context too complex

What did I do wrong in my definition of an outer product?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:48:20+00:00Added an answer on June 3, 2026 at 2:48 am

    This builds cleanly for me:

    template<int N>
    struct Tensor
    {
        Tensor<N - 1> x;
        Tensor<N - 1> y;
        Tensor<N - 1> z;
    
        Tensor() { }
    
        Tensor(const Tensor<N-1>& X, const Tensor<N-1>& Y, const Tensor<N-1>& Z)
          : x(X), y(Y), z(Z)
        { }
    };
    
    template<>
    struct Tensor<1>
    {
        double x;
        double y;
        double z;
    
        Tensor() : x(), y(), z() { }
        Tensor(double x, double y, double z) : x(x), y(y), z(z)
        { }
    };
    
    template<int N, int M>
    Tensor<N + M> Outer(const Tensor<N>& lhs, const Tensor<M>& rhs)
    {
        Tensor<N + M> result;
    
        result.x = Outer(lhs.x, rhs);
        result.y = Outer(lhs.y, rhs);
        result.z = Outer(lhs.z, rhs);
    
        return result;
    }
    
    template<int N>
    Tensor<N + 1> Outer(const Tensor<N>& lhs, const Tensor<1>& rhs)
    {
        Tensor<N + 1> result;
    
        result.x = Outer(lhs.x, rhs);
        result.y = Outer(lhs.y, rhs);
        result.z = Outer(lhs.z, rhs);
    
        return result;
    }
    
    template<int N>
    Tensor<N + 1> Outer(const Tensor<1>& lhs, const Tensor<N>& rhs)
    {
        return Outer(rhs, lhs);
    }
    
    Tensor<2> Outer(const Tensor<1>& lhs, const Tensor<1>& rhs)
    {
        Tensor<2> result;
    
        result.x.x = lhs.x * rhs.x;
        result.x.y = lhs.x * rhs.y;
        result.x.z = lhs.x * rhs.z;
        result.y.x = lhs.y * rhs.x;
        result.y.y = lhs.y * rhs.y;
        result.y.z = lhs.y * rhs.z;
        result.z.x = lhs.z * rhs.x;
        result.z.y = lhs.z * rhs.y;
        result.z.z = lhs.z * rhs.z;
    
        return result;
    }
    
    int main()
    {
        Tensor<4> a;
        Tensor<4> b;
        Outer(a, b);
    }
    

    The notable changes are:

    1. The Tensor<1> specialization needs to be defined before any of the Outer overloads.
    2. The Tensor<1> specialization needs to be default-constructible, since Tensor<2> will attempt to default-construct its x, y, and z data members.
    3. A template<int N> Tensor<N + 1> Outer(const Tensor<1> &lhs, const Tensor<N> &rhs) overload is needed for symmetry with template<int N> Tensor<N + 1> Outer(const Tensor<N> &lhs, const Tensor<1> &rhs), or you need to add an overload that takes a double for lhs.
    4. Remove template<> from the Tensor<2> Outer(const Tensor<1> &lhs, const Tensor<1> &rhs) overload – we’re overloading here, not specializing.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.