Package com.stata.sfi
Class Mata
- java.lang.Object
-
- com.stata.sfi.Mata
-
public final class Mata extends Object
This class provides access to global Mata matrices. All methods are not thread-safe unless otherwise stated.Example:
From Stata...public static int printMataMatrix(String[] args) { String name = args[0]; long numCol = Mata.getMataColTotal(name); long numRow = Mata.getMataRowTotal(name); if (Mata.isTypeReal(name)) { for (long i = 0; i < numRow; i++) { for (long j = 0; j < numCol; j++) { double value = Mata.getMataRealAt(name, i, j); String index = "[" + (i + 1) + ", " + (j + 1) + "]"; SFIToolkit.displayln(index + " = " + value); } } } else { String type = Mata.getMataEltype(name); SFIToolkit.errorln("Matrix is type " + type + "; real expected"); return (3250); } return 0; }. mata // matrix must be global for sfi.Mata to access mat = (1, 3, 5 \ 5, 6, 4) . end . javacall Examples printMataMatrix, jar(examples.jar) args(mat) [1, 1] = 1.0 [1, 2] = 3.0 [1, 3] = 5.0 [2, 1] = 5.0 [2, 2] = 6.0 [2, 3] = 4.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static double[]getComplexAt(double[] matrix, int colCount, int row, int col)Get an element from a previously returned matrix.static voidgetComplexValues(double[] complex, Double real, Double imaginary)Get the real and imaginary parts from a complex result.static longgetMataColTotal(String name)Get the number of columns in a Mata matrix.static double[]getMataCompAt(String name, long row, long col)Read a complex Mata matrix element.static StringgetMataEltype(String name)Get the type of a Mata object.static doublegetMataRealAt(String name, long row, long col)Read a real Mata matrix element.static longgetMataRowTotal(String name)Get the number of rows in a Mata matrix.static StringgetMataStringAt(String name, long row, long col)Read a string Mata matrix element.static booleanisTypeComplex(String name)Determine if the matrix type is complex.static booleanisTypeReal(String name)Determine if the matrix type is real.static booleanisTypeString(String name)Determine if the matrix type is string.
-
-
-
Method Detail
-
getComplexAt
@Synchronized public static double[] getComplexAt(double[] matrix, int colCount, int row, int col)
Get an element from a previously returned matrix.- Parameters:
matrix- The matrix.colCount- The number of columns in the matrix. This value can be obtained fromgetMataColTotal().row- Zero-based row number.col- Zero-based column number.- Returns:
- The element; a double[2] containing the matrix element.
-
getComplexValues
@Synchronized public static void getComplexValues(double[] complex, Double real, Double imaginary)
Get the real and imaginary parts from a complex result.
-
getMataColTotal
@Synchronized public static long getMataColTotal(String name)
Get the number of columns in a Mata matrix.- Parameters:
name- Name of the Mata matrix.- Returns:
- The number of columns. Returns -1 if an error occurs.
-
getMataCompAt
@Synchronized public static double[] getMataCompAt(String name, long row, long col)
Read a complex Mata matrix element.- Parameters:
name- Name of the Mata matrix.row- Zero-based row number.col- Zero-based column number.- Returns:
- A double[2] containing the matrix element. Returns null if an error occurs.
-
getMataEltype
@Synchronized public static String getMataEltype(String name)
Get the type of a Mata object.
-
getMataRealAt
@Synchronized public static double getMataRealAt(String name, long row, long col)
Read a real Mata matrix element.- Parameters:
name- Name of the Mata matrix.row- Zero-based row number.col- Zero-based column number.- Returns:
- The element. Returns a Stata missing if an error occurs.
-
getMataRowTotal
@Synchronized public static long getMataRowTotal(String name)
Get the number of rows in a Mata matrix.- Parameters:
name- Name of the Mata matrix.- Returns:
- The number of rows. Returns -1 if an error occurs.
-
getMataStringAt
@Synchronized public static String getMataStringAt(String name, long row, long col)
Read a string Mata matrix element.
-
isTypeComplex
@Synchronized public static boolean isTypeComplex(String name)
Determine if the matrix type is complex.- Parameters:
name- Name of the Mata matrix.- Returns:
- True if the matrix type is complex.
-
isTypeReal
@Synchronized public static boolean isTypeReal(String name)
Determine if the matrix type is real.- Parameters:
name- Name of the Mata matrix.- Returns:
- True if the matrix type is real.
-
isTypeString
@Synchronized public static boolean isTypeString(String name)
Determine if the matrix type is string.- Parameters:
name- Name of the Mata matrix.- Returns:
- True if the matrix type is string.
-
-