2 matrix-storage.cc -- implement Matrix_storage
4 source file of the Flower Library
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
9 #include "full-storage.hh"
10 #include "diagonal-storage.hh"
13 Matrix_storage::set_addition_result (Matrix_storage *&dat, Matrix_storage *right)
15 if (dat && dat->name() == Diagonal_storage::static_name ()
16 && right->name() == Diagonal_storage::static_name ())
18 Diagonal_storage *L = (Diagonal_storage*)dat;
19 Diagonal_storage* R = (Diagonal_storage*) right;
21 if ( R->band_size_i() > L->band_size_i ())
23 L->set_band_size (R->band_size_i());
27 if (!dat || !dat->is_type_b (Full_storage::static_name()))
30 Matrix_storage *new_stor = (dat)? new Full_storage (dat) :
31 new Full_storage (right->rows(), right->cols ());
38 Matrix_storage::get_product_result (Matrix_storage*left, Matrix_storage*right)
40 Matrix_storage* dest =0;
41 set_product_result (dest, left,right);
50 Matrix_storage::set_product_result (Matrix_storage*&dest,
51 Matrix_storage*left, Matrix_storage*right)
53 if ( left->name() == Diagonal_storage::static_name ()
54 && right->name() == Diagonal_storage::static_name ())
56 Diagonal_storage *L = (Diagonal_storage*)left;
57 Diagonal_storage* R = (Diagonal_storage*) right;
59 if (L->band_size_i() + R->band_size_i () < L->dim ()/2)
61 if (dest ->name() != Diagonal_storage::static_name ())
64 dest = new Diagonal_storage;
67 dest->set_size (L->dim());
72 if ( dest && dest->name() == Full_storage::static_name ())
74 dest->set_size (left->rows(), right->cols ());
79 dest = new Full_storage (left->rows(), right->cols ());
83 IMPLEMENT_IS_TYPE_B(Matrix_storage);
86 Matrix_storage::get_full (int n, int m)
88 return new Full_storage (n,m);
94 Matrix_storage::try_right_multiply (Matrix_storage *,
95 const Matrix_storage *)const
101 Matrix_storage::row (int n) const
104 for (int j = 0; j < cols(); j++)
110 Matrix_storage::column (int n) const
113 for (int i = 0; i < rows(); i++)
119 Matrix_storage::set_size (int rows, int cols)
126 Matrix_storage::set_size (int rows)
134 Matrix_storage::set_band (Matrix_storage *&mat, int b)
136 Matrix_storage* ns = new Diagonal_storage (mat, b);
143 Matrix_storage::set_full (Matrix_storage *&mat)
145 Matrix_storage* ns = new Full_storage (mat);