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 6821029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:29:47+00:00 2026-05-26T21:29:47+00:00

I know it is easy to compute a sparse dot product in SQL, but

  • 0

I know it is easy to compute a sparse dot product in SQL, but what is the best way to do a sum (for very long vectors)?

A join is not enough because if a coordinate is filled in one vector but not in the other, it will be ignored.

Thus, I computed the sum with a PHP loop… and that was a pretty stupid idea.

I’m currently thinking of filling the missing 0’s in order to prepare an inner join, but is there a shortcut (like an outer join converting NULL to 0)?

Edit. Here is the structure of my table of vectors:

CREATE TABLE `eigaki_vectors` (
  `name` varchar(2) COLLATE utf8_unicode_ci NOT NULL,
  `i1` int(10) NOT NULL,
  `i2` int(10) NOT NULL,
  `value` double NOT NULL,
  UNIQUE KEY `key` (`name`,`i1`,`i2`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

In this particular case, a vector has composed indices: v_{i_1, i_2}, but this has nothing to do with the problem.

I expected to do something like (thanks xQbert):

SELECT v1.i1, v1.i2, isNull(v1.value, 0) + isNull(v2.value, 0)
FROM eigaki_vectors v1 FULL OUTER JOIN eigaki_vectors v2
ON v1.i1 = v2.i1 AND v1.i2 = v2.i2
AND v1.name = 'a' AND v2.name = 'b'

to add vectors a and b. But FULL OUTER JOIN doesn’t exist on MySQL, and I think I’m clumsy with the name column. Any ideas?

  • 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-05-26T21:29:47+00:00Added an answer on May 26, 2026 at 9:29 pm

    I managed to get something, thanks to the snippet provided in MySQL: Union of a Left Join with a Right Join:

    SELECT IFNULL(v1.value, 0) + IFNULL(v2.value, 0) FROM
    (
        SELECT i1, i2 FROM eigaki_vectors WHERE name = 'a'
        UNION
        SELECT i1, i2 FROM eigaki_vectors WHERE name = 'b'
    ) indices
    LEFT OUTER JOIN eigaki_vectors v1 ON indices.i1 = v1.i1 AND indices.i2 = v1.i2 AND v1.name = 'a'
    LEFT OUTER JOIN eigaki_vectors v2 ON indices.i1 = v2.i1 AND indices.i2 = v2.i2 AND v2.name = 'b'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know of an easy way to copy a database from one computer
Do you know any easy or simple way to make a map object (from
Does anyone know an easy way to hide hashtags in the user's address bar?
Do you know any easy way to find a logging call that throws not
Anyone know of an easy way to parse a Lua datastructure in C# or
Does anyone know of an easy way to escape HTML from strings in jQuery
I know it is relatively easy to compute the sets of k-nearest neighbours from
I'm looking for an easy way to compute SHA 256 in Action Script on
I would like to know an easy way to get all the css rules
Do you know an easy and straight-forward method/sub/module which allows me to convert a

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.