On Wednesday, 15 July 2015 at 11:47:53 UTC, Mike Parker wrote:
On Tuesday, 14 July 2015 at 13:35:40 UTC, Mike Parker wrote:
--
4000 _Dmain
_D4main6selectFZk 40002736471
4000 _D3std6random27__T7uniformVAyaa2_5b29TkTkZ7uniformFNfkkZk
--
On Tuesday, 14 July 2015 at 17:24:41 UTC, anonymous wrote:
This fails with "Error: None of the overloads of 'cos' are
callable using argument types (int[])".
The problem is that template mixins cannot add to existing
overload sets. The spec says: "If the name of a declaration in
a mixin is
On Tuesday, 14 July 2015 at 12:12:41 UTC, anonymous wrote:
Works for me. Please show the complete code and the error
message you get.
Here's what works for me:
Thanks for posting that. I figured out the issue. Before you had
recommended that I use
alias cos = std.math.cos;
I had kept tha
On Monday, 13 July 2015 at 02:52:11 UTC, Laeeth Isharc wrote:
I am venturing in territory still new to me, but I think that
was his point - foreach with tuples looks like it is looping,
but really it is unpacking them statically at compile time.
And similarly with the recursive version. I d
On Sunday, 12 July 2015 at 22:26:44 UTC, anonymous wrote:
You don't need the lambda, do you? -> return x.map!fun.array;
You're right.
I don't know what exactly you're after, but you can use foreach
on a whatever-they're-called-now tuple (there's been a
discussion about the name which I h
On Sunday, 12 July 2015 at 20:31:20 UTC, jmh530 wrote:
On Sunday, 12 July 2015 at 17:11:04 UTC, anonymous wrote:
And personally, I'd probably just type out `x.map!fun.array`
every time.
[1] http://dlang.org/hijack.html
Thanks for the comments.
After thinking it over, I think you're absol
On Sunday, 12 July 2015 at 17:11:04 UTC, anonymous wrote:
And personally, I'd probably just type out `x.map!fun.array`
every time.
[1] http://dlang.org/hijack.html
Thanks for the comments.
On Wednesday, 8 July 2015 at 18:31:00 UTC, Steven Schveighoffer
wrote:
You can use a function lambda:
auto fp = (real a) => cos(a);
Note, I had to put (real a) even though I would have expected
"a => cos(a)" to work.
-Steve
I've been playing around with this a little more. I wrote this
f
On Wednesday, 8 July 2015 at 18:31:00 UTC, Steven Schveighoffer
wrote:
You can use a function lambda:
auto fp = (real a) => cos(a);
Note, I had to put (real a) even though I would have expected
"a => cos(a)" to work.
-Steve
Interesting. You have to put real because there is also a float
a
On Wednesday, 8 July 2015 at 14:37:23 UTC, jmh530 wrote:
Thanks. I was worried I was doing something wrong.
It seems like if you wrap the intrinsic function in another
function than it works fine (below). Easy enough work-around, I
suppose.
If there is no intention to fix the pointer to ass
On Wednesday, 8 July 2015 at 11:15:12 UTC, Marc Schütz wrote:
It seems std.math.cos is an intrinsic function (i.e. one that
the compiler implements when needed, or generates the
appropriate asm for):
https://github.com/D-Programming-Language/phobos/blob/master/std/math.d#L630
The compiler sh
I'm still not sure why I'm getting the error I mention in the
original post. For instance, the code below is giving that Error
42 Symbol Undefined error. Seems very mystifying...
import std.math : cos;
real foo(T)(T fp, real x)
{
return fp(x);
}
void main()
{
real x = 0;
On Tuesday, 7 July 2015 at 20:23:08 UTC, H. S. Teoh wrote:
The reason for this is that function pointers have attributes
associated with them, as part of the type system. The address
of a @safe function is a @safe function pointer, meaning that
it's legal to call the function through this poi
On Tuesday, 7 July 2015 at 20:13:08 UTC, anonymous wrote:
So long as you exclamation mark? Huh?
Thanks for the detailed answer. All I meant here is that if I
have some
T foo(T)(T x), then to take the address, sometimes I've needed to
&foo!int or &foo!real, etc.
I'm not sure I understand the safety of function pointers vs. the
addresses of functions. The code below illustrates the issue.
I was under the impression that pointers are not allowed in safe
code. Naturally, I took that to also mean that function pointers
are not allowed in safe code. Indeed
On Tuesday, 7 July 2015 at 17:05:21 UTC, Steven Schveighoffer
wrote:
Sure, file as an enhancement.
-Steve
https://issues.dlang.org/show_bug.cgi?id=14783
On Tuesday, 7 July 2015 at 13:58:17 UTC, Steven Schveighoffer
wrote:
Yeah, this seems like an unnecessary limitation for exact
matching. In other words, if your destination array exactly
matches one or more of the arguments, it should be fine. Where
the overlapping starts causing problems is so
On Tuesday, 7 July 2015 at 08:06:50 UTC, tcak wrote:
I have never used arrays in that way before, though I don't get
why you are writing return line in that way. Shouldn't it be
like `return (x[] * x[]);` ?
There's nothing fundamentally wrong with doing that in the return
line. For instanc
If I call a function like
int[] square_array(int[] x)
{
return x[] *= x[];
}
I get an error that there is an overlapping array in a vector
operation. I guess this makes sense as the lhs and rhs are
occupying the same memory. Nevertheless, I find it a little
frustrating.
I tried two
On Thursday, 2 July 2015 at 19:27:57 UTC, J Miller wrote:
I knew that automatic allocation doesn't happen, but I'm
confused by the fact if you explicitly declare "c" with "int[]
c;" and then assign "c[] = a[] * b[]", versus using "auto c =
a[] * b[]", you get two different errors (array length
On Tuesday, 30 June 2015 at 21:02:39 UTC, DLearner wrote:
On Tuesday, 30 June 2015 at 20:33:31 UTC, jmh530 wrote:
On Tuesday, 30 June 2015 at 20:17:12 UTC, Justin Whear wrote:
[...]
I think this is a good explanation.
Looking through
http://dlang.org/arrays.html
I see that the multidimension
On Tuesday, 30 June 2015 at 20:17:12 UTC, Justin Whear wrote:
No. The order of braces when indexing is the opposite of the
order when
declaring.
The declaration
int [1][2] foo;
reads innermost to outermost, "((int [1] ) [2])"
When indexing foo, you index from outermost to innermost, so
foo[
My understanding of pure is that a function labeled pure can only
include pure functions. I've been confused by the fact that a
function calling map (like below) can be labeled pure without any
problems. The only way I can rationalize it is that map really
isn't a function, it's (if I'm underst
On Sunday, 28 June 2015 at 16:15:31 UTC, Marc Schütz wrote:
Secondly, `map` is indeed a template function, as you write.
For templates functions, the compiler infers many properties,
including purity.
Thanks for the reply. Two follow ups: 1) Does labeling a template
as pure matter if the co
On Saturday, 27 June 2015 at 18:32:10 UTC, Ali Çehreli wrote:
Luckily, it is very easy to achieve it with std.range.enumerate:
FTFY
On Thursday, 25 June 2015 at 17:20:46 UTC, jmh530 wrote:
On Thursday, 25 June 2015 at 14:37:28 UTC, Binarydepth wrote:
I organize some exercises in some source files, it's more how
I like to work with C. I'm used to organize source files this
way and I was wondering if this was possible with
On Thursday, 25 June 2015 at 14:37:28 UTC, Binarydepth wrote:
I organize some exercises in some source files, it's more how I
like to work with C. I'm used to organize source files this way
and I was wondering if this was possible with D.
If the files are in the same folder, just import lo
On Tuesday, 23 June 2015 at 10:50:51 UTC, John Colvin wrote:
If I remember correctly, core.simd should work with every
compiler on every supported OS. What did you try that didn't
work?
I figured out the issue! You have to compile using the -m64 flag
to get it to work on Windows (this works
On Tuesday, 16 June 2015 at 16:37:35 UTC, John Colvin wrote:
If you want really fast exponentiation of an array though, you
want to use SIMD. Something like http://www.yeppp.info would be
easy to use from D.
I've been looking into SIMD a little. It turns out that core.simd
only works for DMD
On Wednesday, 17 June 2015 at 20:33:11 UTC, Namespace wrote:
import std.stdio;
template BaseTypeOf(T) {
static if (is(T : U[], U))
alias BaseTypeOf = BaseTypeOf!(U);
else
alias BaseTypeOf = T;
}
void foo(T : U[], U)(T arr) if (is(BaseTypeOf!(U) == real)) {
On Wednesday, 17 June 2015 at 20:06:54 UTC, Alex Parrill wrote:
Try:
void foo(T)(T[] arg) {
// In here, T should be the element type, and T[] the array
type.
}
Not a general solution, but you mentioned that you wanted this
for a function parameter.
I don't think this works for multi-
I want to write a function template that works for any array of a
particular type, but not the base type, so real[], real[][], etc,
but not real. I was using ForeachType to do some testing, but it
doesn't really get the base type. It just takes one of the [] off
and returns the remaining type (
Err...vectors not matrices.
On Tuesday, 16 June 2015 at 16:38:55 UTC, John Colvin wrote:
What OS are you on? See http://wiki.dlang.org/Compilers
I'm on Windows 7 at work, and I have both Win7 and linux at home.
I figure I can try it on linux at home. Sometimes the work
computer is a bit funky with installing things, so
On Tuesday, 16 June 2015 at 13:15:05 UTC, John Colvin wrote:
*consistent as in different implementations performing very
similarly instead of seeing big differences like you have here.
That's a good point. I tried numpy's exp (which uses C at a low
level, I think) and found it takes about a
On Monday, 15 June 2015 at 22:40:31 UTC, Baz wrote:
Right, my bad. This one whould work:
---
float[] test(float[] x) {
auto result = x.dup;
result.each!((ref a) => (a = exp(a)));
return result;
}
---
That works. Thanks.
I did some benchmarking and found that map tended to be fast
I suppose I would want whichever has the best performance.
Without testing, I'm not sure which one would be better.
Thoughts?
I had been fighting with the map results because I didn't
realize there was an easy way to get just the array.
I'm actually not having much luck with your original fu
On Monday, 15 June 2015 at 19:32:12 UTC, Baz wrote:
On Monday, 15 June 2015 at 19:30:08 UTC, Baz wrote:
On Monday, 15 June 2015 at 19:22:31 UTC, jmh530 wrote:
On Monday, 15 June 2015 at 19:04:32 UTC, Baz wrote:
In addition to the other answers you can use
std.algorithm.iteration.each():
---
On Monday, 15 June 2015 at 19:04:32 UTC, Baz wrote:
In addition to the other answers you can use
std.algorithm.iteration.each():
---
float[] _exp(float[] x) {
auto result = x.dup;
result.each!(a => exp(a));
return result;
}
---
Am I right that the difference is that map is lazy an
I have a little bit of a follow up.
After making the recommended changes, the function seems to work
with both static and dynamic arrays. I then noticed that all of
the examples for functions that pass arrays in
http://dlang.org/function.html use the dynamic array notation
like my function ab
Thank you all for the very fast answers. It looks like that works.
I wrote a simple function to apply map to a float dynamic array
auto exp(float[] x) {
auto y = x.map!(a => exp(a));
return y;
}
However, the type of the result is MapResult!(__lambda2,
float[]). It seems like some of the things that I might do to a
float[], I can't do to this t
On Thursday, 4 June 2015 at 17:25:52 UTC, Alex Parrill wrote:
On Thursday, 4 June 2015 at 17:04:06 UTC, jmh530 wrote:
float output[len];
This creates a fixed-sized array of length `len` (using the
deprecated syntax). Since the length is part of the type, it
needs to be known at compi
I'm trying to run the following code (to create an array of
uniform random variables) on the latest version of rdmd (2.067.1).
import std.random;
auto uniform_array(int len, float a, float b) {
Random gen;
float output[len];
foreach(ref float i; output)
{
On Thursday, 26 February 2015 at 20:23:10 UTC, Rinzler wrote:
Hello,
This question might have already been asked, but maybe new
answers come up, with new updates.
I a beginner with D, actually I have almost done nothing. I am
using a Mac, and Xamarin Studio seem to be the best choice, but
I
I had seen some stuff on alias thing, but I hadn't bothered to
try to understand it until now. If I'm understanding the first
example http://dlang.org/class.html#AliasThis";>here,
alias this let's you refer to x in s by writing either s.x (as
normally) or just s. That didn't seem that interesting,
ink what I was trying to do
is more like make_unique than unique_ptr.
On Monday, 12 January 2015 at 19:42:14 UTC, ketmar via
Digitalmars-d-learn wrote:
On Mon, 12 Jan 2015 19:29:53 +0000
jmh530 via Digitalmars-d-learn
wrote:
the proper answer is too long to write (it will be more an
artic
I'm new to D. I have some modest knowledge of C++, but am more
familiar with scripting languages (Matlab, Python, R). D seems so
much easier than C++ in a lot of ways (and I just learned about
rdmd today, which is pretty cool). I am concerned about
performance of D vs. C++, so I wanted to learn
401 - 448 of 448 matches
Mail list logo