Coder Social home page Coder Social logo

Comments (4)

panisson avatar panisson commented on July 22, 2024

The following patch could work as a solution to this problem:

    diff --git a/sktensor/sptensor.py b/sktensor/sptensor.py
    index 21baf74..0eacfb6 100644
    --- a/sktensor/sptensor.py
    +++ b/sktensor/sptensor.py
    @@ -134,9 +134,9 @@ class sptensor(tensor_mixin):

             # Case 2: result is a vector
             if len(remdims) == 1:
    -            c = accum(nsubs, nvals, shape=nshp)
    +            c, s = accum(nsubs, nvals, shape=nshp, with_subs=True)
                 if len(np.nonzero(c)[0]) <= 0.5 * prod(nshp):
    -                return sptensor(arange(nshp), c)
    +                return sptensor(s, c)
                 else:
                     return c

combined with this correction on the function accum:

    diff --git a/sktensor/utils.py b/sktensor/utils.py
    index b76ad83..ae6fa82 100644
    --- a/sktensor/utils.py
    +++ b/sktensor/utils.py
    @@ -24,7 +24,7 @@ def accum(subs, vals, func=np.sum, sorted=False, shape=None, with_subs=False):

         # return results
         if with_subs:
    -        return nvals, subs[idx[:-1]]
    +        return nvals, tuple(sub[idx[:-1]] for sub in subs)
         else:
             return nvals

from scikit-tensor.

mnick avatar mnick commented on July 22, 2024

Thanks for the bug report. The bug occured because of some API changes for sptensor.

I incorporated your fix in 10116c8 and the test case in 7a7502d.

from scikit-tensor.

panisson avatar panisson commented on July 22, 2024

Thanks for the fix, Maximilian.

I have another error, that seems related to this, since it occurs when ttv returns a sptensor.
It can be reproduced with this test case:

def test_uttkrp():
    subs, vals, shape = mysetup()
    S = sptensor(subs, vals, shape)
    U = []
    for shp in (25, 11, 18, 7, 2):
        U.append(np.zeros((shp, 5)))
    SU = S.uttkrp(U, mode=0)
    assert_equal(SU.shape, (25, 5))

The error is "TypeError: float() argument must be a string or a number", and it happens in sptensor.py, line 191, in uttkrp:

    V[:, r] = self.ttv(Z, mode, without=True)

It seems that, when the result of ttv is a sptensor, it cannot be assigned to V using this operation.

Let me know if I should open a new issue report or if you will reopen this one.

from scikit-tensor.

mnick avatar mnick commented on July 22, 2024

Please open a new issue, as this is a different issue. Thank you!

from scikit-tensor.

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.