Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Wynn
purr-data
Commits
9a2fdfc7
Commit
9a2fdfc7
authored
Jul 05, 2018
by
Pranay Gupta
Browse files
double precision patches for choice_class
parent
9eb33fae
Changes
1
Show whitespace changes
Inline
Side-by-side
pd/extra/choice/choice.c
View file @
9a2fdfc7
...
...
@@ -17,7 +17,7 @@ static t_class *choice_class;
typedef
struct
_elem
{
float
e_age
;
t_
float
e_age
;
t_float
e_weight
[
DIMENSION
];
}
t_elem
;
...
...
@@ -63,7 +63,7 @@ static void choice_add(t_choice *x, t_symbol *s, int argc, t_atom *argv)
{
int
oldn
=
x
->
x_n
,
newn
=
oldn
+
1
,
i
;
t_elem
*
e
;
float
sum
,
normal
;
t_
float
sum
,
normal
;
x
->
x_vec
=
(
t_elem
*
)
resizebytes
(
x
->
x_vec
,
oldn
*
sizeof
(
t_elem
),
newn
*
sizeof
(
t_elem
));
x
->
x_n
=
newn
;
...
...
@@ -72,11 +72,11 @@ static void choice_add(t_choice *x, t_symbol *s, int argc, t_atom *argv)
for
(
i
=
0
,
sum
=
0
;
i
<
DIMENSION
;
i
++
)
{
float
f
=
atom_getfloatarg
(
i
,
argc
,
argv
);
t_
float
f
=
atom_getfloatarg
(
i
,
argc
,
argv
);
e
->
e_weight
[
i
]
=
f
;
sum
+=
f
*
f
;
}
normal
=
(
float
)(
sum
>
0
?
1
.
/
sqrt
(
sum
)
:
1
);
normal
=
(
t_
float
)(
sum
>
0
?
1
.
/
sqrt
(
sum
)
:
1
);
for
(
i
=
0
;
i
<
DIMENSION
;
i
++
)
e
->
e_weight
[
i
]
*=
normal
;
}
...
...
@@ -84,7 +84,7 @@ static void choice_add(t_choice *x, t_symbol *s, int argc, t_atom *argv)
static
void
choice_list
(
t_choice
*
x
,
t_symbol
*
s
,
int
argc
,
t_atom
*
argv
)
{
int
i
,
j
;
float
bestsum
=
0
;
t_
float
bestsum
=
0
;
int
bestindex
=
-
1
;
t_float
invec
[
DIMENSION
];
for
(
i
=
0
;
i
<
DIMENSION
;
i
++
)
...
...
@@ -92,10 +92,10 @@ static void choice_list(t_choice *x, t_symbol *s, int argc, t_atom *argv)
for
(
j
=
0
;
j
<
x
->
x_n
;
j
++
)
{
t_elem
*
e
=
x
->
x_vec
+
j
;
float
sum
;
t_
float
sum
;
for
(
i
=
0
,
sum
=
0
;
i
<
DIMENSION
;
i
++
)
sum
+=
e
->
e_weight
[
i
]
*
invec
[
i
];
if
(
x
->
x_nonrepeat
)
sum
*=
(
float
)(
log
(
e
->
e_age
));
if
(
x
->
x_nonrepeat
)
sum
*=
(
t_
float
)(
log
(
e
->
e_age
));
if
(
sum
>
bestsum
)
{
bestsum
=
sum
;
...
...
@@ -109,7 +109,7 @@ static void choice_list(t_choice *x, t_symbol *s, int argc, t_atom *argv)
x
->
x_vec
[
j
].
e_age
+=
1
.;
x
->
x_vec
[
bestindex
].
e_age
=
1
;
}
outlet_float
(
x
->
x_obj
.
ob_outlet
,
(
float
)
bestindex
);
outlet_float
(
x
->
x_obj
.
ob_outlet
,
(
t_
float
)
bestindex
);
}
static
void
choice_free
(
t_choice
*
x
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment