[ 
https://issues.apache.org/jira/browse/MAHOUT-65?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12720871#action_12720871
 ] 

Jeff Eastman commented on MAHOUT-65:
------------------------------------

I implemented a little test using a TestVector that inherits from 
AbstractVector and has Sean's new SparseVector instvars. It also implements 
Serializable. The results are a bit surprising:


{noformat}
 public void testThree() {
    int[] indexes = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    double[] values = { 1.111, 2.222, 3.333, 4.444, 5.555, 6.666, 7.777, 8.888,
        9.999 };
    Vector obj = new TestVector(indexes, values);

    Type vectorType = new TypeToken<Vector>() {
    }.getType();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(vectorType, new JsonVectorAdapter());
    Gson gson = builder.create();
    String json = gson.toJson(obj, vectorType);
    System.out.println("3 " + json.length() + " = " + json);
  }

  public void testFour() throws IOException {
    int[] indexes = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    double[] values = { 1.111, 2.222, 3.333, 4.444, 5.555, 6.666, 7.777, 8.888,
        9.999 };
    TestVector obj = new TestVector(indexes, values);
    OutputStream stm = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(stm);
    out.writeObject(obj);
    String json = stm.toString();
    System.out.println("4 " + json.length() + " = " + json);
  }

{noformat}

It produced the following results:
{noformat}
3 159 = 
{"class":"org.apache.mahout.matrix.TestVector","vector":"{\"indexes\":[1,2,3,4,5,6,7,8,9],\"values\":[1.111,2.222,3.333,4.444,5.555,6.666,7.777,8.888,9.999]}"}
4 239 = ¨Ì

> Add Element Labels to Vectors and Matrices
> ------------------------------------------
>
>                 Key: MAHOUT-65
>                 URL: https://issues.apache.org/jira/browse/MAHOUT-65
>             Project: Mahout
>          Issue Type: New Feature
>          Components: Matrix
>    Affects Versions: 0.1
>            Reporter: Jeff Eastman
>            Assignee: Jeff Eastman
>         Attachments: MAHOUT-65-name.patch, MAHOUT-65-name.patch, 
> MAHOUT-65-name.patch, MAHOUT-65.patch, MAHOUT-65b.patch, MAHOUT-65c.patch, 
> MAHOUT-65d.patch
>
>
> Many applications can benefit by accessing elements in vectors and matrices 
> using String labels in addition to numeric indices. Investigate adding such a 
> capability.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to