Пример #1
0
    void forward( ccube_p<real> const & f ) override
    {
        if ( !enabled_ ) return;

        last_input = exp(*f);
        layer_data->add_to_the_sum(get_copy(*last_input));
    }
Пример #2
0
int					get_next_line(int const fd, char **line)
{
	static t_list	*list;
	static int		pos;
	static int		start;
	char			*str;
	static int		ilk;

	if (start == -2)
	{
		*line = ft_strnew(0);
		return (0);
	}
	if (fd < 0)
		return (-1);
	ilk = 0;
	pos = get_buf(&list, start, fd, &ilk);
	str = get_copy(&list, pos, &start);
	*line = str;
	if (ilk == -1)
	{
		start = -2;
		ft_putstr(*line);
		return (0);
	}
	return (1);
}
Пример #3
0
int
main ()
{
  if (copy == get_copy () && &copy == get_copy_p ())
    printf ("PASS\n");

  return 0;
}
Пример #4
0
j_value Lambda_Expression::derived_get_value(const Arguments& /*i_args*/)const {

	Arguments args;
	args.push_back(get_copy());
	return j_value(Aggregate_Value_Symbol(args), J_Unit());


}
Пример #5
0
inline void convolve_flipped( cube<T> const & a,
                              cube<T> const & b,
                              cube<T> const & r ) noexcept
{
    ZI_ASSERT(size(r)==(vec3i::one+size(a)-size(b)));

    auto tmp = get_copy(a);
    flip(*tmp);
    return convolve(*tmp,b,r);
}
Пример #6
0
 void forward( ccube_p<real> const & f ) override
 {
     ZI_ASSERT(size(*f)==insize);
     auto r = pooling_filter(get_copy(*f),
                             [](real a, real b){ return a>b; },
                             filter_size,
                             filter_stride);
     indices = r.second;
     out_nodes->forward(out_num,std::move(r.first));
 }
Пример #7
0
static void push_copied_stacks(int init)
{
  /* This is called after everything else is marked.
     Mark from those stacks that are still reachable. If
     we mark from a stack, we need to go back though the list
     all over to check the previously unmarked stacks. */
  CopiedStack *cs;
  int pushed_one;

  if (init) {
    for (cs = *first_copied_stack; cs; cs = *cs->next) {
      if (get_copy(cs))
	cs->pushed = 0;
      else
	cs->pushed = 1;
    }
  }

  GC_flush_mark_stack();

  do {
    pushed_one = 0;
    for (cs = *first_copied_stack; cs; cs = *cs->next) {
      if (!cs->pushed && GC_is_marked(get_copy(cs))) {
	pushed_one = 1;
	cs->pushed = 1;
	GC_push_all_stack(get_copy(cs), (char *)get_copy(cs) + cs->size);
	if (GC_did_mark_stack_overflow()) {
	  /* printf("mark stack overflow\n"); */
	  return;
	} else {
	  GC_flush_mark_stack();
	  if (GC_did_mark_stack_overflow()) {
	    /* printf("mark stack overflow (late)\n"); */
	    return;
	  }
	}
      }
    }
  } while (pushed_one);
}
Пример #8
0
    void forward( ccube_p<real> const & f ) override
    {
        ZI_ASSERT(size(*f)==insize);
        auto r = pooling_filter(get_copy(*f),
                                [](real a, real b){ return a>b; },
                                filter_size,
                                vec3i::one);

        indices = sparse_implode_slow(*r.second,filter_size,outsize);
        out_nodes->forward(out_num,
                           sparse_implode_slow(*r.first,filter_size,outsize));
    }
Пример #9
0
    void forward( ccube_p<real> const & f ) override
    {
        ZI_ASSERT(size(*f)==insize);

        auto fmap = get_copy(*f);
        if ( phase_ == phase::TRAIN )
        {
            dropout_forward(*fmap);
        }

        out_nodes->forward(out_num, std::move(fmap));
    }
inline cube_p<T> convolve_sparse_inverse( cube<T> const & a,
                                          cube<T> const & borig,
                                          vec3i const & s )
{
    if ( s == vec3i::one )
    {
        return convolve_inverse(a,borig);
    }

    auto bp = get_copy(borig);
    cube<T>& b = *bp;
    flip(b);

    vec3i as = size(a);
    vec3i bs = size(b);
    vec3i rs = size(a) + (size(b) - vec3i::one) * s;

    cube_p<T> r = get_cube<T>(rs);

    int a_strides[3]  = { s[2], as[2]*s[1], as[2]*as[1]*s[0] };
    int r_strides[3]  = { s[2], rs[2]*s[1], rs[2]*rs[1]*s[0] };

    for (int xs=0; xs<s[0]; xs++)
        for (int ys=0; ys<s[1]; ys++)
            for (int zs=0; zs<s[2]; zs++)
            {
                vec3i in_size( (as[0]-1)/s[0] + (xs == 0),
                               (as[1]-1)/s[1] + (ys == 0),
                               (as[2]-1)/s[2] + (zs == 0) );

                const T* in_ptr  = &(a[xs][ys][zs]);
                T* out_ptr = &((*r)[xs][ys][zs]);

#ifdef ZNN_USE_FLOATS
                int status = vslsConvExec( conv_plans.get_inv(in_size, bs),
                                           in_ptr, a_strides,
                                           b.data(), NULL,
                                           out_ptr, r_strides );
#else
                int status = vsldConvExec( conv_plans.get_inv(in_size, bs),
                                           in_ptr, a_strides,
                                           b.data(), NULL,
                                           out_ptr, r_strides );
#endif

            }
    return r;
}
Пример #11
0
    void backward( ccube_p<real> const & g )
    {
        ZI_ASSERT(insize==size(*g));

        auto gmap = get_copy(*g);
        if ( phase_ == phase::TRAIN )
        {
            dropout_backward(*gmap);
        }

        if ( in_nodes->is_input() )
        {
            in_nodes->backward(in_num, cube_p<real>());
        }
        else
        {
            in_nodes->backward(in_num, std::move(gmap));
        }
    }
Пример #12
0
inline void convolve_inverse( cube<T> const & a,
                              cube<T> const & b,
                              cube<T> const & r) noexcept
{
    ZI_ASSERT(size(r)==(size(a)+size(b)-vec3i::one));

    auto tmp = get_copy(b);
    flip(*tmp);

#ifdef ZNN_USE_FLOATS
    int status = vslsConvExec(conv_plans.get_inv(size(a),size(b)),
                              a.data(), NULL,
                              tmp->data(), NULL,
                              r.data(), NULL);
#else
    int status = vsldConvExec(conv_plans.get_inv(size(a),size(b)),
                              a.data(), NULL,
                              tmp->data(), NULL,
                              r.data(), NULL);
}
Пример #13
0
  std::tuple<real,real,cube_p<real>> square_loss( cube<real> const & cprop,
                                                  cube<real> const & clab )
    {
        std::tuple<real,real,cube_p<real>> ret;
        std::get<0>(ret) = 0;
        std::get<1>(ret) = 0;
        std::get<2>(ret) = get_copy(cprop);

        real* grad = std::get<2>(ret)->data();
        const real* lab  = clab.data();

        long_t n = clab.num_elements();

        for ( long_t i = 0; i < n; ++i )
        {
            std::get<1>(ret) += ( grad[i] > 0.5 ? ( lab[i] > 0.5 ? 0 : 1 ) : ( lab[i] > 0.5 ? 1 : 0 ) );
            grad[i] -= lab[i];
            std::get<0>(ret) += grad[i]*grad[i];
            grad[i] *= 2;
        }

        return ret;
    }
Пример #14
0
 void shoot( ccube_p<real> const & sum )
 {
     *last_input /= *sum;
     out_nodes->forward(out_num,get_copy(*last_input));
 }
Пример #15
0
 void backward( ccube_p<real> const & g )
 {
     in_nodes->backward(in_num,get_copy(*g));
 }
Пример #16
0
 void forward( ccube_p<real> const & f ) override
 {
     out_nodes->forward(out_num,get_copy(*f));
 }
Пример #17
0
    void backward( ccube_p<real> const & g ) override
    {
        if ( !enabled_ ) return;

        in_nodes->backward(in_num,get_copy(*g));
    }
Пример #18
0
    void forward( ccube_p<real> const & f ) override
    {
        if ( !enabled_ ) return;

        out_nodes->forward(out_num,get_copy(*f));
    }
Пример #19
0
 void shoot( ccube_p<real> const & sum )
 {
     ZI_ASSERT(enabled_);
     *last_input /= *sum;
     out_nodes->forward(out_num,get_copy(*last_input));
 }