2015-04-29 15:50:57 -04:00
|
|
|
#ifndef ISAAC_ARRAY_H_
|
|
|
|
#define ISAAC_ARRAY_H_
|
2015-01-12 13:20:53 -05:00
|
|
|
|
|
|
|
#include <iostream>
|
2015-04-29 15:50:57 -04:00
|
|
|
#include "isaac/types.h"
|
|
|
|
#include "isaac/driver/backend.h"
|
|
|
|
#include "isaac/symbolic/expression.h"
|
2015-01-12 13:20:53 -05:00
|
|
|
|
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
namespace isaac
|
2015-01-12 13:20:53 -05:00
|
|
|
{
|
|
|
|
|
2015-01-13 01:17:27 -05:00
|
|
|
class scalar;
|
2015-02-04 22:06:15 -05:00
|
|
|
|
|
|
|
class array: public array_base
|
2015-01-12 13:20:53 -05:00
|
|
|
{
|
2015-06-25 08:12:16 -07:00
|
|
|
protected:
|
|
|
|
//Slices
|
|
|
|
array(numeric_type dtype, driver::Buffer data, slice const & s1, slice const & s2, int_t ld);
|
|
|
|
|
2015-01-12 13:20:53 -05:00
|
|
|
public:
|
|
|
|
//1D Constructors
|
2015-04-29 15:50:57 -04:00
|
|
|
array(int_t size1, numeric_type dtype, driver::Context context = driver::queues.default_context());
|
2015-06-25 08:12:16 -07:00
|
|
|
array(int_t size1, numeric_type dtype, driver::Buffer data, int_t start, int_t inc);
|
|
|
|
|
2015-01-21 20:08:52 -05:00
|
|
|
template<typename DT>
|
2015-04-29 15:50:57 -04:00
|
|
|
array(std::vector<DT> const & data, driver::Context context = driver::queues.default_context());
|
2015-01-12 13:20:53 -05:00
|
|
|
array(array & v, slice const & s1);
|
|
|
|
|
|
|
|
//2D Constructors
|
2015-04-29 15:50:57 -04:00
|
|
|
array(int_t size1, int_t size2, numeric_type dtype, driver::Context context = driver::queues.default_context());
|
2015-06-25 08:12:16 -07:00
|
|
|
array(int_t size1, int_t size2, numeric_type dtype, driver::Buffer data, int_t start, int_t ld);
|
2015-01-21 20:08:52 -05:00
|
|
|
template<typename DT>
|
2015-04-29 15:50:57 -04:00
|
|
|
array(int_t size1, int_t size2, std::vector<DT> const & data, driver::Context context = driver::queues.default_context());
|
2015-01-12 13:20:53 -05:00
|
|
|
array(array & M, slice const & s1, slice const & s2);
|
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
//3D Constructors
|
|
|
|
array(int_t size1, int_t size2, int_t size3, numeric_type dtype, driver::Context context = driver::queues.default_context());
|
|
|
|
|
2015-01-12 13:20:53 -05:00
|
|
|
//General constructor
|
2015-02-06 22:11:03 -05:00
|
|
|
|
2015-02-04 22:06:15 -05:00
|
|
|
array(array_expression const & proxy);
|
2015-01-18 14:52:45 -05:00
|
|
|
array(array const &);
|
2015-02-06 22:11:03 -05:00
|
|
|
template<class T>
|
|
|
|
array(controller<T> const &);
|
2015-01-12 13:20:53 -05:00
|
|
|
//Getters
|
|
|
|
numeric_type dtype() const;
|
2015-04-29 15:50:57 -04:00
|
|
|
size4 const & shape() const;
|
2015-02-04 22:06:15 -05:00
|
|
|
int_t nshape() const;
|
2015-04-29 15:50:57 -04:00
|
|
|
size4 const & start() const;
|
|
|
|
size4 const & stride() const;
|
|
|
|
int_t const & ld() const;
|
|
|
|
driver::Context const & context() const;
|
|
|
|
driver::Buffer const & data() const;
|
|
|
|
driver::Buffer & data();
|
2015-01-12 13:20:53 -05:00
|
|
|
int_t dsize() const;
|
|
|
|
|
|
|
|
//Setters
|
2015-01-16 07:31:39 -05:00
|
|
|
array& resize(int_t size1, int_t size2=1);
|
2015-01-12 13:20:53 -05:00
|
|
|
|
|
|
|
//Numeric operators
|
|
|
|
array& operator=(array const &);
|
2015-02-04 22:06:15 -05:00
|
|
|
array& operator=(array_expression const &);
|
2015-02-05 04:42:57 -05:00
|
|
|
template<class T>
|
|
|
|
array& operator=(controller<T> const &);
|
|
|
|
template<class T>
|
|
|
|
array & operator=(std::vector<T> const & rhs);
|
2015-06-27 11:44:50 -04:00
|
|
|
array & operator=(value_scalar const & rhs);
|
2015-01-12 13:20:53 -05:00
|
|
|
|
2015-01-19 21:29:47 -05:00
|
|
|
array_expression operator-();
|
2015-01-29 15:19:40 -05:00
|
|
|
array_expression operator!();
|
|
|
|
|
2015-01-16 07:31:39 -05:00
|
|
|
array& operator+=(value_scalar const &);
|
|
|
|
array& operator+=(array const &);
|
|
|
|
array& operator+=(array_expression const &);
|
|
|
|
array& operator-=(value_scalar const &);
|
|
|
|
array& operator-=(array const &);
|
|
|
|
array& operator-=(array_expression const &);
|
2015-01-12 13:20:53 -05:00
|
|
|
array& operator*=(value_scalar const &);
|
|
|
|
array& operator*=(array const &);
|
|
|
|
array& operator*=(array_expression const &);
|
|
|
|
array& operator/=(value_scalar const &);
|
|
|
|
array& operator/=(array const &);
|
|
|
|
array& operator/=(array_expression const &);
|
|
|
|
|
|
|
|
//Indexing operators
|
2015-01-16 15:24:24 -05:00
|
|
|
const scalar operator[](int_t) const;
|
2015-01-13 01:17:27 -05:00
|
|
|
scalar operator[](int_t);
|
2015-01-12 13:20:53 -05:00
|
|
|
array operator[](slice const &);
|
|
|
|
array operator()(slice const &, slice const &);
|
2015-01-21 20:08:52 -05:00
|
|
|
|
|
|
|
array_expression T() const;
|
2015-01-12 13:20:53 -05:00
|
|
|
protected:
|
2015-02-04 22:06:15 -05:00
|
|
|
numeric_type dtype_;
|
|
|
|
|
|
|
|
size4 shape_;
|
|
|
|
size4 start_;
|
|
|
|
size4 stride_;
|
|
|
|
int_t ld_;
|
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
driver::Context context_;
|
|
|
|
driver::Buffer data_;
|
2015-01-12 13:20:53 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
class scalar : public array
|
|
|
|
{
|
2015-05-04 21:23:05 -04:00
|
|
|
friend value_scalar::value_scalar(const scalar &);
|
|
|
|
friend value_scalar::value_scalar(const array_expression &);
|
2015-01-13 01:17:27 -05:00
|
|
|
private:
|
2015-05-04 21:23:05 -04:00
|
|
|
void inject(values_holder&) const;
|
2015-01-13 01:17:27 -05:00
|
|
|
template<class T> T cast() const;
|
2015-01-12 13:20:53 -05:00
|
|
|
public:
|
2015-06-24 07:51:27 -07:00
|
|
|
explicit scalar(numeric_type dtype, driver::Buffer const & data, int_t offset);
|
2015-04-29 15:50:57 -04:00
|
|
|
explicit scalar(value_scalar value, driver::Context context = driver::queues.default_context());
|
|
|
|
explicit scalar(numeric_type dtype, driver::Context context = driver::queues.default_context());
|
2015-02-04 22:06:15 -05:00
|
|
|
scalar(array_expression const & proxy);
|
2015-01-16 07:31:39 -05:00
|
|
|
scalar& operator=(value_scalar const &);
|
2015-01-19 21:29:47 -05:00
|
|
|
// scalar& operator=(scalar const & s);
|
|
|
|
using array::operator =;
|
2015-01-13 01:17:27 -05:00
|
|
|
|
|
|
|
#define INSTANTIATE(type) operator type() const;
|
2015-05-04 21:23:05 -04:00
|
|
|
INSTANTIATE(char)
|
|
|
|
INSTANTIATE(unsigned char)
|
|
|
|
INSTANTIATE(short)
|
|
|
|
INSTANTIATE(unsigned short)
|
|
|
|
INSTANTIATE(int)
|
|
|
|
INSTANTIATE(unsigned int)
|
|
|
|
INSTANTIATE(long)
|
|
|
|
INSTANTIATE(unsigned long)
|
2015-05-04 23:54:43 -04:00
|
|
|
INSTANTIATE(long long)
|
|
|
|
INSTANTIATE(unsigned long long)
|
2015-05-04 21:23:05 -04:00
|
|
|
INSTANTIATE(float)
|
|
|
|
INSTANTIATE(double)
|
2015-01-13 01:17:27 -05:00
|
|
|
#undef INSTANTIATE
|
2015-01-12 13:20:53 -05:00
|
|
|
};
|
|
|
|
|
2015-01-16 07:31:39 -05:00
|
|
|
|
2015-01-21 20:08:52 -05:00
|
|
|
|
2015-01-16 07:31:39 -05:00
|
|
|
|
2015-01-12 13:20:53 -05:00
|
|
|
//copy
|
2015-04-29 15:50:57 -04:00
|
|
|
void copy(void const * data, array & gx, driver::CommandQueue & queue, bool blocking = true);
|
|
|
|
void copy(array const & gx, void* data, driver::CommandQueue & queue, bool blocking = true);
|
2015-01-12 13:20:53 -05:00
|
|
|
void copy(void const *data, array &gx, bool blocking = true);
|
|
|
|
void copy(array const & gx, void* data, bool blocking = true);
|
2015-04-29 15:50:57 -04:00
|
|
|
template<class T> void copy(std::vector<T> const & cA, array& gA, driver::CommandQueue & queue, bool blocking = true);
|
|
|
|
template<class T> void copy(array const & gA, std::vector<T> & cA, driver::CommandQueue & queue, bool blocking = true);
|
2015-01-12 13:20:53 -05:00
|
|
|
template<class T> void copy(std::vector<T> const & cA, array & gA, bool blocking = true);
|
|
|
|
template<class T> void copy(array const & gA, std::vector<T> & cA, bool blocking = true);
|
|
|
|
|
|
|
|
//Operators
|
|
|
|
//Binary operators
|
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
#define ISAAC_DECLARE_ELEMENT_BINARY_OPERATOR(OPNAME) \
|
2015-01-12 13:20:53 -05:00
|
|
|
array_expression OPNAME (array_expression const & x, array_expression const & y);\
|
|
|
|
array_expression OPNAME (array const & x, array_expression const & y);\
|
|
|
|
array_expression OPNAME (array_expression const & x, array const & y);\
|
|
|
|
array_expression OPNAME (array const & x, array const & y);\
|
|
|
|
array_expression OPNAME (array_expression const & x, value_scalar const & y);\
|
|
|
|
array_expression OPNAME (array const & x, value_scalar const & y);\
|
|
|
|
array_expression OPNAME (value_scalar const & y, array_expression const & x);\
|
|
|
|
array_expression OPNAME (value_scalar const & y, array const & x);
|
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
ISAAC_DECLARE_ELEMENT_BINARY_OPERATOR(operator +)
|
|
|
|
ISAAC_DECLARE_ELEMENT_BINARY_OPERATOR(operator -)
|
|
|
|
ISAAC_DECLARE_ELEMENT_BINARY_OPERATOR(operator *)
|
|
|
|
ISAAC_DECLARE_ELEMENT_BINARY_OPERATOR(operator /)
|
2015-01-12 13:20:53 -05:00
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
ISAAC_DECLARE_ELEMENT_BINARY_OPERATOR(operator >)
|
|
|
|
ISAAC_DECLARE_ELEMENT_BINARY_OPERATOR(operator >=)
|
|
|
|
ISAAC_DECLARE_ELEMENT_BINARY_OPERATOR(operator <)
|
|
|
|
ISAAC_DECLARE_ELEMENT_BINARY_OPERATOR(operator <=)
|
|
|
|
ISAAC_DECLARE_ELEMENT_BINARY_OPERATOR(operator ==)
|
|
|
|
ISAAC_DECLARE_ELEMENT_BINARY_OPERATOR(operator !=)
|
2015-01-12 13:20:53 -05:00
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
ISAAC_DECLARE_ELEMENT_BINARY_OPERATOR(maximum)
|
|
|
|
ISAAC_DECLARE_ELEMENT_BINARY_OPERATOR(minimum)
|
|
|
|
ISAAC_DECLARE_ELEMENT_BINARY_OPERATOR(pow)
|
2015-01-12 13:20:53 -05:00
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
ISAAC_DECLARE_ELEMENT_BINARY_OPERATOR(dot)
|
|
|
|
ISAAC_DECLARE_ELEMENT_BINARY_OPERATOR(outer)
|
2015-01-12 13:20:53 -05:00
|
|
|
|
2015-06-28 17:53:16 -07:00
|
|
|
ISAAC_DECLARE_ELEMENT_BINARY_OPERATOR(assign)
|
|
|
|
|
2015-01-12 13:20:53 -05:00
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
#undef ISAAC_DECLARE_ELEMENT_BINARY_OPERATOR
|
2015-01-12 13:20:53 -05:00
|
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
|
|
|
//Unary operators
|
2015-04-29 15:50:57 -04:00
|
|
|
#define ISAAC_DECLARE_UNARY_OPERATOR(OPNAME) \
|
2015-01-12 13:20:53 -05:00
|
|
|
array_expression OPNAME (array const & x);\
|
|
|
|
array_expression OPNAME (array_expression const & x);
|
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
ISAAC_DECLARE_UNARY_OPERATOR(abs)
|
|
|
|
ISAAC_DECLARE_UNARY_OPERATOR(acos)
|
|
|
|
ISAAC_DECLARE_UNARY_OPERATOR(asin)
|
|
|
|
ISAAC_DECLARE_UNARY_OPERATOR(atan)
|
|
|
|
ISAAC_DECLARE_UNARY_OPERATOR(ceil)
|
|
|
|
ISAAC_DECLARE_UNARY_OPERATOR(cos)
|
|
|
|
ISAAC_DECLARE_UNARY_OPERATOR(cosh)
|
|
|
|
ISAAC_DECLARE_UNARY_OPERATOR(exp)
|
|
|
|
ISAAC_DECLARE_UNARY_OPERATOR(floor)
|
|
|
|
ISAAC_DECLARE_UNARY_OPERATOR(log)
|
|
|
|
ISAAC_DECLARE_UNARY_OPERATOR(log10)
|
|
|
|
ISAAC_DECLARE_UNARY_OPERATOR(sin)
|
|
|
|
ISAAC_DECLARE_UNARY_OPERATOR(sinh)
|
|
|
|
ISAAC_DECLARE_UNARY_OPERATOR(sqrt)
|
|
|
|
ISAAC_DECLARE_UNARY_OPERATOR(tan)
|
|
|
|
ISAAC_DECLARE_UNARY_OPERATOR(tanh)
|
|
|
|
ISAAC_DECLARE_UNARY_OPERATOR(trans)
|
2015-01-12 13:20:53 -05:00
|
|
|
|
2015-01-29 01:00:50 -05:00
|
|
|
array_expression cast(array const &, numeric_type dtype);
|
|
|
|
array_expression cast(array_expression const &, numeric_type dtype);
|
|
|
|
|
2015-01-16 07:31:39 -05:00
|
|
|
array_expression norm(array const &, unsigned int order = 2);
|
|
|
|
array_expression norm(array_expression const &, unsigned int order = 2);
|
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
#undef ISAAC_DECLARE_UNARY_OPERATOR
|
2015-01-12 13:20:53 -05:00
|
|
|
|
|
|
|
array_expression repmat(array const &, int_t const & rep1, int_t const & rep2);
|
|
|
|
|
2015-07-11 09:36:01 -04:00
|
|
|
#define ISAAC_DECLARE_DOT(OPNAME) \
|
2015-01-12 13:20:53 -05:00
|
|
|
array_expression OPNAME(array const & M, int_t axis = -1);\
|
|
|
|
array_expression OPNAME(array_expression const & M, int_t axis = -1);
|
|
|
|
|
2015-07-11 09:36:01 -04:00
|
|
|
ISAAC_DECLARE_DOT(sum)
|
|
|
|
ISAAC_DECLARE_DOT(argmax)
|
|
|
|
ISAAC_DECLARE_DOT(max)
|
|
|
|
ISAAC_DECLARE_DOT(min)
|
|
|
|
ISAAC_DECLARE_DOT(argmin)
|
2015-01-12 13:20:53 -05:00
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
array_expression eye(std::size_t, std::size_t, isaac::numeric_type, driver::Context context = driver::queues.default_context());
|
|
|
|
array_expression zeros(std::size_t M, std::size_t N, numeric_type dtype, driver::Context context = driver::queues.default_context());
|
|
|
|
array_expression reshape(array const &, int_t, int_t);
|
2015-01-21 20:08:52 -05:00
|
|
|
|
2015-01-12 13:20:53 -05:00
|
|
|
//
|
|
|
|
std::ostream& operator<<(std::ostream &, array const &);
|
2015-01-19 21:29:47 -05:00
|
|
|
std::ostream& operator<<(std::ostream & os, scalar const & s);
|
2015-01-12 13:20:53 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|