1 //=================================================================================================
2 /*!
3 // \file blaze/math/proxy/DenseVectorProxy.h
4 // \brief Header file for the DenseVectorProxy class
5 //
6 // Copyright (C) 2012-2020 Klaus Iglberger - All Rights Reserved
7 //
8 // This file is part of the Blaze library. You can redistribute it and/or modify it under
9 // the terms of the New (Revised) BSD License. Redistribution and use in source and binary
10 // forms, with or without modification, are permitted provided that the following conditions
11 // are met:
12 //
13 // 1. Redistributions of source code must retain the above copyright notice, this list of
14 // conditions and the following disclaimer.
15 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
16 // of conditions and the following disclaimer in the documentation and/or other materials
17 // provided with the distribution.
18 // 3. Neither the names of the Blaze development group nor the names of its contributors
19 // may be used to endorse or promote products derived from this software without specific
20 // prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
23 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25 // SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 // BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 // DAMAGE.
32 */
33 //=================================================================================================
34
35 #ifndef _BLAZE_MATH_PROXY_DENSEVECTORPROXY_H_
36 #define _BLAZE_MATH_PROXY_DENSEVECTORPROXY_H_
37
38
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42
43 #include <blaze/math/Aliases.h>
44 #include <blaze/math/constraints/DenseVector.h>
45 #include <blaze/math/Exception.h>
46 #include <blaze/math/expressions/DenseVector.h>
47 #include <blaze/math/shims/Clear.h>
48 #include <blaze/math/shims/Reset.h>
49 #include <blaze/math/typetraits/IsResizable.h>
50 #include <blaze/math/typetraits/IsRowVector.h>
51 #include <blaze/system/Inline.h>
52 #include <blaze/util/EnableIf.h>
53 #include <blaze/util/MaybeUnused.h>
54 #include <blaze/util/Types.h>
55
56
57 namespace blaze {
58
59 //=================================================================================================
60 //
61 // CLASS DEFINITION
62 //
63 //=================================================================================================
64
65 //*************************************************************************************************
66 /*!\brief Proxy backend for dense vector types.
67 // \ingroup math
68 //
69 // The DenseVectorProxy class serves as a backend for the Proxy class. It is used in case the
70 // data type represented by the proxy is a dense vector and augments the Proxy interface by
71 // the complete interface required of dense vectors.
72 */
73 template< typename PT // Type of the proxy
74 , typename VT > // Type of the dense vector
75 class DenseVectorProxy
76 : public DenseVector< PT, IsRowVector_v<VT> >
77 {
78 public:
79 //**Type definitions****************************************************************************
80 using ResultType = ResultType_t<VT>; //!< Result type for expression template evaluations.
81 using TransposeType = TransposeType_t<VT>; //!< Transpose type for expression template evaluations.
82 using ElementType = ElementType_t<VT>; //!< Type of the vector elements.
83 using ReturnType = ReturnType_t<VT>; //!< Return type for expression template evaluations
84 using CompositeType = CompositeType_t<VT>; //!< Data type for composite expression templates.
85 using Reference = Reference_t<VT>; //!< Reference to a non-constant vector value.
86 using ConstReference = ConstReference_t<VT>; //!< Reference to a constant vector value.
87 using Pointer = Pointer_t<VT>; //!< Pointer to a non-constant vector value.
88 using ConstPointer = ConstPointer_t<VT>; //!< Pointer to a constant vector value.
89 using Iterator = Iterator_t<VT>; //!< Iterator over non-constant elements.
90 using ConstIterator = ConstIterator_t<VT>; //!< Iterator over constant elements.
91 //**********************************************************************************************
92
93 //**Compilation flags***************************************************************************
94 //! Compilation flag for SIMD optimization.
95 static constexpr bool simdEnabled = VT::simdEnabled;
96
97 //! Compilation flag for SMP assignments.
98 static constexpr bool smpAssignable = VT::smpAssignable;
99 //**********************************************************************************************
100
101 //**Data access functions***********************************************************************
102 /*!\name Data access functions */
103 //@{
104 inline Reference operator[]( size_t index ) const;
105 inline Reference at( size_t index ) const;
106
107 inline Pointer data () const;
108 inline Iterator begin () const;
109 inline ConstIterator cbegin() const;
110 inline Iterator end () const;
111 inline ConstIterator cend () const;
112 //@}
113 //**********************************************************************************************
114
115 //**Utility functions***************************************************************************
116 /*!\name Utility functions */
117 //@{
118 inline size_t size() const;
119 inline size_t capacity() const;
120 inline size_t nonZeros() const;
121 inline void reset() const;
122 inline void clear() const;
123 inline void resize( size_t n, bool preserve=true ) const;
124 inline void extend( size_t n, bool preserve=true ) const;
125 inline void reserve( size_t n ) const;
126 //@}
127 //**********************************************************************************************
128
129 //**Numeric functions***************************************************************************
130 /*!\name Numeric functions */
131 //@{
132 template< typename Other > inline void scale( const Other& scalar ) const;
133 //@}
134 //**********************************************************************************************
135
136 protected:
137 //**Special member functions********************************************************************
138 /*!\name Special member functions */
139 //@{
140 DenseVectorProxy() = default;
141 DenseVectorProxy( const DenseVectorProxy& ) = default;
142 DenseVectorProxy( DenseVectorProxy&& ) = default;
143 ~DenseVectorProxy() = default;
144 DenseVectorProxy& operator=( const DenseVectorProxy& ) = default;
145 DenseVectorProxy& operator=( DenseVectorProxy&& ) = default;
146 //@}
147 //**********************************************************************************************
148
149 private:
150 //**Compile time checks*************************************************************************
151 /*! \cond BLAZE_INTERNAL */
152 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE( VT );
153 /*! \endcond */
154 //**********************************************************************************************
155 };
156 //*************************************************************************************************
157
158
159
160
161 //=================================================================================================
162 //
163 // DATA ACCESS FUNCTIONS
164 //
165 //=================================================================================================
166
167 //*************************************************************************************************
168 /*!\brief Subscript operator for the direct access to vector elements.
169 //
170 // \param index Access index. The index has to be in the range \f$[0..N-1]\f$.
171 // \return Reference to the accessed value.
172 // \exception std::invalid_argument Invalid access to restricted element.
173 */
174 template< typename PT // Type of the proxy
175 , typename VT > // Type of the dense vector
176 inline typename DenseVectorProxy<PT,VT>::Reference
177 DenseVectorProxy<PT,VT>::operator[]( size_t index ) const
178 {
179 if( (**this).isRestricted() ) {
180 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
181 }
182
183 return (**this).get()[index];
184 }
185 //*************************************************************************************************
186
187
188 //*************************************************************************************************
189 /*!\brief Checked access to the vector elements.
190 //
191 // \param index Access index. The index has to be in the range \f$[0..N-1]\f$.
192 // \return Reference to the accessed value.
193 // \exception std::invalid_argument Invalid access to restricted element.
194 // \exception std::out_of_range Invalid vector access index.
195 //
196 // In contrast to the subscript operator this function always performs a check of the given
197 // access index.
198 */
199 template< typename PT // Type of the proxy
200 , typename VT > // Type of the dense vector
201 inline typename DenseVectorProxy<PT,VT>::Reference
at(size_t index)202 DenseVectorProxy<PT,VT>::at( size_t index ) const
203 {
204 if( (**this).isRestricted() ) {
205 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
206 }
207
208 return (**this).get().at( index );
209 }
210 //*************************************************************************************************
211
212
213 //*************************************************************************************************
214 /*!\brief Low-level data access to vector elements.
215 //
216 // \return Pointer to the internal element storage.
217 // \exception std::invalid_argument Invalid access to restricted element.
218 //
219 // This function returns a pointer to the internal storage of the dynamic vector.
220 */
221 template< typename PT // Type of the proxy
222 , typename VT > // Type of the dense vector
data()223 inline typename DenseVectorProxy<PT,VT>::Pointer DenseVectorProxy<PT,VT>::data() const
224 {
225 if( (**this).isRestricted() ) {
226 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
227 }
228
229 return (**this).get().data();
230 }
231 //*************************************************************************************************
232
233
234 //*************************************************************************************************
235 /*!\brief Returns an iterator to the first element of the represented vector.
236 //
237 // \return Iterator to the first element of the vector.
238 // \exception std::invalid_argument Invalid access to restricted element.
239 */
240 template< typename PT // Type of the proxy
241 , typename VT > // Type of the dense vector
begin()242 inline typename DenseVectorProxy<PT,VT>::Iterator DenseVectorProxy<PT,VT>::begin() const
243 {
244 if( (**this).isRestricted() ) {
245 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
246 }
247
248 return (**this).get().begin();
249 }
250 //*************************************************************************************************
251
252
253 //*************************************************************************************************
254 /*!\brief Returns an iterator to the first element of the represented vector.
255 //
256 // \return Iterator to the first element of the vector.
257 */
258 template< typename PT // Type of the proxy
259 , typename VT > // Type of the dense vector
cbegin()260 inline typename DenseVectorProxy<PT,VT>::ConstIterator DenseVectorProxy<PT,VT>::cbegin() const
261 {
262 return (**this).get().cbegin();
263 }
264 //*************************************************************************************************
265
266
267 //*************************************************************************************************
268 /*!\brief Returns an iterator just past the last element of the represented vector.
269 //
270 // \return Iterator just past the last element of the vector.
271 // \exception std::invalid_argument Invalid access to restricted element.
272 */
273 template< typename PT // Type of the proxy
274 , typename VT > // Type of the dense vector
end()275 inline typename DenseVectorProxy<PT,VT>::Iterator DenseVectorProxy<PT,VT>::end() const
276 {
277 if( (**this).isRestricted() ) {
278 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
279 }
280
281 return (**this).get().end();
282 }
283 //*************************************************************************************************
284
285
286 //*************************************************************************************************
287 /*!\brief Returns an iterator just past the last element of the represented vector.
288 //
289 // \return Iterator just past the last element of the vector.
290 */
291 template< typename PT // Type of the proxy
292 , typename VT > // Type of the dense vector
cend()293 inline typename DenseVectorProxy<PT,VT>::ConstIterator DenseVectorProxy<PT,VT>::cend() const
294 {
295 return (**this).get().cend();
296 }
297 //*************************************************************************************************
298
299
300
301
302 //=================================================================================================
303 //
304 // UTILITY FUNCTIONS
305 //
306 //=================================================================================================
307
308 //*************************************************************************************************
309 /*!\brief Returns the current size/dimension of the represented vector.
310 //
311 // \return The size of the vector.
312 */
313 template< typename PT // Type of the proxy
314 , typename VT > // Type of the dense vector
size()315 inline size_t DenseVectorProxy<PT,VT>::size() const
316 {
317 return (**this).get().size();
318 }
319 //*************************************************************************************************
320
321
322 //*************************************************************************************************
323 /*!\brief Returns the maximum capacity of the represented vector.
324 //
325 // \return The capacity of the vector.
326 */
327 template< typename PT // Type of the proxy
328 , typename VT > // Type of the dense vector
capacity()329 inline size_t DenseVectorProxy<PT,VT>::capacity() const
330 {
331 return (**this).get().capacity();
332 }
333 //*************************************************************************************************
334
335
336 //*************************************************************************************************
337 /*!\brief Returns the number of non-zero elements in the represented vector.
338 //
339 // \return The number of non-zero elements in the vector.
340 //
341 // Note that the number of non-zero elements is always less than or equal to the current size
342 // of the vector.
343 */
344 template< typename PT // Type of the proxy
345 , typename VT > // Type of the dense vector
nonZeros()346 inline size_t DenseVectorProxy<PT,VT>::nonZeros() const
347 {
348 return (**this).get().nonZeros();
349 }
350 //*************************************************************************************************
351
352
353 //*************************************************************************************************
354 /*!\brief Reset to the default initial value.
355 //
356 // \return void
357 //
358 // This function resets all elements of the vector to the default initial values.
359 */
360 template< typename PT // Type of the proxy
361 , typename VT > // Type of the dense vector
reset()362 inline void DenseVectorProxy<PT,VT>::reset() const
363 {
364 using blaze::reset;
365
366 reset( (**this).get() );
367 }
368 //*************************************************************************************************
369
370
371 //*************************************************************************************************
372 /*!\brief Clearing the represented vector.
373 //
374 // \return void
375 //
376 // This function clears the vector to its default initial state.
377 */
378 template< typename PT // Type of the proxy
379 , typename VT > // Type of the dense vector
clear()380 inline void DenseVectorProxy<PT,VT>::clear() const
381 {
382 using blaze::clear;
383
384 clear( (**this).get() );
385 }
386 //*************************************************************************************************
387
388
389 //*************************************************************************************************
390 /*!\brief Changing the size of the represented vector.
391 //
392 // \param n The new size of the vector.
393 // \param preserve \a true if the old values of the vector should be preserved, \a false if not.
394 // \return void
395 // \exception std::invalid_argument Invalid access to restricted element.
396 //
397 // This function changes the size of the vector. Depending on the type of the vector, during this
398 // operation new dynamic memory may be allocated in case the capacity of the vector is too small.
399 // Note that this function may invalidate all existing views (subvectors, ...) on the vector if
400 // it is used to shrink the vector. Additionally, the resize() operation potentially changes all
401 // vector elements. In order to preserve the old vector values, the \a preserve flag can be set
402 // to \a true. However, note that depending on the type of the vector new vector elements may not
403 // initialized!
404 */
405 template< typename PT // Type of the proxy
406 , typename VT > // Type of the dense vector
resize(size_t n,bool preserve)407 inline void DenseVectorProxy<PT,VT>::resize( size_t n, bool preserve ) const
408 {
409 if( (**this).isRestricted() ) {
410 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
411 }
412
413 (**this).get().resize( n, preserve );
414 }
415 //*************************************************************************************************
416
417
418 //*************************************************************************************************
419 /*!\brief Extending the size of the represented vector.
420 //
421 // \param n Number of additional vector elements.
422 // \param preserve \a true if the old values of the vector should be preserved, \a false if not.
423 // \return void
424 // \exception std::invalid_argument Invalid access to restricted element.
425 //
426 // This function extends the size of the vector. Depending on the type of the vector, during this
427 // operation new dynamic memory may be allocated in case the capacity of the vector is too small.
428 // Therefore this function potentially changes all vector elements. In order to preserve the old
429 // vector values, the \a preserve flag can be set to \a true. However, note that depending on the
430 // type vector new vector elements may not initialized!
431 */
432 template< typename PT // Type of the proxy
433 , typename VT > // Type of the dense vector
extend(size_t n,bool preserve)434 inline void DenseVectorProxy<PT,VT>::extend( size_t n, bool preserve ) const
435 {
436 if( (**this).isRestricted() ) {
437 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
438 }
439
440 (**this).get().extend( n, preserve );
441 }
442 //*************************************************************************************************
443
444
445 //*************************************************************************************************
446 /*!\brief Setting the minimum capacity of the represented vector.
447 //
448 // \param n The new minimum capacity of the vector.
449 // \return void
450 // \exception std::invalid_argument Invalid access to restricted element.
451 //
452 // This function increases the capacity of the vector to at least \a n elements. The current
453 // values of the vector elements are preserved.
454 */
455 template< typename PT // Type of the proxy
456 , typename VT > // Type of the dense vector
reserve(size_t n)457 inline void DenseVectorProxy<PT,VT>::reserve( size_t n ) const
458 {
459 if( (**this).isRestricted() ) {
460 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
461 }
462
463 (**this).get().reserve( n );
464 }
465 //*************************************************************************************************
466
467
468 //*************************************************************************************************
469 /*!\brief Scaling of the vector by the scalar value \a scalar (\f$ \vec{a}=\vec{b}*s \f$).
470 //
471 // \param scalar The scalar value for the vector scaling.
472 // \return void
473 // \exception std::invalid_argument Invalid access to restricted element.
474 //
475 // This function scales the vector by applying the given scalar value \a scalar to each element
476 // of the vector. For built-in and \c complex data types it has the same effect as using the
477 // multiplication assignment operator.
478 */
479 template< typename PT // Type of the proxy
480 , typename VT > // Type of the dense vector
481 template< typename Other > // Data type of the scalar value
scale(const Other & scalar)482 inline void DenseVectorProxy<PT,VT>::scale( const Other& scalar ) const
483 {
484 if( (**this).isRestricted() ) {
485 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
486 }
487
488 (**this).get().scale( scalar );
489 }
490 //*************************************************************************************************
491
492
493
494
495 //=================================================================================================
496 //
497 // GLOBAL FUNCTIONS
498 //
499 //=================================================================================================
500
501 //*************************************************************************************************
502 /*!\name DenseVectorProxy global functions */
503 //@{
504 template< typename PT, typename VT >
505 typename DenseVectorProxy<PT,VT>::Iterator
506 begin( const DenseVectorProxy<PT,VT>& proxy );
507
508 template< typename PT, typename VT >
509 typename DenseVectorProxy<PT,VT>::ConstIterator
510 cbegin( const DenseVectorProxy<PT,VT>& proxy );
511
512 template< typename PT, typename VT >
513 typename DenseVectorProxy<PT,VT>::Iterator
514 end( const DenseVectorProxy<PT,VT>& proxy );
515
516 template< typename PT, typename VT >
517 typename DenseVectorProxy<PT,VT>::ConstIterator
518 cend( const DenseVectorProxy<PT,VT>& proxy );
519
520 template< typename PT, typename VT >
521 size_t size( const DenseVectorProxy<PT,VT>& proxy );
522
523 template< typename PT, typename VT >
524 size_t capacity( const DenseVectorProxy<PT,VT>& proxy );
525
526 template< typename PT, typename VT >
527 size_t nonZeros( const DenseVectorProxy<PT,VT>& proxy );
528
529 template< typename PT, typename VT >
530 void resize( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve=true );
531
532 template< typename PT, typename VT >
533 void reset( const DenseVectorProxy<PT,VT>& proxy );
534
535 template< typename PT, typename VT >
536 void clear( const DenseVectorProxy<PT,VT>& proxy );
537 //@}
538 //*************************************************************************************************
539
540
541 //*************************************************************************************************
542 /*!\brief Returns an iterator to the first element of the represented vector.
543 // \ingroup math
544 //
545 // \param proxy The given access proxy.
546 // \return Iterator to the first element of the vector.
547 */
548 template< typename PT // Type of the proxy
549 , typename VT > // Type of the dense vector
550 BLAZE_ALWAYS_INLINE typename DenseVectorProxy<PT,VT>::Iterator
begin(const DenseVectorProxy<PT,VT> & proxy)551 begin( const DenseVectorProxy<PT,VT>& proxy )
552 {
553 return proxy.begin();
554 }
555 //*************************************************************************************************
556
557
558 //*************************************************************************************************
559 /*!\brief Returns an iterator to the first element of the represented vector.
560 // \ingroup math
561 //
562 // \param proxy The given access proxy.
563 // \return Iterator to the first element of the vector.
564 */
565 template< typename PT // Type of the proxy
566 , typename VT > // Type of the dense vector
567 BLAZE_ALWAYS_INLINE typename DenseVectorProxy<PT,VT>::ConstIterator
cbegin(const DenseVectorProxy<PT,VT> & proxy)568 cbegin( const DenseVectorProxy<PT,VT>& proxy )
569 {
570 return proxy.cbegin();
571 }
572 //*************************************************************************************************
573
574
575 //*************************************************************************************************
576 /*!\brief Returns an iterator just past the last element of the represented vector.
577 // \ingroup math
578 //
579 // \param proxy The given access proxy.
580 // \return Iterator just past the last element of the vector.
581 */
582 template< typename PT // Type of the proxy
583 , typename VT > // Type of the dense vector
584 BLAZE_ALWAYS_INLINE typename DenseVectorProxy<PT,VT>::Iterator
end(const DenseVectorProxy<PT,VT> & proxy)585 end( const DenseVectorProxy<PT,VT>& proxy )
586 {
587 return proxy.end();
588 }
589 //*************************************************************************************************
590
591
592 //*************************************************************************************************
593 /*!\brief Returns an iterator just past the last element of the represented vector.
594 // \ingroup math
595 //
596 // \param proxy The given access proxy.
597 // \return Iterator just past the last element of the vector.
598 */
599 template< typename PT // Type of the proxy
600 , typename VT > // Type of the dense vector
601 BLAZE_ALWAYS_INLINE typename DenseVectorProxy<PT,VT>::ConstIterator
cend(const DenseVectorProxy<PT,VT> & proxy)602 cend( const DenseVectorProxy<PT,VT>& proxy )
603 {
604 return proxy.cend();
605 }
606 //*************************************************************************************************
607
608
609 //*************************************************************************************************
610 /*!\brief Returns the current size/dimension of the represented vector.
611 // \ingroup math
612 //
613 // \param proxy The given access proxy.
614 // \return The size of the vector.
615 */
616 template< typename PT // Type of the proxy
617 , typename VT > // Type of the dense vector
size(const DenseVectorProxy<PT,VT> & proxy)618 BLAZE_ALWAYS_INLINE size_t size( const DenseVectorProxy<PT,VT>& proxy )
619 {
620 return proxy.size();
621 }
622 //*************************************************************************************************
623
624
625 //*************************************************************************************************
626 /*!\brief Returns the maximum capacity of the represented vector.
627 // \ingroup math
628 //
629 // \param proxy The given access proxy.
630 // \return The capacity of the vector.
631 */
632 template< typename PT // Type of the proxy
633 , typename VT > // Type of the dense vector
capacity(const DenseVectorProxy<PT,VT> & proxy)634 BLAZE_ALWAYS_INLINE size_t capacity( const DenseVectorProxy<PT,VT>& proxy )
635 {
636 return proxy.capacity();
637 }
638 //*************************************************************************************************
639
640
641 //*************************************************************************************************
642 /*!\brief Returns the number of non-zero elements in the represented vector.
643 // \ingroup math
644 //
645 // \param proxy The given access proxy.
646 // \return The number of non-zero elements in the vector.
647 //
648 // Note that the number of non-zero elements is always less than or equal to the current size
649 // of the vector.
650 */
651 template< typename PT // Type of the proxy
652 , typename VT > // Type of the dense vector
nonZeros(const DenseVectorProxy<PT,VT> & proxy)653 BLAZE_ALWAYS_INLINE size_t nonZeros( const DenseVectorProxy<PT,VT>& proxy )
654 {
655 return proxy.nonZeros();
656 }
657 //*************************************************************************************************
658
659
660 //*************************************************************************************************
661 /*! \cond BLAZE_INTERNAL */
662 /*!\brief Backend implementation of the \c resize() function for non-resizable vectors.
663 // \ingroup math
664 //
665 // \param proxy The given access proxy
666 // \param n The new size of the vector.
667 // \param preserve \a true if the old values of the vector should be preserved, \a false if not.
668 // \return void
669 // \exception std::invalid_argument Vector cannot be resized.
670 //
671 // This function tries to change the number of rows and columns of a non-resizable vector. Since
672 // the vector cannot be resized, in case the specified size is not identical to the current size
673 // of the vector, a \a std::invalid_argument exception is thrown.
674 */
675 template< typename PT // Type of the proxy
676 , typename VT > // Type of the dense vector
677 BLAZE_ALWAYS_INLINE DisableIf_t< IsResizable_v<VT> >
resize_backend(const DenseVectorProxy<PT,VT> & proxy,size_t n,bool preserve)678 resize_backend( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve )
679 {
680 MAYBE_UNUSED( preserve );
681
682 if( proxy.size() != n ) {
683 BLAZE_THROW_INVALID_ARGUMENT( "Vector cannot be resized" );
684 }
685 }
686 /*! \endcond */
687 //*************************************************************************************************
688
689
690 //*************************************************************************************************
691 /*! \cond BLAZE_INTERNAL */
692 /*!\brief Backend implementation of the \c resize() function for resizable vectors.
693 // \ingroup math
694 //
695 // \param proxy The given access proxy
696 // \param n The new size of the vector.
697 // \param preserve \a true if the old values of the vector should be preserved, \a false if not.
698 // \return void
699 //
700 // This function changes the size of the given resizable vector.
701 */
702 template< typename PT // Type of the proxy
703 , typename VT > // Type of the dense vector
704 BLAZE_ALWAYS_INLINE EnableIf_t< IsResizable_v<VT> >
resize_backend(const DenseVectorProxy<PT,VT> & proxy,size_t n,bool preserve)705 resize_backend( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve )
706 {
707 proxy.resize( n, preserve );
708 }
709 /*! \endcond */
710 //*************************************************************************************************
711
712
713 //*************************************************************************************************
714 /*!\brief Changing the size of the represented vector.
715 // \ingroup math
716 //
717 // \param proxy The given access proxy.
718 // \param n The new size of the vector.
719 // \param preserve \a true if the old values of the vector should be preserved, \a false if not.
720 // \return void
721 // \exception std::invalid_argument Vector cannot be resized.
722 //
723 // This function resizes the represented vector to the specified \a size. Note that in contrast
724 // to the \c resize() member function, which is only available on resizable vector types, this
725 // function can be used on both resizable and non-resizable vectors. In case the type \a VT of
726 // the represented vector is resizable (i.e. provides a \c resize() function), the type-specific
727 // \c resize() member function is called. Depending on the type \a VT, this may result in the
728 // allocation of new dynamic memory and the invalidation of existing views (subvectors, ...). In
729 // case \a VT is non-resizable (i.e. does not provide a \c resize() function) and if the specified
730 // size is not identical to the current size of the vector, a \a std::invalid_argument exception
731 // is thrown.
732 */
733 template< typename PT // Type of the proxy
734 , typename VT > // Type of the dense vector
resize(const DenseVectorProxy<PT,VT> & proxy,size_t n,bool preserve)735 BLAZE_ALWAYS_INLINE void resize( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve )
736 {
737 resize_backend( proxy, n, preserve );
738 }
739 //*************************************************************************************************
740
741
742 //*************************************************************************************************
743 /*!\brief Resetting the represented vector to the default initial values.
744 // \ingroup math
745 //
746 // \param proxy The given access proxy.
747 // \return void
748 //
749 // This function resets all elements of the vector to the default initial values.
750 */
751 template< typename PT // Type of the proxy
752 , typename VT > // Type of the dense vector
reset(const DenseVectorProxy<PT,VT> & proxy)753 BLAZE_ALWAYS_INLINE void reset( const DenseVectorProxy<PT,VT>& proxy )
754 {
755 proxy.reset();
756 }
757 //*************************************************************************************************
758
759
760 //*************************************************************************************************
761 /*!\brief Clearing the represented vector.
762 // \ingroup math
763 //
764 // \param proxy The given access proxy.
765 // \return void
766 //
767 // This function clears the vector to its default initial state.
768 */
769 template< typename PT // Type of the proxy
770 , typename VT > // Type of the dense vector
clear(const DenseVectorProxy<PT,VT> & proxy)771 BLAZE_ALWAYS_INLINE void clear( const DenseVectorProxy<PT,VT>& proxy )
772 {
773 proxy.clear();
774 }
775 //*************************************************************************************************
776
777 } // namespace blaze
778
779 #endif
780