Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial vector variate generation functions #1296

Merged
merged 2 commits into from
May 26, 2023

Conversation

jshook
Copy link
Contributor

@jshook jshook commented May 25, 2023

closes #1295

Copy link
Contributor

@jeffbanks jeffbanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm; nice addition

for (Double scalar : doubles) {
accumulator+=scalar*scalar;
}
double vectorLen = Math.sqrt(accumulator);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: name this vectorNorm? vector length can be potentially misinterpreted as the number of components

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's too ambiguous as well. But it's not the norm. It's the scalar length that is used to compute the norm. So maybe we should call it scalarLength?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

this.funcs = new LongToDoubleFunction[dim];
for (int i = 0; i < dim; i++) {
if (i<dims.length/2) {
funcs[i]=new HashedDoubleRange(dims[i<<1].doubleValue(),dims[i<<1].doubleValue()+1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may have glossed over this, but question: the bit shift to the left doubles index i. Should the second argument in HashedDoubleRange be:

dims[(i<<1) + 1].doubleValue()

So that we are getting for i < dim.length / 2:

i = 0 => HashedDoubleRange(dims[0], dims[1])
i = 1 => HashedDoubleRange(dims[2], dims[3])
...

? Perhaps I'm misunderstanding something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks to me like you found a bug, and either the passing test is a mathematical coincidence, or I've missed coverage here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah the test was not specific enough. I made it quantitative. The previous version was asserting only a subset of the expected range.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼 Good catch @ShaunakDas88

public UniformVectorSizedStepped(Number... dims) {
if (dims.length>=1 && (dims.length)%2==1 && dims[0] instanceof Integer) {
this.dim = dims[0].intValue();
dims = Arrays.copyOfRange(dims,1,dims.length);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor performance nit: Rather than making a copy from index 1 on of the array, perhaps a startOffset pointer to index 1 here (and index 0 in the else). Then the true length we care about is dims.length - startOffset, and we can just iterate through the original dims appropriately and do index arithmetic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would generally agree, except that in this case the constructor logic is only used during initialzation. Once a binding function is resolved and installed, it is static, and only what happens in the apply method will be perf sensitive. Not opposed to the change, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ShaunakDas88 I had a similar question in the past, this is the preferred way for init and apply in the bindings for performance reasons.

@jshook jshook merged commit 7084ce0 into main May 26, 2023
6 checks passed
@jshook jshook deleted the nosqlbench-1295-vectorfuncs branch May 26, 2023 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add vector generation bindings
3 participants