Skip to content

Commit

Permalink
handling models created via rc1 in rc2 (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
sudiptoguha authored Apr 14, 2022
1 parent 52cd7d6 commit cb882c3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@

package com.amazon.randomcutforest.state.store;

import static com.amazon.randomcutforest.CommonUtils.checkArgument;
import static com.amazon.randomcutforest.CommonUtils.checkNotNull;
import static com.amazon.randomcutforest.CommonUtils.toDoubleArray;
import static com.amazon.randomcutforest.CommonUtils.toFloatArray;

import lombok.Getter;
import lombok.Setter;

import com.amazon.randomcutforest.config.Precision;
import com.amazon.randomcutforest.state.IStateMapper;
import com.amazon.randomcutforest.state.Version;
import com.amazon.randomcutforest.store.PointStore;
import com.amazon.randomcutforest.store.PointStoreLarge;
import com.amazon.randomcutforest.util.ArrayPacking;
import lombok.Getter;
import lombok.Setter;

import java.util.Arrays;

import static com.amazon.randomcutforest.CommonUtils.checkArgument;
import static com.amazon.randomcutforest.CommonUtils.checkNotNull;
import static com.amazon.randomcutforest.CommonUtils.toDoubleArray;
import static com.amazon.randomcutforest.CommonUtils.toFloatArray;

@Getter
@Setter
Expand All @@ -53,6 +54,7 @@ public PointStore toModel(PointStoreState state, long seed) {
int startOfFreeSegment = state.getStartOfFreeSegment();
int[] refCount = ArrayPacking.unpackInts(state.getRefCount(), indexCapacity, state.isCompressed());
int[] locationList = new int[indexCapacity];
Arrays.fill(locationList,PointStore.INFEASIBLE_LOCN);
int[] tempList = ArrayPacking.unpackInts(state.getLocationList(), state.isCompressed());
if (!state.getVersion().equals(Version.V3_0)) {
int shingleSize = state.getShingleSize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,26 @@

package com.amazon.randomcutforest.parkservices.state;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
import com.amazon.randomcutforest.parkservices.ThresholdedRandomCutForest;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.protostuff.ProtostuffIOUtil;
import io.protostuff.Schema;
import io.protostuff.runtime.RuntimeSchema;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Random;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

import com.amazon.randomcutforest.parkservices.ThresholdedRandomCutForest;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.protostuff.ProtostuffIOUtil;
import io.protostuff.Schema;
import io.protostuff.runtime.RuntimeSchema;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;

public class V2TRCFToV3StateConverterTest {

Expand All @@ -50,6 +49,11 @@ public void testJson(V2TRCFJsonResource jsonResource) throws JsonProcessingExcep
mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
ThresholdedRandomCutForestState state = mapper.readValue(json, ThresholdedRandomCutForestState.class);
ThresholdedRandomCutForest forest = trcfMapper.toModel(state);
Random r = new Random(0);
for (int i = 0; i < 200000; i++) {
double[] point = r.ints(forest.getForest().getDimensions(), 0, 50).asDoubleStream().toArray();
forest.process(point, 0L);
}
assertNotNull(forest);
}

Expand Down

0 comments on commit cb882c3

Please sign in to comment.