I am just starting to learn Java J2RE 5.0. I coded the matrix library
below and found that the array accessing is really slow since each
access is checked: http://f1.pg.briefcase.yahoo.com/bc/...va.zip&.src=bc
It appears that with gcj and a -f switch I can turn off the array
bounds checking.
Will a JVM ever be smart enough to know that if the array bound is a
constant variable within a loop, that it can multiply and check the
final array index is within bounds before doing the loop, and then only
have to check once? It seems stupid to me that a general Matrix isn't
included in the Java class libraries. Anybody have a better general
Matrix library in Java?
Also, a newbie observation, that Double (capital D) didn't get passed
as a reference. Why not? This seems dumb to me, as all other objects
seem to get passed by reference. 1 4183 ag******@yahoo. com wrote: Also, a newbie observation, that Double (capital D) didn't get passed as a reference. Why not? This seems dumb to me, as all other objects seem to get passed by reference.
To be pedantic, a reference to the object instance is passed by value.
So that means you can invoke methods that change the object instance and
the object instance is changed for the caller as well.
But you cannot change the reference to point to a difference reference
and expect that to register with the caller.
For example (not compiled),
public class Example
{
public static final String NL =
System.getPrope rty("line.separ ator");
public static void example(StringB uffer buf, Double d)
{
buf.append("d = ").append(d).ap pend(NL);
d = new Double(2.78);
buf.append("d = ").append(d).ap pend(NL);
}
public static void main(String args[])
{
StringBuffer buf = new StringBuffer();
Double d = new Double(3.14);
example(buf, d);
buf.append("d = ").append(d).ap pend(NL);
System.out.prin tln(buf.toStrin g());
}
}
The output should be:
d = 3.14
d = 2.78
d = 3.14
HTH,
Ray
--
XML is the programmer's duct tape. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Michael Bader |
last post by:
Hi,
I'm currently working on a matrix multiplication code (matrix times
matrix), and have come along some interesting/confusing results
concerning the running time of the (apparently) same algorithm,
when implemented in C or C++. I noticed that the implementation
in C is faster by a factor of 2.5 compared to a identical(?)
C++-implementation.
The basic algorithm in C is:
|
by: Flip |
last post by:
I'm reading the O'Reilly's Progamming C# book and I have a question about
array bounds checking. On page 174, near the top, they show an example
where c# does indeed to array bounds checking cause the example shows a
System.IndexOutOfRangeException being thrown. However, in the very next
section (Jagged arrays) they have warning section that says "Java
programmers take note: While Java does bounds checking on array use, C# does
not." ...
|
by: noleander |
last post by:
Hey. I'm new to Visual C++. I've got a large application, and I need to
make sure all array accesses are within bounds. Back on Unix we had a tool
called Purify that detected array-out-of-bounds references at run-time. My
application is not "managed".
Question: Does Visual C++ 2003 (std edition) have a built-in array-bounds
checking ability? If not, what tools do Vis C++ developers usually use to
handle this.
|
by: VijaKhara |
last post by:
Hi all,
Is there any method which can implememt the matrix multiplication
faster than using the formula as we often do by hand?
I am writing the following code and my matrice: one is 3x40000 and the
other one 40000x3.
the program runs too slow:
/*multiply two matrice: xyz_trans * xyz , the output is w 3x3*/
|
by: amitsoni.1984 |
last post by:
Hi,
Is there any direct function for matrix multiplication in Python or
any of its packages? or do we have to multiply element by element?
Thank you,
Amit
| |
by: jacob navia |
last post by:
We hear very often in this discussion group that
bounds checking, or safety tests are too expensive
to be used in C.
Several researchers of UCSD have published an interesting
paper about this problem.
http://www.jilp.org/vol9/v9paper10.pdf
Specifically, they measured the overhead of a bounds
|
by: polas |
last post by:
Afternoon everyone.
I have a quick question about standard C. Generally speaking, in my
experience, whenever one accesses an array there is never any bounds
checking done (either statically during compilation or dynamically
during runtime.) However, I was wondering if whether there is anything
defined in the standard about this.
The reason for this is I have some code conforming to ANSI C99 and
wish to write to both arrays and a block...
|
by: Sozos |
last post by:
Hi guys. I have a problem with writing the base case for the following matrix multiplication function I have implemented. Please help.
#define index(i,j,power) (((i)<<(power))+(j))
void recMultiply(int i, int j, float a, int k, int l, float b, int x, int y, float c, int s);
int i, j, k, s, matrixsize, blocksize, jj, kk, power, bsize;
float sum, maxr, total=0.0, startmult, finishmult, multtime;
float* A = NULL;
float* B = NULL;
|
by: joegao1 |
last post by:
can some one give me a hint?
I want to program the code for matrix multiplication with as less arithmetical / multiplication operations as possible.
my task is to calculate the matrix multiplication A*B*A' , where
- A' refers to the transpose of matrix A
- matrix B is symmetric matrix.
- (optional) it will be much better if the result of (A*B) or (A*B)' can be stored as temperal matrix, as
this value is required thereafter.
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |