[vsipl++] Matlab IO
Jules Bergmann
jules at codesourcery.com
Fri Jun 16 18:30:11 UTC 2006
Assem Salama wrote:
> Everyone,
> I apologize about last e-mail, I forgot to include layout.hpp in the
> patch.
>
Assem,
This looks good. Three small comments:
- delete old get_real_ptr/get_imag_ptr functions
- make new get_real_ptr/get_imag_ptr functions static members of
Storage (and use storage_type::get_real_ptr(...) to access them).
- change type of 'sz' from int32_t to uint32_t.
Also, please coordinate with Stefan, I believe he had some
questions/comments for you on this patch.
Once the items above are fixed and Stefan's happy, please check it in.
thanks,
-- Jules
> +
You should delete these now that they've been moved to layout.hpp:
> + template<typename T>
> + inline T* get_real_ptr(std::pair<T*,T*> ptr)
> + { return ptr.first; }
> + template<typename T>
> + inline T* get_real_ptr(T* ptr)
> + { return ptr; }
> +
> + template<typename T>
> + inline T* get_imag_ptr(std::pair<T*,T*> ptr)
> + { return ptr.second; }
> + template<typename T>
> + inline T* get_imag_ptr(T* ptr)
> + { return ptr; }
> +
> +
> +
> +}
> +// operator to write a view to a matlab file
> +template <typename T,
> + typename Block0,
> + template <typename,typename> class const_View>
> +inline
> +std::ostream&
> +operator<<(
> + std::ostream& o,
> + Matlab_bin_formatter<const_View<T,Block0> > const& mbf)
> +{
> + typedef typename vsip::impl::Scalar_of<T>::type scalar_type;
> + matlab::data_element temp_data_element;
> + int32_t sz;
Since 'sz' is going into a uint32_t (m_view.header.size), it should be a
unit32_t too.
...
> + m_view.header.size = sz;
> +
> + o.write(reinterpret_cast<char*>(&m_view),sizeof(m_view));
> +
> + // write array name
> + o.write(mbf.name.c_str(),mbf.name.length());
> + // pad
> + {
> + char c=0;
> + for(vsip::length_type i=0;i<((8-mbf.name.length())&0x7);i++) o.write(&c,1);
> + }
> +
> + // write data
> + {
> +
> + // make sure we don't need a copy if we use Ext data
> + if(vsip::impl::Ext_data_cost<Block0,
> + typename matlab::Matlab_desired_LP<const_View>::type >::value==0)
> + {
> + vsip::impl::Ext_data<Block0,
> + typename matlab::Matlab_desired_LP<const_View>::type >
> +
> + m_ext(mbf.view.block());
> +
> + typedef typename vsip::impl::Ext_data<Block0,
> + typename matlab::Matlab_desired_LP<const_View>::type >::storage_type
> + storage_type;
> +
> + storage_type tmp_storage;
> +
> + temp_data_element.type = matlab::Matlab_header_traits<sizeof(scalar_type),
> + std::numeric_limits<scalar_type>::is_signed,
> + std::numeric_limits<scalar_type>::is_integer>::value_type;
> +
> + temp_data_element.size = num_points*sizeof(scalar_type);
> + for(int i=0;i<=vsip::impl::Is_complex<T>::value;i++)
> + {
> + o.write(reinterpret_cast<char*>(&temp_data_element),
> + sizeof(temp_data_element));
> + if(i==0) o.write(reinterpret_cast<char*>
> + (tmp_storage.get_real_ptr(m_ext.data())),
Once you make get_real_ptr a static member of Storage, you should do:
storage_type::get_real_ptr(m_ext.data())),
> + num_points*sizeof(scalar_type));
> + else o.write(reinterpret_cast<char*>
> + (tmp_storage.get_imag_ptr(m_ext.data())),
> + num_points*sizeof(scalar_type));
> + }
> + }
> + else
> + {
> + typedef matlab::Subview_helper<const_View<T,Block0> > subview;
> + typedef typename subview::realview_type r_v;
> + typedef typename subview::imagview_type i_v;
> + typedef typename vsip::impl::Scalar_of<T>::type sT;
> +
> + // conventional way
> + temp_data_element.type = matlab::Matlab_header_traits<sizeof(scalar_type),
> + std::numeric_limits<scalar_type>::is_signed,
> + std::numeric_limits<scalar_type>::is_integer>::value_type;
> +
> + temp_data_element.size = num_points*sizeof(scalar_type);
> + for(int i=0;i<=vsip::impl::Is_complex<T>::value;i++)
> + {
> + o.write(reinterpret_cast<char*>(&temp_data_element),
> + sizeof(temp_data_element));
> + if(i==0) matlab::write<sT,r_v>(o,subview::real(mbf.view));
> + else matlab::write<sT,i_v>(o,subview::imag(mbf.view));
> + }
> + }
> + }
> +
> + return o;
> +}
>
> #endif // VSIP_CSL_OUTPUT_HPP
> Index: layout.hpp
> ===================================================================
> RCS file: /home/cvs/Repository/vpp/src/vsip/impl/layout.hpp,v
> retrieving revision 1.23
> diff -u -r1.23 layout.hpp
> --- layout.hpp 14 May 2006 02:21:04 -0000 1.23
> +++ layout.hpp 16 Jun 2006 10:21:06 -0000
> @@ -1089,6 +1089,12 @@
>
> static type offset(type ptr, stride_type stride)
> { return ptr + stride; }
These should be static member functions:
> +
> + T* get_real_ptr(type ptr)
> + { return ptr; }
> + T* get_imag_ptr(type ptr)
> + { return ptr; }
> +
> };
>
>
> @@ -1147,6 +1153,12 @@
>
> static type offset(type ptr, stride_type stride)
> { return type(ptr.first + stride, ptr.second + stride); }
> +
Likewise:
> + T* get_real_ptr(type ptr)
> + { return ptr.first; }
> + T* get_imag_ptr(type ptr)
> + { return ptr.second; }
> +
> };
>
>
--
Jules Bergmann
CodeSourcery
jules at codesourcery.com
(650) 331-3385 x705
More information about the vsipl++
mailing list