Наследование blitz::array
От: Аноним  
Дата: 27.07.11 15:10
Оценка:
В Blitz++ есть возможность итерирования массивов без написания циклов следующим образом:


blitz::Array<AD, 2> a(n, n)
blitz::Range I(0, n - 1), J(0, n - 1);
a(I, J) = 1; // цикл по всем целым i, j от 0 до n - 1



Возникла необходимость вместо 1 подставить внешнюю функцию f(i, j), принимающую целые индексы.
Сначала думал, что оператор (I, J) внутри библиотеки обращается к (i, j) и написал обертку

class FArray : public blitz::Array<double, 2> {
public:
  const double& restrict operator()(int i0, int i1) const {
    return f(i0, i1);
  }
};


Однако реализация (I, J) оказалась хитрее и не обращается к (i, j).
Саппорт особо не помог:
"Well, yes. You only defined operator() to take ints. This definition hides all definitions of operator() in the base classArray, so it won't be found. If you want to use Range indexing (or any of the other roughly 100 variations of operator() declared for Array), you'll need to define it.

Do note that what you are doing is not recommended. All function resolution is static (which is the point). In particular, operator() is not virtual, so internally blitz will still use the default operator(). Using any of the blitz methods that return arrays will also chop off your rhsarray."

Может у кого есть опыт подобного переопределения? Чешу репу как сотворить...
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.