Browse Source

Slice assign value (#111)

* Assign value to slice

* Readme for formatting
master
kritz 5 years ago committed by Julian Kent
parent
commit
de6a2d31ff
  1. 10
      README.md
  2. 11
      matrix/Slice.hpp
  3. 12
      test/slice.cpp

10
README.md

@ -40,6 +40,16 @@ cmake -DTESTING=ON .. @@ -40,6 +40,16 @@ cmake -DTESTING=ON ..
make check
```
## Formatting
The format can be checked as following:
```
mkdir build
cd build
cmake -DFORMAT=ON ..
make check_format
```
## Example
See the test directory for detailed examples. Some simple examples are included below:

11
matrix/Slice.hpp

@ -63,6 +63,17 @@ public: @@ -63,6 +63,17 @@ public:
return self;
}
Slice<Type, P, Q, M, N>& operator=(const Type& other)
{
Slice<Type, P, Q, M, N>& self = *this;
for (size_t i = 0; i < P; i++) {
for (size_t j = 0; j < Q; j++) {
self(i, j) = other;
}
}
return self;
}
// allow assigning vectors to a slice that are in the axis
template <size_t DUMMY = 1> // make this a template function since it only exists for some instantiations
Slice<Type, 1, Q, M, N>& operator=(const Vector<Type, Q>& other)

12
test/slice.cpp

@ -125,6 +125,18 @@ int main() @@ -125,6 +125,18 @@ int main()
TEST(!v5.xy().longerThan(5.f));
TEST(isEqualF(5.f, v5.xy().norm()));
// assign scalar value to slice
Matrix<float, 3, 1> L;
L(0,0) = -1;
L(1,0) = 1;
L(2,0) = 3;
L.slice<2,1>(0,0) = 0.0f;
float data_5_check[3] = {0, 0, 3};
Matrix<float, 3, 1> M (data_5_check);
TEST(isEqual(L, M));
return 0;
}

Loading…
Cancel
Save