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>
|
template <typename Data>
|
||||||
void MatrixCSR<Data>::RowResize(const ulong& new_row_size){
|
void MatrixCSR<Data>::RowResize(const ulong& new_row_size){
|
||||||
if(new_row_size == 0){
|
if(new_row_size > rows){
|
||||||
Clear();
|
|
||||||
}
|
|
||||||
else if(new_row_size > rows){
|
|
||||||
R.Resize(new_row_size+1);
|
R.Resize(new_row_size+1);
|
||||||
for(ulong i=rows+1 ; i<R.Size(); ++i){
|
for(ulong i=rows+1 ; i<R.Size(); ++i){
|
||||||
R[i] = R[rows];
|
R[i] = R[rows];
|
||||||
|
@ -143,10 +140,7 @@ void MatrixCSR<Data>::RowResize(const ulong& new_row_size){
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
void MatrixCSR<Data>::ColumnResize(const ulong& new_column_size){
|
void MatrixCSR<Data>::ColumnResize(const ulong& new_column_size){
|
||||||
if(new_column_size == 0){
|
if(new_column_size < columns){
|
||||||
Clear();
|
|
||||||
}
|
|
||||||
else if(new_column_size < columns){
|
|
||||||
Node** prev;
|
Node** prev;
|
||||||
Node* toDelete;
|
Node* toDelete;
|
||||||
Node** toModify;
|
Node** toModify;
|
||||||
|
|
|
@ -70,22 +70,17 @@ bool MatrixVec<Data>::operator!=(const MatrixVec& toCompare) const noexcept{
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
void MatrixVec<Data>::RowResize(const ulong& newdim){
|
void MatrixVec<Data>::RowResize(const ulong& new_row_dim){
|
||||||
if(newdim == 0){
|
if(new_row_dim != rows){
|
||||||
Clear();
|
Vector<Data>::Resize(new_row_dim * columns);
|
||||||
}else{
|
rows = new_row_dim;
|
||||||
Vector<Data>::Resize(newdim * columns);
|
size = new_row_dim * columns;
|
||||||
rows = newdim;
|
|
||||||
size = newdim * columns;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
void MatrixVec<Data>::ColumnResize(const ulong& new_column_dim){
|
void MatrixVec<Data>::ColumnResize(const ulong& new_column_dim){
|
||||||
if(new_column_dim == 0){
|
if(new_column_dim != columns){
|
||||||
Clear();
|
|
||||||
}
|
|
||||||
else if(new_column_dim != columns){
|
|
||||||
ulong limit = (new_column_dim < columns)? new_column_dim : columns;
|
ulong limit = (new_column_dim < columns)? new_column_dim : columns;
|
||||||
Data* tmp = new Data[rows * new_column_dim]{};
|
Data* tmp = new Data[rows * new_column_dim]{};
|
||||||
for(ulong i=0 ; i<rows ; ++i){
|
for(ulong i=0 ; i<rows ; ++i){
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
void menu(){
|
void menu(){
|
||||||
|
|
||||||
DataType chosenDataType;
|
DataType chosenDataType;
|
||||||
|
@ -67,32 +66,38 @@ void UseChosenType(Implementation chosenImplementation, DataType chosenDataType)
|
||||||
if(chosenDataType == DataType::integer){
|
if(chosenDataType == DataType::integer){
|
||||||
MatrixVec<int> mtx;
|
MatrixVec<int> mtx;
|
||||||
mtx = GenerateIntegerMat(mtx);
|
mtx = GenerateIntegerMat(mtx);
|
||||||
|
cout<<"\nThe matrix has been randomly generated.\n";
|
||||||
IntegerFunctions(mtx);
|
IntegerFunctions(mtx);
|
||||||
|
|
||||||
}else if(chosenDataType == DataType::ffloat){
|
}else if(chosenDataType == DataType::ffloat){
|
||||||
MatrixVec<float> mtx;
|
MatrixVec<float> mtx;
|
||||||
mtx = GenerateFloatMat(mtx);
|
mtx = GenerateFloatMat(mtx);
|
||||||
|
cout<<"\nThe matrix has been randomly generated.\n";
|
||||||
FloatFunctions(mtx);
|
FloatFunctions(mtx);
|
||||||
|
|
||||||
}else if(chosenDataType == DataType::sstring){
|
}else if(chosenDataType == DataType::sstring){
|
||||||
MatrixVec<string> mtx;
|
MatrixVec<string> mtx;
|
||||||
mtx = GenerateStringsMat(mtx);
|
mtx = GenerateStringsMat(mtx);
|
||||||
|
cout<<"\nThe matrix has been randomly generated.\n";
|
||||||
StringFunctions(mtx);
|
StringFunctions(mtx);
|
||||||
}
|
}
|
||||||
}else if(chosenImplementation == Implementation::yale){
|
}else if(chosenImplementation == Implementation::yale){
|
||||||
if(chosenDataType == DataType::integer){
|
if(chosenDataType == DataType::integer){
|
||||||
MatrixCSR<int> mtx;
|
MatrixCSR<int> mtx;
|
||||||
mtx = GenerateIntegerMat(mtx);
|
mtx = GenerateIntegerMat(mtx);
|
||||||
|
cout<<"\nThe matrix has been randomly generated.\n";
|
||||||
IntegerFunctions(mtx);
|
IntegerFunctions(mtx);
|
||||||
|
|
||||||
}else if(chosenDataType == DataType::ffloat){
|
}else if(chosenDataType == DataType::ffloat){
|
||||||
MatrixCSR<float> mtx;
|
MatrixCSR<float> mtx;
|
||||||
mtx = GenerateFloatMat(mtx);
|
mtx = GenerateFloatMat(mtx);
|
||||||
|
cout<<"\nThe matrix has been randomly generated.\n";
|
||||||
FloatFunctions(mtx);
|
FloatFunctions(mtx);
|
||||||
|
|
||||||
}else if(chosenDataType == DataType::sstring){
|
}else if(chosenDataType == DataType::sstring){
|
||||||
MatrixCSR<string> mtx;
|
MatrixCSR<string> mtx;
|
||||||
mtx = GenerateStringsMat(mtx);
|
mtx = GenerateStringsMat(mtx);
|
||||||
|
cout<<"\nThe matrix has been randomly generated.\n";
|
||||||
StringFunctions(mtx);
|
StringFunctions(mtx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -360,7 +365,7 @@ void Double(T& mtx){
|
||||||
void (*fun)(int&, void*) = MultiplyAnElement;
|
void (*fun)(int&, void*) = MultiplyAnElement;
|
||||||
int par = 2;
|
int par = 2;
|
||||||
mtx.MapPreOrder(fun,(void*)&par);
|
mtx.MapPreOrder(fun,(void*)&par);
|
||||||
cout<<"Done.\n";
|
cout<<" Done.\n";
|
||||||
}
|
}
|
||||||
void MultiplyAnElement(int& data, void* par){
|
void MultiplyAnElement(int& data, void* par){
|
||||||
data *= *(int*)par;
|
data *= *(int*)par;
|
||||||
|
@ -371,11 +376,11 @@ void ProductsElementsLessThan(T& mtx){
|
||||||
int n, acc=1;
|
int n, acc=1;
|
||||||
void (*func)(const int&, const void*, void*) = AccumulateProduct;
|
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;
|
cin>>ws>>n;
|
||||||
|
|
||||||
mtx.FoldPreOrder(func, (void*)&n, (void*)&acc);
|
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>
|
template <template <typename...> class Matrix, typename Data>
|
||||||
void CheckExistence(Matrix<Data>& mtx){
|
void CheckExistence(Matrix<Data>& mtx){
|
||||||
Data elementToLookFor;
|
Data elementToLookFor;
|
||||||
cout<<"\n\nCheck existence in the matrix of: ";
|
cout<<"\n\n Check existence in the matrix of: ";
|
||||||
cin>>ws;
|
cin>>ws;
|
||||||
cin>>elementToLookFor;
|
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>
|
template <template <typename...> class Matrix, typename Data>
|
||||||
|
@ -524,7 +529,6 @@ T GenerateStringsMat(T& mat){
|
||||||
}while(column >= n_columns);
|
}while(column >= n_columns);
|
||||||
matrix(row,column) = generateRandomString(dist(gen));
|
matrix(row,column) = generateRandomString(dist(gen));
|
||||||
}
|
}
|
||||||
|
|
||||||
return matrix;
|
return matrix;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue