More all-rounded implementation of the new objecty features, several bugfixes, and updates to the standard library to behave. Vector still needs a bit more work for some operations

This commit is contained in:
Nathan Braswell
2015-06-05 00:34:24 -04:00
parent 6f9ceaa717
commit 7abab02fbf
15 changed files with 185 additions and 87 deletions

View File

@@ -1,11 +1,11 @@
import vector:*;
import io:*;
typedef matrix (Destructable) {
typedef matrix (Object) {
var data: vector<double>;
var rows: int;
var cols: int;
///******************************
// Constructors
///*****************************/
@@ -18,16 +18,16 @@ typedef matrix (Destructable) {
data.construct();
return this;
}
//Constructor with single argument
//Creates an N x N matrix
fun construct(size: int): matrix* {
rows = size;
cols = size;
data.construct(rows*cols);
return this;
return this;
}
//Constructor with two arguments
//Creates an N x M matrix
fun construct(r: int, c: int): matrix* {
@@ -36,16 +36,16 @@ typedef matrix (Destructable) {
data.construct(rows*cols);
return this;
}
///****************************
// Utility Functions
///***************************/
//Test using indexing at 0
fun test0(i: int, j: int): bool {
var index = i*rows + j;
if(index > (rows * cols - 1) ) {
print("Index (");
print(i);
@@ -59,15 +59,15 @@ typedef matrix (Destructable) {
println(").");
return false;
}
return true;
}
//Test using indexing at 1
fun test1(i: int, j: int): bool {
var index = (i-1)*rows + (j-1);
if(index > (rows * cols - 1) ) {
print("Index (");
print(i);
@@ -81,24 +81,24 @@ typedef matrix (Destructable) {
println(").");
return false;
}
return true;
}
//Access matrix element
fun at(i: int, j: int): double {
var index = i*rows + j;
if(test0(i,j))
return data.at(index);
return 0;
}
//Set matrix element
fun set(i: int, j: int, num: double): void {
var index = i*rows + j;
if(test0(i,j))
@@ -106,11 +106,11 @@ typedef matrix (Destructable) {
return;
}
fun printMatrix(): void {
for(var i: int = 0; i < rows; i++;)
{
{
for(var j: int = 0; j < cols; j++;)
{
print(at(i,j));
@@ -121,11 +121,11 @@ typedef matrix (Destructable) {
return;
}
///**************************
// Linear Algebra Functions
//**************************/
fun transpose(): void {
var val1: double;
var val2: double;
@@ -138,7 +138,7 @@ typedef matrix (Destructable) {
set(n, m, val2);
set(m, n, val1);
}
return;
}