forked from CppModules/xtensor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxoptional_assembly_base.hpp
More file actions
1049 lines (897 loc) · 36.9 KB
/
Copy pathxoptional_assembly_base.hpp
File metadata and controls
1049 lines (897 loc) · 36.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
* Copyright (c) QuantStack *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XOPTIONAL_ASSEMBLY_BASE_HPP
#define XOPTIONAL_ASSEMBLY_BASE_HPP
#include "xiterable.hpp"
#include "xoptional_assembly_storage.hpp"
#include "xtensor_forward.hpp"
namespace xt
{
template <class D, bool is_const>
class xoptional_assembly_stepper;
/***************************
* xoptional_assembly_base *
***************************/
/**
* @class xoptional_assembly_base
* @brief Base class for dense multidimensional optional assemblies.
*
* The xoptional_assembly_base class defines the interface for dense multidimensional
* optional assembly classes. Optional assembly classes hold optional values and are
* optimized for tensor operations. xoptional_assembly_base does not embed any data
* container, this responsibility is delegated to the inheriting classes.
*
* @tparam D The derived type, i.e. the inheriting class for which xoptional_assembly_base
* provides the interface.
*/
template <class D>
class xoptional_assembly_base : private xiterable<D>
{
public:
using self_type = xoptional_assembly_base<D>;
using derived_type = D;
using inner_types = xcontainer_inner_types<D>;
using raw_value_expression = typename inner_types::raw_value_expression;
using base_value_type = typename raw_value_expression::value_type;
using base_reference = typename raw_value_expression::reference;
using base_const_reference = typename raw_value_expression::const_reference;
using raw_flag_expression = typename inner_types::raw_flag_expression;
using flag_type = typename raw_flag_expression::value_type;
using flag_reference = typename raw_flag_expression::reference;
using flag_const_reference = typename raw_flag_expression::const_reference;
using storage_type = typename inner_types::storage_type;
using value_type = typename storage_type::value_type;
using reference = typename storage_type::reference;
using const_reference = typename storage_type::const_reference;
using pointer = typename storage_type::pointer;
using const_pointer = typename storage_type::const_pointer;
using size_type = typename raw_value_expression::size_type;
using difference_type = typename raw_value_expression::difference_type;
using simd_value_type = xt_simd::simd_type<value_type>;
using bool_load_type = xt::bool_load_type<value_type>;
using shape_type = typename raw_value_expression::shape_type;
using strides_type = typename raw_value_expression::strides_type;
using backstrides_type = typename raw_value_expression::backstrides_type;
using inner_shape_type = typename raw_value_expression::inner_shape_type;
using inner_strides_type = typename raw_value_expression::inner_strides_type;
using inner_backstrides_type = typename raw_value_expression::inner_backstrides_type;
using iterable_base = xiterable<D>;
using stepper = typename iterable_base::stepper;
using const_stepper = typename iterable_base::const_stepper;
static constexpr layout_type static_layout = raw_value_expression::static_layout;
static constexpr bool contiguous_layout = raw_value_expression::contiguous_layout;
using expression_tag = xoptional_expression_tag;
using value_expression = raw_value_expression&;
using flag_expression = raw_flag_expression&;
using const_value_expression = const raw_value_expression&;
using const_flag_expression = const raw_flag_expression&;
template <layout_type L>
using layout_iterator = typename iterable_base::template layout_iterator<L>;
template <layout_type L>
using const_layout_iterator = typename iterable_base::template const_layout_iterator<L>;
template <layout_type L>
using reverse_layout_iterator = typename iterable_base::template reverse_layout_iterator<L>;
template <layout_type L>
using const_reverse_layout_iterator = typename iterable_base::template const_reverse_layout_iterator<L>;
template <class S, layout_type L>
using broadcast_iterator = typename iterable_base::template broadcast_iterator<S, L>;
template <class S, layout_type L>
using const_broadcast_iterator = typename iterable_base::template const_broadcast_iterator<S, L>;
template <class S, layout_type L>
using reverse_broadcast_iterator = typename iterable_base::template reverse_broadcast_iterator<S, L>;
template <class S, layout_type L>
using const_reverse_broadcast_iterator = typename iterable_base::template const_reverse_broadcast_iterator<S, L>;
using linear_iterator = typename storage_type::iterator;
using const_linear_iterator = typename storage_type::const_iterator;
using reverse_linear_iterator = typename storage_type::reverse_iterator;
using const_reverse_linear_iterator = typename storage_type::const_reverse_iterator;
using iterator = typename iterable_base::iterator;
using const_iterator = typename iterable_base::const_iterator;
using reverse_iterator = typename iterable_base::reverse_iterator;
using const_reverse_iterator = typename iterable_base::const_reverse_iterator;
size_type size() const noexcept;
constexpr size_type dimension() const noexcept;
const inner_shape_type& shape() const noexcept;
size_type shape(size_type index) const;
const inner_strides_type& strides() const noexcept;
const inner_backstrides_type& backstrides() const noexcept;
template <class S = shape_type>
void resize(const S& shape, bool force = false);
template <class S = shape_type>
void resize(const S& shape, layout_type l);
template <class S = shape_type>
void resize(const S& shape, const strides_type& strides);
template <class S = shape_type>
auto& reshape(const S& shape, layout_type layout = static_layout) &;
template <class T>
auto& reshape(std::initializer_list<T> shape, layout_type layout = static_layout) &;
layout_type layout() const noexcept;
bool is_contiguous() const noexcept;
template <class T>
void fill(const T& value);
template <class... Args>
reference operator()(Args... args);
template <class... Args>
const_reference operator()(Args... args) const;
template <class... Args>
reference at(Args... args);
template <class... Args>
const_reference at(Args... args) const;
template <class... Args>
reference unchecked(Args... args);
template <class... Args>
const_reference unchecked(Args... args) const;
template <class S>
disable_integral_t<S, reference> operator[](const S& index);
template <class I>
reference operator[](std::initializer_list<I> index);
reference operator[](size_type i);
template <class S>
disable_integral_t<S, const_reference> operator[](const S& index) const;
template <class I>
const_reference operator[](std::initializer_list<I> index) const;
const_reference operator[](size_type i) const;
template <class... Args>
reference periodic(Args... args);
template <class... Args>
const_reference periodic(Args... args) const;
reference front();
const_reference front() const;
reference back();
const_reference back() const;
reference flat(size_type args);
const_reference flat(size_type args) const;
template <class It>
reference element(It first, It last);
template <class It>
const_reference element(It first, It last) const;
template <class... Args>
bool in_bounds(Args... args) const;
storage_type& storage() noexcept;
const storage_type& storage() const noexcept;
value_type* data() noexcept;
const value_type* data() const noexcept;
const size_type data_offset() const noexcept;
template <class S>
bool broadcast_shape(S& shape, bool reuse_cache = false) const;
template <class S>
bool has_linear_assign(const S& strides) const noexcept;
using iterable_base::begin;
using iterable_base::cbegin;
using iterable_base::cend;
using iterable_base::crbegin;
using iterable_base::crend;
using iterable_base::end;
using iterable_base::rbegin;
using iterable_base::rend;
linear_iterator linear_begin() noexcept;
linear_iterator linear_end() noexcept;
const_linear_iterator linear_begin() const noexcept;
const_linear_iterator linear_end() const noexcept;
const_linear_iterator linear_cbegin() const noexcept;
const_linear_iterator linear_cend() const noexcept;
reverse_linear_iterator linear_rbegin() noexcept;
reverse_linear_iterator linear_rend() noexcept;
const_reverse_linear_iterator linear_rbegin() const noexcept;
const_reverse_linear_iterator linear_rend() const noexcept;
const_reverse_linear_iterator linear_crbegin() const noexcept;
const_reverse_linear_iterator linear_crend() const noexcept;
template <class S>
stepper stepper_begin(const S& shape) noexcept;
template <class S>
stepper stepper_end(const S& shape, layout_type l) noexcept;
template <class S>
const_stepper stepper_begin(const S& shape) const noexcept;
template <class S>
const_stepper stepper_end(const S& shape, layout_type l) const noexcept;
value_expression value() noexcept;
const_value_expression value() const noexcept;
flag_expression has_value() noexcept;
const_flag_expression has_value() const noexcept;
protected:
xoptional_assembly_base() = default;
~xoptional_assembly_base() = default;
xoptional_assembly_base(const xoptional_assembly_base&) = default;
xoptional_assembly_base& operator=(const xoptional_assembly_base&) = default;
xoptional_assembly_base(xoptional_assembly_base&&) = default;
xoptional_assembly_base& operator=(xoptional_assembly_base&&) = default;
private:
derived_type& derived_cast() noexcept;
const derived_type& derived_cast() const noexcept;
friend class xiterable<D>;
friend class xconst_iterable<D>;
};
/******************************
* xoptional_assembly_stepper *
******************************/
template <class D, bool is_const>
class xoptional_assembly_stepper
{
public:
using self_type = xoptional_assembly_stepper<D, is_const>;
using assembly_type = typename D::assembly_type;
using value_type = typename assembly_type::value_type;
using reference = std::
conditional_t<is_const, typename assembly_type::const_reference, typename assembly_type::reference>;
using pointer = std::conditional_t<is_const, typename assembly_type::const_pointer, typename assembly_type::pointer>;
using size_type = typename assembly_type::size_type;
using difference_type = typename assembly_type::difference_type;
using raw_value_expression = typename assembly_type::raw_value_expression;
using raw_flag_expression = typename assembly_type::raw_flag_expression;
using value_stepper = std::
conditional_t<is_const, typename raw_value_expression::const_stepper, typename raw_value_expression::stepper>;
using flag_stepper = std::
conditional_t<is_const, typename raw_flag_expression::const_stepper, typename raw_flag_expression::stepper>;
xoptional_assembly_stepper(value_stepper vs, flag_stepper fs) noexcept;
void step(size_type dim);
void step_back(size_type dim);
void step(size_type dim, size_type n);
void step_back(size_type dim, size_type n);
void reset(size_type dim);
void reset_back(size_type dim);
void to_begin();
void to_end(layout_type l);
reference operator*() const;
private:
value_stepper m_vs;
flag_stepper m_fs;
};
/******************************************
* xoptional_assembly_base implementation *
******************************************/
/**
* @name Size and shape
*/
//@{
/**
* Returns the number of element in the optional assembly.
*/
template <class D>
inline auto xoptional_assembly_base<D>::size() const noexcept -> size_type
{
return value().size();
}
/**
* Returns the number of dimensions of the optional assembly.
*/
template <class D>
inline constexpr auto xoptional_assembly_base<D>::dimension() const noexcept -> size_type
{
return value().dimension();
}
/**
* Returns the shape of the optional assembly.
*/
template <class D>
inline auto xoptional_assembly_base<D>::shape() const noexcept -> const inner_shape_type&
{
return value().shape();
}
/**
* Returns the i-th dimension of the expression.
*/
template <class D>
inline auto xoptional_assembly_base<D>::shape(size_type i) const -> size_type
{
return value().shape(i);
}
/**
* Returns the strides of the optional assembly.
*/
template <class D>
inline auto xoptional_assembly_base<D>::strides() const noexcept -> const inner_strides_type&
{
return value().strides();
}
/**
* Returns the backstrides of the optional assembly.
*/
template <class D>
inline auto xoptional_assembly_base<D>::backstrides() const noexcept -> const inner_backstrides_type&
{
return value().backstrides();
}
//@}
/**
* Resizes the optional assembly.
* @param shape the new shape
* @param force force reshaping, even if the shape stays the same (default: false)
*/
template <class D>
template <class S>
inline void xoptional_assembly_base<D>::resize(const S& shape, bool force)
{
value().resize(shape, force);
has_value().resize(shape, force);
}
/**
* Resizes the optional assembly.
* @param shape the new shape
* @param l the new layout_type
*/
template <class D>
template <class S>
inline void xoptional_assembly_base<D>::resize(const S& shape, layout_type l)
{
value().resize(shape, l);
has_value().resize(shape, l);
}
/**
* Resizes the optional assembly.
* @param shape the new shape
* @param strides the new strides
*/
template <class D>
template <class S>
inline void xoptional_assembly_base<D>::resize(const S& shape, const strides_type& strides)
{
value().resize(shape, strides);
has_value().resize(shape, strides);
}
/**
* Reshapes the optional assembly.
* @param shape the new shape
* @param layout the new layout
*/
template <class D>
template <class S>
inline auto& xoptional_assembly_base<D>::reshape(const S& shape, layout_type layout) &
{
value().reshape(shape, layout);
has_value().reshape(shape, layout);
return *this;
}
template <class D>
template <class T>
inline auto& xoptional_assembly_base<D>::reshape(std::initializer_list<T> shape, layout_type layout) &
{
value().reshape(shape, layout);
has_value().reshape(shape, layout);
return *this;
}
/**
* Return the layout_type of the container
* @return layout_type of the container
*/
template <class D>
inline layout_type xoptional_assembly_base<D>::layout() const noexcept
{
return value().layout();
}
template <class D>
inline bool xoptional_assembly_base<D>::is_contiguous() const noexcept
{
return value().is_contiguous();
}
/**
* Fills the data with the given value.
* @param value the value to fill the data with.
*/
template <class D>
template <class T>
inline void xoptional_assembly_base<D>::fill(const T& value)
{
std::fill(this->linear_begin(), this->linear_end(), value);
}
/**
* @name Data
*/
//@{
/**
* Returns a reference to the element at the specified position in the optional assembly.
* @param args a list of indices specifying the position in the optional assembly. Indices
* must be unsigned integers, the number of indices should be equal or greater than
* the number of dimensions of the optional assembly.
*/
template <class D>
template <class... Args>
inline auto xoptional_assembly_base<D>::operator()(Args... args) -> reference
{
return reference(value()(args...), has_value()(args...));
}
/**
* Returns a constant reference to the element at the specified position in the optional assembly.
* @param args a list of indices specifying the position in the optional assembly. Indices
* must be unsigned integers, the number of indices should be equal or greater than
* the number of dimensions of the optional assembly.
*/
template <class D>
template <class... Args>
inline auto xoptional_assembly_base<D>::operator()(Args... args) const -> const_reference
{
return const_reference(value()(args...), has_value()(args...));
}
/**
* Returns a reference to the element at the specified position in the optional assembly,
* after dimension and bounds checking.
* @param args a list of indices specifying the position in the optional assembly. Indices
* must be unsigned integers, the number of indices should be equal to the number of dimensions
* of the optional assembly.
* @exception std::out_of_range if the number of argument is greater than the number of dimensions
* or if indices are out of bounds.
*/
template <class D>
template <class... Args>
inline auto xoptional_assembly_base<D>::at(Args... args) -> reference
{
return reference(value().at(args...), has_value().at(args...));
}
/**
* Returns a constant reference to the element at the specified position in the optional assembly,
* after dimension and bounds checking.
* @param args a list of indices specifying the position in the optional assembly. Indices
* must be unsigned integers, the number of indices should be equal to the number of dimensions
* of the optional assembly.
* @exception std::out_of_range if the number of argument is greater than the number of dimensions
* or if indices are out of bounds.
*/
template <class D>
template <class... Args>
inline auto xoptional_assembly_base<D>::at(Args... args) const -> const_reference
{
return const_reference(value().at(args...), has_value().at(args...));
}
/**
* Returns a reference to the element at the specified position in the optional assembly.
* @param args a list of indices specifying the position in the optional assembly. Indices
* must be unsigned integers, the number of indices must be equal to the number of
* dimensions of the optional assembly, else the behavior is undefined.
*
* @warning This method is meant for performance, for expressions with a dynamic
* number of dimensions (i.e. not known at compile time). Since it may have
* undefined behavior (see parameters), operator() should be preferred whenever
* it is possible.
* @warning This method is NOT compatible with broadcasting, meaning the following
* code has undefined behavior:
* @code{.cpp}
* xt::xarray<double> a = {{0, 1}, {2, 3}};
* xt::xarray<double> b = {0, 1};
* auto fd = a + b;
* double res = fd.uncheked(0, 1);
* @endcode
*/
template <class D>
template <class... Args>
inline auto xoptional_assembly_base<D>::unchecked(Args... args) -> reference
{
return reference(value().unchecked(args...), has_value().unchecked(args...));
}
/**
* Returns a constant reference to the element at the specified position in the optional assembly.
* @param args a list of indices specifying the position in the optional assembly. Indices
* must be unsigned integers, the number of indices must be equal to the number of
* dimensions of the optional assembly, else the behavior is undefined.
*
* @warning This method is meant for performance, for expressions with a dynamic
* number of dimensions (i.e. not known at compile time). Since it may have
* undefined behavior (see parameters), operator() should be preferred whenever
* it is possible.
* @warning This method is NOT compatible with broadcasting, meaning the following
* code has undefined behavior:
* @code{.cpp}
* xt::xarray<double> a = {{0, 1}, {2, 3}};
* xt::xarray<double> b = {0, 1};
* auto fd = a + b;
* double res = fd.uncheked(0, 1);
* @endcode
*/
template <class D>
template <class... Args>
inline auto xoptional_assembly_base<D>::unchecked(Args... args) const -> const_reference
{
return const_reference(value().unchecked(args...), has_value().unchecked(args...));
}
/**
* Returns a reference to the element at the specified position in the optional assembly.
* @param index a sequence of indices specifying the position in the optional assembly. Indices
* must be unsigned integers, the number of indices in the list should be equal or greater
* than the number of dimensions of the optional assembly.
*/
template <class D>
template <class S>
inline auto xoptional_assembly_base<D>::operator[](const S& index) -> disable_integral_t<S, reference>
{
return reference(value()[index], has_value()[index]);
}
template <class D>
template <class I>
inline auto xoptional_assembly_base<D>::operator[](std::initializer_list<I> index) -> reference
{
return reference(value()[index], has_value()[index]);
}
template <class D>
inline auto xoptional_assembly_base<D>::operator[](size_type i) -> reference
{
return reference(value()[i], has_value()[i]);
}
/**
* Returns a constant reference to the element at the specified position in the optional assembly.
* @param index a sequence of indices specifying the position in the optional assembly. Indices
* must be unsigned integers, the number of indices in the list should be equal or greater
* than the number of dimensions of the optional assembly.
*/
template <class D>
template <class S>
inline auto xoptional_assembly_base<D>::operator[](const S& index) const
-> disable_integral_t<S, const_reference>
{
return const_reference(value()[index], has_value()[index]);
}
template <class D>
template <class I>
inline auto xoptional_assembly_base<D>::operator[](std::initializer_list<I> index) const -> const_reference
{
return const_reference(value()[index], has_value()[index]);
}
template <class D>
inline auto xoptional_assembly_base<D>::operator[](size_type i) const -> const_reference
{
return const_reference(value()[i], has_value()[i]);
}
/**
* Returns a reference to the element at the specified position in the optional assembly,
* after applying periodicity to the indices (negative and 'overflowing' indices are changed).
* @param args a list of indices specifying the position in the optional assembly. Indices
* must be unsigned integers, the number of indices should be equal to the number of dimensions
* of the optional assembly.
*/
template <class D>
template <class... Args>
inline auto xoptional_assembly_base<D>::periodic(Args... args) -> reference
{
return reference(value().periodic(args...), has_value().periodic(args...));
}
/**
* Returns a constant reference to the element at the specified position in the optional assembly,
* after applying periodicity to the indices (negative and 'overflowing' indices are changed).
* @param args a list of indices specifying the position in the optional assembly. Indices
* must be unsigned integers, the number of indices should be equal to the number of dimensions
* of the optional assembly.
*/
template <class D>
template <class... Args>
inline auto xoptional_assembly_base<D>::periodic(Args... args) const -> const_reference
{
return const_reference(value().periodic(args...), has_value().periodic(args...));
}
/**
* Returns a reference to the first element of the optional assembly.
*/
template <class D>
inline auto xoptional_assembly_base<D>::front() -> reference
{
return reference(value().front(), has_value().front());
}
/**
* Returns a constant reference to the first element of the optional assembly.
*/
template <class D>
inline auto xoptional_assembly_base<D>::front() const -> const_reference
{
return const_reference(value().front(), has_value().front());
}
/**
* Returns a reference to the last element of the optional assembly.
*/
template <class D>
inline auto xoptional_assembly_base<D>::back() -> reference
{
return reference(value().back(), has_value().back());
}
/**
* Returns a constant reference to the last element of the optional assembly.
*/
template <class D>
inline auto xoptional_assembly_base<D>::back() const -> const_reference
{
return const_reference(value().back(), has_value().back());
}
/**
* Returns a reference to the element at the specified position
* of the underlying storage in the optional assembly.
* @param index index to underlying flat storage.
*/
template <class D>
inline auto xoptional_assembly_base<D>::flat(size_type i) -> reference
{
return reference(value().flat(i), has_value().flat(i));
}
/**
* Returns a constant reference to the element at the specified position
* of the underlying storage in the optional assembly.
* @param index index to underlying flat storage.
*/
template <class D>
inline auto xoptional_assembly_base<D>::flat(size_type i) const -> const_reference
{
return const_reference(value().flat(i), has_value().flat(i));
}
/**
* Returns a reference to the element at the specified position in the optional assembly.
* @param first iterator starting the sequence of indices
* @param last iterator ending the sequence of indices
* The number of indices in the sequence should be equal to or greater
* than the number of dimensions of the optional assembly.
*/
template <class D>
template <class It>
inline auto xoptional_assembly_base<D>::element(It first, It last) -> reference
{
return reference(value().element(first, last), has_value().element(first, last));
}
/**
* Returns a constant reference to the element at the specified position in the optional assembly.
* @param first iterator starting the sequence of indices
* @param last iterator ending the sequence of indices
* The number of indices in the sequence should be equal to or greater
* than the number of dimensions of the optional assembly.
*/
template <class D>
template <class It>
inline auto xoptional_assembly_base<D>::element(It first, It last) const -> const_reference
{
return const_reference(value().element(first, last), has_value().element(first, last));
}
/**
* Returns ``true`` only if the the specified position is a valid entry in the expression.
* @param args a list of indices specifying the position in the expression.
* @return bool
*/
template <class D>
template <class... Args>
inline bool xoptional_assembly_base<D>::in_bounds(Args... args) const
{
return value().in_bounds(args...) && has_value().in_bounds(args...);
}
//@}
template <class D>
inline auto xoptional_assembly_base<D>::storage() noexcept -> storage_type&
{
return derived_cast().storage_impl();
}
template <class D>
inline auto xoptional_assembly_base<D>::storage() const noexcept -> const storage_type&
{
return derived_cast().storage_impl();
}
template <class D>
inline auto xoptional_assembly_base<D>::data() noexcept -> value_type*
{
return storage().data();
}
template <class D>
inline auto xoptional_assembly_base<D>::data() const noexcept -> const value_type*
{
return storage().data();
}
template <class D>
inline auto xoptional_assembly_base<D>::data_offset() const noexcept -> const size_type
{
return size_type(0);
}
/**
* @name Broadcasting
*/
//@{
/**
* Broadcast the shape of the optional assembly to the specified parameter.
* @param shape the result shape
* @param reuse_cache parameter for internal optimization
* @return a boolean indicating whether the broadcasting is trivial
*/
template <class D>
template <class S>
inline bool xoptional_assembly_base<D>::broadcast_shape(S& shape, bool reuse_cache) const
{
bool res = value().broadcast_shape(shape, reuse_cache);
return res && has_value().broadcast_shape(shape, reuse_cache);
}
/**
* Checks whether the xoptional_assembly_base can be linearly assigned to an expression
* with the specified strides.
* @return a boolean indicating whether a linear assign is possible
*/
template <class D>
template <class S>
inline bool xoptional_assembly_base<D>::has_linear_assign(const S& strides) const noexcept
{
return value().has_linear_assign(strides) && has_value().has_linear_assign(strides);
}
//@}
template <class D>
inline auto xoptional_assembly_base<D>::linear_begin() noexcept -> linear_iterator
{
return linear_iterator(value().linear_begin(), has_value().linear_begin());
}
template <class D>
inline auto xoptional_assembly_base<D>::linear_end() noexcept -> linear_iterator
{
return linear_iterator(value().linear_end(), has_value().linear_end());
}
template <class D>
inline auto xoptional_assembly_base<D>::linear_begin() const noexcept -> const_linear_iterator
{
return linear_cbegin();
}
template <class D>
inline auto xoptional_assembly_base<D>::linear_end() const noexcept -> const_linear_iterator
{
return linear_cend();
}
template <class D>
inline auto xoptional_assembly_base<D>::linear_cbegin() const noexcept -> const_linear_iterator
{
return const_linear_iterator(value().linear_cbegin(), has_value().linear_cbegin());
}
template <class D>
inline auto xoptional_assembly_base<D>::linear_cend() const noexcept -> const_linear_iterator
{
return const_linear_iterator(value().linear_cend(), has_value().linear_cend());
}
template <class D>
inline auto xoptional_assembly_base<D>::linear_rbegin() noexcept -> reverse_linear_iterator
{
return reverse_linear_iterator(linear_end());
}
template <class D>
inline auto xoptional_assembly_base<D>::linear_rend() noexcept -> reverse_linear_iterator
{
return reverse_linear_iterator(linear_begin());
}
template <class D>
inline auto xoptional_assembly_base<D>::linear_rbegin() const noexcept -> const_reverse_linear_iterator
{
return linear_crbegin();
}
template <class D>
inline auto xoptional_assembly_base<D>::linear_rend() const noexcept -> const_reverse_linear_iterator
{
return linear_crend();
}
template <class D>
inline auto xoptional_assembly_base<D>::linear_crbegin() const noexcept -> const_reverse_linear_iterator
{
return const_reverse_linear_iterator(linear_cend());
}
template <class D>
inline auto xoptional_assembly_base<D>::linear_crend() const noexcept -> const_reverse_linear_iterator
{
return const_reverse_linear_iterator(linear_cbegin());
}
template <class D>
template <class S>
inline auto xoptional_assembly_base<D>::stepper_begin(const S& shape) noexcept -> stepper
{
return stepper(value().stepper_begin(shape), has_value().stepper_begin(shape));
}
template <class D>
template <class S>
inline auto xoptional_assembly_base<D>::stepper_end(const S& shape, layout_type l) noexcept -> stepper
{
return stepper(value().stepper_end(shape, l), has_value().stepper_end(shape, l));
}
template <class D>
template <class S>
inline auto xoptional_assembly_base<D>::stepper_begin(const S& shape) const noexcept -> const_stepper
{
return const_stepper(value().stepper_begin(shape), has_value().stepper_begin(shape));
}
template <class D>
template <class S>
inline auto xoptional_assembly_base<D>::stepper_end(const S& shape, layout_type l) const noexcept
-> const_stepper
{
return const_stepper(value().stepper_end(shape, l), has_value().stepper_end(shape, l));
}
/**
* Return an expression for the values of the optional assembly.
*/
template <class D>
inline auto xoptional_assembly_base<D>::value() noexcept -> value_expression
{
return derived_cast().value_impl();
}
/**
* Return a constant expression for the values of the optional assembly.
*/
template <class D>
inline auto xoptional_assembly_base<D>::value() const noexcept -> const_value_expression
{
return derived_cast().value_impl();
}
/**
* Return an expression for the missing mask of the optional assembly.
*/
template <class D>
inline auto xoptional_assembly_base<D>::has_value() noexcept -> flag_expression
{
return derived_cast().has_value_impl();
}
/**
* Return a constant expression for the missing mask of the optional assembly.
*/
template <class D>
inline auto xoptional_assembly_base<D>::has_value() const noexcept -> const_flag_expression
{
return derived_cast().has_value_impl();
}
template <class D>
inline auto xoptional_assembly_base<D>::derived_cast() noexcept -> derived_type&
{
return *static_cast<derived_type*>(this);
}
template <class D>
inline auto xoptional_assembly_base<D>::derived_cast() const noexcept -> const derived_type&
{
return *static_cast<const derived_type*>(this);
}
/*********************************************
* xoptional_assembly_stepper implementation *
*********************************************/
template <class D, bool C>
inline xoptional_assembly_stepper<D, C>::xoptional_assembly_stepper(value_stepper vs, flag_stepper fs) noexcept
: m_vs(vs)
, m_fs(fs)
{
}
template <class D, bool C>
inline void xoptional_assembly_stepper<D, C>::step(size_type dim)
{
m_vs.step(dim);
m_fs.step(dim);
}
template <class D, bool C>
inline void xoptional_assembly_stepper<D, C>::step_back(size_type dim)
{
m_vs.step_back(dim);
m_fs.step_back(dim);
}
template <class D, bool C>