Coder Social home page Coder Social logo

Comments (4)

mnick avatar mnick commented on July 3, 2024

I can't reproduce the behaviour you are describing. Can you provide a test case for the bug? The following test seems to work correctly:

def test_getitem():
    subs = (
        array([0, 1, 0, 5, 7, 8]),
        array([2, 0, 4, 5, 3, 9]),
        array([0, 1, 2, 2, 1, 0])
    )
    vals = array([1, 2, 3, 4, 5, 6])
    S = sptensor(subs, vals, shape=[10, 10, 3])
    assert_equal(0, S[1, 1, 1])
    assert_equal(0, S[1, 2, 3])
    assert_equal(1, S[0, 2, 0])
    assert_equal(2, S[1, 0, 1])
    assert_equal(3, S[0, 4, 2])
    assert_equal(4, S[5, 5, 2])
    assert_equal(5, S[7, 3, 1])
    assert_equal(6, S[8, 9, 0])

from scikit-tensor.

ucarbehlul avatar ucarbehlul commented on July 3, 2024

Hmm your example is working indeed.

But I found that if I use python array instead of numpy array, it won't work. Since it works correctly with ndarray, the bug may be resolved but I think it may be helpful to add a notice for this to docstrings.

Try it like this:

def test_getitem():
    subs = (
        [0, 1, 0, 5, 7, 8],
        [2, 0, 4, 5, 3, 9],
        [0, 1, 2, 2, 1, 0]
    )
    vals = [1, 2, 3, 4, 5, 6]
    S = sptensor(subs, vals, shape=[10, 10, 3])
    assert_equal(0, S[1, 1, 1])
    assert_equal(0, S[1, 2, 3])
    assert_equal(1, S[0, 2, 0])
    assert_equal(2, S[1, 0, 1])
    assert_equal(3, S[0, 4, 2])
    assert_equal(4, S[5, 5, 2])
    assert_equal(5, S[7, 3, 1])
    assert_equal(6, S[8, 9, 0])

from scikit-tensor.

kastnerkyle avatar kastnerkyle commented on July 3, 2024

@mnick do you think adding support for lists as indices and values for sparse tensors is worthwhile? Basically something like

if type(subs) != np.ndarray:
    subs = np.array(subs)

and the same for vals. Or would it be better to raise an error if the type is not ndarray?

from scikit-tensor.

mnick avatar mnick commented on July 3, 2024

For now I would prefer the later until the API / functionality matured.

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.