Skip to content

Commit

Permalink
LAPACK-style vector_*_copyDataTo
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Feb 10, 2023
1 parent 65ef114 commit 6760d6c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
11 changes: 3 additions & 8 deletions genpp.pl
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,9 @@ sub topdl2 {
my ($self, $compmode) = @_;
die "Called topdl2 on OtherPar" if $self->{is_other};
my ($name, $type, $pcount) = @$self{qw(name type pcount)};
return <<EOF if $self->{is_vector};
CW_err = cw_${type}_get@{[$self->{fixeddims} ? 'Data' : 'Ptr']}(&vptmp, @{[$self->c_input($compmode)]});
$IF_ERROR_RETURN;
memmove(\$P($name), vptmp, \$PDL($name)->nbytes);
@{[$self->{fixeddims} ? 'free(vptmp);' : '']}
EOF
return <<EOF if !$self->{fixeddims};
return <<EOF if $self->{is_vector} or !$self->{fixeddims};
CW_err = cw_${type}_copyDataTo(@{[$self->c_input($compmode)]}, \$P($name), \$PDL($name)->nbytes);
$IF_ERROR_RETURN;
EOF
qq{CW_err = cw_${type}_getVals(}.$self->c_input($compmode).qq{,@{[join ',', map "&\$$name(n${type}$pcount=>$_)", 0..@{$DIMTYPES{$type}}-1]}); $IF_ERROR_RETURN;\n};
}
Expand Down Expand Up @@ -246,7 +241,7 @@ sub genpp {
@{[!@outputs ? '' : "!wantarray ? \$$outputs[-1]{name} : (@{[join ',', map qq{\$$_->{name}}, @outputs]})"]}
}
EOF
Code => "void *vptmp;\ncw_error CW_err;\n",
Code => "cw_error CW_err;\n",
);
$doxy->{brief}[0] .= " NO BROADCASTING." if $compmode;
$doxy->{brief}[0] .= make_example($func, $ismethod, \@inputs, \@outputs);
Expand Down
13 changes: 8 additions & 5 deletions genwrap.pl
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ sub gen_wrapper {
$hstr .= <<EOF;
cw_error cw_$vector_str${class}_newWithVals($wrapper **cw_retval, @{[!@fields ? $class : $fields[0][0]]} *data, ptrdiff_t count);
cw_error cw_$vector_str${class}_size(ptrdiff_t *count, $wrapper *self);
cw_error cw_$vector_str${class}_get@{[@fields ? 'Data' : 'Ptr']}(void **data, $wrapper *self);
cw_error cw_$vector_str${class}_copyDataTo($wrapper *self, void *data, ptrdiff_t bytes);
EOF
my $field_count = 0;
$cstr .= <<EOF;
Expand All @@ -259,13 +259,16 @@ sub gen_wrapper {
} $CATCH
return CW_err;
}
cw_error cw_$vector_str${class}_get@{[@fields ? 'Data' : 'Ptr']}(void **data, $wrapper *self) {
cw_error cw_$vector_str${class}_copyDataTo($wrapper *self, void *data, ptrdiff_t bytes) {
cw_error CW_err = {CW_ENONE, NULL, 0};
ptrdiff_t i = 0, stride = @{[(0+@fields) || 1]}, count = self->held.size();
ptrdiff_t shouldbe = sizeof(@{[@fields ? $fields[0][0] : $class]}) * stride * count;
$SHOULDBE_CHECK
try {
@{[do {$field_count = 0; @fields ? "$fields[0][0] *ptmp;" : ""}]}
*data = @{[!@fields ? 'self->held.data();' :
@{[!@fields ? 'memmove(data, self->held.data(), bytes);' :
join "\n ",
"ptmp = ($fields[0][0] *)malloc(sizeof($fields[0][0]) * @{[0+@fields]} * self->held.size());",
do {$field_count = 0; ()},
"$fields[0][0] *ptmp = ($fields[0][0] *)data;",
"ptrdiff_t i = 0, stride = @{[0+@fields]}, count = self->held.size();",
"for (i = 0; i < count; i++) {",
(map " ptmp[i*stride + ".$field_count++."] = self->held[i].@{[$_->[2]||$_->[1]]};", @fields),
Expand Down

0 comments on commit 6760d6c

Please sign in to comment.