QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fdmlinearoplayout.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2008 Andreas Gaida
5 Copyright (C) 2008 Ralph Schreyer
6 Copyright (C) 2008 Klaus Spanderen
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
26#ifndef quantlib_linear_op_layout_hpp
27#define quantlib_linear_op_layout_hpp
28
29#include <ql/methods/finitedifferences/operators/fdmlinearopiterator.hpp>
30#include <functional>
31
32namespace QuantLib {
33
35 public:
36 explicit FdmLinearOpLayout(std::vector<Size> dim)
37 : dim_(std::move(dim)), spacing_(dim_.size()) {
38 spacing_[0] = 1;
39 std::partial_sum(dim_.begin(), dim_.end()-1,
40 spacing_.begin()+1, std::multiplies<>());
41
42 size_ = spacing_.back()*dim_.back();
43 }
44
47 }
48
51 }
52
53 const std::vector<Size>& dim() const {
54 return dim_;
55 }
56
57 const std::vector<Size>& spacing() const {
58 return spacing_;
59 }
60
61 Size size() const {
62 return size_;
63 }
64
65 Size index(const std::vector<Size>& coordinates) const {
66 return std::inner_product(coordinates.begin(),
67 coordinates.end(),
68 spacing_.begin(), Size(0));
69 }
70
72 Size i, Integer offset) const;
73
75 Size i1, Integer offset1,
76 Size i2, Integer offset2) const;
77
78 // smart but sometimes too slow
80 const FdmLinearOpIterator& iterator, Size i, Integer offset) const;
81
82 private:
84 std::vector<Size> dim_, spacing_;
85 };
86}
87
88#endif
const std::vector< Size > & spacing() const
FdmLinearOpIterator iter_neighbourhood(const FdmLinearOpIterator &iterator, Size i, Integer offset) const
FdmLinearOpIterator end() const
Size neighbourhood(const FdmLinearOpIterator &iterator, Size i, Integer offset) const
const std::vector< Size > & dim() const
FdmLinearOpLayout(std::vector< Size > dim)
FdmLinearOpIterator begin() const
Size index(const std::vector< Size > &coordinates) const
QL_INTEGER Integer
integer number
Definition: types.hpp:35
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
STL namespace.