ALP User Documentation  0.8.preview
Algebraic Programming User Documentation
vector.hpp
Go to the documentation of this file.
1 
2 /*
3  * Copyright 2021 Huawei Technologies Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
27 #ifndef _H_GRB_VECTOR_BASE
28 #define _H_GRB_VECTOR_BASE
29 
30 #include <cstdlib> //size_t
31 #include <iterator> //std::iterator
32 #include <stdexcept>
33 #include <utility> //pair
34 
35 #include <graphblas/backends.hpp>
37 #include <graphblas/ops.hpp>
38 #include <graphblas/rc.hpp>
39 
40 
41 namespace grb {
42 
63  template< typename D, enum Backend implementation, typename C >
64  class Vector {
65 
66  public :
67 
69  typedef D value_type;
70 
124  typedef D& lambda_reference;
125 
141  public std::iterator<
142  std::forward_iterator_tag,
143  std::pair< const size_t, const D >,
144  size_t
145  >
146  {
147 
148  public :
149 
151  bool operator==( const const_iterator &other ) const {
152  (void) other;
153  return false;
154  }
155 
157  bool operator!=( const const_iterator &other ) const {
158  (void) other;
159  return true;
160  }
161 
173  std::pair< const size_t, const D > operator*() const {
174  return std::pair< const size_t, const D >();
175  }
176 
191  return *this;
192  }
193 
194  };
195 
226  Vector( const size_t n, const size_t nz ) {
227  (void) n;
228  (void) nz;
229  }
230 
235  Vector( const size_t n ) {
236  (void) n;
237  }
238 
257  Vector( const std::initializer_list< D > &vals ) {
258  (void) vals;
259  }
260 
282  (void) x;
283  }
284 
302  ) noexcept {
303  (void) x;
304  return *this;
305  }
306 
329  ~Vector() {}
330 
332 
362  const_iterator cbegin() const {
363  const_iterator ret;
364  return ret;
365  }
366 
373  const_iterator begin() const {
374  const_iterator ret;
375  return ret;
376  }
377 
379 
381 
402  const_iterator cend() const {
403  const_iterator ret;
404  return ret;
405  }
406 
413  const_iterator end() const {
414  const_iterator ret;
415  return ret;
416  }
418 
502  template<
504  class Accum = typename operators::right_assign< D, D, D >,
505  typename fwd_iterator = const D * __restrict__
506  >
508  const Accum &accum,
509  const fwd_iterator start, const fwd_iterator end,
510  fwd_iterator npos
511  ) {
512  (void) accum;
513  (void) start;
514  (void) end;
515  (void) npos;
516  return PANIC;
517  }
518 
617  template<
620  typename ind_iterator = const size_t * __restrict__,
621  typename nnz_iterator = const D * __restrict__,
623  >
625  const Accum &accum,
626  const ind_iterator ind_start, const ind_iterator ind_end,
627  const nnz_iterator nnz_start, const nnz_iterator nnz_end,
628  const Dup &dup = Dup()
629  ) {
630  (void) accum;
631  (void) ind_start;
632  (void) ind_end;
633  (void) nnz_start;
634  (void) nnz_end;
635  (void) dup;
636  return PANIC;
637  }
638 
742  template<
744  typename mask_type,
745  class Accum,
746  typename ind_iterator = const size_t * __restrict__,
747  typename nnz_iterator = const D * __restrict__,
749  >
752  const Accum &accum,
753  const ind_iterator ind_start,
754  const ind_iterator ind_end,
755  const nnz_iterator nnz_start,
756  const nnz_iterator nnz_end,
757  const Dup &dup = Dup()
758  ) {
759  (void) mask;
760  (void) accum;
761  (void) ind_start;
762  (void) ind_end;
763  (void) nnz_start;
764  (void) nnz_end;
765  (void) dup;
766  return PANIC;
767  }
768 
793  template< typename T >
794  RC size( T &size ) const {
795  (void) size;
796  return PANIC;
797  }
798 
823  template< typename T >
824  RC nnz( T &nnz ) const {
825  (void) nnz;
826  return PANIC;
827  }
828 
888  template< class Monoid >
890  const size_t i, const Monoid &monoid = Monoid()
891  ) {
892  (void) i;
893  (void) monoid;
894  return PANIC;
895  }
896 
941  lambda_reference operator[]( const size_t i ) {
942  (void) i;
943  #ifndef _GRB_NO_EXCEPTIONS
944  throw std::runtime_error(
945  "Requesting lambda reference of unimplemented Vector backend."
946  );
947  #endif
948  }
949  };
950 
951 } // end namespace ``grb''
952 
953 #endif // _H_GRB_VECTOR_BASE
954 
D & lambda_reference
Defines a reference to a value of type D.
Definition: vector.hpp:124
Defines the ALP error codes.
This file contains a register of all backends that are either implemented, under implementation,...
RC
Return codes of ALP primitives.
Definition: rc.hpp:47
A GraphBLAS vector.
Definition: vector.hpp:64
RC nnz(T &nnz) const
Return the number of nonzeroes in this vector.
Definition: vector.hpp:824
Vector(Vector< D, implementation, C > &&x) noexcept
Move constructor.
Definition: vector.hpp:281
static constexpr Descriptor no_operation
Indicates no additional pre- or post-processing on any of the GraphBLAS function arguments.
Definition: descriptors.hpp:63
RC build(const Accum &accum, const fwd_iterator start, const fwd_iterator end, fwd_iterator npos)
Copy from raw user-supplied data into a vector.
Definition: vector.hpp:507
unsigned int Descriptor
Descriptors indicate pre- or post-processing for some or all of the arguments to an ALP/GraphBLAS cal...
Definition: descriptors.hpp:54
A standard iterator for the Vector< D > class.
Definition: vector.hpp:140
const_iterator cbegin() const
Provides the only mechanism to extract data from this GraphBLAS vector.
Definition: vector.hpp:362
RC build(const Accum &accum, const ind_iterator ind_start, const ind_iterator ind_end, const nnz_iterator nnz_start, const nnz_iterator nnz_end, const Dup &dup=Dup())
Copy from raw user-supplied data into a vector.
Definition: vector.hpp:624
const_iterator begin() const
Same as cbegin().
Definition: vector.hpp:373
const_iterator & operator++()
Advances the position of this iterator by one.
Definition: vector.hpp:190
lambda_reference operator()(const size_t i, const Monoid &monoid=Monoid())
Returns a lambda reference to an element of this sparse vector.
Definition: vector.hpp:889
const_iterator end() const
Same as cend().
Definition: vector.hpp:413
Vector(const size_t n)
Creates an ALP/GraphBLAS vector.
Definition: vector.hpp:235
~Vector()
Default destructor.
Definition: vector.hpp:329
Defines all ALP/GraphBLAS descriptors.
RC build(const Vector< mask_type, implementation, C > &mask, const Accum &accum, const ind_iterator ind_start, const ind_iterator ind_end, const nnz_iterator nnz_start, const nnz_iterator nnz_end, const Dup &dup=Dup())
Copy from raw user-supplied data into a vector.
Definition: vector.hpp:750
Vector< D, implementation, C > & operator=(Vector< D, implementation, C > &&x) noexcept
Move-from-temporary assignment.
Definition: vector.hpp:300
This operator discards all left-hand side input and simply copies the right-hand side input to the ou...
Definition: ops.hpp:115
const_iterator cend() const
Indicates the end to the elements in this container.
Definition: vector.hpp:402
The ALP/GraphBLAS namespace.
Definition: graphblas.hpp:477
Vector(const size_t n, const size_t nz)
Creates an ALP/GraphBLAS vector.
Definition: vector.hpp:226
Generic fatal error code.
Definition: rc.hpp:68
bool operator==(const const_iterator &other) const
Standard equals operator.
Definition: vector.hpp:151
RC size(T &size) const
Return the dimension of this vector.
Definition: vector.hpp:794
D value_type
The type of elements stored in this vector.
Definition: vector.hpp:69
bool operator!=(const const_iterator &other) const
Definition: vector.hpp:157
lambda_reference operator[](const size_t i)
Returns a lambda reference to an element of this vector.
Definition: vector.hpp:941
std::pair< const size_t, const D > operator*() const
Dereferences the current position of this iterator.
Definition: vector.hpp:173
Provides a set of standard binary operators.
Vector(const std::initializer_list< D > &vals)
Creates a dense ALP/GraphBLAS vector.
Definition: vector.hpp:257
A generalised monoid.
Definition: monoid.hpp:54