Skip to content

Commit

Permalink
Merge branch 'hotfix' into branch-2.0.2
Browse files Browse the repository at this point in the history
# Conflicts:
#	angel-ps/mllib/src/test/java/com/tencent/angel/ml/logisticregression/LRTest.java
  • Loading branch information
payniexiao committed Jan 30, 2019
2 parents 7f61eb2 + bd62453 commit 4915e83
Show file tree
Hide file tree
Showing 262 changed files with 57,114 additions and 40,623 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ spark-on-angel/mllib/log/
spark-on-angel/log/
angel-ps/core/velocity.*
angel-ps/core/src/main/java/com/tencent/angel/ml/math2/velocity
angel-math/target
angel-mlcore/target
angel-format/target

258 changes: 160 additions & 98 deletions angel-ps/core/src/main/java/com/tencent/angel/ml/math2/MFactory.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* 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
*
* https://opensource.org/licenses/Apache-2.0
Expand All @@ -19,6 +19,7 @@
package com.tencent.angel.ml.math2;

public abstract class MathObject {

protected int matrixId;
protected int clock;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,22 @@
*/
public class MatrixExecutors {

public static final String WORKER_NUM_PARAMETER_NAME = "angel.math.matrix.op.parallel.worker.num";
private static final Log LOG = LogFactory.getLog(MatrixExecutors.class);
/**
* Matrix executor instance
*/
private static MatrixExecutors instance;

static {

}

/**
* Worker pool of the executor
*/
private final ForkJoinPool pool;

public static final String WORKER_NUM_PARAMETER_NAME = "angel.math.matrix.op.parallel.worker.num";

static {

}

private MatrixExecutors(int poolSize) {
pool = new ForkJoinPool(poolSize);
}
Expand All @@ -55,7 +54,7 @@ private MatrixExecutors(int poolSize) {
* @return matrix executor instance
*/
public synchronized static MatrixExecutors getInstance() {
if(instance == null) {
if (instance == null) {
int poolSize;
int defaultPoolSize = Runtime.getRuntime().availableProcessors();
String numStr = System.getProperty(WORKER_NUM_PARAMETER_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* 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
*
* https://opensource.org/licenses/Apache-2.0
Expand Down
276 changes: 160 additions & 116 deletions angel-ps/core/src/main/java/com/tencent/angel/ml/math2/VFactory.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* 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
*
* https://opensource.org/licenses/Apache-2.0
Expand All @@ -19,13 +19,22 @@
package com.tencent.angel.ml.math2.matrix;

import com.tencent.angel.exception.AngelException;
import com.tencent.angel.ml.math2.storage.*;
import com.tencent.angel.ml.math2.vector.*;
import com.tencent.angel.ml.math2.VFactory;
import it.unimi.dsi.fastutil.ints.*;
import com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage;
import com.tencent.angel.ml.math2.vector.IntDoubleVector;
import com.tencent.angel.ml.math2.vector.IntDummyVector;
import com.tencent.angel.ml.math2.vector.IntFloatVector;
import com.tencent.angel.ml.math2.vector.IntIntVector;
import com.tencent.angel.ml.math2.vector.IntLongVector;
import com.tencent.angel.ml.math2.vector.Vector;
import it.unimi.dsi.fastutil.ints.Int2DoubleMap;
import it.unimi.dsi.fastutil.ints.Int2FloatMap;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2LongMap;
import it.unimi.dsi.fastutil.objects.ObjectIterator;

public class BlasDoubleMatrix extends BlasMatrix {

private double[] data;

public BlasDoubleMatrix() {
Expand All @@ -52,7 +61,8 @@ public void setData(double[] data) {
this.data = data;
}

@Override public double min() {
@Override
public double min() {
double minVal = Double.MAX_VALUE;
for (int k = 0; k < numRows * numCols; k++) {
if (data[k] < minVal) {
Expand All @@ -63,7 +73,8 @@ public void setData(double[] data) {
return minVal;
}

@Override public Vector min(int axis) {
@Override
public Vector min(int axis) {
// axis = 0: on rows
// axis = 1: on cols
assert (axis == 0 || axis == 1);
Expand Down Expand Up @@ -102,7 +113,8 @@ public void setData(double[] data) {
return VFactory.denseDoubleVector(matrixId, 0, clock, rdVec);
}

@Override public double max() {
@Override
public double max() {
double maxVal = Double.MIN_VALUE;
for (int k = 0; k < numRows * numCols; k++) {
if (data[k] > maxVal) {
Expand All @@ -113,7 +125,8 @@ public void setData(double[] data) {
return maxVal;
}

@Override public Vector max(int axis) {
@Override
public Vector max(int axis) {
// axis = 0: on rows
// axis = 1: on cols
assert (axis == 0 || axis == 1);
Expand Down Expand Up @@ -198,15 +211,17 @@ public Vector argmax(int axis) {
return VFactory.denseDoubleVector(matrixId, 0, clock, idxVec);
}

@Override public double sum() {
@Override
public double sum() {
double res = 0.0;
for (double value : data) {
res += value;
}
return res;
}

@Override public Vector sum(int axis) {
@Override
public Vector sum(int axis) {
// axis = 0: on rows
// axis = 1: on cols
assert (axis == 0 || axis == 1);
Expand All @@ -233,7 +248,8 @@ public Vector argmax(int axis) {
return VFactory.denseDoubleVector(matrixId, 0, clock, rdVec);
}

@Override public double std() {
@Override
public double std() {
double sum1 = 0.0, sum2 = 0.0;
for (double value : data) {
sum1 += value;
Expand All @@ -245,7 +261,8 @@ public Vector argmax(int axis) {
return Math.sqrt(sum2 - sum1 * sum1);
}

@Override public Vector std(int axis) {
@Override
public Vector std(int axis) {
// axis = 0: on rows
// axis = 1: on cols
assert (axis == 0 || axis == 1);
Expand Down Expand Up @@ -291,11 +308,13 @@ public Vector argmax(int axis) {
return VFactory.denseDoubleVector(matrixId, 0, clock, rdVec);
}

@Override public double average() {
@Override
public double average() {
return sum() / (numRows * numCols);
}

@Override public Vector average(int axis) {
@Override
public Vector average(int axis) {
assert (axis == 0 || axis == 1);
Vector res = null;
switch (axis) {
Expand All @@ -310,15 +329,17 @@ public Vector argmax(int axis) {
return res;
}

@Override public double norm() {
@Override
public double norm() {
double res = 0.0;
for (double value : data) {
res += value * value;
}
return Math.sqrt(res);
}

@Override public Vector norm(int axis) {
@Override
public Vector norm(int axis) {
// axis = 0: on rows
// axis = 1: on cols
assert (axis == 0 || axis == 1);
Expand Down Expand Up @@ -355,7 +376,8 @@ public Vector argmax(int axis) {
return VFactory.denseDoubleVector(matrixId, 0, clock, rdVec);
}

@Override public Vector diag() {
@Override
public Vector diag() {
int numDiag = Math.min(numRows, numCols);
double[] resArr = new double[numDiag];
for (int i = 0; i < numDiag; i++) {
Expand All @@ -366,7 +388,8 @@ public Vector argmax(int axis) {
return new IntDoubleVector(getMatrixId(), 0, getClock(), resArr.length, storage);
}

@Override public void clear() {
@Override
public void clear() {
for (int i = 0; i < numCols * numRows; i++) {
data[i] = 0;
}
Expand All @@ -377,7 +400,8 @@ public Vector argmax(int axis) {
numCols = 0;
}

@Override public Matrix copy() {
@Override
public Matrix copy() {
double[] newData = new double[numCols * numRows];
System.arraycopy(data, 0, newData, 0, numCols * numRows);
return new BlasDoubleMatrix(matrixId, clock, numRows, numCols, newData);
Expand All @@ -397,15 +421,17 @@ public void set(int i, int j, double value) {
data[i * numCols + j] = value;
}

@Override public Vector getRow(int i) {
@Override
public Vector getRow(int i) {
double[] row = new double[numCols];
System.arraycopy(data, i * numCols, row, 0, numCols);

IntDoubleDenseVectorStorage storage = new IntDoubleDenseVectorStorage(row);
return new IntDoubleVector(getMatrixId(), i, getClock(), numCols, storage);
}

@Override public Vector getCol(int j) {
@Override
public Vector getCol(int j) {
double[] col = new double[numRows];

for (int i = 0; i < numRows; i++) {
Expand All @@ -424,7 +450,7 @@ public Matrix setRow(int i, Vector v) {
} else if (v.isSparse()) {
rowData = new double[numCols];
ObjectIterator<Int2DoubleMap.Entry> iter =
((IntDoubleVector) v).getStorage().entryIterator();
((IntDoubleVector) v).getStorage().entryIterator();
while (iter.hasNext()) {
Int2DoubleMap.Entry entry = iter.next();
int j = entry.getIntKey();
Expand Down Expand Up @@ -547,7 +573,7 @@ public Matrix setCol(int i, Vector v) {
} else if (v.isSparse()) {
rowData = new double[numRows];
ObjectIterator<Int2DoubleMap.Entry> iter =
((IntDoubleVector) v).getStorage().entryIterator();
((IntDoubleVector) v).getStorage().entryIterator();
while (iter.hasNext()) {
Int2DoubleMap.Entry entry = iter.next();
int j = entry.getIntKey();
Expand Down
Loading

0 comments on commit 4915e83

Please sign in to comment.