OpenZGY/C++ API and Internals (ALPHA)
Access seismic data stored in ZGY format.
arrayops.h
Go to the documentation of this file.
1 // Copyright 2017-2020, Schlumberger
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <array>
18 #include <ostream>
19 
43 namespace InternalZGY { namespace ArrayOps {
44 #if 0
45 }}
46 #endif
47 
48 // Operations on arrays. TODO-Low ugly code smell.
49 // I probably need to make a dedicated "index3_t" type
50 // that will support these operators.
51 
52 template<typename T, std::size_t N>
53 static std::array<T,N> operator+(const std::array<T,N>& a, const std::array<T,N>& b)
54 {
55  std::array<T,N> result;
56  for (std::size_t dim=0; dim<N; ++dim)
57  result[dim] = a[dim] + b[dim];
58  return result;
59 }
60 
61 template<typename T, std::size_t N>
62 static std::array<T,N> operator-(const std::array<T,N>& a, const std::array<T,N>& b)
63 {
64  std::array<T,N> result;
65  for (std::size_t dim=0; dim<N; ++dim)
66  result[dim] = a[dim] - b[dim];
67  return result;
68 }
69 
70 template<typename T, std::size_t N>
71 static std::array<T,N> operator*(const std::array<T,N>& a, const std::array<T,N>& b)
72 {
73  std::array<T,N> result;
74  for (std::size_t dim=0; dim<N; ++dim)
75  result[dim] = a[dim] * b[dim];
76  return result;
77 }
78 
79 template<typename T, std::size_t N>
80 static std::array<T,N> operator/(const std::array<T,N>& a, const std::array<T,N>& b)
81 {
82  std::array<T,N> result;
83  for (std::size_t dim=0; dim<N; ++dim)
84  result[dim] = a[dim] / b[dim];
85  return result;
86 }
87 
88 template<typename T, std::size_t N>
89 static std::array<T,N> operator+(const std::array<T,N>& a, T b)
90 {
91  std::array<T,N> result;
92  for (std::size_t dim=0; dim<N; ++dim)
93  result[dim] = a[dim] + b;
94  return result;
95 }
96 
97 template<typename T, std::size_t N>
98 static std::array<T,N> operator-(const std::array<T,N>& a, T b)
99 {
100  std::array<T,N> result;
101  for (std::size_t dim=0; dim<N; ++dim)
102  result[dim] = a[dim] - b;
103  return result;
104 }
105 
106 template<typename T, std::size_t N>
107 static std::array<T,N> operator*(const std::array<T,N>& a, T b)
108 {
109  std::array<T,N> result;
110  for (std::size_t dim=0; dim<N; ++dim)
111  result[dim] = a[dim] * b;
112  return result;
113 }
114 
115 template<typename T, std::size_t N>
116 static std::array<T,N> operator/(const std::array<T,N>& a, T b)
117 {
118  std::array<T,N> result;
119  for (std::size_t dim=0; dim<N; ++dim)
120  result[dim] = a[dim] / b;
121  return result;
122 }
123 
124 }} // namespace
125 
126 namespace InternalZGY { namespace Formatters {
127 template<typename T, std::size_t N>
128 static std::ostream& operator<<(std::ostream& os, const std::array<T,N>& a)
129 {
130  os << "(";
131  for (std::size_t dim=0; dim<N; ++dim)
132  os << a[dim] << (dim==N-1 ? "" : ", ");
133  os << ")";
134  return os;
135 }
136 
137 }} // namespace
OpenZGY::Formatters::operator<<
std::ostream & operator<<(std::ostream &os, SampleDataType value)
Output the string representation of the input enum type.
Definition: api.cpp:1296
InternalZGY
Implementation not visible to clients.