00001 /**** 00002 ***** Copyright 2010 Intel Corporation All Rights Reserved. 00003 ***** 00004 ***** The source code, information and material contained herein are owned by Intel Corporation or its suppliers ***** 00005 ***** or licensors, and title to such Material remains with Intel Corporation or its suppliers or licensors. ***** 00006 ***** The Material contains proprietary information of Intel or its suppliers and licensors. The Material is ***** 00007 ***** protected by worldwide copyright laws and treaty provisions. No part of the Material may be used, copied, ***** 00008 ***** reproduced, modified, published, uploaded, posted, transmitted, distributed or disclosed in any way without ***** 00009 ***** Intel's prior express written permission. 00010 ***** 00011 ***** No license under any patent, copyright or other intellectual property rights in the material is granted to ***** 00012 ***** or conferred upon you, either expressly, by implication, inducement, estoppel or otherwise. Any license ***** 00013 ***** under such intellectual property rights must be express and approved by Intel in writing. 00014 ****/ 00015 00016 /**** Copyright Ends ****/ 00017 00018 #ifndef ARBB_CPP_DENSE_HPP 00019 #define ARBB_CPP_DENSE_HPP 00020 00021 #include <arbb_vmapi.h> 00022 #include "namespace.hpp" 00023 #include "detail/enable_if.hpp" 00024 #include "detail/type_traits.hpp" 00025 #include "detail/type_capture.hpp" 00026 #include "detail/scalar_traits.hpp" 00027 #include "detail/container.hpp" 00028 #include "detail/container_element.hpp" 00029 #include "scalar.hpp" 00030 #include "range.hpp" 00031 00032 namespace ARBB_CPP_NS { 00033 00035 00036 namespace detail { 00037 00038 // forward declaration of 00039 // 00040 template <std::size_t D> 00041 class zipped_dense; 00042 }; // namespace detail 00043 00045 00048 00053 template <typename T, std::size_t D = 1> 00054 class dense { 00055 00056 private: 00057 00059 00061 enum { elementsize = sizeof(T) }; 00062 typedef detail::container_element<T> element; 00063 00064 typedef typename detail::container_array<detail::is_scalar<T>::value ? 1 : detail::default_container_array_size> container_list; 00065 container_list m_members; 00066 00067 void init(); 00068 void assign(const dense& src); 00069 void sized_alloc(const array<const detail::scalar*, D>& sizes); 00070 template <typename U> 00071 void cast(const dense<U, D>& src); 00072 00074 00075 public: 00076 00078 typedef T element_type; 00079 00081 dense(); 00082 00085 dense(const dense& src); 00086 00090 explicit dense(const usize& length); 00091 00095 dense(const usize& width, const usize& height); 00096 00100 dense(const usize& width, const usize& height, const usize& depth); 00101 00109 explicit dense(const array<usize, D>& size); 00110 00115 template <typename U> 00116 dense(const dense<U, D>& src); 00117 00118 static dense<T, D> parse(const char* data); 00119 00123 T operator[](const usize& index) const; 00131 element operator[](const usize& index); 00132 00136 T operator()(const usize& col, const usize& row) const; 00144 element operator()(const usize& col, const usize& row); 00145 00149 T operator()(const usize& col, const usize& row, const usize& page) const; 00157 element operator()(const usize& col, const usize& row, const usize& page); 00158 00161 dense<T, 1> operator[](const dense<usize, 1>& indices) const; 00164 dense<T, 2> operator[](const dense<array<usize, 2>, 2>& indices) const; 00167 dense<T, 3> operator[](const dense<array<usize, 3>, 3>& indices) const; 00168 00175 dense<T, 1> operator[](const dense<boolean, 1>& mask) const; 00176 00189 dense& operator=(const dense& src); 00190 00192 dense<T, 1> flatten() const; 00193 00195 usize length() const; 00196 00198 usize num_cols() const; 00199 00202 usize num_rows() const; 00203 00207 usize num_pages() const; 00208 00212 array<usize, D> size() const; 00213 00216 dense<T, 1> row(const usize& index) const; 00220 dense<T, 1> row(const usize& row_index, const usize& page_index)const; 00223 dense<T, 1> col(const usize& index) const; 00227 dense<T, 1> col(const usize& column_index, const usize& page_index) const; 00230 dense<T, 2> page(const usize& index) const; 00234 dense<T, 1> dim3(const usize& column_index, const usize& row_index) const; 00235 00239 range<T> read_write_range(); 00240 00244 const_range<T> read_only_range() const; 00245 00249 range<T> write_only_range(); 00250 00262 template <typename S, std::size_t N> 00263 typename detail::enable_if<detail::is_scalar<S>::value, dense<S, D> >::type get() const; 00264 00265 00282 template <std::size_t N, arbb_scalar_type_t S> 00283 void set(const dense<scalar<S>, D>& val); 00284 00309 template <typename U> 00310 detail::zipped_dense<D> zip(const dense<U, D>& other) const; 00311 00313 00315 00318 arbb_variable_t vm_variable(std::size_t index = 0) const; 00319 00320 typedef typename container_list::iterator container_iterator; 00321 typedef typename container_list::const_iterator container_const_iterator; 00322 00323 container_iterator containers_begin() { return m_members.begin(); } 00324 container_iterator containers_end() { return m_members.end(); } 00325 container_const_iterator containers_begin() const { return m_members.begin(); } 00326 container_const_iterator containers_end() const { return m_members.end(); } 00327 00329 }; 00330 00331 template <typename T> 00332 void expect_size(const dense<T, 1>& container, std::size_t width); 00333 template <typename T> 00334 void expect_size(const dense<T, 2>& container, std::size_t width, std::size_t height); 00335 template <typename T> 00336 void expect_size(const dense<T, 3>& container, std::size_t width, std::size_t height, std::size_t depth); 00337 template <typename T, std::size_t D> 00338 void expect_size(const dense<T, D>& container, const array<std::size_t, D>& size); 00339 00341 00343 00344 namespace detail { 00345 00346 template <typename T, std::size_t D> 00347 struct container_traits<dense<T, D> > { 00348 enum { shape = 1 << D }; 00349 enum { is_container = 1 }; 00350 typedef T element_type; 00351 }; 00352 00353 } // namespace detail 00354 00356 00357 } // namespace ARBB_CPP_NS 00358 00359 00360 #endif // ARBB_CPP_DENSE_HPP
Copyright © 2010, Intel Corporation. All rights reserved.