org.scilab.modules.types
Class ScilabSparse

java.lang.Object
  extended by org.scilab.modules.types.ScilabSparse
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, ScilabType

public class ScilabSparse
extends java.lang.Object
implements ScilabType

This class provides a representation on the Scilab Sparse datatype

This class is Serializable and any modification could impact load and store of data (Xcos files, Javasci saved data, etc...).

//TODO Sly : ajouter de la doc

See Also:
Scilab, Serialized Form

Field Summary
protected  boolean byref
           
protected  int[] colPos
           
protected  int cols
           
protected  double[] imaginaryPart
           
protected  int nbItem
           
protected  int[] nbItemRow
           
protected  double[] realPart
           
protected  int rows
           
protected  java.lang.String varName
           
 
Constructor Summary
ScilabSparse()
          Default constructor
ScilabSparse(double data)
          Constructor with a unique value.
ScilabSparse(double[][] data)
          Constructor with a matrix of real data.
ScilabSparse(double[][] realData, double[][] imagData)
          Constructor with a matrix of complex numbers
ScilabSparse(double realData, double imagData)
          Constructor with a unique complex value.
ScilabSparse(int rows, int cols, int nbItem, int[] nbItemRow, int[] colPos, double[] real)
          Constructor
ScilabSparse(int rows, int cols, int nbItem, int[] nbItemRow, int[] colPos, double[] data, boolean check)
          Constructor
ScilabSparse(int rows, int cols, int nbItem, int[] nbItemRow, int[] colPos, double[] real, double[] imag)
          Constructor
ScilabSparse(int rows, int cols, int nbItem, int[] nbItemRow, int[] colPos, double[] real, double[] imag, boolean check)
          Constructor
ScilabSparse(java.lang.String varName, int rows, int cols, int nbItem, int[] nbItemRow, int[] colPos, double[] real, double[] imag)
          Constructor
 
Method Summary
 boolean equals(java.lang.Object obj)
          Compare if obj is the same object or not
 int[] getColPos()
          Get the column positions of the non null items.
 int getColPosElement(int i)
          Get the element in column position
 double[] getElement(int i)
          Get the real and imaginary elements at position i
 double[] getElement(int i, int j)
          Get the real and imanginary element at position (i, j) in the sparse matrix
 double[][] getFullImaginaryPart()
          Get the imaginary part of the full sparse matrix
 double[][][] getFullMatrix()
          Get the full sparse matrix representation as an array 2 x rows x cols If d = getFullMatrix(), then d[0] contains realpart and d[1] the imaginary one.
 double[][] getFullRealPart()
          Get the real part of the full sparse matrix
 int getHeight()
          Return the height (number of elements) of the stored data
 double getImaginaryElement(int i)
          Get the imaginary element at position i
 double getImaginaryElement(int i, int j)
          Get the imanginary element at position (i, j) in the sparse matrix
 double[] getImaginaryPart()
          Get the imaginary part of the data.
 int getNbItemElement(int i)
          Get the number of non-null item in row i
 int[] getNbItemRow()
          Get the number of non null items by row.
 int getNbNonNullItems()
          Get the number of non null items in the matrix.
 double getRealElement(int i)
          Get the real element at position i
 double getRealElement(int i, int j)
          Get the real element at position (i, j) in the sparse matrix
 double[] getRealPart()
          Get the real part of the data.
 int[] getScilabColPos()
          Get the column positions of the non null items.
 java.lang.Object getSerializedObject()
          Get a single object used to easily rebuild a Scilab variable from the Java ScilabType
 double[] getSerializedSparseMatrix()
          Get complex matrix as a serialized form
 ScilabTypeEnum getType()
          Return the type of Scilab
 java.lang.String getVarName()
          Get the variable name or null if it has not a name
 int getWidth()
          Return the width (number of elements) of the stored data
 boolean isEmpty()
          Check the emptiness of the associated data.
 boolean isReal()
          Check if the current data doesn't have an imaginary part.
 boolean isReference()
          
 boolean isSwaped()
          Get the how the matrix is stored
 void readExternal(java.io.ObjectInput in)
           
 void setColPos(int[] colPos)
          Set the column positions of the non null items.
 void setColPosElement(int i, int x)
          Set the element in column position
 void setElement(int i, double x, double y)
          Set the real and imaginary elements at position i
 void setImaginaryElement(int i, double x)
          Set the imaginary element at position i
 void setImaginaryElement(int i, int j, double x)
          Set the imaginary element at position (i, j) in sparse matrix Take care only an already non-null element can be set
 void setImaginaryPart(double[] imaginaryPart)
          Set the imaginary part of the data.
 void setNbItemElement(int i, int x)
          Set the number of non-null item in row i
 void setNbItemRow(int[] nbItemRow)
          Set the number of non null items by row.
 void setNbNonNullItems(int nbItem)
          Set the number of non null items in the matrix.
 void setRealElement(int i, double x)
          Set the real element at position i
 void setRealElement(int i, int j, double x)
          Set the real element at position (i, j) in sparse matrix Take care only an already non-null element can be set
 void setRealPart(double[] realPart)
          Set the real part of the data.
 java.lang.String toString()
          Display the representation in the Scilab language of the type
Note that the representation can be copied/pasted straight into Scilab
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

rows

protected int rows

cols

protected int cols

nbItem

protected int nbItem

nbItemRow

protected int[] nbItemRow

colPos

protected int[] colPos

realPart

protected double[] realPart

imaginaryPart

protected double[] imaginaryPart

varName

protected java.lang.String varName

byref

protected boolean byref
Constructor Detail

ScilabSparse

public ScilabSparse()
Default constructor


ScilabSparse

public ScilabSparse(double data)
Constructor with a unique value.

Parameters:
data - the unique value

ScilabSparse

public ScilabSparse(double realData,
                    double imagData)
Constructor with a unique complex value.

Parameters:
realData - the real part
imagData - the complex part

ScilabSparse

public ScilabSparse(int rows,
                    int cols,
                    int nbItem,
                    int[] nbItemRow,
                    int[] colPos,
                    double[] data,
                    boolean check)
             throws ScilabSparseException
Constructor

Parameters:
rows - the number of rows
cols - the number of cols
nbItem - the number of non null items
nbItemRow - contains the number of true in each rows
colPos - the column position of each non null item
data - the non null data
check - if true the parameters validity is checked
Throws:
ScilabSparseException

ScilabSparse

public ScilabSparse(int rows,
                    int cols,
                    int nbItem,
                    int[] nbItemRow,
                    int[] colPos,
                    double[] real)
Constructor

Parameters:
rows - the number of rows
cols - the number of cols
nbItem - the number of non null items
nbItemRow - contains the number of true in each rows
colPos - the column position of each non null item
real - the non null real data

ScilabSparse

public ScilabSparse(int rows,
                    int cols,
                    int nbItem,
                    int[] nbItemRow,
                    int[] colPos,
                    double[] real,
                    double[] imag,
                    boolean check)
             throws ScilabSparseException
Constructor

Parameters:
rows - the number of rows
cols - the number of cols
nbItem - the number of non null items
nbItemRow - contains the number of true in each rows
colPos - the column position of each non null item
real - the non null real data
imag - the non null imaginary data
check - if true the parameters validity is checked
Throws:
ScilabSparseException

ScilabSparse

public ScilabSparse(int rows,
                    int cols,
                    int nbItem,
                    int[] nbItemRow,
                    int[] colPos,
                    double[] real,
                    double[] imag)
Constructor

Parameters:
rows - the number of rows
cols - the number of cols
nbItem - the number of non null items
nbItemRow - contains the number of true in each rows
colPos - the column position of each non null item
real - the non null real data
imag - the non null imaginary data

ScilabSparse

public ScilabSparse(double[][] data)
Constructor with a matrix of real data.

Parameters:
data - the data

ScilabSparse

public ScilabSparse(double[][] realData,
                    double[][] imagData)
Constructor with a matrix of complex numbers

Parameters:
realData - the real part of the data
imagData - the imaginary part of the data

ScilabSparse

public ScilabSparse(java.lang.String varName,
                    int rows,
                    int cols,
                    int nbItem,
                    int[] nbItemRow,
                    int[] colPos,
                    double[] real,
                    double[] imag)
Constructor

Parameters:
varName - the variable name
rows - the number of rows
cols - the number of cols
nbItem - the number of non null items
nbItemRow - contains the number of true in each rows
colPos - the column position of each non null item
real - the non null real data
imag - the non null imaginary data
Method Detail

isReference

public boolean isReference()

Specified by:
isReference in interface ScilabType
Returns:
true if data are backed in a java.nio.Buffer

getType

public ScilabTypeEnum getType()
Return the type of Scilab

Specified by:
getType in interface ScilabType
Returns:
the type of Scilab
Since:
5.4.0

isEmpty

public boolean isEmpty()
Check the emptiness of the associated data.

Specified by:
isEmpty in interface ScilabType
Returns:
true, if the associated data array is empty.

isReal

public boolean isReal()
Check if the current data doesn't have an imaginary part.

Returns:
true, if the data are real only.

getColPosElement

public int getColPosElement(int i)
Get the element in column position

Parameters:
i - the position
Returns:
the column position

setColPosElement

public void setColPosElement(int i,
                             int x)
Set the element in column position

Parameters:
i - the position
x - the column position

getNbItemElement

public int getNbItemElement(int i)
Get the number of non-null item in row i

Parameters:
i - the row
Returns:
the number of non-null items

setNbItemElement

public void setNbItemElement(int i,
                             int x)
Set the number of non-null item in row i

Parameters:
i - the row
x - the number of non-null items

getRealElement

public double getRealElement(int i)
Get the real element at position i

Parameters:
i - the position
Returns:
a real

getRealElement

public double getRealElement(int i,
                             int j)
Get the real element at position (i, j) in the sparse matrix

Parameters:
i - the row index
j - the column index
Returns:
a real

getImaginaryElement

public double getImaginaryElement(int i)
Get the imaginary element at position i

Parameters:
i - the position
Returns:
a real

getImaginaryElement

public double getImaginaryElement(int i,
                                  int j)
Get the imanginary element at position (i, j) in the sparse matrix

Parameters:
i - the row index
j - the column index
Returns:
a real

getElement

public double[] getElement(int i)
Get the real and imaginary elements at position i

Parameters:
i - the position
Returns:
a 2-array containing real and imaginary part

getElement

public double[] getElement(int i,
                           int j)
Get the real and imanginary element at position (i, j) in the sparse matrix

Parameters:
i - the row index
j - the column index
Returns:
a 2-array containing real and imaginary parts

setRealElement

public void setRealElement(int i,
                           double x)
Set the real element at position i

Parameters:
i - the position
x - the value to set

setRealElement

public void setRealElement(int i,
                           int j,
                           double x)
Set the real element at position (i, j) in sparse matrix Take care only an already non-null element can be set

Parameters:
i - the row index
j - the column index
x - the value to set

setImaginaryElement

public void setImaginaryElement(int i,
                                double x)
Set the imaginary element at position i

Parameters:
i - the position
x - the value to set

setImaginaryElement

public void setImaginaryElement(int i,
                                int j,
                                double x)
Set the imaginary element at position (i, j) in sparse matrix Take care only an already non-null element can be set

Parameters:
i - the row index
j - the column index
x - the value to set

setElement

public void setElement(int i,
                       double x,
                       double y)
Set the real and imaginary elements at position i

Parameters:
i - the position
x - the real part to set
y - the imaginary part to set

getRealPart

public double[] getRealPart()
Get the real part of the data.

Returns:
the real part.

setRealPart

public void setRealPart(double[] realPart)
Set the real part of the data.

Parameters:
realPart - the real part.

getImaginaryPart

public double[] getImaginaryPart()
Get the imaginary part of the data.

Returns:
the imaginary part.

setImaginaryPart

public void setImaginaryPart(double[] imaginaryPart)
Set the imaginary part of the data.

Parameters:
imaginaryPart - the imaginary part.

getNbNonNullItems

public int getNbNonNullItems()
Get the number of non null items in the matrix.

Returns:
the number of non null items.

setNbNonNullItems

public void setNbNonNullItems(int nbItem)
Set the number of non null items in the matrix.

Parameters:
nbItem - the number of non null items.

getNbItemRow

public int[] getNbItemRow()
Get the number of non null items by row.

Returns:
an integer array.

setNbItemRow

public void setNbItemRow(int[] nbItemRow)
Set the number of non null items by row.

Parameters:
nbItemRow - an integer array.

getScilabColPos

public int[] getScilabColPos()
Get the column positions of the non null items.

Returns:
an integer array.

getColPos

public int[] getColPos()
Get the column positions of the non null items.

Returns:
an integer array.

setColPos

public void setColPos(int[] colPos)
Set the column positions of the non null items.

Parameters:
colPos - an integer array.

getVarName

public java.lang.String getVarName()
Get the variable name or null if it has not a name

Specified by:
getVarName in interface ScilabType
Returns:
the name

isSwaped

public boolean isSwaped()
Get the how the matrix is stored

Specified by:
isSwaped in interface ScilabType
Returns:
true if the matrix is stored row by row

getFullRealPart

public double[][] getFullRealPart()
Get the real part of the full sparse matrix

Returns:
the full real matrix

getFullImaginaryPart

public double[][] getFullImaginaryPart()
Get the imaginary part of the full sparse matrix

Returns:
the full imaginary matrix

getFullMatrix

public double[][][] getFullMatrix()
Get the full sparse matrix representation as an array 2 x rows x cols If d = getFullMatrix(), then d[0] contains realpart and d[1] the imaginary one.

Returns:
the full matrix components

getSerializedSparseMatrix

public double[] getSerializedSparseMatrix()
Get complex matrix as a serialized form

Returns:
the serialized matrix with complex values

getHeight

public int getHeight()
Description copied from interface: ScilabType
Return the height (number of elements) of the stored data

Specified by:
getHeight in interface ScilabType
Returns:
the height of the data matrix
See Also:
ScilabType.getHeight()

getWidth

public int getWidth()
Description copied from interface: ScilabType
Return the width (number of elements) of the stored data

Specified by:
getWidth in interface ScilabType
Returns:
the width of the data matrix
See Also:
ScilabType.getWidth()

equals

public boolean equals(java.lang.Object obj)
Description copied from interface: ScilabType
Compare if obj is the same object or not

Specified by:
equals in interface ScilabType
Overrides:
equals in class java.lang.Object
Parameters:
obj - the object we want to compare
Returns:
true if the two objects are equals, false otherwise
See Also:
ScilabType.equals(Object)

getSerializedObject

public java.lang.Object getSerializedObject()
Get a single object used to easily rebuild a Scilab variable from the Java ScilabType

Specified by:
getSerializedObject in interface ScilabType
Returns:
an very simple object reflecting this ScilabType.

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

toString

public java.lang.String toString()
Display the representation in the Scilab language of the type
Note that the representation can be copied/pasted straight into Scilab

Specified by:
toString in interface ScilabType
Overrides:
toString in class java.lang.Object
Returns:
a Scilab-like String representation of the data.
See Also:
Object.toString()