id stringlengths 8 13 | source stringlengths 164 33.1k | target stringlengths 36 5.98k |
|---|---|---|
150938406_205 | class AnnotationUtils {
public static BaseDB createDB(String name, Params parameter) throws Exception {
Wrapper<BaseDB> db = DB_CLASSES.get(name);
Preconditions.checkArgument(db != null, "No DB named %s", name);
return db.clazz.getConstructor(Params.class).newInstance(parameter);
}
... | BaseDB db1 = AnnotationUtils.createDB("test_fake_db_1", new Params());
Assert.assertTrue(db1 instanceof FakeDB1);
BaseDB db2 = AnnotationUtils.createDB("test_fake_db_2", new Params());
Assert.assertTrue(db2 instanceof FakeDB2);
}
} |
150938406_207 | class AnnotationUtils {
public static boolean isDB(String name) {
return DB_CLASSES.containsKey(name);
}
@SuppressWarnings("unchecked") private static Map<String, Wrapper<BaseDB>> loadDBClasses();
@SuppressWarnings("unchecked") private static Map<String, Class<? extends BaseFileSystem<?>>> loa... | Assert.assertTrue(AnnotationUtils.isDB("test_fake_db_1"));
Assert.assertTrue(AnnotationUtils.isDB("test_fake_db_2"));
Assert.assertFalse(AnnotationUtils.isDB("test_fake_op_1"));
Assert.assertFalse(AnnotationUtils.isDB("test_fake_op_2"));
Assert.assertFalse(AnnotationUtils.isDB("d... |
150938406_208 | class AnnotationUtils {
public static boolean isDBHasTimestamp(String name) {
Wrapper<BaseDB> db = DB_CLASSES.get(name);
Preconditions.checkArgument(db != null, "No DB named %s", name);
return db.clazz.getAnnotation(DBAnnotation.class).hasTimestamp();
}
@SuppressWarnings("unchecked... | Assert.assertFalse(AnnotationUtils.isDBHasTimestamp("test_fake_db_1"));
Assert.assertTrue(AnnotationUtils.isDBHasTimestamp("test_fake_db_2"));
}
} |
150938406_209 | class AnnotationUtils {
public static boolean isDBHasTimestamp(String name) {
Wrapper<BaseDB> db = DB_CLASSES.get(name);
Preconditions.checkArgument(db != null, "No DB named %s", name);
return db.clazz.getAnnotation(DBAnnotation.class).hasTimestamp();
}
@SuppressWarnings("unchecked... | Assert.assertFalse(AnnotationUtils.isDBHasTimestamp("A_DB_HAS_NO_NAME"));
}
} |
150938406_210 | class AnnotationUtils {
public static boolean isIoOpHasTimestamp(String name, IOType type) {
Wrapper<AlgoOperator> op = IO_OP_CLASSES.get(name, type);
Preconditions.checkArgument(op != null, "No OP named %s has IOType: %s", name, type);
return op.hasTimestamp;
}
@SuppressWarnings("... | Assert.assertFalse(AnnotationUtils.isIoOpHasTimestamp("test_fake_op_1", IOType.SourceBatch));
Assert.assertTrue(AnnotationUtils.isIoOpHasTimestamp("test_fake_op_2", IOType.SourceBatch));
}
} |
150938406_211 | class AnnotationUtils {
public static boolean isIoOpHasTimestamp(String name, IOType type) {
Wrapper<AlgoOperator> op = IO_OP_CLASSES.get(name, type);
Preconditions.checkArgument(op != null, "No OP named %s has IOType: %s", name, type);
return op.hasTimestamp;
}
@SuppressWarnings("... | Assert.assertFalse(AnnotationUtils.isIoOpHasTimestamp("test_fake_op_1", IOType.SinkStream));
}
} |
150938406_212 | class AnnotationUtils {
public static boolean isIoOpHasTimestamp(String name, IOType type) {
Wrapper<AlgoOperator> op = IO_OP_CLASSES.get(name, type);
Preconditions.checkArgument(op != null, "No OP named %s has IOType: %s", name, type);
return op.hasTimestamp;
}
@SuppressWarnings("... | Assert.assertFalse(AnnotationUtils.isIoOpHasTimestamp("A_DB_HAS_NO_NAME", IOType.SourceBatch));
}
} |
150938406_213 | class AnnotationUtils {
public static AlgoOperator createOp(String name, IOType type, Params parameter) throws Exception {
Wrapper<AlgoOperator> op = IO_OP_CLASSES.get(name, type);
Preconditions.checkArgument(op != null, "No OP named %s has IOType: %s", name, type);
return op.clazz.getConst... | AlgoOperator op1 = AnnotationUtils.createOp("test_fake_op_1", IOType.SourceBatch, new Params());
Assert.assertTrue(op1 instanceof FakeOp1);
AlgoOperator op2 = AnnotationUtils.createOp("test_fake_op_2", IOType.SourceBatch, new Params());
Assert.assertTrue(op2 instanceof FakeOp2);
}
... |
150938406_216 | class ModelConverterUtils {
static void appendMetaRow(Params meta, Collector<Row> collector, final int numFields) {
if (meta != null) {
appendStringData(meta.toJson(), collector, numFields, 0);
}
}
static void appendDataRows(Iterable<String> data, Collector<Row> collector, fina... | Params meta = new Params().set(SOME_PARAM, "value");
MockCollector collector = new MockCollector();
ModelConverterUtils.appendMetaRow(meta, collector, 2);
Row row = collector.buffer.get(0);
Assert.assertEquals(row.getArity(), 2);
Assert.assertEquals(row.getField(0), 0L);
... |
150938406_217 | class ModelConverterUtils {
static void appendDataRows(Iterable<String> data, Collector<Row> collector, final int numFields) {
if (data != null) {
int index = 0;
for (String s : data) {
appendStringData(s, collector, numFields, index + 1);
index++;
... | List<String> stringList = new ArrayList<>();
stringList.add("apple");
stringList.add("banana");
MockCollector collector = new MockCollector();
ModelConverterUtils.appendDataRows(stringList, collector, 2);
Row row1 = collector.buffer.get(0);
Assert.assertEquals(row... |
150938406_218 | class ModelConverterUtils {
static <T> void appendAuxiliaryData(Iterable<T> auxData, Collector<Row> collector, final int numFields) {
if (auxData == null) {
return;
}
final int numAdditionalFields = numFields - 2;
int sliceIndex = 0;
for (T data : auxData) {
... | List<String> stringList = new ArrayList<>();
stringList.add("apple");
stringList.add("banana");
MockCollector collector = new MockCollector();
ModelConverterUtils.appendAuxiliaryData(stringList, collector, 3);
Row row1 = collector.buffer.get(0);
Assert.assertEqual... |
150938406_219 | class ModelConverterUtils {
static Tuple2<Params, Iterable<String>> extractModelMetaAndData(List<Row> rows) {
Integer[] order = orderModelRows(rows);
// extract meta
List<String> metaSegments = new ArrayList<>();
for (int i = 0; i < order.length; i++) {
long id = (Long)... | Params meta = new Params().set(SOME_PARAM, "value");
List<String> stringList = new ArrayList<>();
stringList.add("apple");
stringList.add("banana");
MockCollector collector = new MockCollector();
ModelConverterUtils.appendMetaRow(meta, collector, 2);
ModelConverte... |
150938406_220 | class ModelConverterUtils {
static <T> Iterable<T> extractAuxiliaryData(List<Row> rows, boolean isLabel) {
Integer[] order = orderModelRows(rows);
return new AuxiliaryDataIterable<T>(rows, order, isLabel);
}
static void appendMetaRow(Params meta, Collector<Row> collector, final int numFiel... | Params meta = new Params().set(SOME_PARAM, "value");
List<String> stringList = new ArrayList<>();
stringList.add("apple");
stringList.add("banana");
MockCollector collector = new MockCollector();
ModelConverterUtils.appendMetaRow(meta, collector, 3);
ModelConverte... |
150938406_221 | class VectorUtil {
public static DenseVector parseDense(String str) {
if (org.apache.flink.util.StringUtils.isNullOrWhitespaceOnly(str)) {
return new DenseVector();
}
int len = str.length();
int inDataBuffPos = 0;
boolean isInBuff = false;
for (int i = 0; i < len; ++i) {
char c = str.charAt(i);
... | DenseVector vec1 = VectorUtil.parseDense("1 2 -3");
DenseVector vec2 = VectorUtil.parseDense(" 1 2 -3 ");
DenseVector vec = new DenseVector(new double[]{1, 2, -3});
Assert.assertArrayEquals(vec1.getData(), vec.getData(), 0);
Assert.assertArrayEquals(vec2.getData(), vec.getData(), 0);
}
} |
150938406_222 | class VectorUtil {
public static String toString(Vector vector) {
if (vector instanceof SparseVector) {
return toString((SparseVector) vector);
}
return toString((DenseVector) vector);
}
private static Vector parse(String str);
public static DenseVector parseDense(String str);
public static SparseVector... | SparseVector v1 = new SparseVector(8, new int[]{1, 3, 5, 7}, new double[]{2.0, 2.0, 2.0, 2.0});
Assert.assertEquals(VectorUtil.toString(v1), "$8$1:2.0 3:2.0 5:2.0 7:2.0");
}
} |
150938406_223 | class VectorUtil {
public static SparseVector parseSparse(String str) {
try {
if (org.apache.flink.util.StringUtils.isNullOrWhitespaceOnly(str)) {
return new SparseVector();
}
int n = -1;
int firstDollarPos = str.indexOf(HEADER_DELIMITER);
int lastDollarPos = -1;
if (firstDollarPos >= 0) {
... | SparseVector vec1 = VectorUtil.parseSparse("0:1 2:-3");
SparseVector vec3 = VectorUtil.parseSparse("$4$0:1 2:-3");
SparseVector vec4 = VectorUtil.parseSparse("$4$");
SparseVector vec5 = VectorUtil.parseSparse("");
Assert.assertEquals(vec1.get(0), 1., 0.);
Assert.assertEquals(vec1.get(2), -3., 0.);
Assert.... |
150938406_224 | class MatVecOp {
public static Vector plus(Vector vec1, Vector vec2) {
return vec1.plus(vec2);
}
public static Vector minus(Vector vec1, Vector vec2);
public static double dot(Vector vec1, Vector vec2);
public static double sumAbsDiff(Vector vec1, Vector vec2);
public static double sum... | Vector plusResult1 = MatVecOp.plus(dv, sv);
Vector plusResult2 = MatVecOp.plus(sv, dv);
Vector plusResult3 = MatVecOp.plus(sv, sv);
Vector plusResult4 = MatVecOp.plus(dv, dv);
Assert.assertTrue(plusResult1 instanceof DenseVector);
Assert.assertTrue(plusResult2 instanceof ... |
150938406_225 | class MatVecOp {
public static Vector minus(Vector vec1, Vector vec2) {
return vec1.minus(vec2);
}
public static Vector plus(Vector vec1, Vector vec2);
public static double dot(Vector vec1, Vector vec2);
public static double sumAbsDiff(Vector vec1, Vector vec2);
public static double su... | Vector minusResult1 = MatVecOp.minus(dv, sv);
Vector minusResult2 = MatVecOp.minus(sv, dv);
Vector minusResult3 = MatVecOp.minus(sv, sv);
Vector minusResult4 = MatVecOp.minus(dv, dv);
Assert.assertTrue(minusResult1 instanceof DenseVector);
Assert.assertTrue(minusResult2 i... |
150938406_226 | class MatVecOp {
public static double dot(Vector vec1, Vector vec2) {
return vec1.dot(vec2);
}
public static Vector plus(Vector vec1, Vector vec2);
public static Vector minus(Vector vec1, Vector vec2);
public static double sumAbsDiff(Vector vec1, Vector vec2);
public static double sumS... | Assert.assertEquals(MatVecOp.dot(dv, sv), 4.0, TOL);
Assert.assertEquals(MatVecOp.dot(sv, dv), 4.0, TOL);
Assert.assertEquals(MatVecOp.dot(sv, sv), 2.0, TOL);
Assert.assertEquals(MatVecOp.dot(dv, dv), 30.0, TOL);
}
} |
150938406_227 | class MatVecOp {
public static double sumAbsDiff(Vector vec1, Vector vec2) {
if (vec1 instanceof DenseVector) {
if (vec2 instanceof DenseVector) {
return MatVecOp.applySum((DenseVector)vec1, (DenseVector)vec2, (a, b) -> Math.abs(a - b));
} else {
retu... | Assert.assertEquals(MatVecOp.sumAbsDiff(dv, sv), 8.0, TOL);
Assert.assertEquals(MatVecOp.sumAbsDiff(sv, dv), 8.0, TOL);
Assert.assertEquals(MatVecOp.sumAbsDiff(sv, sv), 0.0, TOL);
Assert.assertEquals(MatVecOp.sumAbsDiff(dv, dv), 0.0, TOL);
}
} |
150938406_228 | class MatVecOp {
public static double sumSquaredDiff(Vector vec1, Vector vec2) {
if (vec1 instanceof DenseVector) {
if (vec2 instanceof DenseVector) {
return MatVecOp.applySum((DenseVector)vec1, (DenseVector)vec2, (a, b) -> (a - b) * (a - b));
} else {
... | Assert.assertEquals(MatVecOp.sumSquaredDiff(dv, sv), 24.0, TOL);
Assert.assertEquals(MatVecOp.sumSquaredDiff(sv, dv), 24.0, TOL);
Assert.assertEquals(MatVecOp.sumSquaredDiff(sv, sv), 0.0, TOL);
Assert.assertEquals(MatVecOp.sumSquaredDiff(dv, dv), 0.0, TOL);
}
} |
150938406_229 | class SparseVector extends Vector {
@Override
public int size() {
return n;
}
public SparseVector();
public SparseVector(int n);
public SparseVector(int n, int[] indices, double[] values);
public SparseVector(int n, Map<Integer, Double> kv);
private void checkSizeAndIndice... | Assert.assertEquals(v1.size(), 8);
}
} |
150938406_230 | class SparseVector extends Vector {
@Override
public void set(int i, double val) {
int pos = Arrays.binarySearch(indices, i);
if (pos >= 0) {
this.values[pos] = val;
} else {
pos = -(pos + 1);
insert(pos, i, val);
}
}
public SparseVe... | SparseVector v = v1.clone();
v.set(2, 2.0);
v.set(3, 3.0);
Assert.assertEquals(v.get(2), 2.0, TOL);
Assert.assertEquals(v.get(3), 3.0, TOL);
}
} |
150938406_231 | class SparseVector extends Vector {
@Override
public void add(int i, double val) {
int pos = Arrays.binarySearch(indices, i);
if (pos >= 0) {
this.values[pos] += val;
} else {
pos = -(pos + 1);
insert(pos, i, val);
}
}
public SparseV... | SparseVector v = v1.clone();
v.add(2, 2.0);
v.add(3, 3.0);
Assert.assertEquals(v.get(2), 2.0, TOL);
Assert.assertEquals(v.get(3), 5.0, TOL);
}
} |
150938406_232 | class SparseVector extends Vector {
@Override
public SparseVector prefix(double d) {
int[] indices = new int[this.indices.length + 1];
double[] values = new double[this.values.length + 1];
int n = (this.n >= 0) ? this.n + 1 : this.n;
indices[0] = 0;
values[0] = d;
... | SparseVector prefixed = v1.prefix(0.2);
Assert.assertArrayEquals(prefixed.getIndices(), new int[]{0, 2, 4, 6, 8});
Assert.assertArrayEquals(prefixed.getValues(), new double[]{0.2, 2, 2, 2, 2}, 0);
}
} |
150938406_233 | class SparseVector extends Vector {
@Override
public SparseVector append(double d) {
int[] indices = new int[this.indices.length + 1];
double[] values = new double[this.values.length + 1];
int n = (this.n >= 0) ? this.n + 1 : this.n;
System.arraycopy(this.indices, 0, indices, 0... | SparseVector prefixed = v1.append(0.2);
Assert.assertArrayEquals(prefixed.getIndices(), new int[]{1, 3, 5, 7, 8});
Assert.assertArrayEquals(prefixed.getValues(), new double[]{2, 2, 2, 2, 0.2}, 0);
}
} |
150938406_234 | class SparseVector extends Vector {
private void sortIndices() {
boolean outOfOrder = false;
for (int i = 0; i < this.indices.length - 1; i++) {
if (this.indices[i] > this.indices[i + 1]) {
outOfOrder = true;
break;
}
}
if (out... | int n = 8;
int[] indices = new int[]{7, 5, 3, 1};
double[] values = new double[]{7, 5, 3, 1};
v1 = new SparseVector(n, indices, values);
Assert.assertArrayEquals(values, new double[]{1, 3, 5, 7}, 0.);
Assert.assertArrayEquals(v1.getValues(), new double[]{1, 3, 5, 7}, 0.);... |
150938406_235 | class SparseVector extends Vector {
@Override
public double normL2Square() {
double d = 0;
for (double t : values) {
d += t * t;
}
return d;
}
public SparseVector();
public SparseVector(int n);
public SparseVector(int n, int[] indices, double[] va... | Assert.assertEquals(v2.normL2Square(), 3.0, TOL);
}
} |
150938406_236 | class SparseVector extends Vector {
@Override
public Vector minus(Vector vec) {
if (this.size() != vec.size()) {
throw new IllegalArgumentException("The size of the two vectors are different.");
}
if (vec instanceof DenseVector) {
DenseVector r = ((DenseVector) ... | Vector d = v2.minus(v1);
Assert.assertEquals(d.get(0), 0.0, TOL);
Assert.assertEquals(d.get(1), -2.0, TOL);
Assert.assertEquals(d.get(2), 0.0, TOL);
Assert.assertEquals(d.get(3), -1.0, TOL);
Assert.assertEquals(d.get(4), 1.0, TOL);
}
} |
150938406_237 | class SparseVector extends Vector {
@Override
public Vector plus(Vector vec) {
if (this.size() != vec.size()) {
throw new IllegalArgumentException("The size of the two vectors are different.");
}
if (vec instanceof DenseVector) {
DenseVector r = ((DenseVector) v... | Vector d = v1.plus(v2);
Assert.assertEquals(d.get(0), 0.0, TOL);
Assert.assertEquals(d.get(1), 2.0, TOL);
Assert.assertEquals(d.get(2), 0.0, TOL);
Assert.assertEquals(d.get(3), 3.0, TOL);
DenseVector dv = DenseVector.ones(8);
dv = dv.plus(v2);
Assert.asse... |
150938406_238 | class SparseVector extends Vector {
private double dot(SparseVector other) {
if (this.size() != other.size()) {
throw new RuntimeException("the size of the two vectors are different");
}
double d = 0;
int p0 = 0;
int p1 = 0;
while (p0 < this.values.lengt... | Assert.assertEquals(v1.dot(v2), 4.0, TOL);
}
} |
150938406_239 | class SparseVector extends Vector {
@Override
public double get(int i) {
int pos = Arrays.binarySearch(indices, i);
if (pos >= 0) {
return values[pos];
}
return 0.;
}
public SparseVector();
public SparseVector(int n);
public SparseVector(int n, in... | Assert.assertEquals(v1.get(5), 2.0, TOL);
Assert.assertEquals(v1.get(6), 0.0, TOL);
}
} |
150938406_240 | class SparseVector extends Vector {
@Override
public SparseVector slice(int[] indices) {
SparseVector sliced = new SparseVector(indices.length);
int nnz = 0;
sliced.indices = new int[indices.length];
sliced.values = new double[indices.length];
for (int i = 0; i < indice... | int n = 8;
int[] indices = new int[]{1, 3, 5, 7};
double[] values = new double[]{2.0, 3.0, 4.0, 5.0};
SparseVector v = new SparseVector(n, indices, values);
int[] indices1 = new int[]{5, 4, 3};
SparseVector vec1 = v.slice(indices1);
Assert.assertEquals(vec1.size(... |
150938406_241 | class SparseVector extends Vector {
public DenseVector toDenseVector() {
if (n >= 0) {
DenseVector r = new DenseVector(n);
for (int i = 0; i < this.indices.length; i++) {
r.set(this.indices[i], this.values[i]);
}
return r;
} else {
... | int[] indices = new int[]{1, 3, 5};
double[] values = new double[]{1.0, 3.0, 5.0};
SparseVector v = new SparseVector(-1, indices, values);
DenseVector dv = v.toDenseVector();
Assert.assertEquals(dv.size(), 6);
Assert.assertArrayEquals(dv.getData(), new double[]{0, 1, 0, 3... |
150938406_242 | class SparseVector extends Vector {
public void removeZeroValues() {
if (this.values.length != 0) {
List<Integer> idxs = new ArrayList<>();
for (int i = 0; i < values.length; i++) {
if (0 != values[i]) {
idxs.add(i);
}
... | int[] indices = new int[]{1, 3, 5};
double[] values = new double[]{0.0, 3.0, 0.0};
SparseVector v = new SparseVector(6, indices, values);
v.removeZeroValues();
Assert.assertArrayEquals(v.getIndices(), new int[]{3});
Assert.assertArrayEquals(v.getValues(), new double[]{3},... |
150938406_243 | class SparseVector extends Vector {
@Override
public DenseMatrix outer() {
return this.outer(this);
}
public SparseVector();
public SparseVector(int n);
public SparseVector(int n, int[] indices, double[] values);
public SparseVector(int n, Map<Integer, Double> kv);
private... | DenseMatrix outerProduct = v1.outer(v2);
Assert.assertEquals(outerProduct.numRows(), 8);
Assert.assertEquals(outerProduct.numCols(), 8);
Assert.assertArrayEquals(outerProduct.getRow(0), new double[]{0, 0, 0, 0, 0, 0, 0, 0}, TOL);
Assert.assertArrayEquals(outerProduct.getRow(1), n... |
150938406_244 | class SparseVector extends Vector {
@Override
public VectorIterator iterator() {
return new SparseVectorVectorIterator();
}
public SparseVector();
public SparseVector(int n);
public SparseVector(int n, int[] indices, double[] values);
public SparseVector(int n, Map<Integer, Dou... | VectorIterator iterator = v1.iterator();
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.getIndex(), 1);
Assert.assertEquals(iterator.getValue(), 2, 0);
iterator.next();
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.getInd... |
150938406_250 | class DenseVector extends Vector {
@Override
public DenseVector slice(int[] indices) {
double[] values = new double[indices.length];
for (int i = 0; i < indices.length; ++i) {
if (indices[i] >= data.length) {
throw new IllegalArgumentException("Index is larger than v... | DenseVector vec = new DenseVector(new double[]{1, 2, -3});
DenseVector sliced = vec.slice(new int[]{0, 2});
Assert.assertArrayEquals(new double[]{1, -3}, sliced.getData(), 0);
}
} |
150938406_254 | class DenseVector extends Vector {
@Override
public double dot(Vector vec) {
if (vec instanceof DenseVector) {
return BLAS.dot(this, (DenseVector) vec);
} else {
return ((SparseVector) vec).dot(this);
}
}
public DenseVector();
public DenseVector(in... | DenseVector vec1 = new DenseVector(new double[]{1, 2, -3});
DenseVector vec2 = new DenseVector(new double[]{3, 2, 1});
Assert.assertEquals(vec1.dot(vec2), 3 + 4 - 3, TOL);
}
} |
150938406_259 | class BLAS {
public static double asum(int n, double[] x, int offset) {
return F2J_BLAS.dasum(n, x, offset, 1);
}
public static double asum(DenseVector x);
public static double asum(SparseVector x);
public static void axpy(double a, double[] x, double[] y);
public static void axpy(doub... | Assert.assertEquals(BLAS.asum(dv1), 3.0, TOL);
Assert.assertEquals(BLAS.asum(spv1), 3.0, TOL);
}
} |
150938406_260 | class BLAS {
public static void scal(double a, double[] x) {
F2J_BLAS.dscal(x.length, a, x, 1);
}
public static double asum(int n, double[] x, int offset);
public static double asum(DenseVector x);
public static double asum(SparseVector x);
public static void axpy(double a, double[] x,... | DenseVector v1 = dv1.clone();
BLAS.scal(0.5, v1);
Assert.assertArrayEquals(v1.getData(), new double[]{0.5, 1.0}, TOL);
SparseVector v2 = spv1.clone();
BLAS.scal(0.5, v2);
Assert.assertArrayEquals(v2.getIndices(), spv1.getIndices());
Assert.assertArrayEquals(v2.ge... |
150938406_261 | class BLAS {
public static double dot(double[] x, double[] y) {
Preconditions.checkArgument(x.length == y.length, "Array dimension mismatched.");
double s = 0.;
for (int i = 0; i < x.length; i++) {
s += x[i] * y[i];
}
return s;
}
public static double asu... | DenseVector v = DenseVector.ones(2);
Assert.assertEquals(BLAS.dot(dv1, v), 3.0, TOL);
}
} |
150938406_262 | class BLAS {
public static void axpy(double a, double[] x, double[] y) {
Preconditions.checkArgument(x.length == y.length, "Array dimension mismatched.");
F2J_BLAS.daxpy(x.length, a, x, 1, y, 1);
}
public static double asum(int n, double[] x, int offset);
public static double asum(Dens... | DenseVector v = DenseVector.ones(2);
BLAS.axpy(1.0, dv1, v);
Assert.assertArrayEquals(v.getData(), new double[]{2, 3}, TOL);
BLAS.axpy(1.0, spv1, v);
Assert.assertArrayEquals(v.getData(), new double[]{3, 5}, TOL);
BLAS.axpy(1, 1.0, new double[]{1}, 0, v.getData(), 1);
... |
150938406_272 | class DenseMatrix implements Serializable {
public void plusEquals(DenseMatrix mat) {
BLAS.axpy(1.0, mat, this);
}
public DenseMatrix();
public DenseMatrix(int m, int n);
public DenseMatrix(int m, int n, double[] data);
public DenseMatrix(int m, int n, double[] data, boolean inRowM... | DenseMatrix matA = new DenseMatrix(new double[][]{
new double[]{1, 3, 5},
new double[]{2, 4, 6},
});
DenseMatrix matB = DenseMatrix.ones(2, 3);
matA.plusEquals(matB);
Assert.assertArrayEquals(matA.getData(), new double[]{2, 3, 4, 5, 6, 7}, TOL);
ma... |
150938406_273 | class DenseMatrix implements Serializable {
public void minusEquals(DenseMatrix mat) {
BLAS.axpy(-1.0, mat, this);
}
public DenseMatrix();
public DenseMatrix(int m, int n);
public DenseMatrix(int m, int n, double[] data);
public DenseMatrix(int m, int n, double[] data, boolean inRo... | DenseMatrix matA = new DenseMatrix(new double[][]{
new double[]{1, 3, 5},
new double[]{2, 4, 6},
});
DenseMatrix matB = DenseMatrix.ones(2, 3);
matA.minusEquals(matB);
Assert.assertArrayEquals(matA.getData(), new double[]{0, 1, 2, 3, 4, 5}, TOL);
}
} |
150938406_274 | class DenseMatrix implements Serializable {
public DenseMatrix plus(DenseMatrix mat) {
DenseMatrix r = this.clone();
BLAS.axpy(1.0, mat, r);
return r;
}
public DenseMatrix();
public DenseMatrix(int m, int n);
public DenseMatrix(int m, int n, double[] data);
public D... | DenseMatrix matA = new DenseMatrix(new double[][]{
new double[]{1, 3, 5},
new double[]{2, 4, 6},
});
DenseMatrix matB = DenseMatrix.ones(2, 3);
DenseMatrix matC = matA.plus(matB);
Assert.assertArrayEquals(matC.getData(), new double[]{2, 3, 4, 5, 6, 7}, TOL... |
150938406_275 | class DenseMatrix implements Serializable {
public DenseMatrix minus(DenseMatrix mat) {
DenseMatrix r = this.clone();
BLAS.axpy(-1.0, mat, r);
return r;
}
public DenseMatrix();
public DenseMatrix(int m, int n);
public DenseMatrix(int m, int n, double[] data);
public ... | DenseMatrix matA = new DenseMatrix(new double[][]{
new double[]{1, 3, 5},
new double[]{2, 4, 6},
});
DenseMatrix matB = DenseMatrix.ones(2, 3);
DenseMatrix matC = matA.minus(matB);
Assert.assertArrayEquals(matC.getData(), new double[]{0, 1, 2, 3, 4, 5}, TO... |
150938406_276 | class DenseMatrix implements Serializable {
public double sum() {
double s = 0.;
for (int i = 0; i < this.data.length; i++) {
s += this.data[i];
}
return s;
}
public DenseMatrix();
public DenseMatrix(int m, int n);
public DenseMatrix(int m, int n, dou... | DenseMatrix matA = DenseMatrix.ones(3, 2);
Assert.assertEquals(matA.sum(), 6.0, TOL);
}
} |
150938406_277 | class DenseMatrix implements Serializable {
public double[] getData() {
return this.data;
}
public DenseMatrix();
public DenseMatrix(int m, int n);
public DenseMatrix(int m, int n, double[] data);
public DenseMatrix(int m, int n, double[] data, boolean inRowMajor);
public Dens... | double[] data = new double[]{1, 2, 3, 4, 5, 6};
DenseMatrix matA = new DenseMatrix(2, 3, data, true);
Assert.assertArrayEquals(data, new double[]{1, 4, 2, 5, 3, 6}, 0.);
Assert.assertArrayEquals(matA.getData(), new double[]{1, 4, 2, 5, 3, 6}, 0.);
data = new double[]{1, 2, 3, 4}... |
150938406_278 | class DenseMatrix implements Serializable {
public double norm2() {
return new SingularValueDecomposition(this).norm2();
}
public DenseMatrix();
public DenseMatrix(int m, int n);
public DenseMatrix(int m, int n, double[] data);
public DenseMatrix(int m, int n, double[] data, boolea... | DenseMatrix matA = DenseMatrix.zeros(4, 5);
matA.set(0, 0, 1);
matA.set(0, 4, 2);
matA.set(1, 2, 3);
matA.set(3, 1, 2);
Assert.assertEquals(matA.norm2(), 3., TOL);
}
} |
150938406_279 | class DenseMatrix implements Serializable {
public double cond() {
return new SingularValueDecomposition(this).cond();
}
public DenseMatrix();
public DenseMatrix(int m, int n);
public DenseMatrix(int m, int n, double[] data);
public DenseMatrix(int m, int n, double[] data, boolean ... | DenseMatrix matA = DenseMatrix.zeros(4, 5);
matA.set(0, 0, 1);
matA.set(0, 4, 2);
matA.set(1, 2, 3);
matA.set(3, 1, 2);
double[] answer = new double[]{3.0, 2.23606797749979, 2.0, 0.0};
Assert.assertArrayEquals(answer, new SingularValueDecomposition(matA).getSingul... |
150938406_280 | class DenseMatrix implements Serializable {
public double det() {
assert (this.isSquare());
return BreezeUtils.det(this);
}
public DenseMatrix();
public DenseMatrix(int m, int n);
public DenseMatrix(int m, int n, double[] data);
public DenseMatrix(int m, int n, double[] dat... | double[][] data1 = {
{-2, 2, -3},
{-1, 1, 3},
{2, 0, -1},
};
DenseMatrix matA = new DenseMatrix(data1);
Assert.assertEquals(matA.det(), 18.0, TOL);
}
} |
150938406_281 | class DenseMatrix implements Serializable {
public int rank() {
return BreezeUtils.rank(this);
}
public DenseMatrix();
public DenseMatrix(int m, int n);
public DenseMatrix(int m, int n, double[] data);
public DenseMatrix(int m, int n, double[] data, boolean inRowMajor);
public ... | double[][] data1 = {
{-2, 2, -3},
{-1, 1, 3},
{2, 0, -1},
};
DenseMatrix matA = new DenseMatrix(data1);
Assert.assertEquals(matA.rank(), 3);
double[][] data2 = {
{-2, 2, -3},
{-1, 1, -1.5},
{2, 0, -1},
... |
150938406_282 | class DenseMatrix implements Serializable {
public DenseMatrix solve(DenseMatrix matB) {
assert (this.numRows() == matB.numRows());
if (this.m == this.n) {
if (this.isSymmetric()) {
DenseMatrix matA = this.clone();
DenseMatrix x = matB.clone();
... | {
// symmetric case
DenseMatrix matA = DenseMatrix.randSymmetric(5);
DenseMatrix b = DenseMatrix.rand(5, 7);
DenseMatrix x = matA.solve(b);
DenseMatrix b0 = matA.multiplies(x);
assertEqual2D(b.getArrayCopy2D(), b0.getArrayCopy2D());
... |
150938406_284 | class DenseMatrix implements Serializable {
public DenseMatrix inverse() {
return BreezeUtils.inverse(this);
}
public DenseMatrix();
public DenseMatrix(int m, int n);
public DenseMatrix(int m, int n, double[] data);
public DenseMatrix(int m, int n, double[] data, boolean inRowMajor... | DenseMatrix matA = DenseMatrix.rand(5, 5);
DenseMatrix matIA = matA.inverse();
DenseMatrix matAIA = matA.multiplies(matIA);
DenseMatrix matI = DenseMatrix.eye(5);
assertEqual2D(matAIA.getArrayCopy2D(), matI.getArrayCopy2D());
}
} |
150938406_290 | class TableUtil {
public static String[] getNumericCols(TableSchema tableSchema) {
return getNumericCols(tableSchema, null);
}
public static synchronized String getTempTableName();
public static int findColIndex(String[] tableCols, String targetCol);
public static int findColIndexWithAsser... | TableSchema tableSchema = new TableSchema(new String[]{"f0", "f1", "F2", "f3"},
new TypeInformation[]{Types.INT, Types.LONG, Types.STRING, Types.BOOLEAN});
Assert.assertArrayEquals(TableUtil.getNumericCols(tableSchema), new String[]{"f0", "f1"});
Assert.assertArrayEquals(TableUtil.g... |
150938406_292 | class TableUtil {
public static int findColIndexWithAssertAndHint(String[] tableCols, String targetCol) {
int index = findColIndex(tableCols, targetCol);
if(index < 0){
double maxSimilarity = 0.0;
String similarCol = null;
for(String s : tableCols){
... | thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Can not find column: features, do you mean: feature ?");
String[] colNames = new String[]{"id", "text", "vector", "feature"};
TableUtil.findColIndexWithAssertAndHint(colNames, "features");
}
} |
150938406_293 | class OutputColsHelper implements Serializable {
public TableSchema getResultSchema() {
int resultLength = reservedCols.length + outputColNames.length;
String[] resultColNames = new String[resultLength];
TypeInformation[] resultColTypes = new TypeInformation[resultLength];
for (int ... | TableSchema expectSchema = new TableSchema(
new String[]{"f0", "f1", "f2", "res"},
new TypeInformation[]{
TypeInformation.of(String.class),
TypeInformation.of(Long.class),
TypeInformation.of(Integer.class),
TypeInformation.o... |
150938406_294 | class OutputColsHelper implements Serializable {
public Row getResultRow(Row input, Row output) {
int numOutputs = outputColsPosInResult.length;
if (output.getArity() != numOutputs) {
throw new IllegalArgumentException("Invalid output size");
}
int resultLength = reserve... | OutputColsHelper helper = new OutputColsHelper(
tableSchema, "res", TypeInformation.of(String.class)
);
Row expectRow = Row.of("a", 1L, 1, "b");
Assert.assertEquals(helper.getResultRow(row, Row.of("b")), expectRow);
helper = new OutputColsHelper(
tableSch... |
150938406_295 | class OutputColsHelper implements Serializable {
public TableSchema getResultSchema() {
int resultLength = reservedCols.length + outputColNames.length;
String[] resultColNames = new String[resultLength];
TypeInformation[] resultColTypes = new TypeInformation[resultLength];
for (int ... | TableSchema expectSchema = new TableSchema(
new String[]{"f0", "res"},
new TypeInformation[]{
TypeInformation.of(String.class),
TypeInformation.of(Integer.class)
}
);
OutputColsHelper helper = new OutputColsHelper(
t... |
150938406_296 | class IterativeComQueue extends BaseComQueue <IterativeComQueue> {
@Override
public IterativeComQueue setMaxIter(int maxIter) {
return super.setMaxIter(maxIter);
}
public IterativeComQueue();
@Override public IterativeComQueue setCompareCriterionOfNode0(CompareCriterionFunction compareCriterion);
private s... | DataSet<Row> result = new IterativeComQueue()
.add(new ComputeFunction() {
@Override
public void calc(ComContext context) {
if (1 == context.getStepNo()) {
context.putObj("cnt", new int[]{0});
}
int[] cnt = context.getObj("cnt");
double x = Math.random();
double y = Math.rand... |
150938406_297 | class IterativeComQueue extends BaseComQueue <IterativeComQueue> {
@Override
public IterativeComQueue setMaxIter(int maxIter) {
return super.setMaxIter(maxIter);
}
public IterativeComQueue();
@Override public IterativeComQueue setCompareCriterionOfNode0(CompareCriterionFunction compareCriterion);
private s... | final int m = 10000;
final int n = 3;
List<Tuple2<DenseVector, Double>> data = new ArrayList<>();
for (int i = 0; i < m; ++i) {
DenseVector feature = DenseVector.rand(n);
data.add(Tuple2.of(feature.append(1.0), feature.dot(DenseVector.ones(n))));
}
DataSet<Tuple2<DenseVector, Double>> trainData =
... |
150938406_298 | class IterativeComQueue extends BaseComQueue <IterativeComQueue> {
@Override
public IterativeComQueue setMaxIter(int maxIter) {
return super.setMaxIter(maxIter);
}
public IterativeComQueue();
@Override public IterativeComQueue setCompareCriterionOfNode0(CompareCriterionFunction compareCriterion);
private s... | final long start = System.currentTimeMillis();
final int m = 10000;
final int n = 20;
List<Tuple2<DenseVector, Double>> data = new ArrayList<>();
for (int i = 0; i < m; ++i) {
DenseVector feature = DenseVector.rand(n);
data.add(Tuple2.of(feature.append(1.0), feature.dot(DenseVector.ones(n))));
}
... |
150938406_299 | class IterativeComQueue extends BaseComQueue <IterativeComQueue> {
@Override
public IterativeComQueue setMaxIter(int maxIter) {
return super.setMaxIter(maxIter);
}
public IterativeComQueue();
@Override public IterativeComQueue setCompareCriterionOfNode0(CompareCriterionFunction compareCriterion);
private s... | try {
DataSet<Row> ret = new IterativeComQueue()
.setMaxIter(1)
.add(new ComputeFunction() {
@Override
public void calc(ComContext context) {
context.putObj("allReduce", new double[]{1.0, 1.0, 1.0});
}
})
.add(new AllReduce("allReduce"))
.add(new ComputeFunction() {
@O... |
150938406_300 | class BaseComQueue implements Serializable {
private void optimize() {
if (queue.isEmpty()) {
return;
}
int current = 0;
for (int ahead = 1; ahead < queue.size(); ++ahead) {
ComQueueItem curItem = queue.get(current);
ComQueueItem aheadItem = queue.get(ahead);
if (aheadItem instanceof ComputeFunc... | IterativeComQueue queue = new IterativeComQueue()
.add(new MyComputeFunction())
.add(new MyComputeFunction())
.add(new MyCommunicateFunction())
.add(new MyCommunicateFunction())
.add(new MyComputeFunction())
.add(new MyComputeFunction())
.add(new MyCommunicateFunction());
queue.exec();
Asse... |
95081481_1009 | class OspfConfigUtil {
public static List<OspfProcess> processes(JsonNode jsonNodes) {
List<OspfProcess> ospfProcesses = new ArrayList<>();
if (jsonNodes == null) {
return ospfProcesses;
}
//From each Process nodes, get area and related interface details.
jsonNod... | jsonNode.path("areas");
ospfProcessList = OspfConfigUtil.processes(jsonNode);
assertThat(ospfProcessList, is(notNullValue()));
}
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.