Coverage Report - org.apache.giraph.aggregators.matrix.sparse.IntSparseMatrix
 
Classes in this File Line Coverage Branch Coverage Complexity
IntSparseMatrix
0%
0/16
0%
0/2
1.143
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 package org.apache.giraph.aggregators.matrix.sparse;
 20  
 
 21  
 import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
 22  
 
 23  
 /**
 24  
  * A int matrix holds the values of the entries in int vectors. It keeps one
 25  
  * int aggregator per matrix row.
 26  
  */
 27  
 public class IntSparseMatrix {
 28  
   /** The number of rows in the matrix */
 29  
   private final int numRows;
 30  
   /** The rows of the matrix */
 31  
   private final Int2ObjectOpenHashMap<IntSparseVector> rows;
 32  
 
 33  
   /**
 34  
    * Create a new matrix with the given number of rows.
 35  
    *
 36  
    * @param numRows the number of rows.
 37  
    */
 38  0
   public IntSparseMatrix(int numRows) {
 39  0
     this.numRows = numRows;
 40  0
     rows = new Int2ObjectOpenHashMap<IntSparseVector>(numRows);
 41  0
     rows.defaultReturnValue(null);
 42  0
   }
 43  
 
 44  
   /**
 45  
    * Create a empty matrix with all values set to 0.0
 46  
    */
 47  
   public void initialize() {
 48  0
     rows.clear();
 49  0
     for (int i = 0; i < numRows; ++i) {
 50  0
       setRow(i, new IntSparseVector());
 51  
     }
 52  0
   }
 53  
 
 54  
   /**
 55  
    * Get the number of rows in the matrix.
 56  
    *
 57  
    * @return the number of rows.
 58  
    */
 59  
   public int getNumRows() {
 60  0
     return numRows;
 61  
   }
 62  
 
 63  
   /**
 64  
    * Get a specific entry of the matrix.
 65  
    *
 66  
    * @param i the row
 67  
    * @param j the column
 68  
    * @return the value of the entry
 69  
    */
 70  
   public int get(int i, int j) {
 71  0
     return rows.get(i).get(j);
 72  
   }
 73  
 
 74  
   /**
 75  
    * Set a specific entry of the matrix.
 76  
    *
 77  
    * @param i the row
 78  
    * @param j the column
 79  
    * @param v the value of the entry
 80  
    */
 81  
   public void set(int i, int j, int v) {
 82  0
     rows.get(i).set(j, v);
 83  0
   }
 84  
 
 85  
   /**
 86  
    * Get a specific row of the matrix.
 87  
    *
 88  
    * @param i the row number
 89  
    * @return the row of the matrix
 90  
    */
 91  
   public IntSparseVector getRow(int i) {
 92  0
     return rows.get(i);
 93  
   }
 94  
 
 95  
   /**
 96  
    * Set the int vector as the row specified.
 97  
    *
 98  
    * @param i the row
 99  
    * @param vec the vector to set as the row
 100  
    */
 101  
   public void setRow(int i, IntSparseVector vec) {
 102  0
     rows.put(i, vec);
 103  0
   }
 104  
 }