aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-11-23 00:13:16 +0100
committerJon Bratseth <bratseth@yahoo-inc.com>2016-11-23 00:13:16 +0100
commitc038ac2edd3f22fa42a4b479de8c754ff4113992 (patch)
tree9da990d7c3fe6811f480cfbdb431c8673479aca2 /vespajlib
parent79c58529b9e505352cc97942b3d9cf932d622ada (diff)
Remove old tensorproduct
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/TensorOperations.java28
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/TensorProduct.java89
2 files changed, 0 insertions, 117 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/TensorOperations.java b/vespajlib/src/main/java/com/yahoo/tensor/TensorOperations.java
deleted file mode 100644
index aca306b914c..00000000000
--- a/vespajlib/src/main/java/com/yahoo/tensor/TensorOperations.java
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.tensor;
-
-import com.google.common.collect.ImmutableSet;
-
-import java.util.Set;
-
-/**
- * Functions on tensors
- *
- * @author bratseth
- */
-class TensorOperations {
-
- /**
- * A utility method which returns an ummutable set of the union of the dimensions
- * of the two argument tensors.
- *
- * @return the combined dimensions as an unmodifiable set
- */
- static Set<String> combineDimensions(Tensor a, Tensor b) {
- ImmutableSet.Builder<String> setBuilder = new ImmutableSet.Builder<>();
- setBuilder.addAll(a.dimensions());
- setBuilder.addAll(b.dimensions());
- return setBuilder.build();
- }
-
-}
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/TensorProduct.java b/vespajlib/src/main/java/com/yahoo/tensor/TensorProduct.java
deleted file mode 100644
index 7018b189326..00000000000
--- a/vespajlib/src/main/java/com/yahoo/tensor/TensorProduct.java
+++ /dev/null
@@ -1,89 +0,0 @@
-// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.tensor;
-
-import com.google.common.collect.ImmutableMap;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Computes a <i>sparse tensor product</i>, see {@link Tensor#multiply}
- *
- * @author bratseth
- */
-class TensorProduct {
-
- private final Set<String> dimensionsA, dimensionsB;
-
- private final Set<String> dimensions;
- private final ImmutableMap.Builder<TensorAddress, Double> cells = new ImmutableMap.Builder<>();
-
- public TensorProduct(Tensor a, Tensor b) {
- dimensionsA = a.dimensions();
- dimensionsB = b.dimensions();
-
- // Dimension product
- dimensions = TensorOperations.combineDimensions(a, b);
-
- // Cell product (slow baseline implementation)
- for (Map.Entry<TensorAddress, Double> aCell : a.cells().entrySet()) {
- for (Map.Entry<TensorAddress, Double> bCell : b.cells().entrySet()) {
- TensorAddress combinedAddress = combine(aCell.getKey(), bCell.getKey());
- if (combinedAddress == null) continue; // not combinable
- cells.put(combinedAddress, aCell.getValue() * bCell.getValue());
- }
- }
- }
-
- private TensorAddress combine(TensorAddress a, TensorAddress b) {
- List<TensorAddress.Element> combined = new ArrayList<>();
- combined.addAll(dense(a, dimensionsA));
- combined.addAll(dense(b, dimensionsB));
- Collections.sort(combined);
- TensorAddress.Element previous = null;
- for (ListIterator<TensorAddress.Element> i = combined.listIterator(); i.hasNext(); ) {
- TensorAddress.Element current = i.next();
- if (previous != null && previous.dimension().equals(current.dimension())) { // an overlapping dimension
- if (previous.label().equals(current.label()))
- i.remove(); // a match: remove the duplicate
- else
- return null; // no match: a combination isn't viable
- }
- previous = current;
- }
- return TensorAddress.fromSorted(sparse(combined));
- }
-
- /**
- * Returns a set of tensor elements which contains an entry for each dimension including "undefined" values
- * (which are not present in the sparse elements list).
- */
- private List<TensorAddress.Element> dense(TensorAddress sparse, Set<String> dimensions) {
- if (sparse.elements().size() == dimensions.size()) return sparse.elements();
-
- List<TensorAddress.Element> dense = new ArrayList<>(sparse.elements());
- for (String dimension : dimensions) {
- }
- return dense;
- }
-
- /**
- * Removes any "undefined" entries from the given elements.
- */
- private List<TensorAddress.Element> sparse(List<TensorAddress.Element> dense) {
- List<TensorAddress.Element> sparse = new ArrayList<>();
- for (TensorAddress.Element element : dense) {
- }
- return sparse;
- }
-
- /** Returns the result of taking this product */
- public Tensor result() {
- return new MapTensor(dimensions, cells.build());
- }
-
-}