DO-NOT-MERGE: this needs some repairs first

This commit is contained in:
Jonathan Shook 2023-05-30 23:14:29 -05:00 committed by jeffbanks
parent 9518b622bf
commit fa0afdd388
30 changed files with 314 additions and 203 deletions

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.datamappers.functions.to_cqlvector;
import io.nosqlbench.virtdata.api.annotations.Categories;
import io.nosqlbench.virtdata.api.annotations.Category;
import io.nosqlbench.virtdata.api.annotations.Example;
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import io.nosqlbench.virtdata.api.bindings.VirtDataConversions;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection.ListSizedHashed;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_float.HashRange;
import java.util.List;
import java.util.function.LongFunction;
/**
* Create a new CqlVector from a composed function, where the inner function
* is a list generation function.
*/
@ThreadSafeMapper
@Categories(Category.HOF)
public class CqlVector implements LongFunction<com.datastax.oss.driver.api.core.data.CqlVector> {
private final LongFunction<List<?>> func;
@Example({"CqlVector(ListSized(2,HashedRange(0.2f, 5.0f)","Create a 2-component vector with the given range of values."})
public CqlVector(Object func) {
this.func = VirtDataConversions.adaptFunction(func,LongFunction.class, List.class);
}
@Example({"CqlVector()","Create a default 5-component vector with unit-interval components."})
public CqlVector() {
this(new ListSizedHashed(5, new HashRange(0.0f, 1.0f)));
}
@Override
public com.datastax.oss.driver.api.core.data.CqlVector apply(long value) {
List components = func.apply(value);
com.datastax.oss.driver.api.core.data.CqlVector.Builder vbuilder = com.datastax.oss.driver.api.core.data.CqlVector.builder();
vbuilder.add(components.toArray());
return vbuilder.build();
}
}

View File

@ -24,19 +24,30 @@ import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import java.util.function.Function;
import java.util.List;
/**
* Convert the incoming object List, Number, or Array to a CqlVector
* using {@link CqlVector.Builder#add(Object[])}}. If any numeric value
* is passed in, then it becomes the only component of a 1D vector.
* Otherwise, the individual values are added as vector components.
*/
@ThreadSafeMapper
@Categories(Category.experimental)
public class ToCqlVector implements Function<Object, CqlVector> {
@Override
public CqlVector apply(Object object) {
Object[] ary = null;
if (object instanceof List list) {
CqlVector.Builder vbuilder = CqlVector.builder();
vbuilder.add(list.toArray());
return vbuilder.build();
ary = list.toArray();
} else if (object instanceof Number number) {
ary = new Object[]{number.floatValue()};
} else if (object.getClass().isArray()) {
ary = (Object[]) object;
} else {
// handle ary types, etc
throw new RuntimeException("Unsupported input type for CqlVector: " + object.getClass().getCanonicalName());
}
CqlVector.Builder vbuilder = CqlVector.builder();
vbuilder.add(ary);
return vbuilder.build();
}
}

View File

@ -0,0 +1,20 @@
description: |
A small collection of binding functions for the CqlVector type.
scenarios:
default: run driver=stdout cycles=10 format=readout
simple: run driver=stdout bindings='simple.*' cycles=10 format=readout
hof-four: run driver=stdout bindings=hof_vector cycles=10 format=readout
hof-vary: run driver=stdout bindings='hof_vary.*' cycles=10 format=readout
hof-tenunit: run driver=stdout bindings='"'hof_ten.*' cycles=10 format=readout
bindings:
# # default provides a 5-component vector, with unit-interval values. (Not normalized)
# simple_vector: CqlVector()
# # create a HOF CqlVector(dim 4) binding which composes around a long -> list function
# hof_vector: CqlVector(ListSizedHashed(4,HashRange(0.0f,1.0f)))
# # create a HOF CqlVector binding
# hof_vary_vector: CqlVector(ListSizedHashed(HashRange(3,5)->int,HashRange(0.0f,1.0f)))
# create a normalized vectors of dimension 10
hof_ten_unit: CqlVector(NormalizeVector(ListSizedHashed(10,HashRange(0.0f,1.0f))))

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.datamappers.functions.to_cqlvector;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection.ListSized;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_float.HashRange;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class CqlVectorTest {
@Test
public void testCqlVector() {
CqlVector func = new CqlVector(new ListSized(2, new HashRange(0.2f, 5.0f)));
com.datastax.oss.driver.api.core.data.CqlVector result = func.apply(23L);
List<Object> values = new ArrayList<>();
for (Object value : result.getValues()) {
values.add(value);
}
assertThat(values.get(0)).isInstanceOf(Float.class);
}
}

View File

@ -42,6 +42,12 @@
<version>${revision}</version>
</dependency>
<dependency>
<groupId>io.nosqlbench</groupId>
<artifactId>nb-annotations</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>io.nosqlbench</groupId>
<artifactId>nb-api</artifactId>

View File

@ -30,5 +30,6 @@ public enum Category {
general,
objects,
periodic,
experimental
experimental,
HOF
}

View File

@ -55,6 +55,10 @@ import java.util.function.*;
*/
public class NBFunctionConverter {
public static LongToIntFunction adapt(LongFunction<Float> f, Float i1, LongToIntFunction i2) {
return v -> f.apply(v).intValue();
}
public static LongFunction<Object> adapt(DoubleToIntFunction f, LongFunction<Integer> i1, Object i2) {
return f::applyAsInt;
}

View File

@ -24,7 +24,7 @@ public class FloatArg implements ArgType {
this.floatValue = floatValue;
}
public double getFloatValue() {
public float getFloatValue() {
return floatValue;
}

View File

@ -9,8 +9,8 @@ expression : (lvalue ASSIGN)? virtdataCall ;
virtdataCall :
( inputType TYPEARROW )?
( funcName '(' (arg (',' arg )* )? ')' )
( TYPEARROW outputType )?
( funcName '(' (WS? arg ( WS? ',' WS? arg )* WS? )? WS? ')' )
( TYPEARROW outputType )? WS?
;
lvalue : ID;

View File

@ -0,0 +1,59 @@
/*
* Copyright (c) 2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.virtdata.library.basics.shared.conversions.from_long;
import io.nosqlbench.virtdata.api.annotations.Categories;
import io.nosqlbench.virtdata.api.annotations.Category;
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import io.nosqlbench.virtdata.api.bindings.VirtDataConversions;
import java.util.function.LongToDoubleFunction;
/**
* Create a double by converting values. This function works in the following modes:
* <UL>
* <LI>If a double is provided, then the long input is scaled to be between 0.0f and the value provided,
* as a fraction of the highest possible long.</LI>
* <LI>If any other type of number is provided, then this function returns the equivalent double value.</LI>
* <LI>Otherwise, the input is assumed to be a function which takes a long input, and, if necessary,
* adapts to return a double with an appropriate type conversion.</LI>
* </UL>
*/
@Categories(Category.conversion)
@ThreadSafeMapper
public class ToDouble implements LongToDoubleFunction {
private final LongToDoubleFunction func;
ToDouble(Object func) {
if (func instanceof Double aDouble) {
double scale = aDouble.doubleValue();
this.func = l -> (double) (l % scale);
} else if (func instanceof Number number) {
final double aDouble = number.doubleValue();
this.func = l -> aDouble;
} else {
this.func = VirtDataConversions.adaptFunction(func, LongToDoubleFunction.class);
}
}
@Override
public double applyAsDouble(long value) {
return func.applyAsDouble(value);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 nosqlbench
* Copyright (c) 2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,23 +19,41 @@ package io.nosqlbench.virtdata.library.basics.shared.conversions.from_long;
import io.nosqlbench.virtdata.api.annotations.Categories;
import io.nosqlbench.virtdata.api.annotations.Category;
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import io.nosqlbench.virtdata.api.bindings.VirtDataConversions;
import java.util.function.LongFunction;
@ThreadSafeMapper
@Categories({Category.conversion})
public class ToFloat implements LongFunction<Float> {
private final long scale;
public ToFloat(long scale) {
this.scale = scale;
}
public ToFloat() {
this.scale = Long.MAX_VALUE;
/**
* Create a float by converting values. This function works in the following modes:
* <UL>
* <LI>If a float is provided, then the long input is scaled to be between 0.0f and the value provided,
* as a fraction of the highest possible long.</LI>
* <LI>If any other type of number is provided, then this function returns the equivalent float value.</LI>
* <LI>Otherwise, the input is assumed to be a function which takes a long input, and, if necessary,
* adapts to return a float with an appropriate type conversion.</LI>
* </UL>
*/
@Categories(Category.conversion)
@ThreadSafeMapper
public class ToFloat implements LongFunction<Float> {
private final LongFunction<Float> func;
ToFloat(Object func) {
if (func instanceof Float afloat) {
float scale = afloat.floatValue();
this.func = l -> (float) (l % scale);
} else if (func instanceof Number number) {
final float afloat = number.floatValue();
this.func = l -> afloat;
} else {
this.func = VirtDataConversions.adaptFunction(func, LongFunction.class, Float.class);
}
}
@Override
public Float apply(long input) {
return (float)(input % scale);
public Float apply(long value) {
return func.apply(value);
}
}

View File

@ -1,50 +0,0 @@
/*
* Copyright (c) 2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.virtdata.library.basics.shared.from_long;
import io.nosqlbench.virtdata.api.annotations.Categories;
import io.nosqlbench.virtdata.api.annotations.Category;
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import io.nosqlbench.virtdata.api.bindings.VirtDataConversions;
import java.util.function.LongFunction;
/**
* Wrap any function producing a valid numeric value as a float.
*/
@Categories(Category.conversion)
@ThreadSafeMapper
public class ToFloat implements LongFunction<Float> {
private final LongFunction<Float> func;
ToFloat(Object funcOrValue) {
if (funcOrValue instanceof Number number) {
final float afloat = number.floatValue();
this.func = l -> afloat;
} else {
this.func = VirtDataConversions.adaptFunction(funcOrValue,LongFunction.class,Float.class);
}
}
@Override
public Float apply(long value) {
return func.apply(value);
}
}

View File

@ -59,10 +59,6 @@ public class ListSized implements LongFunction<List<Object>> {
}
this.valueFuncs = VirtDataConversions.adaptFunctionList(funcs, LongFunction.class, Object.class);
}
public ListSized(int size, Object... funcs) {
this.sizeFunc = (s) -> size;
this.valueFuncs = VirtDataConversions.adaptFunctionList(funcs, LongFunction.class, Object.class);
}
@Override
public List<Object> apply(long value) {

View File

@ -61,11 +61,6 @@ public class ListSizedHashed implements LongFunction<List<Object>> {
this.valueFuncs = VirtDataConversions.adaptFunctionList(funcs, LongFunction.class, Object.class);
}
public ListSizedHashed(int size, Object... funcs) {
this.sizeFunc = s -> size;
this.valueFuncs = VirtDataConversions.adaptFunctionList(funcs, LongFunction.class, Object.class);
}
@Override
public List<Object> apply(long value) {
int size = sizeFunc.applyAsInt(value);

View File

@ -49,7 +49,7 @@ import java.util.function.LongToDoubleFunction;
*/
@ThreadSafeMapper
@Categories({Category.general})
public class HashedDoubleRange implements LongToDoubleFunction {
public class HashRange implements LongToDoubleFunction {
private final double min;
private final double max;
@ -57,7 +57,7 @@ public class HashedDoubleRange implements LongToDoubleFunction {
private final static double MAX_DOUBLE_VIA_LONG = (double) Long.MAX_VALUE;
private final Hash hash = new Hash();
public HashedDoubleRange(double min, double max) {
public HashRange(double min, double max) {
this.min = min;
this.max = max;
this.interval = max - min;

View File

@ -1,36 +0,0 @@
/*
* Copyright (c) 2022 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_double;
import io.nosqlbench.virtdata.api.annotations.Categories;
import io.nosqlbench.virtdata.api.annotations.Category;
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import java.util.function.LongToDoubleFunction;
/**
* Convert the input value to a double.
*/
@ThreadSafeMapper
@Categories({Category.conversion})
public class ToDouble implements LongToDoubleFunction {
@Override
public double applyAsDouble(long value) {
return (double) value;
}
}

View File

@ -23,33 +23,9 @@ import io.nosqlbench.virtdata.library.basics.shared.from_long.to_long.Hash;
import java.util.function.LongFunction;
/*
* <p>This simulates a uniform sample from a range of double values
* via long hashing. This function attempts to take a double
* unit interval value from a long/long division over the whole
* range of long values but via double value types, thus providing
* a very linear sample. This means that the range of double
* values to be accessed will not fall along all possible doubles,
* but will still provide suitable values for ranges close to
* high-precision points in the IEEE floating point number line.
* This suffices for most reasonable ranges in practice outside
* of scientific computing, where large exponents put adjacent
* IEEE floating point values much further apart.</p>
*
* <p>This should be consider the default double range sampling
* function for most uses, when the exponent is not needed for
* readability.</p>
*/
/**
* Return a double value within the specified range. This function
* uses an intermediate long to arrive at the sampled value before
* conversion to double, thus providing a more linear sample at the
* expense of some precision at extremely large values.
*/
@ThreadSafeMapper
@Categories({Category.general})
public class HashedFloatRange implements LongFunction<Float> {
public class HashRange implements LongFunction<Float> {
private final float min;
private final float max;
@ -57,7 +33,7 @@ public class HashedFloatRange implements LongFunction<Float> {
private final static float MAX_FLOAT_VIA_LONG = (float) Long.MAX_VALUE;
private final Hash hash = new Hash();
public HashedFloatRange(float min, float max) {
public HashRange(float min, float max) {
this.min = min;
this.max = max;
this.interval = max - min;

View File

@ -1,36 +0,0 @@
/*
* Copyright (c) 2022 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_float;
import io.nosqlbench.virtdata.api.annotations.Categories;
import io.nosqlbench.virtdata.api.annotations.Category;
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import java.util.function.LongToDoubleFunction;
/**
* Convert the input value to a double.
*/
@ThreadSafeMapper
@Categories({Category.conversion})
public class ToDouble implements LongToDoubleFunction {
@Override
public double applyAsDouble(long value) {
return (double) value;
}
}

View File

@ -24,9 +24,10 @@ import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import java.util.function.LongUnaryOperator;
/**
* Return a value within a range, pseudo-randomly. This is equivalent to
* returning a value with in range between 0 and some maximum value, but
* with a minimum value added.
* The various HashRange functions take an input long, hash it to a random
* long value, and then use to interpolate a fractional value between the minimum
* and maximum values. To select a specific type of HashRange function,
* simply use the same datatype in the min and max values you wish to have on output.
*
* You can specify hash ranges as small as a single-element range, like
* (5,5), or as wide as the relevant data type allows.

View File

@ -20,7 +20,7 @@ import io.nosqlbench.virtdata.api.annotations.Categories;
import io.nosqlbench.virtdata.api.annotations.Category;
import io.nosqlbench.virtdata.api.annotations.Example;
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_double.HashedDoubleRange;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_double.HashRange;
import java.util.ArrayList;
import java.util.List;
@ -40,7 +40,7 @@ public class WeightedLongs implements LongFunction<Long> {
private final String valuesAndWeights;
private double[] unitWeights; // Positional weights after parsing and unit weight normalization
private double[] cumulativeWeights;
private final HashedDoubleRange unitRange = new HashedDoubleRange(0.0D, 1.0D);
private final HashRange unitRange = new HashRange(0.0D, 1.0D);
private long[] values;
@Example({"WeightedLongs('1:10;3;5;12345;1","Yield 1 62.5% of the time, 3 31.25% of the time, and 12345 6.2% of the time"})

View File

@ -20,7 +20,7 @@ import io.nosqlbench.virtdata.api.annotations.Categories;
import io.nosqlbench.virtdata.api.annotations.Category;
import io.nosqlbench.virtdata.api.annotations.Example;
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_double.HashedDoubleRange;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_double.HashRange;
import io.nosqlbench.virtdata.api.bindings.VirtDataFunctions;
import java.util.function.Function;
@ -54,7 +54,7 @@ public class CoinFunc implements Function<Long, Object> {
private final double threshold;
private final LongFunction first;
private final LongFunction second;
private final HashedDoubleRange cointoss = new HashedDoubleRange(0.0d, 1.0d);
private final HashRange cointoss = new HashRange(0.0d, 1.0d);
@Example({"CoinFunc(0.15,NumberNameToString(),Combinations('A:1:B:23'))", "use the first function 15% of the time"})

View File

@ -21,7 +21,7 @@ import io.nosqlbench.virtdata.api.annotations.Category;
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import io.nosqlbench.virtdata.library.basics.core.stathelpers.AliasSamplerDoubleInt;
import io.nosqlbench.virtdata.library.basics.core.stathelpers.EvProbD;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_double.HashedDoubleRange;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_double.HashRange;
import io.nosqlbench.virtdata.api.bindings.VirtDataFunctions;
import java.util.ArrayList;
@ -39,7 +39,7 @@ public class WeightedFuncs implements LongFunction<Object> {
private final LongFunction<Object>[] funcs;
private final AliasSamplerDoubleInt functionSampler;
private final HashedDoubleRange unitSampler = new HashedDoubleRange(0.0d, 1.0d);
private final HashRange unitSampler = new HashRange(0.0d, 1.0d);
public WeightedFuncs(Object... weightsAndFuncs) {
List<EvProbD> probabilities = new ArrayList<>();

View File

@ -19,7 +19,7 @@ package io.nosqlbench.virtdata.library.basics.shared.from_long.to_string;
import io.nosqlbench.virtdata.api.annotations.Categories;
import io.nosqlbench.virtdata.api.annotations.Category;
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_double.HashedDoubleRange;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_double.HashRange;
import java.util.ArrayList;
import java.util.List;
@ -39,7 +39,7 @@ public class WeightedStrings implements LongFunction<String> {
private final String valuesAndWeights;
private double[] unitWeights; // Positional weights after parsing and unit weight normalization
private double[] cumulativeWeights;
private final HashedDoubleRange unitRange = new HashedDoubleRange(0.0D, 1.0D);
private final HashRange unitRange = new HashRange(0.0D, 1.0D);
private String[] values;
public WeightedStrings(String valuesAndWeights) {

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_vector;
import io.nosqlbench.virtdata.api.annotations.Categories;
import io.nosqlbench.virtdata.api.annotations.Category;
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import java.util.List;
import java.util.function.Function;
/**
* Normalize a vector in List<Number> form, calling the appropriate conversion function
* depending on the component (Class) type of the incoming List values.
*/
@ThreadSafeMapper
@Categories(Category.experimental)
public class NormalizeVector implements Function<List,List> {
private final NormalizeDoubleVectorList ndv = new NormalizeDoubleVectorList();
private final NormalizeFloatVectorList nfv = new NormalizeFloatVectorList();
@Override
public List apply(List list) {
if (list.size()==0) {
return List.of();
} else if (list.get(0) instanceof Float) {
return nfv.apply(list);
} else if (list.get(1) instanceof Double) {
return ndv.apply(list);
} else {
throw new RuntimeException("Only Doubles and Floats are recognized.");
}
}
}

View File

@ -20,7 +20,7 @@ import io.nosqlbench.virtdata.api.annotations.Categories;
import io.nosqlbench.virtdata.api.annotations.Category;
import io.nosqlbench.virtdata.api.annotations.Example;
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_double.HashedDoubleRange;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_double.HashRange;
import java.util.Arrays;
import java.util.List;
@ -58,9 +58,9 @@ public class UniformVectorSizedStepped implements LongFunction<List<Double>> {
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)+1].doubleValue());
funcs[i]=new HashRange(dims[i<<1].doubleValue(),dims[(i<<1)+1].doubleValue());
} else {
funcs[i]=new HashedDoubleRange(0.0d,1.0d);
funcs[i]=new HashRange(0.0d,1.0d);
}
}
}

View File

@ -19,7 +19,7 @@ package io.nosqlbench.virtdata.library.basics.shared.stateful;
import io.nosqlbench.virtdata.api.annotations.Categories;
import io.nosqlbench.virtdata.api.annotations.Category;
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_double.HashedDoubleRange;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_double.HashRange;
import java.util.function.LongFunction;
@ -34,7 +34,7 @@ public class NullOrLoad implements LongFunction<Object> {
private final String varname;
private final double ratio;
private final HashedDoubleRange rangefunc = new HashedDoubleRange(0.0D,1.0D);
private final HashRange rangefunc = new HashRange(0.0D,1.0D);
private final Load load;
public NullOrLoad(double ratio, String varname) {

View File

@ -20,7 +20,7 @@ import io.nosqlbench.virtdata.api.annotations.Categories;
import io.nosqlbench.virtdata.api.annotations.Category;
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import io.nosqlbench.virtdata.library.basics.core.threadstate.SharedState;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_double.HashedDoubleRange;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_double.HashRange;
import java.util.function.Function;
@ -35,7 +35,7 @@ public class NullOrPass implements Function<Object, Object> {
private final String varname;
private final double ratio;
private final HashedDoubleRange rangefunc = new HashedDoubleRange(0.0D, 1.0D);
private final HashRange rangefunc = new HashRange(0.0D, 1.0D);
public NullOrPass(double ratio, String varname) {
if (ratio < 0.0D || ratio > 1.0D) {

View File

@ -20,7 +20,7 @@ import io.nosqlbench.virtdata.api.annotations.Categories;
import io.nosqlbench.virtdata.api.annotations.Category;
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import io.nosqlbench.virtdata.api.bindings.VALUE;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_double.HashedDoubleRange;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_double.HashRange;
import java.util.function.LongFunction;
@ -35,7 +35,7 @@ public class UnsetOrLoad implements LongFunction<Object> {
private final String varname;
private final double ratio;
private final HashedDoubleRange rangefunc = new HashedDoubleRange(0.0D,1.0D);
private final HashRange rangefunc = new HashRange(0.0D,1.0D);
private final Load load;
public UnsetOrLoad(double ratio, String varname) {

View File

@ -21,7 +21,7 @@ import io.nosqlbench.virtdata.api.annotations.Category;
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import io.nosqlbench.virtdata.api.bindings.VALUE;
import io.nosqlbench.virtdata.library.basics.core.threadstate.SharedState;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_double.HashedDoubleRange;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_double.HashRange;
import java.util.function.Function;
@ -36,7 +36,7 @@ public class UnsetOrPass implements Function<Object,Object> {
private final String varname;
private final double ratio;
private final HashedDoubleRange rangefunc = new HashedDoubleRange(0.0D,1.0D);
private final HashRange rangefunc = new HashRange(0.0D,1.0D);
public UnsetOrPass(double ratio, String varname) {
if (ratio<0.0D || ratio >1.0D) {

View File

@ -16,7 +16,7 @@
package io.nosqlbench.virtdata.library.basics.tests.long_double;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_double.HashedDoubleRange;
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_double.HashRange;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@ -25,7 +25,7 @@ public class HashedDoubleRangeTest {
@Test
public void testBasicRanges() {
HashedDoubleRange r = new HashedDoubleRange(0.0D, 100.0D);
HashRange r = new HashRange(0.0D, 100.0D);
for(long i=1;i<1000;i++) {
assertThat(r.applyAsDouble(i)).isBetween(0.0D,100.0D);
}