Search in sources :

Example 1 with PartialAddress

use of com.yahoo.tensor.PartialAddress in project vespa by vespa-engine.

the class Join method joinTo.

private void joinTo(IndexedTensor a, IndexedTensor b, TensorType joinedType, DimensionSizes joinedSize, int[] aToIndexes, int[] bToIndexes, boolean reversedOrder, Tensor.Builder builder) {
    Set<String> sharedDimensions = Sets.intersection(a.type().dimensionNames(), b.type().dimensionNames());
    Set<String> dimensionsOnlyInA = Sets.difference(a.type().dimensionNames(), b.type().dimensionNames());
    DimensionSizes aIterateSize = joinedSizeOf(a.type(), joinedType, joinedSize);
    DimensionSizes bIterateSize = joinedSizeOf(b.type(), joinedType, joinedSize);
    // for each combination of dimensions only in a
    for (Iterator<IndexedTensor.SubspaceIterator> ia = a.subspaceIterator(dimensionsOnlyInA, aIterateSize); ia.hasNext(); ) {
        IndexedTensor.SubspaceIterator aSubspace = ia.next();
        // for each combination of dimensions in a which is also in b
        while (aSubspace.hasNext()) {
            Tensor.Cell aCell = aSubspace.next();
            PartialAddress matchingBCells = partialAddress(a.type(), aSubspace.address(), sharedDimensions);
            // for each matching combination of dimensions ony in b
            for (IndexedTensor.SubspaceIterator bSubspace = b.cellIterator(matchingBCells, bIterateSize); bSubspace.hasNext(); ) {
                Tensor.Cell bCell = bSubspace.next();
                TensorAddress joinedAddress = joinAddresses(aCell.getKey(), aToIndexes, bCell.getKey(), bToIndexes, joinedType);
                double joinedValue = reversedOrder ? combinator.applyAsDouble(bCell.getValue(), aCell.getValue()) : combinator.applyAsDouble(aCell.getValue(), bCell.getValue());
                builder.cell(joinedAddress, joinedValue);
            }
        }
    }
}
Also used : TensorAddress(com.yahoo.tensor.TensorAddress) IndexedTensor(com.yahoo.tensor.IndexedTensor) Tensor(com.yahoo.tensor.Tensor) DimensionSizes(com.yahoo.tensor.DimensionSizes) PartialAddress(com.yahoo.tensor.PartialAddress) IndexedTensor(com.yahoo.tensor.IndexedTensor)

Aggregations

DimensionSizes (com.yahoo.tensor.DimensionSizes)1 IndexedTensor (com.yahoo.tensor.IndexedTensor)1 PartialAddress (com.yahoo.tensor.PartialAddress)1 Tensor (com.yahoo.tensor.Tensor)1 TensorAddress (com.yahoo.tensor.TensorAddress)1