Exemple #1
0
    array::array_proxy::operator array()
    {
        af_array tmp = 0;
        af_array arr = 0;

        if(impl->is_linear_)  {
            AF_THROW(af_flat(&arr, impl->parent_->get()));
        } else {
            arr = impl->parent_->get();
        }

        AF_THROW(af_index_gen(&tmp, arr, AF_MAX_DIMS, impl->indices_));
        if(impl->is_linear_)  {
            AF_THROW(af_release_array(arr));
        }

        int dim = gforDim(impl->indices_);
        if (tmp && dim >= 0) {
            arr = gforReorder(tmp, dim);
            if (tmp) AF_THROW(af_release_array(tmp));
        } else {
            arr = tmp;
        }

        return array(arr);
    }
Exemple #2
0
    array::array_proxy::operator array() const
    {
        af_array tmp = 0;
        af_array arr = 0;

        if(impl->is_linear_)  {
            AF_THROW(af_flat(&arr, impl->parent_->get()));
        } else {
            arr = impl->parent_->get();
        }

        AF_THROW(af_index_gen(&tmp, arr, AF_MAX_DIMS, impl->indices_));
        if (impl->is_linear_)  {
            AF_THROW(af_release_array(arr));
        }

        return array(tmp);
    }
Exemple #3
0
    // Assign values to an array
    array::array_proxy&
    af::array::array_proxy::operator=(const array &other)
    {
        unsigned nd = numDims(impl->parent_->get());
        const dim4 this_dims = getDims(impl->parent_->get());
        const dim4 other_dims = other.dims();
        int dim = gforDim(impl->indices_);
        af_array other_arr = other.get();

        bool batch_assign = false;
        bool is_reordered = false;
        if (dim >= 0) {
            //FIXME: Figure out a faster, cleaner way to do this
            dim4 out_dims = seqToDims(impl->indices_, this_dims, false);

            batch_assign = true;
            for (int i = 0; i < AF_MAX_DIMS; i++) {
                if (this->impl->indices_[i].isBatch) batch_assign &= (other_dims[i] == 1);
                else                          batch_assign &= (other_dims[i] == out_dims[i]);
            }

            if (batch_assign) {
                af_array out;
                AF_THROW(af_tile(&out, other_arr,
                                 out_dims[0] / other_dims[0],
                                 out_dims[1] / other_dims[1],
                                 out_dims[2] / other_dims[2],
                                 out_dims[3] / other_dims[3]));
                other_arr = out;

            } else if (out_dims != other_dims) {
                // HACK: This is a quick check to see if other has been reordered inside gfor
                // TODO: Figure out if this breaks and implement a cleaner method
                other_arr = gforReorder(other_arr, dim);
                is_reordered = true;
            }
        }

        af_array par_arr = 0;

        if (impl->is_linear_) {
            AF_THROW(af_flat(&par_arr, impl->parent_->get()));
            nd = 1;
        } else {
            par_arr = impl->parent_->get();
        }

        af_array tmp = 0;
        AF_THROW(af_assign_gen(&tmp, par_arr, nd, impl->indices_, other_arr));

        af_array res = 0;
        if (impl->is_linear_) {
            AF_THROW(af_moddims(&res, tmp, this_dims.ndims(), this_dims.get()));
            AF_THROW(af_release_array(par_arr));
            AF_THROW(af_release_array(tmp));
        } else {
            res = tmp;
        }

        impl->parent_->set(res);

        if (dim >= 0 && (is_reordered || batch_assign)) {
            if (other_arr) AF_THROW(af_release_array(other_arr));
        }
        return *this;
    }
Exemple #4
0
 array flat(const array& in)
 {
     af_array out = 0;
     AF_THROW(af_flat(&out, in.get()));
     return array(out);
 }