divyang4481 / mipt-hw

Automatically exported from code.google.com/p/mipt-hw
0 stars 0 forks source link

task03 TMatrix (Efimov) #194

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
/efimov_andrey/Task02

Original issue reported on code.google.com by ae.insomniac on 30 Mar 2013 at 12:23

GoogleCodeExporter commented 9 years ago
Матрицы - это задание номер 3. Я 
переименовал папку. Сделайте svn update.

Original comment by aivyu...@gmail.com on 6 Apr 2013 at 9:14

GoogleCodeExporter commented 9 years ago

Original comment by aivyu...@gmail.com on 6 Apr 2013 at 9:14

GoogleCodeExporter commented 9 years ago
0. Код компилируется:
Matrices.cpp:52: error: ‘arry’ was not declared in this scope
Matrices.cpp:52: error: ‘>>’ should be ‘> >’ within a nested template 
argument list
Matrices.cpp: In function ‘void MultiplicationTest(int)’:
Matrices.cpp:207: error: no match for ‘operator=’ in ‘b = 
TMatrix<T>::Transpose() [with T = int]()’
Matrices.cpp:86: note: candidates are: bool TMatrix<T>::operator=(TMatrix<T>&) 
[with T = int]
Matrices.cpp:209: error: no match for ‘operator=’ in ‘res = 
TMatrix<T>::operator*(TMatrix<T>&) [with T = int](((TMatrix<int>&)(& b)))’
Matrices.cpp:86: note: candidates are: bool TMatrix<T>::operator=(TMatrix<T>&) 
[with T = int]
Matrices.cpp: In member function ‘TMatrix<T> 
TMatrix<T>::operator*=(TMatrix<T>&) [with T = int]’:
Matrices.cpp:217:   instantiated from here
Matrices.cpp:149: error: no match for ‘operator=’ in 
‘*(TMatrix<int>*)this = TMatrix<T>::operator*(TMatrix<T>&) [with T = 
int](((TMatrix<int>&)((TMatrix<int>*)other)))’
Matrices.cpp:86: note: candidates are: bool TMatrix<T>::operator=(TMatrix<T>&) 
[with T = int]
Matrices.cpp: In member function ‘TMatrix<T> 
TMatrix<T>::operator-=(TMatrix<T>&) [with T = int]’:
Matrices.cpp:231:   instantiated from here
Matrices.cpp:145: error: no match for ‘operator=’ in 
‘*(TMatrix<int>*)this = TMatrix<T>::operator-(TMatrix<T>&) [with T = 
int](((TMatrix<int>&)((TMatrix<int>*)other)))’
Matrices.cpp:86: note: candidates are: bool TMatrix<T>::operator=(TMatrix<T>&) 
[with T = int]
Matrices.cpp: In member function ‘void TMatrix<T>::ArrayBuild() [with T = 
A]’:
Matrices.cpp:63:   instantiated from ‘TMatrix<T>::TMatrix(size_t, size_t) 
[with T = A]’
Matrices.cpp:249:   instantiated from here
Matrices.cpp:56: error: no matching function for call to ‘A::A(A)’
Matrices.cpp:19: note: candidates are: A::A(A&)
Matrices.cpp:15: note:                 A::A(int)
Matrices.cpp:11: note:                 A::A()
/usr/include/c++/4.2.1/bits/vector.tcc: In member function ‘void 
std::vector<_Tp, _Alloc>::_M_fill_insert(__gnu_cxx::__normal_iterator<typename 
std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, 
_Alloc> >, size_t, const _Tp&) [with _Tp = A, _Alloc = std::allocator<A>]’:
/usr/include/c++/4.2.1/bits/stl_vector.h:656:   instantiated from ‘void 
std::vector<_Tp, _Alloc>::insert(__gnu_cxx::__normal_iterator<typename 
std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, 
_Alloc> >, size_t, const _Tp&) [with _Tp = A, _Alloc = std::allocator<A>]’
/usr/include/c++/4.2.1/bits/stl_vector.h:424:   instantiated from ‘void 
std::vector<_Tp, _Alloc>::resize(size_t, _Tp) [with _Tp = A, _Alloc = 
std::allocator<A>]’
Matrices.cpp:56:   instantiated from ‘void TMatrix<T>::ArrayBuild() [with T = 
A]’
Matrices.cpp:63:   instantiated from ‘TMatrix<T>::TMatrix(size_t, size_t) 
[with T = A]’
Matrices.cpp:249:   instantiated from here
/usr/include/c++/4.2.1/bits/vector.tcc:314: error: no matching function for 
call to ‘A::A(const A&)’
Matrices.cpp:19: note: candidates are: A::A(A&)
Matrices.cpp:15: note:                 A::A(int)
/usr/include/c++/4.2.1/bits/stl_construct.h: In function ‘void 
std::_Construct(_T1*, const _T2&) [with _T1 = A, _T2 = A]’:
/usr/include/c++/4.2.1/bits/stl_uninitialized.h:87:   instantiated from 
‘_ForwardIterator std::__uninitialized_copy_aux(_InputIterator, 
_InputIterator, _ForwardIterator, std::__false_type) [with _InputIterator = 
__gnu_cxx::__normal_iterator<const A*, std::vector<A, std::allocator<A> > >, 
_ForwardIterator = A*]’
/usr/include/c++/4.2.1/bits/stl_uninitialized.h:114:   instantiated from 
‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, 
_ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const A*, 
std::vector<A, std::allocator<A> > >, _ForwardIterator = A*]’
/usr/include/c++/4.2.1/bits/stl_uninitialized.h:254:   instantiated from 
‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, 
_ForwardIterator, std::allocator<_Tp>) [with _InputIterator = 
__gnu_cxx::__normal_iterator<const A*, std::vector<A, std::allocator<A> > >, 
_ForwardIterator = A*, _Tp = A]’
/usr/include/c++/4.2.1/bits/stl_vector.h:233:   instantiated from 
‘std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp 
= A, _Alloc = std::allocator<A>]’
Matrices.cpp:54:   instantiated from ‘void TMatrix<T>::ArrayBuild() [with T = 
A]’
Matrices.cpp:63:   instantiated from ‘TMatrix<T>::TMatrix(size_t, size_t) 
[with T = A]’
Matrices.cpp:249:   instantiated from here
/usr/include/c++/4.2.1/bits/stl_construct.h:81: error: no matching function for 
call to ‘A::A(const A&)’
Matrices.cpp:19: note: candidates are: A::A(A&)
Matrices.cpp:15: note:                 A::A(int)
Matrices.cpp:11: note:                 A::A()

Вы вообще хоть как-то проверяете то, что 
сдаете?

1. В конструкторе по умолчанию Вы создаете 
матрицу 1 на 1. Думаю, логичнее создавать 
пустую, т.к. обычно такой объект создается в 
каких-то промежуточных операциях. В таком 
случае лишнее выделение памяти только 
замедляет работу.

2. В конструкторе по умолчанию и operator= 
копи-паст. Правильнее один реализовать 
через другой.

3. Невозможно сложить/вычесть/умножить две 
матрицы если они неконстантные. Это 
нелогично.

4. operator* у Вас принимает объект по значению. 
При этом происходит лишнее копирование 
аргумента. Для матриц это довольно тяжелая 
операция. Правильнее передавать по ссылке, 
как Вы это сделали в operator+, например. Но, 
конечно, по константной ссылке.

5. Не вижу таблицы и графика с результатами 
сравнения алгоритмов умножения.

Решение не принято.

Original comment by aivyu...@gmail.com on 6 Apr 2013 at 9:22

GoogleCodeExporter commented 9 years ago
Redone

Original comment by ae.insomniac on 26 May 2013 at 2:08

Attachments:

GoogleCodeExporter commented 9 years ago
0. Не собирается:
Matrices.cpp: In function 'void MultiplicationTest(int)':
Matrices.cpp:207:16: error: no match for 'operator=' in 'b = 
TMatrix<T>::Transpose() [with T = int; TMatrix<T> = TMatrix<int>]()'
Matrices.cpp:207:16: note: candidate is:
Matrices.cpp:86:7: note: bool TMatrix<T>::operator=(TMatrix<T>&) [with T = int; 
TMatrix<T> = TMatrix<int>]
Matrices.cpp:86:7: note:   no known conversion for argument 1 from 
'TMatrix<int>' to 'TMatrix<int>&'
Matrices.cpp:209:8: error: no match for 'operator=' in 'res = 
TMatrix<T>::operator*(TMatrix<T>&) [with T = int; TMatrix<T> = TMatrix<int>]((* 
& b))'
Matrices.cpp:209:8: note: candidate is:
Matrices.cpp:86:7: note: bool TMatrix<T>::operator=(TMatrix<T>&) [with T = int; 
TMatrix<T> = TMatrix<int>]
Matrices.cpp:86:7: note:   no known conversion for argument 1 from 
'TMatrix<int>' to 'TMatrix<int>&'
Matrices.cpp: In instantiation of 'TMatrix<T> 
TMatrix<T>::operator*=(TMatrix<T>&) [with T = int; TMatrix<T> = TMatrix<int>]':
Matrices.cpp:217:5:   required from here
Matrices.cpp:149:3: error: no match for 'operator=' in '*(TMatrix<int>*)this = 
TMatrix<T>::operator*(TMatrix<T>&) [with T = int; TMatrix<T> = TMatrix<int>]((* 
& other))'
Matrices.cpp:149:3: note: candidate is:
Matrices.cpp:86:7: note: bool TMatrix<T>::operator=(TMatrix<T>&) [with T = int; 
TMatrix<T> = TMatrix<int>]
Matrices.cpp:86:7: note:   no known conversion for argument 1 from 
'TMatrix<int>' to 'TMatrix<int>&'
Matrices.cpp: In instantiation of 'TMatrix<T> 
TMatrix<T>::operator-=(TMatrix<T>&) [with T = int; TMatrix<T> = TMatrix<int>]':
Matrices.cpp:231:5:   required from here
Matrices.cpp:145:3: error: no match for 'operator=' in '*(TMatrix<int>*)this = 
TMatrix<T>::operator-(TMatrix<T>&) [with T = int; TMatrix<T> = TMatrix<int>]((* 
& other))'
Matrices.cpp:145:3: note: candidate is:
Matrices.cpp:86:7: note: bool TMatrix<T>::operator=(TMatrix<T>&) [with T = int; 
TMatrix<T> = TMatrix<int>]
Matrices.cpp:86:7: note:   no known conversion for argument 1 from 
'TMatrix<int>' to 'TMatrix<int>&'
In file included from /opt/local/include/gcc47/c++/vector:63:0,
                 from Matrices.cpp:2:
/opt/local/include/gcc47/c++/bits/stl_construct.h: In instantiation of 'void 
std::_Construct(_T1*, _Args&& ...) [with _T1 = A; _Args = {A}]':
/opt/local/include/gcc47/c++/bits/stl_uninitialized.h:77:3:   required from 
'static _ForwardIterator 
std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator, 
_InputIterator, _ForwardIterator) [with _InputIterator = 
std::move_iterator<A*>; _ForwardIterator = A*; bool _TrivialValueTypes = false]'
/opt/local/include/gcc47/c++/bits/stl_uninitialized.h:119:41:   required from 
'_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, 
_ForwardIterator) [with _InputIterator = std::move_iterator<A*>; 
_ForwardIterator = A*]'
/opt/local/include/gcc47/c++/bits/stl_uninitialized.h:260:63:   required from 
'_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, 
_ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = 
std::move_iterator<A*>; _ForwardIterator = A*; _Tp = A]'
/opt/local/include/gcc47/c++/bits/stl_uninitialized.h:283:69:   required from 
'_ForwardIterator std::__uninitialized_move_if_noexcept_a(_InputIterator, 
_InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = A*; 
_ForwardIterator = A*; _Allocator = std::allocator<A>]'
/opt/local/include/gcc47/c++/bits/vector.tcc:554:5:   required from 'void 
std::vector<_Tp, _Alloc>::_M_default_append(std::vector<_Tp, 
_Alloc>::size_type) [with _Tp = A; _Alloc = std::allocator<A>; std::vector<_Tp, 
_Alloc>::size_type = long unsigned int]'
/opt/local/include/gcc47/c++/bits/stl_vector.h:647:4:   required from 'void 
std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type) [with _Tp 
= A; _Alloc = std::allocator<A>; std::vector<_Tp, _Alloc>::size_type = long 
unsigned int]'
Matrices.cpp:56:4:   required from 'void TMatrix<T>::ArrayBuild() [with T = A]'
Matrices.cpp:63:3:   required from 'TMatrix<T>::TMatrix(size_t, size_t) [with T 
= A; size_t = long unsigned int]'
Matrices.cpp:249:18:   required from here
/opt/local/include/gcc47/c++/bits/stl_construct.h:77:7: error: no matching 
function for call to 'A::A(A)'
/opt/local/include/gcc47/c++/bits/stl_construct.h:77:7: note: candidates are:
Matrices.cpp:19:2: note: A::A(A&)
Matrices.cpp:19:2: note:   no known conversion for argument 1 from 'A' to 'A&'
Matrices.cpp:15:2: note: A::A(int)
Matrices.cpp:15:2: note:   no known conversion for argument 1 from 'A' to 'int'
Matrices.cpp:11:2: note: A::A()
Matrices.cpp:11:2: note:   candidate expects 0 arguments, 1 provided

1. Не вижу в коде теста, в котором измеряется 
время работы алгоритмов.

2. Вы прислали график. Что на нем? В каких 
единицах? Пришлите, пожалуйста, еще таблицу 
с результатами.

3. Исправьте программу так, чтобы она для 
разных N (16, 32, 64 и т.д. по нарастающей):
 - генерирует пару матриц размера N x N со случайными значениями элементов
 - выводит время работы алгоритма умножения матриц по определению
 - выводит время работа алгоритма умножения той же пары матриц с помощью алгоритма Штрассена
 - выводит, совпадают ли результаты работы этих двух алгоритмов

Решение не принято.

Original comment by aivyu...@gmail.com on 26 May 2013 at 2:28

GoogleCodeExporter commented 9 years ago
VS собирает все без варнингов в .cpp, в 11/15/19 
строках (последние ошибки) у меня находятся 
не конструкторы. (необновленное?)

1. он находится в функции void strassentest();

2. снизу размер матрицы, слева миллисекунды, 
красный — штрассен
меньше 64 нет, потому что не видно, и 
различия зависят не от алгоритмов — у 
штрассена <128 просто умножение
таблица —
size | common | strassen
16   | 10     | 8
32   | 32     | 22
64   | 133    | 134
128  | 1031   | 1029
256  | 8133   | 7573
512  | 65639  | 54184

3. Именно это и делает Strassentest, я запускаю ее 
из main

Original comment by ae.insomniac on 26 May 2013 at 2:53

GoogleCodeExporter commented 9 years ago
Решение принято.

Оценка: 0.8 балла.

Original comment by aivyu...@gmail.com on 26 May 2013 at 3:12