mirror of https://github.com/xfarrow/lasd.git
Library 5
This commit is contained in:
parent
98f7065258
commit
d15173a276
|
@ -116,10 +116,7 @@ bool MatrixCSR<Data>::operator!=(const MatrixCSR& toCompare) const noexcept{
|
|||
|
||||
template <typename Data>
|
||||
void MatrixCSR<Data>::RowResize(const ulong& new_row_size){
|
||||
if(new_row_size == 0){
|
||||
Clear();
|
||||
}
|
||||
else if(new_row_size > rows){
|
||||
if(new_row_size > rows){
|
||||
R.Resize(new_row_size+1);
|
||||
for(ulong i=rows+1 ; i<R.Size(); ++i){
|
||||
R[i] = R[rows];
|
||||
|
@ -143,10 +140,7 @@ void MatrixCSR<Data>::RowResize(const ulong& new_row_size){
|
|||
|
||||
template <typename Data>
|
||||
void MatrixCSR<Data>::ColumnResize(const ulong& new_column_size){
|
||||
if(new_column_size == 0){
|
||||
Clear();
|
||||
}
|
||||
else if(new_column_size < columns){
|
||||
if(new_column_size < columns){
|
||||
Node** prev;
|
||||
Node* toDelete;
|
||||
Node** toModify;
|
||||
|
|
|
@ -70,22 +70,17 @@ bool MatrixVec<Data>::operator!=(const MatrixVec& toCompare) const noexcept{
|
|||
}
|
||||
|
||||
template <typename Data>
|
||||
void MatrixVec<Data>::RowResize(const ulong& newdim){
|
||||
if(newdim == 0){
|
||||
Clear();
|
||||
}else{
|
||||
Vector<Data>::Resize(newdim * columns);
|
||||
rows = newdim;
|
||||
size = newdim * columns;
|
||||
void MatrixVec<Data>::RowResize(const ulong& new_row_dim){
|
||||
if(new_row_dim != rows){
|
||||
Vector<Data>::Resize(new_row_dim * columns);
|
||||
rows = new_row_dim;
|
||||
size = new_row_dim * columns;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
void MatrixVec<Data>::ColumnResize(const ulong& new_column_dim){
|
||||
if(new_column_dim == 0){
|
||||
Clear();
|
||||
}
|
||||
else if(new_column_dim != columns){
|
||||
if(new_column_dim != columns){
|
||||
ulong limit = (new_column_dim < columns)? new_column_dim : columns;
|
||||
Data* tmp = new Data[rows * new_column_dim]{};
|
||||
for(ulong i=0 ; i<rows ; ++i){
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include <random>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
void menu(){
|
||||
|
||||
DataType chosenDataType;
|
||||
|
@ -67,32 +66,38 @@ void UseChosenType(Implementation chosenImplementation, DataType chosenDataType)
|
|||
if(chosenDataType == DataType::integer){
|
||||
MatrixVec<int> mtx;
|
||||
mtx = GenerateIntegerMat(mtx);
|
||||
cout<<"\nThe matrix has been randomly generated.\n";
|
||||
IntegerFunctions(mtx);
|
||||
|
||||
}else if(chosenDataType == DataType::ffloat){
|
||||
MatrixVec<float> mtx;
|
||||
mtx = GenerateFloatMat(mtx);
|
||||
cout<<"\nThe matrix has been randomly generated.\n";
|
||||
FloatFunctions(mtx);
|
||||
|
||||
}else if(chosenDataType == DataType::sstring){
|
||||
MatrixVec<string> mtx;
|
||||
mtx = GenerateStringsMat(mtx);
|
||||
cout<<"\nThe matrix has been randomly generated.\n";
|
||||
StringFunctions(mtx);
|
||||
}
|
||||
}else if(chosenImplementation == Implementation::yale){
|
||||
if(chosenDataType == DataType::integer){
|
||||
MatrixCSR<int> mtx;
|
||||
mtx = GenerateIntegerMat(mtx);
|
||||
cout<<"\nThe matrix has been randomly generated.\n";
|
||||
IntegerFunctions(mtx);
|
||||
|
||||
}else if(chosenDataType == DataType::ffloat){
|
||||
MatrixCSR<float> mtx;
|
||||
mtx = GenerateFloatMat(mtx);
|
||||
cout<<"\nThe matrix has been randomly generated.\n";
|
||||
FloatFunctions(mtx);
|
||||
|
||||
}else if(chosenDataType == DataType::sstring){
|
||||
MatrixCSR<string> mtx;
|
||||
mtx = GenerateStringsMat(mtx);
|
||||
cout<<"\nThe matrix has been randomly generated.\n";
|
||||
StringFunctions(mtx);
|
||||
}
|
||||
}
|
||||
|
@ -360,7 +365,7 @@ void Double(T& mtx){
|
|||
void (*fun)(int&, void*) = MultiplyAnElement;
|
||||
int par = 2;
|
||||
mtx.MapPreOrder(fun,(void*)&par);
|
||||
cout<<"Done.\n";
|
||||
cout<<" Done.\n";
|
||||
}
|
||||
void MultiplyAnElement(int& data, void* par){
|
||||
data *= *(int*)par;
|
||||
|
@ -371,11 +376,11 @@ void ProductsElementsLessThan(T& mtx){
|
|||
int n, acc=1;
|
||||
void (*func)(const int&, const void*, void*) = AccumulateProduct;
|
||||
|
||||
cout<<"Multipy all elements of the matrix whose value is less than ";
|
||||
cout<<" Multipy all elements of the matrix whose value is less than ";
|
||||
cin>>ws>>n;
|
||||
|
||||
mtx.FoldPreOrder(func, (void*)&n, (void*)&acc);
|
||||
cout<<"\nThe result is "<<acc<<endl<<endl;
|
||||
cout<<"\n The result is "<<acc<<endl<<endl;
|
||||
|
||||
}
|
||||
|
||||
|
@ -388,10 +393,10 @@ void AccumulateProduct(const int& data, const void* par, void* acc){
|
|||
template <template <typename...> class Matrix, typename Data>
|
||||
void CheckExistence(Matrix<Data>& mtx){
|
||||
Data elementToLookFor;
|
||||
cout<<"\n\nCheck existence in the matrix of: ";
|
||||
cout<<"\n\n Check existence in the matrix of: ";
|
||||
cin>>ws;
|
||||
cin>>elementToLookFor;
|
||||
cout<<"The element " << ( (mtx.FoldableContainer<Data>::Exists(elementToLookFor))? "does" : "does not") << " exist\n\n";
|
||||
cout<<" The element " << ( (mtx.FoldableContainer<Data>::Exists(elementToLookFor))? "does" : "does not") << " exist\n\n";
|
||||
}
|
||||
|
||||
template <template <typename...> class Matrix, typename Data>
|
||||
|
@ -524,7 +529,6 @@ T GenerateStringsMat(T& mat){
|
|||
}while(column >= n_columns);
|
||||
matrix(row,column) = generateRandomString(dist(gen));
|
||||
}
|
||||
|
||||
return matrix;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue