Package org.grouplens.lenskit.symbols

Examples of org.grouplens.lenskit.symbols.Symbol


        Map<TypedSymbol<?>, Long2ObjectMap<?>> newChannels =
                new Reference2ObjectArrayMap<TypedSymbol<?>, Long2ObjectMap<?>>();
        // copy all unboxed channels into both maps
        if (channelVectors != null) {
            for (Map.Entry<Symbol, MutableSparseVector> entry : channelVectors.entrySet()) {
                Symbol key = entry.getKey();
                MutableSparseVector msv = entry.getValue().copy();
                newChanVectors.put(key, msv);
                newChannels.put(key.withType(Double.class), new MutableSparseVectorMap(msv));
            }
        }
        // copy all remaining channels into the channel map
        if (channels != null) {
            for (Entry<TypedSymbol<?>, Long2ObjectMap<?>> entry : channels.entrySet()) {
                TypedSymbol<?> key = entry.getKey();
                if (!key.getType().equals(Double.class)) {
                    Long2ObjectMap<?> chan = entry.getValue();
                    assert chan instanceof MutableTypedSideChannel;
                    newChannels.put(key, ((MutableTypedSideChannel<?>) chan).mutableCopy());
                } else {
                    assert newChannels.containsKey(key);
View Full Code Here


        Map<TypedSymbol<?>, Long2ObjectMap<?>> newChannels = new Reference2ObjectArrayMap<TypedSymbol<?>, Long2ObjectMap<?>>();
        // We recursively generate immutable versions of all channels.  If freeze
        // is true, these versions will be made without copying.
        if (channelVectors != null) {
            for (Map.Entry<Symbol, MutableSparseVector> entry : channelVectors.entrySet()) {
                Symbol key = entry.getKey();
                ImmutableSparseVector chan = entry.getValue().immutable(freeze, newDomain);
                newChannelVectors.put(key, chan);
                newChannels.put(key.withType(Double.class), new SparseVectorMap(chan));
            }
        }

        if (channels != null) {
            for (Entry<TypedSymbol<?>, Long2ObjectMap<?>> entry : channels.entrySet()) {
                TypedSymbol<?> key = entry.getKey();
                if (!key.getType().equals(Double.class)) {
                    Long2ObjectMap<?> chan = entry.getValue();
                    assert chan instanceof MutableTypedSideChannel;
                    newChannels.put(key, ((MutableTypedSideChannel<?>) chan).immutable(newDomain, freeze));
                } else {
                    assert newChannels.containsKey(key);
View Full Code Here

        assertThat(iter.hasNext(), equalTo(false));
    }

    @Test
    public void testAddWithChannels() {
        Symbol sym = Symbol.of("HACKEM MUCHE");
        builder.addChannel(sym);
        builder.add(new ScoredIdBuilder(42, 3.5).addChannel(sym, Math.PI).build());
        PackedScoredIdList list = builder.build();
        assertThat(list.size(), equalTo(1));
        assertThat(list.isEmpty(), equalTo(false));
View Full Code Here

        assertThat(iter.hasNext(), equalTo(false));
    }

    @Test
    public void testAddTwo() {
        Symbol sym = Symbol.of("HACKEM MUCHE");
        ScoredId id1 = new ScoredIdBuilder(42, 3.5).addChannel(sym, Math.PI).build();
        ScoredId id2 = new ScoredIdBuilder(38, 2.6).addChannel(sym, Math.E).build();
        builder.addChannel(sym);
        builder.add(id1);
        builder.add(id2);
View Full Code Here

        assertThat(iter.hasNext(), equalTo(false));
    }

    @Test
    public void testAddWithDefaultChannel() {
        Symbol sym = Symbol.of("HACKEM MUCHE");
        ScoredId id = new ScoredIdBuilder(42, 3.5).build();
        ScoredId withDefault = new ScoredIdBuilder(42, 3.5).addChannel(sym, -1).build();
        PackedScoredIdList list = builder.addChannel(sym, -1)
                                         .add(id)
                                         .build();
View Full Code Here

        assertThat(list.get(0), equalTo(withDefault));
    }

    @Test
    public void testAddWithDefaultDefaultChannel() {
        Symbol sym = Symbol.of("HACKEM MUCHE");
        ScoredId id = new ScoredIdBuilder(42, 3.5).build();
        ScoredId withDefault = new ScoredIdBuilder(42, 3.5).addChannel(sym, 0).build();
        PackedScoredIdList list = builder.addChannel(sym)
                                         .add(id)
                                         .build();
View Full Code Here

        }
    }

    @Test
    public void testAddManyWithChannels() {
        Symbol sym = Symbol.of("VALUE");
        TypedSymbol<String> str = TypedSymbol.of(String.class, "STRING");
        builder.addChannel(sym)
               .addChannel(str);
        Random rng = new Random();
        List<ScoredId> ids = Lists.newArrayListWithCapacity(25);
View Full Code Here

        assertThat(list, equalTo(ids));
    }

    @Test
    public void testAddAll() {
        Symbol sym = Symbol.of("VALUE");
        TypedSymbol<String> str = TypedSymbol.of(String.class, "STRING");
        builder.addChannel(sym)
               .addChannel(str);
        Random rng = new Random();
        List<ScoredId> ids = Lists.newArrayListWithCapacity(25);
View Full Code Here

        assertThat(list, equalTo(ids));
    }

    @Test
    public void testIterateFast() {
        Symbol sym = Symbol.of("VALUE");
        TypedSymbol<String> str = TypedSymbol.of(String.class, "STRING");
        builder.addChannel(sym)
               .addChannel(str);
        Random rng = new Random();
        List<ScoredId> ids = Lists.newArrayListWithCapacity(25);
View Full Code Here

        }
    }

    @Test
    public void testFailOnInvalidChannel() {
        Symbol sym = Symbol.of("symbol");
        ScoredId idWithoutSymbol = new ScoredIdBuilder(72, 8.5).addChannel(sym, 3.5).build();
        try {
            builder.add(idWithoutSymbol);
            fail("add should fail with unknown symbol");
        } catch (IllegalArgumentException e) {
View Full Code Here

TOP

Related Classes of org.grouplens.lenskit.symbols.Symbol

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.