Reads a coordinate vector. First data array contains real entries, and
the second contains imaginary entries
775200
public void readCoordinate(int[] index, float[] dataR, float[] dataI)
            throws IOException {
        int size = index.length;
        if (size != dataR.length || size != dataI.length)
            throw new IllegalArgumentException(
                    "All arrays must be of the same size");
        for (int i = 0; i < size; ++i) {
            index[i] = getInt();
            dataR[i] = getFloat();
            dataI[i] = getFloat();
        }
    }
1360956
public float[] readFloats (int length) throws KryoException {
		float[] array = new float[length];
		if (optional(length << 2) == length << 2) {
			byte[] buffer = this.buffer;
			int p = this.position;
			for (int i = 0; i < length; i++, p += 4) {
				array[i] = Float.intBitsToFloat(buffer[p] & 0xFF //
					| (buffer[p + 1] & 0xFF) << 8 //
					| (buffer[p + 2] & 0xFF) << 16 //
					| (buffer[p + 3] & 0xFF) << 24);
			}
			position = p;
		} else {
			for (int i = 0; i < length; i++)
				array[i] = readFloat();
		}
		return array;
	}
1323544
private int readCorner3(int numRows, int numColumns) {
    int currentByte = 0;
    if (readModule(numRows - 1, 0, numRows, numColumns)) {
      currentByte |= 1;
    }
    currentByte <<= 1;
    if (readModule(numRows - 1, numColumns - 1, numRows, numColumns)) {
      currentByte |= 1;
    }
    currentByte <<= 1;
    if (readModule(0, numColumns - 3, numRows, numColumns)) {
      currentByte |= 1;
    }
    currentByte <<= 1;
    if (readModule(0, numColumns - 2, numRows, numColumns)) {
      currentByte |= 1;
    }
    currentByte <<= 1;
    if (readModule(0, numColumns - 1, numRows, numColumns)) {
      currentByte |= 1;
    }
    currentByte <<= 1;
    if (readModule(1, numColumns - 3, numRows, numColumns)) {
      currentByte |= 1;
    }
    currentByte <<= 1;
    if (readModule(1, numColumns - 2, numRows, numColumns)) {
      currentByte |= 1;
    }
    currentByte <<= 1;
    if (readModule(1, numColumns - 1, numRows, numColumns)) {
      currentByte |= 1;
    }
    return currentByte;
  }
1080306
public static ConcatVectorTable readFromProto(ConcatVectorTableProto.ConcatVectorTable proto) {
        int[] neighborSizes = new int[proto.getDimensionSizeCount()];
        for (int i = 0; i < neighborSizes.length; i++) {
            neighborSizes[i] = proto.getDimensionSize(i);
        }
        ConcatVectorTable factor = new ConcatVectorTable(neighborSizes);
        int i = 0;
        for (int[] assignment : factor) {
            final ConcatVector vector = ConcatVector.readFromProto(proto.getFactorTable(i));
            factor.setAssignmentValue(assignment, () -> vector);
            i++;
        }
        return factor;
    }
106752
private static void svdlibcSparseBinaryToMatlab(File input, File output,
                                                    boolean transpose) 
            throws IOException {
        
        DataInputStream dis = new DataInputStream(
            new BufferedInputStream(new FileInputStream(input)));

        PrintWriter pw = new PrintWriter(output);

        int rows = dis.readInt();
        int cols = dis.readInt();
        int entries = dis.readInt();

        // SVDLIBC sparse binary is organized as column data.  
        int entriesSeen = 0;
        int col = 0;
        for (; entriesSeen < entries; ++col) {
            int nonZero = dis.readInt();

            for (int i = 0; i < nonZero; ++i, ++entriesSeen) {
                int row = dis.readInt();
                float val = dis.readFloat();
                if (transpose)
                    pw.println((1 + col) + " " + (1 + row) + " " + val);
                else
                    pw.println((1 + row) + " " + (1 + col) + " " + val);
            }
        }
        
        dis.close();
        pw.close();
    }
1067014
@SuppressWarnings("unchecked")
    @Override
    public Vector<Long> readVectorUInt() {
        log.debug("readVectorUInt");
        int type = readInteger();
        if ((type & 1) == 0) {
            return (Vector<Long>) getReference(type >> 1);
        }
        int len = type >> 1;
        Vector<Long> array = new Vector<Long>(len);
        storeReference(array);
        @SuppressWarnings("unused")
        int ref2 = readInteger();
        for (int j = 0; j < len; ++j) {
            long value = (buf.get() & 0xff) << 24L;
            value += (buf.get() & 0xff) << 16L;
            value += (buf.get() & 0xff) << 8L;
            value += (buf.get() & 0xff);
            array.add(value);
        }
        return array;
    }
355687
protected void indexVectorInternal(double[] vector) throws Exception {
		if (vector.length != vectorLength) {
			throw new Exception("The dimensionality of the vector is wrong!");
		}
		// apply a random transformation if needed
		if (transformation == TransformationType.RandomRotation) {
			vector = rr.rotate(vector);
		} else if (transformation == TransformationType.RandomPermutation) {
			vector = rp.permute(vector);
		}
		// transform the vector into a PQ code
		int[] pqCode = new int[numSubVectors];

		for (int i = 0; i < numSubVectors; i++) {
			// take the appropriate sub-vector
			int fromIdex = i * subVectorLength;
			int toIndex = fromIdex + subVectorLength;
			double[] subvector = Arrays.copyOfRange(vector, fromIdex, toIndex);
			// assign the sub-vector to the nearest centroid of the respective sub-quantizer
			pqCode[i] = computeNearestProductIndex(subvector, i);
		}

		if (numProductCentroids <= 256) {
			byte[] pqByteCode = transformToByte(pqCode);
			if (loadIndexInMemory) { // append the ram-based index
				pqByteCodes.add(pqByteCode);
			}
			appendPersistentIndex(pqByteCode); // append the disk-based index
		} else {
			short[] pqShortCode = transformToShort(pqCode);
			if (loadIndexInMemory) { // append the ram-based index
				pqShortCodes.add(pqShortCode);
			}
			appendPersistentIndex(pqShortCode); // append the disk-based index
		}

	}
234960
def read_raw_data(self, f):
        """"""

        if not self.toc["kTocRawData"]:
            return

        f.seek(self.data_position)

        total_data_size = self.next_segment_offset - self.raw_data_offset
        log.debug(
            "Reading %d bytes of data at %d in %d chunks" %
            (total_data_size, f.tell(), self.num_chunks))

        for chunk in range(self.num_chunks):
            if self.toc["kTocInterleavedData"]:
                log.debug("Data is interleaved")
                data_objects = [o for o in self.ordered_objects if o.has_data]
                # If all data types have numpy types and all the lengths are
                # the same, then we can read all data at once with numpy,
                # which is much faster
                all_numpy = all(
                    (o.data_type.nptype is not None for o in data_objects))
                same_length = (len(
                    set((o.number_values for o in data_objects))) == 1)
                if (all_numpy and same_length):
                    self._read_interleaved_numpy(f, data_objects)
                else:
                    self._read_interleaved(f, data_objects)
            else:
                object_data = {}
                log.debug("Data is contiguous")
                for obj in self.ordered_objects:
                    if obj.has_data:
                        if (chunk == (self.num_chunks - 1) and
                                self.final_chunk_proportion != 1.0):
                            number_values = int(
                                obj.number_values *
                                self.final_chunk_proportion)
                        else:
                            number_values = obj.number_values
                        object_data[obj.path] = (
                            obj._read_values(f, number_values))

                for obj in self.ordered_objects:
                    if obj.has_data:
                        obj.tdms_object._update_data(object_data[obj.path])
143598
def c_int_array(data):
    """"""
    if is_1d_list(data):
        data = np.array(data, copy=False)
    if is_numpy_1d_array(data):
        data = convert_from_sliced_object(data)
        assert data.flags.c_contiguous
        if data.dtype == np.int32:
            ptr_data = data.ctypes.data_as(ctypes.POINTER(ctypes.c_int32))
            type_data = C_API_DTYPE_INT32
        elif data.dtype == np.int64:
            ptr_data = data.ctypes.data_as(ctypes.POINTER(ctypes.c_int64))
            type_data = C_API_DTYPE_INT64
        else:
            raise TypeError("Expected np.int32 or np.int64, met type({})"
                            .format(data.dtype))
    else:
        raise TypeError("Unknown type({})".format(type(data).__name__))
    return (ptr_data, type_data, data)
438667
int read(byte[] buffer, int length, int bigendianp, int word, int sgned,
            int[] bitstream) {
        int host_endian = host_is_big_endian();
        int index = 0;

        while (true) {
            if (decode_ready) {
                float[][] pcm;
                float[][][] _pcm = new float[1][][];
                int[] _index = new int[getInfo(-1).channels];
                int samples = vd.synthesis_pcmout(_pcm, _index);
                pcm = _pcm[0];
                if (samples != 0) {
                    // yay! proceed to pack data into the byte buffer
                    int channels = getInfo(-1).channels;
                    int bytespersample = word * channels;
                    if (samples > length / bytespersample) {
                        samples = length / bytespersample;
                    }

                    // a tight loop to pack each size
                    {
                        int val;
                        if (word == 1) {
                            int off = (sgned != 0 ? 0 : 128);
                            for (int j = 0; j < samples; j++) {
                                for (int i = 0; i < channels; i++) {
                                    val = (int) (pcm[i][_index[i] + j] * 128. + 0.5);
                                    if (val > 127) {
                                        val = 127;
                                    } else if (val < -128) {
                                        val = -128;
                                    }
                                    buffer[index++] = (byte) (val + off);
                                }
                            }
                        } else {
                            int off = (sgned != 0 ? 0 : 32768);

                            if (host_endian == bigendianp) {
                                if (sgned != 0) {
                                    for (int i = 0; i < channels; i++) { // It's faster in this order
                                        int src = _index[i];
                                        int dest = i;
                                        for (int j = 0; j < samples; j++) {
                                            val = (int) (pcm[i][src + j] * 32768. + 0.5);
                                            if (val > 32767) {
                                                val = 32767;
                                            } else if (val < -32768) {
                                                val = -32768;
                                            }
                                            buffer[dest] = (byte) (val >>> 8);
                                            buffer[dest + 1] = (byte) (val);
                                            dest += channels * 2;
                                        }
                                    }
                                } else {
                                    for (int i = 0; i < channels; i++) {
                                        float[] src = pcm[i];
                                        int dest = i;
                                        for (int j = 0; j < samples; j++) {
                                            val = (int) (src[j] * 32768. + 0.5);
                                            if (val > 32767) {
                                                val = 32767;
                                            } else if (val < -32768) {
                                                val = -32768;
                                            }
                                            buffer[dest] = (byte) ((val + off) >>> 8);
                                            buffer[dest + 1] = (byte) (val + off);
                                            dest += channels * 2;
                                        }
                                    }
                                }
                            } else if (bigendianp != 0) {
                                for (int j = 0; j < samples; j++) {
                                    for (int i = 0; i < channels; i++) {
                                        val = (int) (pcm[i][j] * 32768. + 0.5);
                                        if (val > 32767) {
                                            val = 32767;
                                        } else if (val < -32768) {
                                            val = -32768;
                                        }
                                        val += off;
                                        buffer[index++] = (byte) (val >>> 8);
                                        buffer[index++] = (byte) val;
                                    }
                                }
                            } else {
                                //int val;
                                for (int j = 0; j < samples; j++) {
                                    for (int i = 0; i < channels; i++) {
                                        val = (int) (pcm[i][j] * 32768. + 0.5);
                                        if (val > 32767) {
                                            val = 32767;
                                        } else if (val < -32768) {
                                            val = -32768;
                                        }
                                        val += off;
                                        buffer[index++] = (byte) val;
                                        buffer[index++] = (byte) (val >>> 8);
                                    }
                                }
                            }
                        }
                    }

                    vd.synthesis_read(samples);
                    pcm_offset += samples;
                    if (bitstream != null) {
                        bitstream[0] = current_link;
                    }
                    return (samples * bytespersample);
                }
            }

            // suck in another packet
            switch (process_packet(1)) {
                case 0:
                    return (0);
                case -1:
                    return -1;
                default:
                    break;
            }
        }
    }
1095247
def view_xy(self, negative=False):
        """"""
        vec = np.array([0,0,1])
        viewup = np.array([0,1,0])
        if negative:
            vec = np.array([0,0,-1])
        return self.view_vector(vec, viewup)
773131
public void readCoordinate(int[] row, int[] column, double[] dataR,
            double[] dataI) throws IOException {
        int size = row.length;
        if (size != column.length || size != dataR.length
                || size != dataI.length)
            throw new IllegalArgumentException(
                    "All arrays must be of the same size");
        for (int i = 0; i < size; ++i) {
            row[i] = getInt();
            column[i] = getInt();
            dataR[i] = getDouble();
            dataI[i] = getDouble();
        }
    }
1186549
def vector_poly_data(orig, vec):
    

    # shape, dimention checking
    if not isinstance(orig, np.ndarray):
        orig = np.asarray(orig)

    if not isinstance(vec, np.ndarray):
        vec = np.asarray(vec)

    if orig.ndim != 2:
        orig = orig.reshape((-1, 3))
    elif orig.shape[1] != 3:
        raise Exception('orig array must be 3D')

    if vec.ndim != 2:
        vec = vec.reshape((-1, 3))
    elif vec.shape[1] != 3:
        raise Exception('vec array must be 3D')

    # Create vtk points and cells objects
    vpts = vtk.vtkPoints()
    vpts.SetData(numpy_to_vtk(np.ascontiguousarray(orig), deep=True))

    npts = orig.shape[0]
    cells = np.hstack((np.ones((npts, 1), 'int'),
                       np.arange(npts).reshape((-1, 1))))

    if cells.dtype != ctypes.c_int64 or cells.flags.c_contiguous:
        cells = np.ascontiguousarray(cells, ctypes.c_int64)
    cells = np.reshape(cells, (2*npts))
    vcells = vtk.vtkCellArray()
    vcells.SetCells(npts, numpy_to_vtkIdTypeArray(cells, deep=True))

    # Create vtkPolyData object
    pdata = vtk.vtkPolyData()
    pdata.SetPoints(vpts)
    pdata.SetVerts(vcells)

    # Add vectors to polydata
    name = 'vectors'
    vtkfloat = numpy_to_vtk(np.ascontiguousarray(vec), deep=True)
    vtkfloat.SetName(name)
    pdata.GetPointData().AddArray(vtkfloat)
    pdata.GetPointData().SetActiveVectors(name)

    # Add magnitude of vectors to polydata
    name = 'mag'
    scalars = (vec * vec).sum(1)**0.5
    vtkfloat = numpy_to_vtk(np.ascontiguousarray(scalars), deep=True)
    vtkfloat.SetName(name)
    pdata.GetPointData().AddArray(vtkfloat)
    pdata.GetPointData().SetActiveScalars(name)

    return vtki.PolyData(pdata)
220733
public VectorInfo readVectorInfo() throws IOException {
        String[] component = readTrimmedLine().split(" +");
        if (component.length != 4)
            throw new IOException(
                    "Current line unparsable. It must consist of 4 tokens");

        // Read header
        if (!component[0].equalsIgnoreCase("%%MatrixMarket"))
            throw new IOException("Not in Matrix Market exchange format");

        // This will always be "vector"
        if (!component[1].equalsIgnoreCase("vector"))
            throw new IOException("Expected \"vector\", got " + component[1]);

        // Sparse or dense?
        boolean sparse = false;
        if (component[2].equalsIgnoreCase("coordinate"))
            sparse = true;
        else if (component[2].equalsIgnoreCase("array"))
            sparse = false;
        else
            throw new IOException("Unknown layout " + component[2]);

        // Dataformat
        VectorInfo.VectorField field = null;
        if (component[3].equalsIgnoreCase("real"))
            field = VectorInfo.VectorField.Real;
        else if (component[3].equalsIgnoreCase("integer"))
            field = VectorInfo.VectorField.Integer;
        else if (component[3].equalsIgnoreCase("complex"))
            field = VectorInfo.VectorField.Complex;
        else if (component[3].equalsIgnoreCase("pattern"))
            field = VectorInfo.VectorField.Pattern;
        else
            throw new IOException("Unknown field specification " + component[3]);

        // Pack together. This also verifies the format
        return new VectorInfo(sparse, field);
    }
82601
public void readCoordinate(int[] row, int[] column, double[] data)
            throws IOException {
        int size = row.length;
        if (size != column.length || size != data.length)
            throw new IllegalArgumentException(
                    "All arrays must be of the same size");
        for (int i = 0; i < size; ++i) {
            row[i] = getInt();
            column[i] = getInt();
            data[i] = getDouble();
        }
    }
1272809
private Vector2i getCellOf(Point3D coordinate) {
        int xCell = (int) ((coordinate.x - indexRegion.minX()) / x_size);
        int yCell = (int) ((coordinate.y - indexRegion.minY()) / y_size);
        return new Vector2i(xCell, yCell);
    }
722843
private double[] computeResidualVector(double[] vector, int centroidIndex) {
		double[] residualVector = new double[vectorLength];
		for (int i = 0; i < vectorLength; i++) {
			residualVector[i] = coarseQuantizer[centroidIndex][i] - vector[i];
		}
		return residualVector;
	}