Git Product home page Git Product logo

Comments (5)

mikera avatar mikera commented on August 28, 2024

You are hitting reflection here.... If you use a Clojure type hint then it should solve the issue, e.g.

(.distanceSquared ^AVector sparse-indexed-left ^AVector sparse-indexed-right)

from vectorz.

cnuernber avatar cnuernber commented on August 28, 2024

Definite possibility but I think that is not the case here.

I have:

(set! warn-on-reflection true)

At the top of the file and it compiles with no warnings.

I dove through the code to figure out what is going on and here are the results of the analysis:

First, we are dealing with very sparse vectors, basically 1 out of 100 elements are nonzero. Given that each vector is of len length with num-elems being (* .01 len) nonzero items on average.

The implementation of distance square for AVector is here:

public double distanceSquared(AVector v) {
int len=checkSameLength(v);
double total=0.0;
for (int i=0; i<len; i++) {
double d=unsafeGet(i)-v.unsafeGet(i);
total+=d*d;
}
return total;
}

This has a running time of O(len) where len is the total length of the indexed vectors.

The implementation I attached at the top of the file has a running time on the order of num-elems given that the sparse vector clone, sub, and magnitudeSquared operations are all on the order of O(num-elems).

from vectorz.

mikera avatar mikera commented on August 28, 2024

OK thanks yes I see what is happening. this implementation should probably be in Vectorz itself rather than on the Clojure side, I'll take a look and insert it in the right place.

Thanks!

from vectorz.

mikera avatar mikera commented on August 28, 2024

OK I think this is fixed in this commit:

82bc83a

from vectorz.

cnuernber avatar cnuernber commented on August 28, 2024

Yep, verified from this end.

from vectorz.

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.