Esempio n. 1
0
MyVect<T> &UMatrix<T>:: operator* (const MyVect<T> &s)
{
    if (m_dimension != s.size ())
    {
        throw MatrixError(2);
    }
    MyVect<T> *pro;
    pro = new MyVect<T> (m_dimension);
    for (int i = 0; i < m_dimension; i++)
    {
        pro[i] = 0;
        for (int j = 0; j < m_dimension-i; j++)
        {
            pro[i] = pro[i] + (m_ptr_to_data[i][j] * s[i]);
        }
    }
    return *pro;
}
Esempio n. 2
0
int ne_op ( )
{
    Matrix	a;
    Matrix	b;
    Matrix	c;
    double	lvalue;
    double	rvalue;
    descriptor *left;
    descriptor *right;
    descriptor *result;
    descriptor	temp;
    int		type_error;
    int		status;
    int		cmp;
    unsigned	i;
    unsigned	j;


    right = pop ( );
    result = top ( );
    temp = *result;
    left = &temp;

    left = deref (left);
    right = deref (right);

    if (D_Type (left) != T_String || D_Type (right) != T_String) {
	left = CoerceData (left, T_Double);
	right = CoerceData (right, T_Double);
    }


    status = 0;
    type_error = F_False;


    switch (D_Type (left)) {
    case T_Double:
	switch (D_Type (right)) {
	case T_Double:
	    D_Type    (result) = T_Double;
	    D_Temp    (result) = F_False;
	    D_Trapped (result) = F_False;
	    D_Double  (result) = dbllit (*D_Double (left) != *D_Double (right));
	    break;


	case T_Matrix:
	    a = D_Matrix (right);
	    CreateData (result, left, right, T_Matrix, Mrows (a), Mcols (a));
	    b = D_Matrix (result);
	    lvalue = *D_Double (left);
	    for (i = 1; i <= Mrows (a); i ++)
		for (j = 1; j <= Mcols (a); j ++)
		    sdata (b, i, j) = lvalue != mdata (a, i, j);
	    break;


	default:
	    type_error = F_True;
	    break;
	}
	break;


    case T_Matrix:
	switch (D_Type (right)) {
	case T_Double:
	    a = D_Matrix (left);
	    CreateData (result, left, right, T_Matrix, Mrows (a), Mcols (a));
	    b = D_Matrix (result);
	    rvalue = *D_Double (right);
	    for (i = 1; i <= Mrows (a); i ++)
		for (j = 1; j <= Mcols (a); j ++)
		    sdata (b, i, j) = mdata (a, i, j) != rvalue;
	    break;


	case T_Matrix:
	    a = D_Matrix (left);
	    b = D_Matrix (right);
	    CreateData (result, left, right, T_Matrix, Mrows (a), Mcols (a));
	    c = D_Matrix (result);
	    if ((status = CompareNEQMatrices (c, a, b)))
		MatrixError ("!=", a, b, status, F_False);
	    break;


	default:
	    type_error = F_True;
	    break;
	}
	break;


    case T_String:
	switch (D_Type (right)) {
	case T_String:
	    cmp = strcmp (*D_String (left), *D_String (right));
	    D_Type    (result) = T_Double;
	    D_Temp    (result) = F_False;
	    D_Trapped (result) = F_False;
	    D_Double  (result) = dbllit (cmp != 0);
	    break;


	default:
	    type_error = F_True;
	    break;
	}
	break;


    case T_Function:
    case T_Intrinsic:
    case T_Array:
    case T_Pair:
	if (D_Type (left) == D_Type (right)) {
	    D_Type    (result) = T_Double;
	    D_Temp    (result) = F_False;
	    D_Trapped (result) = F_False;
	    D_Double  (result) = dbllit (D_Pointer (left) == D_Pointer (right));
	} else
	    type_error = F_False;
	break;


    case T_Constraint:
    case T_Definition:
    case T_Element:
    case T_Force:
    case T_Load:
    case T_Material:
    case T_Node:
    case T_Stress:
    case T_External:
	if (D_Type (left) == D_Type (right)) {
	    cmp = *(void **) D_Pointer (left) != *(void **) D_Pointer (right);
	    D_Type    (result) = T_Double;
	    D_Temp    (result) = F_False;
	    D_Trapped (result) = F_False;
	    D_Double  (result) = dbllit (cmp);
	} else if (D_Type (right) == T_Null) {
	    cmp = *(void **) D_Pointer (left) != NULL;
	    D_Type    (result) = T_Double;
	    D_Temp    (result) = F_False;
	    D_Trapped (result) = F_False;
	    D_Double  (result) = dbllit (cmp);
	} else
	    type_error = F_True;
	break;


    case T_Null:
	switch (D_Type (right)) {
	case T_Constraint:
	case T_Definition:
	case T_Element:
	case T_Force:
	case T_Load:
	case T_Material:
	case T_Node:
	case T_Stress:
	case T_External:
	    cmp = *(void **) D_Pointer (right) != NULL;
	    D_Type    (result) = T_Double;
	    D_Temp    (result) = F_False;
	    D_Trapped (result) = F_False;
	    D_Double  (result) = dbllit (cmp);
	    break;


	default:
	    type_error = F_True;
	    break;
	}
	break;


    default:
	type_error = F_True;
	break;
    }


    if (type_error == F_True)
	TypeError ("!=", left, right, NULL, F_False);


    RecycleData (left);
    RecycleData (right);
    d_printf ("ne ans =\n");
    d_PrintData (result);

    return type_error == F_True || status != 0;
}
Esempio n. 3
0
bool SMatrix::setVal(size_type row, size_type col, int val) throw(MatrixError) {
   bool valSet = false;
   if(row > m_ && col > n_) {
      throw MatrixError("Matrix bound error");  //CHANGE LATER??

   } else {
      if(ridx_.find(row) != ridx_.cend()) {   //row already in ridx
         int nElements = ridx_[row].first + ridx_[row].second;   
         //cout << ridx_[row].first << " " << ridx_[row].second << endl;         
         
         //finding insert position
         int pos;
         for(pos = ridx_[row].first;pos < nElements;++pos) {
            if(col < cidx_[pos]) {  
               break;
            }
         }
         
         //if at near capacity double the size of the arrays 
         if(k_ >= arrSize_) { //arrSize_ - 2) {     
            valSet = true;    //returns true if additional memory must be allocated
            int* tempVal = vals_;
            size_type* tempCidx = cidx_;

            arrSize_ = arrSize_*2;
            vals_ = new int[arrSize_];   
            cidx_ = new size_type[arrSize_];
            for(size_type i = 0;i < k_;++i) {
               vals_[i] = tempVal[i];
               cidx_[i] = tempCidx[i];
            }   
         } 
            
         //loop to find insert position
         for(int i = k_; i > pos;--i) {
            vals_[i] = vals_[i-1];
            cidx_[i] = cidx_[i-1];
         }
         vals_[pos] = val;    //inserting new element
         cidx_[pos] = col;
         ++k_;
         ++ridx_[row].second;

         //cout << "row: " << row << "num elements" << ridx_[row].second << endl;
         //cout << vals_[0] << " " << vals_[1] << " " << vals_[2] <<endl;
         //cout << cidx_[0] << " " << cidx_[1] << " " << cidx_[2] << endl;
         //cout << ridx_[row].first << " " << ridx_[row].second << endl;
            


      } else {
         if(val != 0) {      //avoid creating new entry if it is a non zero element
            if(k_ > arrSize_) {
               valSet = true;    //returns true if additional memory must be allocated
               //allocate more memory
            } else {
               vals_[k_] = val;    //setting val 
               cidx_[k_] = col;    //setting corresponding column        
               pair<size_t, unsigned int> newPair(k_,1);   //new pair to add to ridx
               ridx_[row] = newPair;
               ++k_;
            }
         }
     }
   }         
   return valSet; 
}
Esempio n. 4
0
int lt_op ( )
{
    Matrix	a;
    Matrix	b;
    Matrix	c;
    double	lvalue;
    double	rvalue;
    descriptor *left;
    descriptor *right;
    descriptor *result;
    descriptor	temp;
    int		type_error;
    int		status;
    int		cmp;
    unsigned	i;
    unsigned	j;


    right = pop ( );
    result = top ( );
    temp = *result;
    left = &temp;

    left = deref (left);
    right = deref (right);

    if (D_Type (left) != T_String || D_Type (right) != T_String) {
	left = CoerceData (left, T_Double);
	right = CoerceData (right, T_Double);
    }


    status = 0;
    type_error = F_False;


    switch (D_Type (left)) {
    case T_Double:
	switch (D_Type (right)) {
	case T_Double:
	    D_Type    (result) = T_Double;
	    D_Temp    (result) = F_False;
	    D_Trapped (result) = F_False;
	    D_Double  (result) = dbllit (*D_Double (left) < *D_Double (right));
	    break;


	case T_Matrix:
	    a = D_Matrix (right);
	    CreateData (result, left, right, T_Matrix, Mrows (a), Mcols (a));
	    b = D_Matrix (result);
	    lvalue = *D_Double (left);
	    for (i = 1; i <= Mrows (a); i ++)
		for (j = 1; j <= Mcols (a); j ++)
		    sdata (b, i, j) = lvalue < mdata (a, i, j);
	    break;


	default:
	    type_error = F_True;
	    break;
	}
	break;


    case T_Matrix:
	switch (D_Type (right)) {
	case T_Double:
	    a = D_Matrix (left);
	    CreateData (result, left, right, T_Matrix, Mrows (a), Mcols (a));
	    b = D_Matrix (result);
	    rvalue = *D_Double (right);
	    for (i = 1; i <= Mrows (a); i ++)
		for (j = 1; j <= Mcols (a); j ++)
		    sdata (b, i, j) = mdata (a, i, j) < rvalue;
	    break;


	case T_Matrix:
	    a = D_Matrix (left);
	    b = D_Matrix (right);
	    CreateData (result, left, right, T_Matrix, Mrows (a), Mcols (a));
	    c = D_Matrix (result);
	    if ((status = CompareLTMatrices (c, a, b)))
		MatrixError ("<", a, b, status, F_False);
	    break;


	default:
	    type_error = F_True;
	    break;
	}
	break;


    case T_String:
	switch (D_Type (right)) {
	case T_String:
	    cmp = strcmp (*D_String (left), *D_String (right));
	    D_Type    (result) = T_Double;
	    D_Temp    (result) = F_False;
	    D_Trapped (result) = F_False;
	    D_Double  (result) = dbllit (cmp < 0);
	    break;


	default:
	    type_error = F_True;
	    break;
	}
	break;


    default:
	type_error = F_True;
	break;
    }


    if (type_error == F_True)
	TypeError ("<", left, right, NULL, F_False);


    RecycleData (left);
    RecycleData (right);
    d_printf ("lt ans =\n");
    d_PrintData (result);

    return type_error == F_True || status != 0;
}