Skip to content

Commit

Permalink
multiply3d subtract3d maximum3d average3d (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
syt123450 committed Sep 15, 2018
1 parent 85f831d commit e056236
Show file tree
Hide file tree
Showing 10 changed files with 573 additions and 11 deletions.
47 changes: 46 additions & 1 deletion src/merge/Average.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,52 @@
function Average() {
import {MergedLayer3d} from "../layer/abstract/MergedLayer3d";

function Average(layerList) {

let operatorType = "average";

validate(layerList);

return createMergedLayer(layerList);

function validate(layerList) {

let depth;

if (layerList.length > 0) {
depth = layerList[0].layerDimension;
} else {
console.error("Merge Layer missing elements.");
}

for (let i = 0; i < layerList.length; i++) {

if (layerList[i].layerDimension !== depth) {
console.error("Can not add layer with different depth.");
}

}

}

function createMergedLayer(layerList) {

if (layerList[0].layerDimension === 1) {

} else if (layerList[0].layerDimension === 2) {

} else if (layerList[0].layerDimension === 3) {

return new MergedLayer3d({
operator: operatorType,
mergedElements: layerList
});

} else {
console.error("Do not support layer add operation more than 4 dimension.");
}

}

}

export { Average };
47 changes: 46 additions & 1 deletion src/merge/Maximum.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,52 @@
function Maximum() {
import {MergedLayer3d} from "../layer/abstract/MergedLayer3d";

function Maximum(layerList) {

let operatorType = "maximum";

validate(layerList);

return createMergedLayer(layerList);

function validate(layerList) {

let depth;

if (layerList.length > 0) {
depth = layerList[0].layerDimension;
} else {
console.error("Merge Layer missing elements.");
}

for (let i = 0; i < layerList.length; i++) {

if (layerList[i].layerDimension !== depth) {
console.error("Can not add layer with different depth.");
}

}

}

function createMergedLayer(layerList) {

if (layerList[0].layerDimension === 1) {

} else if (layerList[0].layerDimension === 2) {

} else if (layerList[0].layerDimension === 3) {

return new MergedLayer3d({
operator: operatorType,
mergedElements: layerList
});

} else {
console.error("Do not support layer add operation more than 4 dimension.");
}

}

}

export { Maximum };
47 changes: 46 additions & 1 deletion src/merge/Multiply.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,52 @@
function Multiply() {
import {MergedLayer3d} from "../layer/abstract/MergedLayer3d";

function Multiply(layerList) {

let operatorType = "multiply";

validate(layerList);

return createMergedLayer(layerList);

function validate(layerList) {

let depth;

if (layerList.length > 0) {
depth = layerList[0].layerDimension;
} else {
console.error("Merge Layer missing elements.");
}

for (let i = 0; i < layerList.length; i++) {

if (layerList[i].layerDimension !== depth) {
console.error("Can not add layer with different depth.");
}

}

}

function createMergedLayer(layerList) {

if (layerList[0].layerDimension === 1) {

} else if (layerList[0].layerDimension === 2) {

} else if (layerList[0].layerDimension === 3) {

return new MergedLayer3d({
operator: operatorType,
mergedElements: layerList
});

} else {
console.error("Do not support layer add operation more than 4 dimension.");
}

}

}

export { Multiply };
47 changes: 46 additions & 1 deletion src/merge/Subtract.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,52 @@
function Subtract() {
import {MergedLayer3d} from "../layer/abstract/MergedLayer3d";

function Subtract(layerList) {

let operatorType = "subtract";

validate(layerList);

return createMergedLayer(layerList);

function validate(layerList) {

let depth;

if (layerList.length > 0) {
depth = layerList[0].layerDimension;
} else {
console.error("Merge Layer missing elements.");
}

for (let i = 0; i < layerList.length; i++) {

if (layerList[i].layerDimension !== depth) {
console.error("Can not add layer with different depth.");
}

}

}

function createMergedLayer(layerList) {

if (layerList[0].layerDimension === 1) {

} else if (layerList[0].layerDimension === 2) {

} else if (layerList[0].layerDimension === 3) {

return new MergedLayer3d({
operator: operatorType,
mergedElements: layerList
});

} else {
console.error("Do not support layer add operation more than 4 dimension.");
}

}

}

export { Subtract };
96 changes: 95 additions & 1 deletion src/merge/strategy/Average3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,107 @@ Average3d.prototype = {

validate: function() {

let inputShape = this.mergedElements[0].outputShape;

for (let i = 0; i < this.mergedElements.length; i++) {

let outputShape = this.mergedElements[i].outputShape;

for (let j = 0; j < inputShape.length; j++) {

if (outputShape[j] !== inputShape[j]) {
return false;
}

}

}

return true;

},

getShape: function() {

return this.mergedElements[0].outputShape;

},

getRelativeElements: function() {
getRelativeElements: function(selectedElement) {

let curveElements = [];
let straightElements = [];

if (selectedElement.elementType === "aggregationElement") {

let request = {
all: true
};

for (let i = 0; i < this.mergedElements.length; i++) {
let relativeResult = this.mergedElements[i].provideRelativeElements(request);
let relativeElements = relativeResult.elementList;
if (this.mergedElements[i].layerIndex === this.layerIndex - 1) {

for (let j = 0; j < relativeElements.length; j++) {
straightElements.push(relativeElements[j]);
}

} else {

if (relativeResult.isOpen) {
for (let j = 0; j < relativeElements.length; j++) {
straightElements.push(relativeElements[j]);
}
} else {
for (let j = 0; j < relativeElements.length; j++) {
curveElements.push(relativeElements[j]);
}
}

}
}

} else if (selectedElement.elementType === "featureMap") {

let fmIndex = selectedElement.fmIndex;
let request = {
index: fmIndex
};

for (let i = 0; i < this.mergedElements.length; i++) {
let relativeResult = this.mergedElements[i].provideRelativeElements(request);
let relativeElements = relativeResult.elementList;

if (this.mergedElements[i].layerIndex === this.layerIndex - 1) {

for (let j = 0; j < relativeElements.length; j++) {
straightElements.push(relativeElements[j]);
}

} else {

if (relativeResult.isOpen) {
for (let j = 0; j < relativeElements.length; j++) {
straightElements.push(relativeElements[j]);
}
} else {
for (let j = 0; j < relativeElements.length; j++) {
curveElements.push(relativeElements[j]);
}
}

}

}

}

return {
straight: straightElements,
curve: curveElements
};


}

Expand Down
Loading

0 comments on commit e056236

Please sign in to comment.